Skip to content

Commit

Permalink
8292443: Weak CAS VarHandle/Unsafe tests should test always-failing c…
Browse files Browse the repository at this point in the history
…ases

Reviewed-by: phh
Backport-of: e8bc87956abc92851de8694c56a78f6ecc546cbd
  • Loading branch information
zhengxiaolinX authored and Paul Hohensee committed Jun 27, 2023
1 parent 480b23d commit 398f413
Show file tree
Hide file tree
Showing 46 changed files with 2,926 additions and 686 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -212,39 +212,67 @@ static void testAccess(Object base, long offset) {
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSetBooleanPlain(base, offset, true, false);
}
assertEquals(success, true, "weakCompareAndSetPlain boolean");
assertEquals(success, true, "success weakCompareAndSetPlain boolean");
boolean x = UNSAFE.getBoolean(base, offset);
assertEquals(x, false, "weakCompareAndSetPlain boolean value");
assertEquals(x, false, "success weakCompareAndSetPlain boolean value");
}

{
boolean success = UNSAFE.weakCompareAndSetBooleanPlain(base, offset, true, false);
assertEquals(success, false, "failing weakCompareAndSetPlain boolean");
boolean x = UNSAFE.getBoolean(base, offset);
assertEquals(x, false, "failing weakCompareAndSetPlain boolean value");
}

{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSetBooleanAcquire(base, offset, false, true);
}
assertEquals(success, true, "weakCompareAndSetAcquire boolean");
assertEquals(success, true, "success weakCompareAndSetAcquire boolean");
boolean x = UNSAFE.getBoolean(base, offset);
assertEquals(x, true, "success weakCompareAndSetAcquire boolean");
}

{
boolean success = UNSAFE.weakCompareAndSetBooleanAcquire(base, offset, false, false);
assertEquals(success, false, "failing weakCompareAndSetAcquire boolean");
boolean x = UNSAFE.getBoolean(base, offset);
assertEquals(x, true, "weakCompareAndSetAcquire boolean");
assertEquals(x, true, "failing weakCompareAndSetAcquire boolean value");
}

{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSetBooleanRelease(base, offset, true, false);
}
assertEquals(success, true, "weakCompareAndSetRelease boolean");
assertEquals(success, true, "success weakCompareAndSetRelease boolean");
boolean x = UNSAFE.getBoolean(base, offset);
assertEquals(x, false, "weakCompareAndSetRelease boolean");
assertEquals(x, false, "success weakCompareAndSetRelease boolean");
}

{
boolean success = UNSAFE.weakCompareAndSetBooleanRelease(base, offset, true, false);
assertEquals(success, false, "failing weakCompareAndSetRelease boolean");
boolean x = UNSAFE.getBoolean(base, offset);
assertEquals(x, false, "failing weakCompareAndSetRelease boolean value");
}

{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSetBoolean(base, offset, false, true);
}
assertEquals(success, true, "weakCompareAndSet boolean");
assertEquals(success, true, "success weakCompareAndSet boolean");
boolean x = UNSAFE.getBoolean(base, offset);
assertEquals(x, true, "success weakCompareAndSet boolean");
}

{
boolean success = UNSAFE.weakCompareAndSetBoolean(base, offset, false, false);
assertEquals(success, false, "failing weakCompareAndSet boolean");
boolean x = UNSAFE.getBoolean(base, offset);
assertEquals(x, true, "weakCompareAndSet boolean");
assertEquals(x, true, "failing weakCompareAndSet boolean value");
}

UNSAFE.putBoolean(base, offset, false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -241,39 +241,67 @@ static void testAccess(Object base, long offset) {
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSetBytePlain(base, offset, (byte)0x01, (byte)0x23);
}
assertEquals(success, true, "weakCompareAndSetPlain byte");
assertEquals(success, true, "success weakCompareAndSetPlain byte");
byte x = UNSAFE.getByte(base, offset);
assertEquals(x, (byte)0x23, "weakCompareAndSetPlain byte value");
assertEquals(x, (byte)0x23, "success weakCompareAndSetPlain byte value");
}

{
boolean success = UNSAFE.weakCompareAndSetBytePlain(base, offset, (byte)0x01, (byte)0x45);
assertEquals(success, false, "failing weakCompareAndSetPlain byte");
byte x = UNSAFE.getByte(base, offset);
assertEquals(x, (byte)0x23, "failing weakCompareAndSetPlain byte value");
}

{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSetByteAcquire(base, offset, (byte)0x23, (byte)0x01);
}
assertEquals(success, true, "weakCompareAndSetAcquire byte");
assertEquals(success, true, "success weakCompareAndSetAcquire byte");
byte x = UNSAFE.getByte(base, offset);
assertEquals(x, (byte)0x01, "success weakCompareAndSetAcquire byte");
}

{
boolean success = UNSAFE.weakCompareAndSetByteAcquire(base, offset, (byte)0x23, (byte)0x45);
assertEquals(success, false, "failing weakCompareAndSetAcquire byte");
byte x = UNSAFE.getByte(base, offset);
assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
assertEquals(x, (byte)0x01, "failing weakCompareAndSetAcquire byte value");
}

{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSetByteRelease(base, offset, (byte)0x01, (byte)0x23);
}
assertEquals(success, true, "weakCompareAndSetRelease byte");
assertEquals(success, true, "success weakCompareAndSetRelease byte");
byte x = UNSAFE.getByte(base, offset);
assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
assertEquals(x, (byte)0x23, "success weakCompareAndSetRelease byte");
}

{
boolean success = UNSAFE.weakCompareAndSetByteRelease(base, offset, (byte)0x01, (byte)0x45);
assertEquals(success, false, "failing weakCompareAndSetRelease byte");
byte x = UNSAFE.getByte(base, offset);
assertEquals(x, (byte)0x23, "failing weakCompareAndSetRelease byte value");
}

{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSetByte(base, offset, (byte)0x23, (byte)0x01);
}
assertEquals(success, true, "weakCompareAndSet byte");
assertEquals(success, true, "success weakCompareAndSet byte");
byte x = UNSAFE.getByte(base, offset);
assertEquals(x, (byte)0x01, "success weakCompareAndSet byte");
}

{
boolean success = UNSAFE.weakCompareAndSetByte(base, offset, (byte)0x23, (byte)0x45);
assertEquals(success, false, "failing weakCompareAndSet byte");
byte x = UNSAFE.getByte(base, offset);
assertEquals(x, (byte)0x01, "weakCompareAndSet byte");
assertEquals(x, (byte)0x01, "failing weakCompareAndSet byte value");
}

UNSAFE.putByte(base, offset, (byte)0x23);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -259,39 +259,67 @@ static void testAccess(Object base, long offset) {
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSetCharPlain(base, offset, '\u0123', '\u4567');
}
assertEquals(success, true, "weakCompareAndSetPlain char");
assertEquals(success, true, "success weakCompareAndSetPlain char");
char x = UNSAFE.getChar(base, offset);
assertEquals(x, '\u4567', "weakCompareAndSetPlain char value");
assertEquals(x, '\u4567', "success weakCompareAndSetPlain char value");
}

{
boolean success = UNSAFE.weakCompareAndSetCharPlain(base, offset, '\u0123', '\u89AB');
assertEquals(success, false, "failing weakCompareAndSetPlain char");
char x = UNSAFE.getChar(base, offset);
assertEquals(x, '\u4567', "failing weakCompareAndSetPlain char value");
}

{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSetCharAcquire(base, offset, '\u4567', '\u0123');
}
assertEquals(success, true, "weakCompareAndSetAcquire char");
assertEquals(success, true, "success weakCompareAndSetAcquire char");
char x = UNSAFE.getChar(base, offset);
assertEquals(x, '\u0123', "success weakCompareAndSetAcquire char");
}

{
boolean success = UNSAFE.weakCompareAndSetCharAcquire(base, offset, '\u4567', '\u89AB');
assertEquals(success, false, "failing weakCompareAndSetAcquire char");
char x = UNSAFE.getChar(base, offset);
assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
assertEquals(x, '\u0123', "failing weakCompareAndSetAcquire char value");
}

{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSetCharRelease(base, offset, '\u0123', '\u4567');
}
assertEquals(success, true, "weakCompareAndSetRelease char");
assertEquals(success, true, "success weakCompareAndSetRelease char");
char x = UNSAFE.getChar(base, offset);
assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
assertEquals(x, '\u4567', "success weakCompareAndSetRelease char");
}

{
boolean success = UNSAFE.weakCompareAndSetCharRelease(base, offset, '\u0123', '\u89AB');
assertEquals(success, false, "failing weakCompareAndSetRelease char");
char x = UNSAFE.getChar(base, offset);
assertEquals(x, '\u4567', "failing weakCompareAndSetRelease char value");
}

{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSetChar(base, offset, '\u4567', '\u0123');
}
assertEquals(success, true, "weakCompareAndSet char");
assertEquals(success, true, "success weakCompareAndSet char");
char x = UNSAFE.getChar(base, offset);
assertEquals(x, '\u0123', "success weakCompareAndSet char");
}

{
boolean success = UNSAFE.weakCompareAndSetChar(base, offset, '\u4567', '\u89AB');
assertEquals(success, false, "failing weakCompareAndSet char");
char x = UNSAFE.getChar(base, offset);
assertEquals(x, '\u0123', "weakCompareAndSet char");
assertEquals(x, '\u0123', "failing weakCompareAndSet char value");
}

UNSAFE.putChar(base, offset, '\u4567');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -241,39 +241,67 @@ static void testAccess(Object base, long offset) {
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSetDoublePlain(base, offset, 1.0d, 2.0d);
}
assertEquals(success, true, "weakCompareAndSetPlain double");
assertEquals(success, true, "success weakCompareAndSetPlain double");
double x = UNSAFE.getDouble(base, offset);
assertEquals(x, 2.0d, "weakCompareAndSetPlain double value");
assertEquals(x, 2.0d, "success weakCompareAndSetPlain double value");
}

{
boolean success = UNSAFE.weakCompareAndSetDoublePlain(base, offset, 1.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetPlain double");
double x = UNSAFE.getDouble(base, offset);
assertEquals(x, 2.0d, "failing weakCompareAndSetPlain double value");
}

{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSetDoubleAcquire(base, offset, 2.0d, 1.0d);
}
assertEquals(success, true, "weakCompareAndSetAcquire double");
assertEquals(success, true, "success weakCompareAndSetAcquire double");
double x = UNSAFE.getDouble(base, offset);
assertEquals(x, 1.0d, "success weakCompareAndSetAcquire double");
}

{
boolean success = UNSAFE.weakCompareAndSetDoubleAcquire(base, offset, 2.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetAcquire double");
double x = UNSAFE.getDouble(base, offset);
assertEquals(x, 1.0d, "weakCompareAndSetAcquire double");
assertEquals(x, 1.0d, "failing weakCompareAndSetAcquire double value");
}

{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSetDoubleRelease(base, offset, 1.0d, 2.0d);
}
assertEquals(success, true, "weakCompareAndSetRelease double");
assertEquals(success, true, "success weakCompareAndSetRelease double");
double x = UNSAFE.getDouble(base, offset);
assertEquals(x, 2.0d, "weakCompareAndSetRelease double");
assertEquals(x, 2.0d, "success weakCompareAndSetRelease double");
}

{
boolean success = UNSAFE.weakCompareAndSetDoubleRelease(base, offset, 1.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetRelease double");
double x = UNSAFE.getDouble(base, offset);
assertEquals(x, 2.0d, "failing weakCompareAndSetRelease double value");
}

{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSetDouble(base, offset, 2.0d, 1.0d);
}
assertEquals(success, true, "weakCompareAndSet double");
assertEquals(success, true, "success weakCompareAndSet double");
double x = UNSAFE.getDouble(base, offset);
assertEquals(x, 1.0d, "success weakCompareAndSet double");
}

{
boolean success = UNSAFE.weakCompareAndSetDouble(base, offset, 2.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSet double");
double x = UNSAFE.getDouble(base, offset);
assertEquals(x, 1.0d, "weakCompareAndSet double");
assertEquals(x, 1.0d, "failing weakCompareAndSet double value");
}

UNSAFE.putDouble(base, offset, 2.0d);
Expand Down
Loading

1 comment on commit 398f413

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.