This commit is contained in:
Vladimir Kozlov 2016-06-24 15:06:50 -07:00
commit b7a4c8d92a
45 changed files with 14662 additions and 3719 deletions

View file

@ -38,12 +38,14 @@ define GenerateVarHandle
$1_FILENAME := $(VARHANDLES_GENSRC_DIR)/VarHandle$$($1_Type)s.java $1_FILENAME := $(VARHANDLES_GENSRC_DIR)/VarHandle$$($1_Type)s.java
ifneq ($$(findstring $$($1_Type), Object Int Long), ) $1_ARGS += -KCAS
$1_ARGS += -KCAS
ifneq ($$(findstring $$($1_Type), Byte Short Char Int Long Float Double), )
$1_ARGS += -KAtomicAdd
endif endif
ifneq ($$(findstring $$($1_Type), Int Long), ) ifneq ($$(findstring $$($1_Type), Byte Short Char), )
$1_ARGS += -KAtomicAdd $1_ARGS += -KShorterThanInt
endif endif
$$($1_FILENAME): $(VARHANDLES_SRC_DIR)/X-VarHandle.java.template $(BUILD_TOOLS_JDK) $$($1_FILENAME): $(VARHANDLES_SRC_DIR)/X-VarHandle.java.template $(BUILD_TOOLS_JDK)

View file

@ -1208,22 +1208,43 @@ assertEquals(""+l, (String) MH_this.invokeExact(subl)); // Listie method
* <ul> * <ul>
* <li>if the field is declared {@code final}, then the write, atomic * <li>if the field is declared {@code final}, then the write, atomic
* update, and numeric atomic update access modes are unsupported. * update, and numeric atomic update access modes are unsupported.
* <li>if the field type is anything other than {@code int}, * <li>if the field type is anything other than {@code byte},
* {@code long} or a reference type, then atomic update access modes * {@code short}, {@code char}, {@code int} or {@code long},
* are unsupported. (Future major platform releases of the JDK may * {@code float}, or {@code double} then numeric atomic update
* support additional types for certain currently unsupported access * access modes are unsupported.
* modes.)
* <li>if the field type is anything other than {@code int} or
* {@code long}, then numeric atomic update access modes are
* unsupported. (Future major platform releases of the JDK may
* support additional numeric types for certain currently
* unsupported access modes.)
* </ul> * </ul>
* <p> * <p>
* If the field is declared {@code volatile} then the returned VarHandle * If the field is declared {@code volatile} then the returned VarHandle
* will override access to the field (effectively ignore the * will override access to the field (effectively ignore the
* {@code volatile} declaration) in accordance to it's specified * {@code volatile} declaration) in accordance to it's specified
* access modes. * access modes.
* <p>
* If the field type is {@code float} or {@code double} then numeric
* and atomic update access modes compare values using their bitwise
* representation (see {@link Float#floatToRawIntBits} and
* {@link Double#doubleToRawLongBits}, respectively).
* @apiNote
* Bitwise comparison of {@code float} values or {@code double} values,
* as performed by the numeric and atomic update access modes, differ
* from the primitive {@code ==} operator and the {@link Float#equals}
* and {@link Double#equals} methods, specifically with respect to
* comparing NaN values or comparing {@code -0.0} with {@code +0.0}.
* Care should be taken when performing a compare and set or a compare
* and exchange operation with such values since the operation may
* unexpectedly fail.
* There are many possible NaN values that are considered to be
* {@code NaN} in Java, although no IEEE 754 floating-point operation
* provided by Java can distinguish between them. Operation failure can
* occur if the expected or witness value is a NaN value and it is
* transformed (perhaps in a platform specific manner) into another NaN
* value, and thus has a different bitwise representation (see
* {@link Float#intBitsToFloat} or {@link Double#longBitsToDouble} for more
* details).
* The values {@code -0.0} and {@code +0.0} have different bitwise
* representations but are considered equal when using the primitive
* {@code ==} operator. Operation failure can occur if, for example, a
* numeric algorithm computes an expected value to be say {@code -0.0}
* and previously computed the witness value to be say {@code +0.0}.
* @param recv the receiver class, of type {@code R}, that declares the * @param recv the receiver class, of type {@code R}, that declares the
* non-static field * non-static field
* @param name the field's name * @param name the field's name
@ -1306,22 +1327,43 @@ assertEquals(""+l, (String) MH_this.invokeExact(subl)); // Listie method
* <ul> * <ul>
* <li>if the field is declared {@code final}, then the write, atomic * <li>if the field is declared {@code final}, then the write, atomic
* update, and numeric atomic update access modes are unsupported. * update, and numeric atomic update access modes are unsupported.
* <li>if the field type is anything other than {@code int}, * <li>if the field type is anything other than {@code byte},
* {@code long} or a reference type, then atomic update access modes * {@code short}, {@code char}, {@code int} or {@code long},
* are unsupported. (Future major platform releases of the JDK may * {@code float}, or {@code double}, then numeric atomic update
* support additional types for certain currently unsupported access * access modes are unsupported.
* modes.)
* <li>if the field type is anything other than {@code int} or
* {@code long}, then numeric atomic update access modes are
* unsupported. (Future major platform releases of the JDK may
* support additional numeric types for certain currently
* unsupported access modes.)
* </ul> * </ul>
* <p> * <p>
* If the field is declared {@code volatile} then the returned VarHandle * If the field is declared {@code volatile} then the returned VarHandle
* will override access to the field (effectively ignore the * will override access to the field (effectively ignore the
* {@code volatile} declaration) in accordance to it's specified * {@code volatile} declaration) in accordance to it's specified
* access modes. * access modes.
* <p>
* If the field type is {@code float} or {@code double} then numeric
* and atomic update access modes compare values using their bitwise
* representation (see {@link Float#floatToRawIntBits} and
* {@link Double#doubleToRawLongBits}, respectively).
* @apiNote
* Bitwise comparison of {@code float} values or {@code double} values,
* as performed by the numeric and atomic update access modes, differ
* from the primitive {@code ==} operator and the {@link Float#equals}
* and {@link Double#equals} methods, specifically with respect to
* comparing NaN values or comparing {@code -0.0} with {@code +0.0}.
* Care should be taken when performing a compare and set or a compare
* and exchange operation with such values since the operation may
* unexpectedly fail.
* There are many possible NaN values that are considered to be
* {@code NaN} in Java, although no IEEE 754 floating-point operation
* provided by Java can distinguish between them. Operation failure can
* occur if the expected or witness value is a NaN value and it is
* transformed (perhaps in a platform specific manner) into another NaN
* value, and thus has a different bitwise representation (see
* {@link Float#intBitsToFloat} or {@link Double#longBitsToDouble} for more
* details).
* The values {@code -0.0} and {@code +0.0} have different bitwise
* representations but are considered equal when using the primitive
* {@code ==} operator. Operation failure can occur if, for example, a
* numeric algorithm computes an expected value to be say {@code -0.0}
* and previously computed the witness value to be say {@code +0.0}.
* @param decl the class that declares the static field * @param decl the class that declares the static field
* @param name the field's name * @param name the field's name
* @param type the field's type, of type {@code T} * @param type the field's type, of type {@code T}
@ -1590,22 +1632,43 @@ return mh1;
* <ul> * <ul>
* <li>if the field is declared {@code final}, then the write, atomic * <li>if the field is declared {@code final}, then the write, atomic
* update, and numeric atomic update access modes are unsupported. * update, and numeric atomic update access modes are unsupported.
* <li>if the field type is anything other than {@code int}, * <li>if the field type is anything other than {@code byte},
* {@code long} or a reference type, then atomic update access modes * {@code short}, {@code char}, {@code int} or {@code long},
* are unsupported. (Future major platform releases of the JDK may * {@code float}, or {@code double} then numeric atomic update
* support additional types for certain currently unsupported access * access modes are unsupported.
* modes.)
* <li>if the field type is anything other than {@code int} or
* {@code long}, then numeric atomic update access modes are
* unsupported. (Future major platform releases of the JDK may
* support additional numeric types for certain currently
* unsupported access modes.)
* </ul> * </ul>
* <p> * <p>
* If the field is declared {@code volatile} then the returned VarHandle * If the field is declared {@code volatile} then the returned VarHandle
* will override access to the field (effectively ignore the * will override access to the field (effectively ignore the
* {@code volatile} declaration) in accordance to it's specified * {@code volatile} declaration) in accordance to it's specified
* access modes. * access modes.
* <p>
* If the field type is {@code float} or {@code double} then numeric
* and atomic update access modes compare values using their bitwise
* representation (see {@link Float#floatToRawIntBits} and
* {@link Double#doubleToRawLongBits}, respectively).
* @apiNote
* Bitwise comparison of {@code float} values or {@code double} values,
* as performed by the numeric and atomic update access modes, differ
* from the primitive {@code ==} operator and the {@link Float#equals}
* and {@link Double#equals} methods, specifically with respect to
* comparing NaN values or comparing {@code -0.0} with {@code +0.0}.
* Care should be taken when performing a compare and set or a compare
* and exchange operation with such values since the operation may
* unexpectedly fail.
* There are many possible NaN values that are considered to be
* {@code NaN} in Java, although no IEEE 754 floating-point operation
* provided by Java can distinguish between them. Operation failure can
* occur if the expected or witness value is a NaN value and it is
* transformed (perhaps in a platform specific manner) into another NaN
* value, and thus has a different bitwise representation (see
* {@link Float#intBitsToFloat} or {@link Double#longBitsToDouble} for more
* details).
* The values {@code -0.0} and {@code +0.0} have different bitwise
* representations but are considered equal when using the primitive
* {@code ==} operator. Operation failure can occur if, for example, a
* numeric algorithm computes an expected value to be say {@code -0.0}
* and previously computed the witness value to be say {@code +0.0}.
* @param f the reflected field, with a field of type {@code T}, and * @param f the reflected field, with a field of type {@code T}, and
* a declaring class of type {@code R} * a declaring class of type {@code R}
* @return a VarHandle giving access to non-static fields or a static * @return a VarHandle giving access to non-static fields or a static
@ -2289,17 +2352,38 @@ return mh1;
* Certain access modes of the returned VarHandle are unsupported under * Certain access modes of the returned VarHandle are unsupported under
* the following conditions: * the following conditions:
* <ul> * <ul>
* <li>if the component type is anything other than {@code int}, * <li>if the component type is anything other than {@code byte},
* {@code long} or a reference type, then atomic update access modes * {@code short}, {@code char}, {@code int} or {@code long},
* are unsupported. (Future major platform releases of the JDK may * {@code float}, or {@code double} then numeric atomic update access
* support additional types for certain currently unsupported access * modes are unsupported.
* modes.)
* <li>if the component type is anything other than {@code int} or
* {@code long}, then numeric atomic update access modes are
* unsupported. (Future major platform releases of the JDK may
* support additional numeric types for certain currently
* unsupported access modes.)
* </ul> * </ul>
* <p>
* If the component type is {@code float} or {@code double} then numeric
* and atomic update access modes compare values using their bitwise
* representation (see {@link Float#floatToRawIntBits} and
* {@link Double#doubleToRawLongBits}, respectively).
* @apiNote
* Bitwise comparison of {@code float} values or {@code double} values,
* as performed by the numeric and atomic update access modes, differ
* from the primitive {@code ==} operator and the {@link Float#equals}
* and {@link Double#equals} methods, specifically with respect to
* comparing NaN values or comparing {@code -0.0} with {@code +0.0}.
* Care should be taken when performing a compare and set or a compare
* and exchange operation with such values since the operation may
* unexpectedly fail.
* There are many possible NaN values that are considered to be
* {@code NaN} in Java, although no IEEE 754 floating-point operation
* provided by Java can distinguish between them. Operation failure can
* occur if the expected or witness value is a NaN value and it is
* transformed (perhaps in a platform specific manner) into another NaN
* value, and thus has a different bitwise representation (see
* {@link Float#intBitsToFloat} or {@link Double#longBitsToDouble} for more
* details).
* The values {@code -0.0} and {@code +0.0} have different bitwise
* representations but are considered equal when using the primitive
* {@code ==} operator. Operation failure can occur if, for example, a
* numeric algorithm computes an expected value to be say {@code -0.0}
* and previously computed the witness value to be say {@code +0.0}.
* @param arrayClass the class of an array, of type {@code T[]} * @param arrayClass the class of an array, of type {@code T[]}
* @return a VarHandle giving access to elements of an array * @return a VarHandle giving access to elements of an array
* @throws NullPointerException if the arrayClass is null * @throws NullPointerException if the arrayClass is null
@ -2363,16 +2447,11 @@ return mh1;
* int misalignedAtIndex = (misalignedAtZeroIndex + index) % sizeOfT; * int misalignedAtIndex = (misalignedAtZeroIndex + index) % sizeOfT;
* boolean isMisaligned = misalignedAtIndex != 0; * boolean isMisaligned = misalignedAtIndex != 0;
* }</pre> * }</pre>
* * <p>
* @implNote * If the variable type is {@code float} or {@code double} then atomic
* The variable types {@code float} and {@code double} are supported as if * update access modes compare values using their bitwise representation
* by transformation to and access with the variable types {@code int} and * (see {@link Float#floatToRawIntBits} and
* {@code long} respectively. For example, the transformation of a * {@link Double#doubleToRawLongBits}, respectively).
* {@code double} value to a long value is performed as if using
* {@link Double#doubleToRawLongBits(double)}, and the reverse
* transformation is performed as if using
* {@link Double#longBitsToDouble(long)}.
*
* @param viewArrayClass the view array class, with a component type of * @param viewArrayClass the view array class, with a component type of
* type {@code T} * type {@code T}
* @param byteOrder the endianness of the view array elements, as * @param byteOrder the endianness of the view array elements, as
@ -2449,16 +2528,11 @@ return mh1;
* int misalignedAtIndex = bb.alignmentOffset(index, sizeOfT); * int misalignedAtIndex = bb.alignmentOffset(index, sizeOfT);
* boolean isMisaligned = misalignedAtIndex != 0; * boolean isMisaligned = misalignedAtIndex != 0;
* }</pre> * }</pre>
* * <p>
* @implNote * If the variable type is {@code float} or {@code double} then atomic
* The variable types {@code float} and {@code double} are supported as if * update access modes compare values using their bitwise representation
* by transformation to and access with the variable types {@code int} and * (see {@link Float#floatToRawIntBits} and
* {@code long} respectively. For example, the transformation of a * {@link Double#doubleToRawLongBits}, respectively).
* {@code double} value to a long value is performed as if using
* {@link Double#doubleToRawLongBits(double)}, and the reverse
* transformation is performed as if using
* {@link Double#longBitsToDouble(long)}.
*
* @param viewArrayClass the view array class, with a component type of * @param viewArrayClass the view array class, with a component type of
* type {@code T} * type {@code T}
* @param byteOrder the endianness of the view array elements, as * @param byteOrder the endianness of the view array elements, as

View file

@ -139,7 +139,7 @@ import static java.lang.invoke.MethodHandleStatics.newInternalError;
* {@link #weakCompareAndSetAcquire weakCompareAndSetAcquire}, * {@link #weakCompareAndSetAcquire weakCompareAndSetAcquire},
* {@link #weakCompareAndSetRelease weakCompareAndSetRelease}, * {@link #weakCompareAndSetRelease weakCompareAndSetRelease},
* {@link #compareAndExchangeAcquire compareAndExchangeAcquire}, * {@link #compareAndExchangeAcquire compareAndExchangeAcquire},
* {@link #compareAndExchangeVolatile compareAndExchangeVolatile}, * {@link #compareAndExchange compareAndExchange},
* {@link #compareAndExchangeRelease compareAndExchangeRelease}, * {@link #compareAndExchangeRelease compareAndExchangeRelease},
* {@link #getAndSet getAndSet}. * {@link #getAndSet getAndSet}.
* <li>numeric atomic update access modes that, for example, atomically get and * <li>numeric atomic update access modes that, for example, atomically get and
@ -706,9 +706,9 @@ public abstract class VarHandle {
* <p>The method signature is of the form {@code (CT, T expectedValue, T newValue)T}. * <p>The method signature is of the form {@code (CT, T expectedValue, T newValue)T}.
* *
* <p>The symbolic type descriptor at the call site of {@code * <p>The symbolic type descriptor at the call site of {@code
* compareAndExchangeVolatile} * compareAndExchange}
* must match the access mode type that is the result of calling * must match the access mode type that is the result of calling
* {@code accessModeType(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)} * {@code accessModeType(VarHandle.AccessMode.COMPARE_AND_EXCHANGE)}
* on this VarHandle. * on this VarHandle.
* *
* @param args the signature-polymorphic parameter list of the form * @param args the signature-polymorphic parameter list of the form
@ -729,7 +729,7 @@ public abstract class VarHandle {
public final native public final native
@MethodHandle.PolymorphicSignature @MethodHandle.PolymorphicSignature
@HotSpotIntrinsicCandidate @HotSpotIntrinsicCandidate
Object compareAndExchangeVolatile(Object... args); Object compareAndExchange(Object... args);
/** /**
* Atomically sets the value of a variable to the {@code newValue} with the * Atomically sets the value of a variable to the {@code newValue} with the
@ -1199,9 +1199,9 @@ public abstract class VarHandle {
/** /**
* The access mode whose access is specified by the corresponding * The access mode whose access is specified by the corresponding
* method * method
* {@link VarHandle#compareAndExchangeVolatile VarHandle.compareAndExchangeVolatile} * {@link VarHandle#compareAndExchange VarHandle.compareAndExchange}
*/ */
COMPARE_AND_EXCHANGE_VOLATILE("compareAndExchangeVolatile", AccessType.COMPARE_AND_EXCHANGE), COMPARE_AND_EXCHANGE("compareAndExchange", AccessType.COMPARE_AND_EXCHANGE),
/** /**
* The access mode whose access is specified by the corresponding * The access mode whose access is specified by the corresponding
* method * method

View file

@ -132,7 +132,7 @@ final class VarHandle$Type$s {
} }
@ForceInline @ForceInline
static $type$ compareAndExchangeVolatile(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) { static $type$ compareAndExchange(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
return UNSAFE.compareAndExchange$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)), return UNSAFE.compareAndExchange$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
handle.fieldOffset, handle.fieldOffset,
{#if[Object]?handle.fieldType.cast(expected):expected}, {#if[Object]?handle.fieldType.cast(expected):expected},
@ -205,9 +205,9 @@ final class VarHandle$Type$s {
@ForceInline @ForceInline
static $type$ addAndGet(FieldInstanceReadWrite handle, Object holder, $type$ value) { static $type$ addAndGet(FieldInstanceReadWrite handle, Object holder, $type$ value) {
return UNSAFE.getAndAdd$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)), return {#if[ShorterThanInt]?($type$)}(UNSAFE.getAndAdd$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
handle.fieldOffset, handle.fieldOffset,
value) + value; value) + value);
} }
#end[AtomicAdd] #end[AtomicAdd]
@ -313,7 +313,7 @@ final class VarHandle$Type$s {
@ForceInline @ForceInline
static $type$ compareAndExchangeVolatile(FieldStaticReadWrite handle, $type$ expected, $type$ value) { static $type$ compareAndExchange(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
return UNSAFE.compareAndExchange$Type$Volatile(handle.base, return UNSAFE.compareAndExchange$Type$Volatile(handle.base,
handle.fieldOffset, handle.fieldOffset,
{#if[Object]?handle.fieldType.cast(expected):expected}, {#if[Object]?handle.fieldType.cast(expected):expected},
@ -386,9 +386,9 @@ final class VarHandle$Type$s {
@ForceInline @ForceInline
static $type$ addAndGet(FieldStaticReadWrite handle, $type$ value) { static $type$ addAndGet(FieldStaticReadWrite handle, $type$ value) {
return UNSAFE.getAndAdd$Type$(handle.base, return {#if[ShorterThanInt]?($type$)}(UNSAFE.getAndAdd$Type$(handle.base,
handle.fieldOffset, handle.fieldOffset,
value) + value; value) + value);
} }
#end[AtomicAdd] #end[AtomicAdd]
@ -523,7 +523,7 @@ final class VarHandle$Type$s {
} }
@ForceInline @ForceInline
static $type$ compareAndExchangeVolatile(Array handle, Object oarray, int index, $type$ expected, $type$ value) { static $type$ compareAndExchange(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
#if[Object] #if[Object]
Object[] array = (Object[]) handle.arrayType.cast(oarray); Object[] array = (Object[]) handle.arrayType.cast(oarray);
#else[Object] #else[Object]
@ -646,9 +646,9 @@ final class VarHandle$Type$s {
#else[Object] #else[Object]
$type$[] array = ($type$[]) oarray; $type$[] array = ($type$[]) oarray;
#end[Object] #end[Object]
return UNSAFE.getAndAdd$Type$(array, return {#if[ShorterThanInt]?($type$)}(UNSAFE.getAndAdd$Type$(array,
(((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase, (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
value) + value; value) + value);
} }
#end[AtomicAdd] #end[AtomicAdd]

View file

@ -193,7 +193,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
} }
@ForceInline @ForceInline
static $type$ compareAndExchangeVolatile(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) { static $type$ compareAndExchange(ArrayHandle handle, Object oba, int index, $type$ expected, $type$ value) {
byte[] ba = (byte[]) oba; byte[] ba = (byte[]) oba;
return convEndian(handle.be, return convEndian(handle.be,
UNSAFE.compareAndExchange$RawType$Volatile( UNSAFE.compareAndExchange$RawType$Volatile(
@ -436,7 +436,7 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
} }
@ForceInline @ForceInline
static $type$ compareAndExchangeVolatile(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) { static $type$ compareAndExchange(ByteBufferHandle handle, Object obb, int index, $type$ expected, $type$ value) {
ByteBuffer bb = (ByteBuffer) obb; ByteBuffer bb = (ByteBuffer) obb;
return convEndian(handle.be, return convEndian(handle.be,
UNSAFE.compareAndExchange$RawType$Volatile( UNSAFE.compareAndExchange$RawType$Volatile(

View file

@ -25,16 +25,14 @@
package jdk.internal.misc; package jdk.internal.misc;
import java.lang.reflect.Field; import jdk.internal.HotSpotIntrinsicCandidate;
import java.security.ProtectionDomain;
import jdk.internal.reflect.CallerSensitive; import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection; import jdk.internal.reflect.Reflection;
import jdk.internal.misc.VM;
import jdk.internal.HotSpotIntrinsicCandidate;
import jdk.internal.vm.annotation.ForceInline; import jdk.internal.vm.annotation.ForceInline;
import java.lang.reflect.Field;
import java.security.ProtectionDomain;
/** /**
* A collection of methods for performing low-level, unsafe operations. * A collection of methods for performing low-level, unsafe operations.
@ -1400,6 +1398,453 @@ public final class Unsafe {
return compareAndSwapInt(o, offset, expected, x); return compareAndSwapInt(o, offset, expected, x);
} }
@HotSpotIntrinsicCandidate
public final byte compareAndExchangeByteVolatile(Object o, long offset,
byte expected,
byte x) {
long wordOffset = offset & ~3;
int shift = (int) (offset & 3) << 3;
if (BE) {
shift = 24 - shift;
}
int mask = 0xFF << shift;
int maskedExpected = (expected & 0xFF) << shift;
int maskedX = (x & 0xFF) << shift;
int fullWord;
do {
fullWord = getIntVolatile(o, wordOffset);
if ((fullWord & mask) != maskedExpected)
return (byte) ((fullWord & mask) >> shift);
} while (!weakCompareAndSwapIntVolatile(o, wordOffset,
fullWord, (fullWord & ~mask) | maskedX));
return expected;
}
@HotSpotIntrinsicCandidate
public final boolean compareAndSwapByte(Object o, long offset,
byte expected,
byte x) {
return compareAndExchangeByteVolatile(o, offset, expected, x) == expected;
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSwapByteVolatile(Object o, long offset,
byte expected,
byte x) {
return compareAndSwapByte(o, offset, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSwapByteAcquire(Object o, long offset,
byte expected,
byte x) {
return weakCompareAndSwapByteVolatile(o, offset, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSwapByteRelease(Object o, long offset,
byte expected,
byte x) {
return weakCompareAndSwapByteVolatile(o, offset, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSwapByte(Object o, long offset,
byte expected,
byte x) {
return weakCompareAndSwapByteVolatile(o, offset, expected, x);
}
@HotSpotIntrinsicCandidate
public final byte compareAndExchangeByteAcquire(Object o, long offset,
byte expected,
byte x) {
return compareAndExchangeByteVolatile(o, offset, expected, x);
}
@HotSpotIntrinsicCandidate
public final byte compareAndExchangeByteRelease(Object o, long offset,
byte expected,
byte x) {
return compareAndExchangeByteVolatile(o, offset, expected, x);
}
@HotSpotIntrinsicCandidate
public final short compareAndExchangeShortVolatile(Object o, long offset,
short expected,
short x) {
if ((offset & 3) == 3) {
throw new IllegalArgumentException("Update spans the word, not supported");
}
long wordOffset = offset & ~3;
int shift = (int) (offset & 3) << 3;
if (BE) {
shift = 16 - shift;
}
int mask = 0xFFFF << shift;
int maskedExpected = (expected & 0xFFFF) << shift;
int maskedX = (x & 0xFFFF) << shift;
int fullWord;
do {
fullWord = getIntVolatile(o, wordOffset);
if ((fullWord & mask) != maskedExpected) {
return (short) ((fullWord & mask) >> shift);
}
} while (!weakCompareAndSwapIntVolatile(o, wordOffset,
fullWord, (fullWord & ~mask) | maskedX));
return expected;
}
@HotSpotIntrinsicCandidate
public final boolean compareAndSwapShort(Object o, long offset,
short expected,
short x) {
return compareAndExchangeShortVolatile(o, offset, expected, x) == expected;
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSwapShortVolatile(Object o, long offset,
short expected,
short x) {
return compareAndSwapShort(o, offset, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSwapShortAcquire(Object o, long offset,
short expected,
short x) {
return weakCompareAndSwapShortVolatile(o, offset, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSwapShortRelease(Object o, long offset,
short expected,
short x) {
return weakCompareAndSwapShortVolatile(o, offset, expected, x);
}
@HotSpotIntrinsicCandidate
public final boolean weakCompareAndSwapShort(Object o, long offset,
short expected,
short x) {
return weakCompareAndSwapShortVolatile(o, offset, expected, x);
}
@HotSpotIntrinsicCandidate
public final short compareAndExchangeShortAcquire(Object o, long offset,
short expected,
short x) {
return compareAndExchangeShortVolatile(o, offset, expected, x);
}
@HotSpotIntrinsicCandidate
public final short compareAndExchangeShortRelease(Object o, long offset,
short expected,
short x) {
return compareAndExchangeShortVolatile(o, offset, expected, x);
}
@ForceInline
private char s2c(short s) {
return (char) s;
}
@ForceInline
private short c2s(char s) {
return (short) s;
}
@ForceInline
public final boolean compareAndSwapChar(Object o, long offset,
char expected,
char x) {
return compareAndSwapShort(o, offset, c2s(expected), c2s(x));
}
@ForceInline
public final char compareAndExchangeCharVolatile(Object o, long offset,
char expected,
char x) {
return s2c(compareAndExchangeShortVolatile(o, offset, c2s(expected), c2s(x)));
}
@ForceInline
public final char compareAndExchangeCharAcquire(Object o, long offset,
char expected,
char x) {
return s2c(compareAndExchangeShortAcquire(o, offset, c2s(expected), c2s(x)));
}
@ForceInline
public final char compareAndExchangeCharRelease(Object o, long offset,
char expected,
char x) {
return s2c(compareAndExchangeShortRelease(o, offset, c2s(expected), c2s(x)));
}
@ForceInline
public final boolean weakCompareAndSwapCharVolatile(Object o, long offset,
char expected,
char x) {
return weakCompareAndSwapShortVolatile(o, offset, c2s(expected), c2s(x));
}
@ForceInline
public final boolean weakCompareAndSwapCharAcquire(Object o, long offset,
char expected,
char x) {
return weakCompareAndSwapShortAcquire(o, offset, c2s(expected), c2s(x));
}
@ForceInline
public final boolean weakCompareAndSwapCharRelease(Object o, long offset,
char expected,
char x) {
return weakCompareAndSwapShortRelease(o, offset, c2s(expected), c2s(x));
}
@ForceInline
public final boolean weakCompareAndSwapChar(Object o, long offset,
char expected,
char x) {
return weakCompareAndSwapShort(o, offset, c2s(expected), c2s(x));
}
@ForceInline
private boolean byte2bool(byte b) {
return b > 0;
}
@ForceInline
private byte bool2byte(boolean b) {
return b ? (byte)1 : (byte)0;
}
@ForceInline
public final boolean compareAndSwapBoolean(Object o, long offset,
boolean expected,
boolean x) {
return compareAndSwapByte(o, offset, bool2byte(expected), bool2byte(x));
}
@ForceInline
public final boolean compareAndExchangeBooleanVolatile(Object o, long offset,
boolean expected,
boolean x) {
return byte2bool(compareAndExchangeByteVolatile(o, offset, bool2byte(expected), bool2byte(x)));
}
@ForceInline
public final boolean compareAndExchangeBooleanAcquire(Object o, long offset,
boolean expected,
boolean x) {
return byte2bool(compareAndExchangeByteAcquire(o, offset, bool2byte(expected), bool2byte(x)));
}
@ForceInline
public final boolean compareAndExchangeBooleanRelease(Object o, long offset,
boolean expected,
boolean x) {
return byte2bool(compareAndExchangeByteRelease(o, offset, bool2byte(expected), bool2byte(x)));
}
@ForceInline
public final boolean weakCompareAndSwapBooleanVolatile(Object o, long offset,
boolean expected,
boolean x) {
return weakCompareAndSwapByteVolatile(o, offset, bool2byte(expected), bool2byte(x));
}
@ForceInline
public final boolean weakCompareAndSwapBooleanAcquire(Object o, long offset,
boolean expected,
boolean x) {
return weakCompareAndSwapByteAcquire(o, offset, bool2byte(expected), bool2byte(x));
}
@ForceInline
public final boolean weakCompareAndSwapBooleanRelease(Object o, long offset,
boolean expected,
boolean x) {
return weakCompareAndSwapByteRelease(o, offset, bool2byte(expected), bool2byte(x));
}
@ForceInline
public final boolean weakCompareAndSwapBoolean(Object o, long offset,
boolean expected,
boolean x) {
return weakCompareAndSwapByte(o, offset, bool2byte(expected), bool2byte(x));
}
/**
* Atomically updates Java variable to {@code x} if it is currently
* holding {@code expected}.
*
* <p>This operation has memory semantics of a {@code volatile} read
* and write. Corresponds to C11 atomic_compare_exchange_strong.
*
* @return {@code true} if successful
*/
@ForceInline
public final boolean compareAndSwapFloat(Object o, long offset,
float expected,
float x) {
return compareAndSwapInt(o, offset,
Float.floatToRawIntBits(expected),
Float.floatToRawIntBits(x));
}
@ForceInline
public final float compareAndExchangeFloatVolatile(Object o, long offset,
float expected,
float x) {
int w = compareAndExchangeIntVolatile(o, offset,
Float.floatToRawIntBits(expected),
Float.floatToRawIntBits(x));
return Float.intBitsToFloat(w);
}
@ForceInline
public final float compareAndExchangeFloatAcquire(Object o, long offset,
float expected,
float x) {
int w = compareAndExchangeIntVolatile(o, offset,
Float.floatToRawIntBits(expected),
Float.floatToRawIntBits(x));
return Float.intBitsToFloat(w);
}
@ForceInline
public final float compareAndExchangeFloatRelease(Object o, long offset,
float expected,
float x) {
int w = compareAndExchangeIntRelease(o, offset,
Float.floatToRawIntBits(expected),
Float.floatToRawIntBits(x));
return Float.intBitsToFloat(w);
}
@ForceInline
public final boolean weakCompareAndSwapFloat(Object o, long offset,
float expected,
float x) {
return weakCompareAndSwapInt(o, offset,
Float.floatToRawIntBits(expected),
Float.floatToRawIntBits(x));
}
@ForceInline
public final boolean weakCompareAndSwapFloatAcquire(Object o, long offset,
float expected,
float x) {
return weakCompareAndSwapIntAcquire(o, offset,
Float.floatToRawIntBits(expected),
Float.floatToRawIntBits(x));
}
@ForceInline
public final boolean weakCompareAndSwapFloatRelease(Object o, long offset,
float expected,
float x) {
return weakCompareAndSwapIntRelease(o, offset,
Float.floatToRawIntBits(expected),
Float.floatToRawIntBits(x));
}
@ForceInline
public final boolean weakCompareAndSwapFloatVolatile(Object o, long offset,
float expected,
float x) {
return weakCompareAndSwapIntVolatile(o, offset,
Float.floatToRawIntBits(expected),
Float.floatToRawIntBits(x));
}
/**
* Atomically updates Java variable to {@code x} if it is currently
* holding {@code expected}.
*
* <p>This operation has memory semantics of a {@code volatile} read
* and write. Corresponds to C11 atomic_compare_exchange_strong.
*
* @return {@code true} if successful
*/
@ForceInline
public final boolean compareAndSwapDouble(Object o, long offset,
double expected,
double x) {
return compareAndSwapLong(o, offset,
Double.doubleToRawLongBits(expected),
Double.doubleToRawLongBits(x));
}
@ForceInline
public final double compareAndExchangeDoubleVolatile(Object o, long offset,
double expected,
double x) {
long w = compareAndExchangeLongVolatile(o, offset,
Double.doubleToRawLongBits(expected),
Double.doubleToRawLongBits(x));
return Double.longBitsToDouble(w);
}
@ForceInline
public final double compareAndExchangeDoubleAcquire(Object o, long offset,
double expected,
double x) {
long w = compareAndExchangeLongVolatile(o, offset,
Double.doubleToRawLongBits(expected),
Double.doubleToRawLongBits(x));
return Double.longBitsToDouble(w);
}
@ForceInline
public final double compareAndExchangeDoubleRelease(Object o, long offset,
double expected,
double x) {
long w = compareAndExchangeLongRelease(o, offset,
Double.doubleToRawLongBits(expected),
Double.doubleToRawLongBits(x));
return Double.longBitsToDouble(w);
}
@ForceInline
public final boolean weakCompareAndSwapDouble(Object o, long offset,
double expected,
double x) {
return weakCompareAndSwapLong(o, offset,
Double.doubleToRawLongBits(expected),
Double.doubleToRawLongBits(x));
}
@ForceInline
public final boolean weakCompareAndSwapDoubleAcquire(Object o, long offset,
double expected,
double x) {
return weakCompareAndSwapLongAcquire(o, offset,
Double.doubleToRawLongBits(expected),
Double.doubleToRawLongBits(x));
}
@ForceInline
public final boolean weakCompareAndSwapDoubleRelease(Object o, long offset,
double expected,
double x) {
return weakCompareAndSwapLongRelease(o, offset,
Double.doubleToRawLongBits(expected),
Double.doubleToRawLongBits(x));
}
@ForceInline
public final boolean weakCompareAndSwapDoubleVolatile(Object o, long offset,
double expected,
double x) {
return weakCompareAndSwapLongVolatile(o, offset,
Double.doubleToRawLongBits(expected),
Double.doubleToRawLongBits(x));
}
/** /**
* Atomically updates Java variable to {@code x} if it is currently * Atomically updates Java variable to {@code x} if it is currently
* holding {@code expected}. * holding {@code expected}.
@ -1840,7 +2285,7 @@ public final class Unsafe {
int v; int v;
do { do {
v = getIntVolatile(o, offset); v = getIntVolatile(o, offset);
} while (!compareAndSwapInt(o, offset, v, v + delta)); } while (!weakCompareAndSwapIntVolatile(o, offset, v, v + delta));
return v; return v;
} }
@ -1860,7 +2305,60 @@ public final class Unsafe {
long v; long v;
do { do {
v = getLongVolatile(o, offset); v = getLongVolatile(o, offset);
} while (!compareAndSwapLong(o, offset, v, v + delta)); } while (!weakCompareAndSwapLongVolatile(o, offset, v, v + delta));
return v;
}
@HotSpotIntrinsicCandidate
public final byte getAndAddByte(Object o, long offset, byte delta) {
byte v;
do {
v = getByteVolatile(o, offset);
} while (!weakCompareAndSwapByteVolatile(o, offset, v, (byte) (v + delta)));
return v;
}
@HotSpotIntrinsicCandidate
public final short getAndAddShort(Object o, long offset, short delta) {
short v;
do {
v = getShortVolatile(o, offset);
} while (!weakCompareAndSwapShortVolatile(o, offset, v, (short) (v + delta)));
return v;
}
@ForceInline
public final char getAndAddChar(Object o, long offset, char delta) {
return (char) getAndAddShort(o, offset, (short) delta);
}
@ForceInline
public final float getAndAddFloat(Object o, long offset, float delta) {
int expectedBits;
float v;
do {
// Load and CAS with the raw bits to avoid issues with NaNs and
// possible bit conversion from signaling NaNs to quiet NaNs that
// may result in the loop not terminating.
expectedBits = getIntVolatile(o, offset);
v = Float.intBitsToFloat(expectedBits);
} while (!weakCompareAndSwapIntVolatile(o, offset,
expectedBits, Float.floatToRawIntBits(v + delta)));
return v;
}
@ForceInline
public final double getAndAddDouble(Object o, long offset, double delta) {
long expectedBits;
double v;
do {
// Load and CAS with the raw bits to avoid issues with NaNs and
// possible bit conversion from signaling NaNs to quiet NaNs that
// may result in the loop not terminating.
expectedBits = getLongVolatile(o, offset);
v = Double.longBitsToDouble(expectedBits);
} while (!weakCompareAndSwapLongVolatile(o, offset,
expectedBits, Double.doubleToRawLongBits(v + delta)));
return v; return v;
} }
@ -1880,7 +2378,7 @@ public final class Unsafe {
int v; int v;
do { do {
v = getIntVolatile(o, offset); v = getIntVolatile(o, offset);
} while (!compareAndSwapInt(o, offset, v, newValue)); } while (!weakCompareAndSwapIntVolatile(o, offset, v, newValue));
return v; return v;
} }
@ -1900,7 +2398,7 @@ public final class Unsafe {
long v; long v;
do { do {
v = getLongVolatile(o, offset); v = getLongVolatile(o, offset);
} while (!compareAndSwapLong(o, offset, v, newValue)); } while (!weakCompareAndSwapLongVolatile(o, offset, v, newValue));
return v; return v;
} }
@ -1920,10 +2418,49 @@ public final class Unsafe {
Object v; Object v;
do { do {
v = getObjectVolatile(o, offset); v = getObjectVolatile(o, offset);
} while (!compareAndSwapObject(o, offset, v, newValue)); } while (!weakCompareAndSwapObjectVolatile(o, offset, v, newValue));
return v; return v;
} }
@HotSpotIntrinsicCandidate
public final byte getAndSetByte(Object o, long offset, byte newValue) {
byte v;
do {
v = getByteVolatile(o, offset);
} while (!weakCompareAndSwapByteVolatile(o, offset, v, newValue));
return v;
}
@ForceInline
public final boolean getAndSetBoolean(Object o, long offset, boolean newValue) {
return byte2bool(getAndSetByte(o, offset, bool2byte(newValue)));
}
@HotSpotIntrinsicCandidate
public final short getAndSetShort(Object o, long offset, short newValue) {
short v;
do {
v = getShortVolatile(o, offset);
} while (!weakCompareAndSwapShortVolatile(o, offset, v, newValue));
return v;
}
@ForceInline
public final char getAndSetChar(Object o, long offset, char newValue) {
return s2c(getAndSetShort(o, offset, c2s(newValue)));
}
@ForceInline
public final float getAndSetFloat(Object o, long offset, float newValue) {
int v = getAndSetInt(o, offset, Float.floatToRawIntBits(newValue));
return Float.intBitsToFloat(v);
}
@ForceInline
public final double getAndSetDouble(Object o, long offset, double newValue) {
long v = getAndSetLong(o, offset, Double.doubleToRawLongBits(newValue));
return Double.longBitsToDouble(v);
}
/** /**
* Ensures that loads before the fence will not be reordered with loads and * Ensures that loads before the fence will not be reordered with loads and

View file

@ -145,7 +145,7 @@ abstract class VarHandleBaseTest {
GET_OPAQUE(TestAccessType.GET), GET_OPAQUE(TestAccessType.GET),
SET_OPAQUE(TestAccessType.SET), SET_OPAQUE(TestAccessType.SET),
COMPARE_AND_SET(TestAccessType.COMPARE_AND_SET), COMPARE_AND_SET(TestAccessType.COMPARE_AND_SET),
COMPARE_AND_EXCHANGE_VOLATILE(TestAccessType.COMPARE_AND_EXCHANGE), COMPARE_AND_EXCHANGE(TestAccessType.COMPARE_AND_EXCHANGE),
COMPARE_AND_EXCHANGE_ACQUIRE(TestAccessType.COMPARE_AND_EXCHANGE), COMPARE_AND_EXCHANGE_ACQUIRE(TestAccessType.COMPARE_AND_EXCHANGE),
COMPARE_AND_EXCHANGE_RELEASE(TestAccessType.COMPARE_AND_EXCHANGE), COMPARE_AND_EXCHANGE_RELEASE(TestAccessType.COMPARE_AND_EXCHANGE),
WEAK_COMPARE_AND_SET(TestAccessType.COMPARE_AND_SET), WEAK_COMPARE_AND_SET(TestAccessType.COMPARE_AND_SET),

View file

@ -99,15 +99,15 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET));
@ -260,41 +260,6 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest {
vh.setOpaque(recv, false); vh.setOpaque(recv, false);
}); });
checkUOE(() -> {
boolean r = vh.compareAndSet(recv, true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.compareAndExchangeVolatile(recv, true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.compareAndExchangeAcquire(recv, true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.compareAndExchangeRelease(recv, true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(recv, true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(recv, true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(recv, true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(recv, true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.getAndSet(recv, true);
});
checkUOE(() -> { checkUOE(() -> {
boolean o = (boolean) vh.getAndAdd(recv, true); boolean o = (boolean) vh.getAndAdd(recv, true);
@ -350,41 +315,6 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest {
vh.setOpaque(false); vh.setOpaque(false);
}); });
checkUOE(() -> {
boolean r = vh.compareAndSet(true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.compareAndExchangeVolatile(true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.compareAndExchangeAcquire(true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.compareAndExchangeRelease(true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.getAndSet(true);
});
checkUOE(() -> { checkUOE(() -> {
boolean o = (boolean) vh.getAndAdd(true); boolean o = (boolean) vh.getAndAdd(true);
@ -426,45 +356,116 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest {
assertEquals(x, false, "setOpaque boolean value"); assertEquals(x, false, "setOpaque boolean value");
} }
vh.set(recv, true);
// Compare
{
boolean r = vh.compareAndSet(recv, true, false);
assertEquals(r, true, "success compareAndSet boolean");
boolean x = (boolean) vh.get(recv);
assertEquals(x, false, "success compareAndSet boolean value");
}
{
boolean r = vh.compareAndSet(recv, true, false);
assertEquals(r, false, "failing compareAndSet boolean");
boolean x = (boolean) vh.get(recv);
assertEquals(x, false, "failing compareAndSet boolean value");
}
{
boolean r = (boolean) vh.compareAndExchange(recv, false, true);
assertEquals(r, false, "success compareAndExchange boolean");
boolean x = (boolean) vh.get(recv);
assertEquals(x, true, "success compareAndExchange boolean value");
}
{
boolean r = (boolean) vh.compareAndExchange(recv, false, false);
assertEquals(r, true, "failing compareAndExchange boolean");
boolean x = (boolean) vh.get(recv);
assertEquals(x, true, "failing compareAndExchange boolean value");
}
{
boolean r = (boolean) vh.compareAndExchangeAcquire(recv, true, false);
assertEquals(r, true, "success compareAndExchangeAcquire boolean");
boolean x = (boolean) vh.get(recv);
assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) vh.compareAndExchangeAcquire(recv, true, false);
assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
boolean x = (boolean) vh.get(recv);
assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) vh.compareAndExchangeRelease(recv, false, true);
assertEquals(r, false, "success compareAndExchangeRelease boolean");
boolean x = (boolean) vh.get(recv);
assertEquals(x, true, "success compareAndExchangeRelease boolean value");
}
{
boolean r = (boolean) vh.compareAndExchangeRelease(recv, false, false);
assertEquals(r, true, "failing compareAndExchangeRelease boolean");
boolean x = (boolean) vh.get(recv);
assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(recv, true, false);
}
assertEquals(success, true, "weakCompareAndSet boolean");
boolean x = (boolean) vh.get(recv);
assertEquals(x, false, "weakCompareAndSet boolean value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(recv, false, true);
}
assertEquals(success, true, "weakCompareAndSetAcquire boolean");
boolean x = (boolean) vh.get(recv);
assertEquals(x, true, "weakCompareAndSetAcquire boolean");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(recv, true, false);
}
assertEquals(success, true, "weakCompareAndSetRelease boolean");
boolean x = (boolean) vh.get(recv);
assertEquals(x, false, "weakCompareAndSetRelease boolean");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetVolatile(recv, false, true);
}
assertEquals(success, true, "weakCompareAndSetVolatile boolean");
boolean x = (boolean) vh.get(recv);
assertEquals(x, true, "weakCompareAndSetVolatile boolean value");
}
// Compare set and get
{
boolean o = (boolean) vh.getAndSet(recv, false);
assertEquals(o, true, "getAndSet boolean");
boolean x = (boolean) vh.get(recv);
assertEquals(x, false, "getAndSet boolean value");
}
} }
static void testInstanceFieldUnsupported(VarHandleTestAccessBoolean recv, VarHandle vh) { static void testInstanceFieldUnsupported(VarHandleTestAccessBoolean recv, VarHandle vh) {
checkUOE(() -> {
boolean r = vh.compareAndSet(recv, true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.compareAndExchangeVolatile(recv, true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.compareAndExchangeAcquire(recv, true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.compareAndExchangeRelease(recv, true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(recv, true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(recv, true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(recv, true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(recv, true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.getAndSet(recv, true);
});
checkUOE(() -> { checkUOE(() -> {
boolean o = (boolean) vh.getAndAdd(recv, true); boolean o = (boolean) vh.getAndAdd(recv, true);
@ -506,45 +507,116 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest {
assertEquals(x, false, "setOpaque boolean value"); assertEquals(x, false, "setOpaque boolean value");
} }
vh.set(true);
// Compare
{
boolean r = vh.compareAndSet(true, false);
assertEquals(r, true, "success compareAndSet boolean");
boolean x = (boolean) vh.get();
assertEquals(x, false, "success compareAndSet boolean value");
}
{
boolean r = vh.compareAndSet(true, false);
assertEquals(r, false, "failing compareAndSet boolean");
boolean x = (boolean) vh.get();
assertEquals(x, false, "failing compareAndSet boolean value");
}
{
boolean r = (boolean) vh.compareAndExchange(false, true);
assertEquals(r, false, "success compareAndExchange boolean");
boolean x = (boolean) vh.get();
assertEquals(x, true, "success compareAndExchange boolean value");
}
{
boolean r = (boolean) vh.compareAndExchange(false, false);
assertEquals(r, true, "failing compareAndExchange boolean");
boolean x = (boolean) vh.get();
assertEquals(x, true, "failing compareAndExchange boolean value");
}
{
boolean r = (boolean) vh.compareAndExchangeAcquire(true, false);
assertEquals(r, true, "success compareAndExchangeAcquire boolean");
boolean x = (boolean) vh.get();
assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) vh.compareAndExchangeAcquire(true, false);
assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
boolean x = (boolean) vh.get();
assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) vh.compareAndExchangeRelease(false, true);
assertEquals(r, false, "success compareAndExchangeRelease boolean");
boolean x = (boolean) vh.get();
assertEquals(x, true, "success compareAndExchangeRelease boolean value");
}
{
boolean r = (boolean) vh.compareAndExchangeRelease(false, false);
assertEquals(r, true, "failing compareAndExchangeRelease boolean");
boolean x = (boolean) vh.get();
assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(true, false);
}
assertEquals(success, true, "weakCompareAndSet boolean");
boolean x = (boolean) vh.get();
assertEquals(x, false, "weakCompareAndSet boolean value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(false, true);
}
assertEquals(success, true, "weakCompareAndSetAcquire boolean");
boolean x = (boolean) vh.get();
assertEquals(x, true, "weakCompareAndSetAcquire boolean");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(true, false);
}
assertEquals(success, true, "weakCompareAndSetRelease boolean");
boolean x = (boolean) vh.get();
assertEquals(x, false, "weakCompareAndSetRelease boolean");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(false, true);
}
assertEquals(success, true, "weakCompareAndSetVolatile boolean");
boolean x = (boolean) vh.get();
assertEquals(x, true, "weakCompareAndSetVolatile boolean");
}
// Compare set and get
{
boolean o = (boolean) vh.getAndSet(false);
assertEquals(o, true, "getAndSet boolean");
boolean x = (boolean) vh.get();
assertEquals(x, false, "getAndSet boolean value");
}
} }
static void testStaticFieldUnsupported(VarHandle vh) { static void testStaticFieldUnsupported(VarHandle vh) {
checkUOE(() -> {
boolean r = vh.compareAndSet(true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.compareAndExchangeVolatile(true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.compareAndExchangeAcquire(true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.compareAndExchangeRelease(true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.getAndSet(true);
});
checkUOE(() -> { checkUOE(() -> {
boolean o = (boolean) vh.getAndAdd(true); boolean o = (boolean) vh.getAndAdd(true);
@ -589,6 +661,112 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest {
assertEquals(x, false, "setOpaque boolean value"); assertEquals(x, false, "setOpaque boolean value");
} }
vh.set(array, i, true);
// Compare
{
boolean r = vh.compareAndSet(array, i, true, false);
assertEquals(r, true, "success compareAndSet boolean");
boolean x = (boolean) vh.get(array, i);
assertEquals(x, false, "success compareAndSet boolean value");
}
{
boolean r = vh.compareAndSet(array, i, true, false);
assertEquals(r, false, "failing compareAndSet boolean");
boolean x = (boolean) vh.get(array, i);
assertEquals(x, false, "failing compareAndSet boolean value");
}
{
boolean r = (boolean) vh.compareAndExchange(array, i, false, true);
assertEquals(r, false, "success compareAndExchange boolean");
boolean x = (boolean) vh.get(array, i);
assertEquals(x, true, "success compareAndExchange boolean value");
}
{
boolean r = (boolean) vh.compareAndExchange(array, i, false, false);
assertEquals(r, true, "failing compareAndExchange boolean");
boolean x = (boolean) vh.get(array, i);
assertEquals(x, true, "failing compareAndExchange boolean value");
}
{
boolean r = (boolean) vh.compareAndExchangeAcquire(array, i, true, false);
assertEquals(r, true, "success compareAndExchangeAcquire boolean");
boolean x = (boolean) vh.get(array, i);
assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) vh.compareAndExchangeAcquire(array, i, true, false);
assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
boolean x = (boolean) vh.get(array, i);
assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) vh.compareAndExchangeRelease(array, i, false, true);
assertEquals(r, false, "success compareAndExchangeRelease boolean");
boolean x = (boolean) vh.get(array, i);
assertEquals(x, true, "success compareAndExchangeRelease boolean value");
}
{
boolean r = (boolean) vh.compareAndExchangeRelease(array, i, false, false);
assertEquals(r, true, "failing compareAndExchangeRelease boolean");
boolean x = (boolean) vh.get(array, i);
assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(array, i, true, false);
}
assertEquals(success, true, "weakCompareAndSet boolean");
boolean x = (boolean) vh.get(array, i);
assertEquals(x, false, "weakCompareAndSet boolean value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(array, i, false, true);
}
assertEquals(success, true, "weakCompareAndSetAcquire boolean");
boolean x = (boolean) vh.get(array, i);
assertEquals(x, true, "weakCompareAndSetAcquire boolean");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(array, i, true, false);
}
assertEquals(success, true, "weakCompareAndSetRelease boolean");
boolean x = (boolean) vh.get(array, i);
assertEquals(x, false, "weakCompareAndSetRelease boolean");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetVolatile(array, i, false, true);
}
assertEquals(success, true, "weakCompareAndSetVolatile boolean");
boolean x = (boolean) vh.get(array, i);
assertEquals(x, true, "weakCompareAndSetVolatile boolean");
}
// Compare set and get
{
boolean o = (boolean) vh.getAndSet(array, i, false);
assertEquals(o, true, "getAndSet boolean");
boolean x = (boolean) vh.get(array, i);
assertEquals(x, false, "getAndSet boolean value");
}
} }
} }
@ -597,41 +775,6 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest {
boolean[] array = new boolean[10]; boolean[] array = new boolean[10];
int i = 0; int i = 0;
checkUOE(() -> {
boolean r = vh.compareAndSet(array, i, true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.compareAndExchangeVolatile(array, i, true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.compareAndExchangeAcquire(array, i, true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.compareAndExchangeRelease(array, i, true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(array, i, true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(array, i, true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, i, true, false);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(array, i, true, false);
});
checkUOE(() -> {
boolean r = (boolean) vh.getAndSet(array, i, true);
});
checkUOE(() -> { checkUOE(() -> {
boolean o = (boolean) vh.getAndAdd(array, i, true); boolean o = (boolean) vh.getAndAdd(array, i, true);
@ -680,6 +823,41 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest {
vh.setOpaque(array, ci, true); vh.setOpaque(array, ci, true);
}); });
checkIOOBE(() -> {
boolean r = vh.compareAndSet(array, ci, true, false);
});
checkIOOBE(() -> {
boolean r = (boolean) vh.compareAndExchange(array, ci, false, true);
});
checkIOOBE(() -> {
boolean r = (boolean) vh.compareAndExchangeAcquire(array, ci, false, true);
});
checkIOOBE(() -> {
boolean r = (boolean) vh.compareAndExchangeRelease(array, ci, false, true);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSet(array, ci, true, false);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetVolatile(array, ci, true, false);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, ci, true, false);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetRelease(array, ci, true, false);
});
checkIOOBE(() -> {
boolean o = (boolean) vh.getAndSet(array, ci, true);
});
} }
} }

View file

@ -42,11 +42,11 @@ import java.util.List;
import static org.testng.Assert.*; import static org.testng.Assert.*;
public class VarHandleTestAccessByte extends VarHandleBaseTest { public class VarHandleTestAccessByte extends VarHandleBaseTest {
static final byte static_final_v = (byte)1; static final byte static_final_v = (byte)0x01;
static byte static_v; static byte static_v;
final byte final_v = (byte)1; final byte final_v = (byte)0x01;
byte v; byte v;
@ -99,18 +99,18 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET));
} }
@ -220,89 +220,47 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest {
// Plain // Plain
{ {
byte x = (byte) vh.get(recv); byte x = (byte) vh.get(recv);
assertEquals(x, (byte)1, "get byte value"); assertEquals(x, (byte)0x01, "get byte value");
} }
// Volatile // Volatile
{ {
byte x = (byte) vh.getVolatile(recv); byte x = (byte) vh.getVolatile(recv);
assertEquals(x, (byte)1, "getVolatile byte value"); assertEquals(x, (byte)0x01, "getVolatile byte value");
} }
// Lazy // Lazy
{ {
byte x = (byte) vh.getAcquire(recv); byte x = (byte) vh.getAcquire(recv);
assertEquals(x, (byte)1, "getRelease byte value"); assertEquals(x, (byte)0x01, "getRelease byte value");
} }
// Opaque // Opaque
{ {
byte x = (byte) vh.getOpaque(recv); byte x = (byte) vh.getOpaque(recv);
assertEquals(x, (byte)1, "getOpaque byte value"); assertEquals(x, (byte)0x01, "getOpaque byte value");
} }
} }
static void testInstanceFinalFieldUnsupported(VarHandleTestAccessByte recv, VarHandle vh) { static void testInstanceFinalFieldUnsupported(VarHandleTestAccessByte recv, VarHandle vh) {
checkUOE(() -> { checkUOE(() -> {
vh.set(recv, (byte)2); vh.set(recv, (byte)0x23);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setVolatile(recv, (byte)2); vh.setVolatile(recv, (byte)0x23);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setRelease(recv, (byte)2); vh.setRelease(recv, (byte)0x23);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setOpaque(recv, (byte)2); vh.setOpaque(recv, (byte)0x23);
}); });
checkUOE(() -> {
boolean r = vh.compareAndSet(recv, (byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.compareAndExchangeVolatile(recv, (byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.compareAndExchangeAcquire(recv, (byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.compareAndExchangeRelease(recv, (byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(recv, (byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(recv, (byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(recv, (byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(recv, (byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.getAndSet(recv, (byte)1);
});
checkUOE(() -> {
byte o = (byte) vh.getAndAdd(recv, (byte)1);
});
checkUOE(() -> {
byte o = (byte) vh.addAndGet(recv, (byte)1);
});
} }
@ -310,249 +268,353 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest {
// Plain // Plain
{ {
byte x = (byte) vh.get(); byte x = (byte) vh.get();
assertEquals(x, (byte)1, "get byte value"); assertEquals(x, (byte)0x01, "get byte value");
} }
// Volatile // Volatile
{ {
byte x = (byte) vh.getVolatile(); byte x = (byte) vh.getVolatile();
assertEquals(x, (byte)1, "getVolatile byte value"); assertEquals(x, (byte)0x01, "getVolatile byte value");
} }
// Lazy // Lazy
{ {
byte x = (byte) vh.getAcquire(); byte x = (byte) vh.getAcquire();
assertEquals(x, (byte)1, "getRelease byte value"); assertEquals(x, (byte)0x01, "getRelease byte value");
} }
// Opaque // Opaque
{ {
byte x = (byte) vh.getOpaque(); byte x = (byte) vh.getOpaque();
assertEquals(x, (byte)1, "getOpaque byte value"); assertEquals(x, (byte)0x01, "getOpaque byte value");
} }
} }
static void testStaticFinalFieldUnsupported(VarHandle vh) { static void testStaticFinalFieldUnsupported(VarHandle vh) {
checkUOE(() -> { checkUOE(() -> {
vh.set((byte)2); vh.set((byte)0x23);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setVolatile((byte)2); vh.setVolatile((byte)0x23);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setRelease((byte)2); vh.setRelease((byte)0x23);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setOpaque((byte)2); vh.setOpaque((byte)0x23);
}); });
checkUOE(() -> {
boolean r = vh.compareAndSet((byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.compareAndExchangeVolatile((byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.compareAndExchangeAcquire((byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.compareAndExchangeRelease((byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet((byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile((byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire((byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease((byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.getAndSet((byte)1);
});
checkUOE(() -> {
byte o = (byte) vh.getAndAdd((byte)1);
});
checkUOE(() -> {
byte o = (byte) vh.addAndGet((byte)1);
});
} }
static void testInstanceField(VarHandleTestAccessByte recv, VarHandle vh) { static void testInstanceField(VarHandleTestAccessByte recv, VarHandle vh) {
// Plain // Plain
{ {
vh.set(recv, (byte)1); vh.set(recv, (byte)0x01);
byte x = (byte) vh.get(recv); byte x = (byte) vh.get(recv);
assertEquals(x, (byte)1, "set byte value"); assertEquals(x, (byte)0x01, "set byte value");
} }
// Volatile // Volatile
{ {
vh.setVolatile(recv, (byte)2); vh.setVolatile(recv, (byte)0x23);
byte x = (byte) vh.getVolatile(recv); byte x = (byte) vh.getVolatile(recv);
assertEquals(x, (byte)2, "setVolatile byte value"); assertEquals(x, (byte)0x23, "setVolatile byte value");
} }
// Lazy // Lazy
{ {
vh.setRelease(recv, (byte)1); vh.setRelease(recv, (byte)0x01);
byte x = (byte) vh.getAcquire(recv); byte x = (byte) vh.getAcquire(recv);
assertEquals(x, (byte)1, "setRelease byte value"); assertEquals(x, (byte)0x01, "setRelease byte value");
} }
// Opaque // Opaque
{ {
vh.setOpaque(recv, (byte)2); vh.setOpaque(recv, (byte)0x23);
byte x = (byte) vh.getOpaque(recv); byte x = (byte) vh.getOpaque(recv);
assertEquals(x, (byte)2, "setOpaque byte value"); assertEquals(x, (byte)0x23, "setOpaque byte value");
} }
vh.set(recv, (byte)0x01);
// Compare
{
boolean r = vh.compareAndSet(recv, (byte)0x01, (byte)0x23);
assertEquals(r, true, "success compareAndSet byte");
byte x = (byte) vh.get(recv);
assertEquals(x, (byte)0x23, "success compareAndSet byte value");
}
{
boolean r = vh.compareAndSet(recv, (byte)0x01, (byte)0x45);
assertEquals(r, false, "failing compareAndSet byte");
byte x = (byte) vh.get(recv);
assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
}
{
byte r = (byte) vh.compareAndExchange(recv, (byte)0x23, (byte)0x01);
assertEquals(r, (byte)0x23, "success compareAndExchange byte");
byte x = (byte) vh.get(recv);
assertEquals(x, (byte)0x01, "success compareAndExchange byte value");
}
{
byte r = (byte) vh.compareAndExchange(recv, (byte)0x23, (byte)0x45);
assertEquals(r, (byte)0x01, "failing compareAndExchange byte");
byte x = (byte) vh.get(recv);
assertEquals(x, (byte)0x01, "failing compareAndExchange byte value");
}
{
byte r = (byte) vh.compareAndExchangeAcquire(recv, (byte)0x01, (byte)0x23);
assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
byte x = (byte) vh.get(recv);
assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
}
{
byte r = (byte) vh.compareAndExchangeAcquire(recv, (byte)0x01, (byte)0x45);
assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
byte x = (byte) vh.get(recv);
assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
}
{
byte r = (byte) vh.compareAndExchangeRelease(recv, (byte)0x23, (byte)0x01);
assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
byte x = (byte) vh.get(recv);
assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
}
{
byte r = (byte) vh.compareAndExchangeRelease(recv, (byte)0x23, (byte)0x45);
assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
byte x = (byte) vh.get(recv);
assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(recv, (byte)0x01, (byte)0x23);
}
assertEquals(success, true, "weakCompareAndSet byte");
byte x = (byte) vh.get(recv);
assertEquals(x, (byte)0x23, "weakCompareAndSet byte value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(recv, (byte)0x23, (byte)0x01);
}
assertEquals(success, true, "weakCompareAndSetAcquire byte");
byte x = (byte) vh.get(recv);
assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(recv, (byte)0x01, (byte)0x23);
}
assertEquals(success, true, "weakCompareAndSetRelease byte");
byte x = (byte) vh.get(recv);
assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetVolatile(recv, (byte)0x23, (byte)0x01);
}
assertEquals(success, true, "weakCompareAndSetVolatile byte");
byte x = (byte) vh.get(recv);
assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte value");
}
// Compare set and get
{
byte o = (byte) vh.getAndSet(recv, (byte)0x23);
assertEquals(o, (byte)0x01, "getAndSet byte");
byte x = (byte) vh.get(recv);
assertEquals(x, (byte)0x23, "getAndSet byte value");
}
vh.set(recv, (byte)0x01);
// get and add, add and get
{
byte o = (byte) vh.getAndAdd(recv, (byte)0x45);
assertEquals(o, (byte)0x01, "getAndAdd byte");
byte c = (byte) vh.addAndGet(recv, (byte)0x45);
assertEquals(c, (byte)((byte)0x01 + (byte)0x45 + (byte)0x45), "getAndAdd byte value");
}
} }
static void testInstanceFieldUnsupported(VarHandleTestAccessByte recv, VarHandle vh) { static void testInstanceFieldUnsupported(VarHandleTestAccessByte recv, VarHandle vh) {
checkUOE(() -> {
boolean r = vh.compareAndSet(recv, (byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.compareAndExchangeVolatile(recv, (byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.compareAndExchangeAcquire(recv, (byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.compareAndExchangeRelease(recv, (byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(recv, (byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(recv, (byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(recv, (byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(recv, (byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.getAndSet(recv, (byte)1);
});
checkUOE(() -> {
byte o = (byte) vh.getAndAdd(recv, (byte)1);
});
checkUOE(() -> {
byte o = (byte) vh.addAndGet(recv, (byte)1);
});
} }
static void testStaticField(VarHandle vh) { static void testStaticField(VarHandle vh) {
// Plain // Plain
{ {
vh.set((byte)1); vh.set((byte)0x01);
byte x = (byte) vh.get(); byte x = (byte) vh.get();
assertEquals(x, (byte)1, "set byte value"); assertEquals(x, (byte)0x01, "set byte value");
} }
// Volatile // Volatile
{ {
vh.setVolatile((byte)2); vh.setVolatile((byte)0x23);
byte x = (byte) vh.getVolatile(); byte x = (byte) vh.getVolatile();
assertEquals(x, (byte)2, "setVolatile byte value"); assertEquals(x, (byte)0x23, "setVolatile byte value");
} }
// Lazy // Lazy
{ {
vh.setRelease((byte)1); vh.setRelease((byte)0x01);
byte x = (byte) vh.getAcquire(); byte x = (byte) vh.getAcquire();
assertEquals(x, (byte)1, "setRelease byte value"); assertEquals(x, (byte)0x01, "setRelease byte value");
} }
// Opaque // Opaque
{ {
vh.setOpaque((byte)2); vh.setOpaque((byte)0x23);
byte x = (byte) vh.getOpaque(); byte x = (byte) vh.getOpaque();
assertEquals(x, (byte)2, "setOpaque byte value"); assertEquals(x, (byte)0x23, "setOpaque byte value");
} }
vh.set((byte)0x01);
// Compare
{
boolean r = vh.compareAndSet((byte)0x01, (byte)0x23);
assertEquals(r, true, "success compareAndSet byte");
byte x = (byte) vh.get();
assertEquals(x, (byte)0x23, "success compareAndSet byte value");
}
{
boolean r = vh.compareAndSet((byte)0x01, (byte)0x45);
assertEquals(r, false, "failing compareAndSet byte");
byte x = (byte) vh.get();
assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
}
{
byte r = (byte) vh.compareAndExchange((byte)0x23, (byte)0x01);
assertEquals(r, (byte)0x23, "success compareAndExchange byte");
byte x = (byte) vh.get();
assertEquals(x, (byte)0x01, "success compareAndExchange byte value");
}
{
byte r = (byte) vh.compareAndExchange((byte)0x23, (byte)0x45);
assertEquals(r, (byte)0x01, "failing compareAndExchange byte");
byte x = (byte) vh.get();
assertEquals(x, (byte)0x01, "failing compareAndExchange byte value");
}
{
byte r = (byte) vh.compareAndExchangeAcquire((byte)0x01, (byte)0x23);
assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
byte x = (byte) vh.get();
assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
}
{
byte r = (byte) vh.compareAndExchangeAcquire((byte)0x01, (byte)0x45);
assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
byte x = (byte) vh.get();
assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
}
{
byte r = (byte) vh.compareAndExchangeRelease((byte)0x23, (byte)0x01);
assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
byte x = (byte) vh.get();
assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
}
{
byte r = (byte) vh.compareAndExchangeRelease((byte)0x23, (byte)0x45);
assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
byte x = (byte) vh.get();
assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet((byte)0x01, (byte)0x23);
}
assertEquals(success, true, "weakCompareAndSet byte");
byte x = (byte) vh.get();
assertEquals(x, (byte)0x23, "weakCompareAndSet byte value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire((byte)0x23, (byte)0x01);
}
assertEquals(success, true, "weakCompareAndSetAcquire byte");
byte x = (byte) vh.get();
assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease((byte)0x01, (byte)0x23);
}
assertEquals(success, true, "weakCompareAndSetRelease byte");
byte x = (byte) vh.get();
assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease((byte)0x23, (byte)0x01);
}
assertEquals(success, true, "weakCompareAndSetVolatile byte");
byte x = (byte) vh.get();
assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte");
}
// Compare set and get
{
byte o = (byte) vh.getAndSet((byte)0x23);
assertEquals(o, (byte)0x01, "getAndSet byte");
byte x = (byte) vh.get();
assertEquals(x, (byte)0x23, "getAndSet byte value");
}
vh.set((byte)0x01);
// get and add, add and get
{
byte o = (byte) vh.getAndAdd( (byte)0x45);
assertEquals(o, (byte)0x01, "getAndAdd byte");
byte c = (byte) vh.addAndGet((byte)0x45);
assertEquals(c, (byte)((byte)0x01 + (byte)0x45 + (byte)0x45), "getAndAdd byte value");
}
} }
static void testStaticFieldUnsupported(VarHandle vh) { static void testStaticFieldUnsupported(VarHandle vh) {
checkUOE(() -> {
boolean r = vh.compareAndSet((byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.compareAndExchangeVolatile((byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.compareAndExchangeAcquire((byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.compareAndExchangeRelease((byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet((byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile((byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire((byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease((byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.getAndSet((byte)1);
});
checkUOE(() -> {
byte o = (byte) vh.getAndAdd((byte)1);
});
checkUOE(() -> {
byte o = (byte) vh.addAndGet((byte)1);
});
} }
@ -562,34 +624,149 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest {
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
// Plain // Plain
{ {
vh.set(array, i, (byte)1); vh.set(array, i, (byte)0x01);
byte x = (byte) vh.get(array, i); byte x = (byte) vh.get(array, i);
assertEquals(x, (byte)1, "get byte value"); assertEquals(x, (byte)0x01, "get byte value");
} }
// Volatile // Volatile
{ {
vh.setVolatile(array, i, (byte)2); vh.setVolatile(array, i, (byte)0x23);
byte x = (byte) vh.getVolatile(array, i); byte x = (byte) vh.getVolatile(array, i);
assertEquals(x, (byte)2, "setVolatile byte value"); assertEquals(x, (byte)0x23, "setVolatile byte value");
} }
// Lazy // Lazy
{ {
vh.setRelease(array, i, (byte)1); vh.setRelease(array, i, (byte)0x01);
byte x = (byte) vh.getAcquire(array, i); byte x = (byte) vh.getAcquire(array, i);
assertEquals(x, (byte)1, "setRelease byte value"); assertEquals(x, (byte)0x01, "setRelease byte value");
} }
// Opaque // Opaque
{ {
vh.setOpaque(array, i, (byte)2); vh.setOpaque(array, i, (byte)0x23);
byte x = (byte) vh.getOpaque(array, i); byte x = (byte) vh.getOpaque(array, i);
assertEquals(x, (byte)2, "setOpaque byte value"); assertEquals(x, (byte)0x23, "setOpaque byte value");
} }
vh.set(array, i, (byte)0x01);
// Compare
{
boolean r = vh.compareAndSet(array, i, (byte)0x01, (byte)0x23);
assertEquals(r, true, "success compareAndSet byte");
byte x = (byte) vh.get(array, i);
assertEquals(x, (byte)0x23, "success compareAndSet byte value");
}
{
boolean r = vh.compareAndSet(array, i, (byte)0x01, (byte)0x45);
assertEquals(r, false, "failing compareAndSet byte");
byte x = (byte) vh.get(array, i);
assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
}
{
byte r = (byte) vh.compareAndExchange(array, i, (byte)0x23, (byte)0x01);
assertEquals(r, (byte)0x23, "success compareAndExchange byte");
byte x = (byte) vh.get(array, i);
assertEquals(x, (byte)0x01, "success compareAndExchange byte value");
}
{
byte r = (byte) vh.compareAndExchange(array, i, (byte)0x23, (byte)0x45);
assertEquals(r, (byte)0x01, "failing compareAndExchange byte");
byte x = (byte) vh.get(array, i);
assertEquals(x, (byte)0x01, "failing compareAndExchange byte value");
}
{
byte r = (byte) vh.compareAndExchangeAcquire(array, i, (byte)0x01, (byte)0x23);
assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
byte x = (byte) vh.get(array, i);
assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
}
{
byte r = (byte) vh.compareAndExchangeAcquire(array, i, (byte)0x01, (byte)0x45);
assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
byte x = (byte) vh.get(array, i);
assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
}
{
byte r = (byte) vh.compareAndExchangeRelease(array, i, (byte)0x23, (byte)0x01);
assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
byte x = (byte) vh.get(array, i);
assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
}
{
byte r = (byte) vh.compareAndExchangeRelease(array, i, (byte)0x23, (byte)0x45);
assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
byte x = (byte) vh.get(array, i);
assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(array, i, (byte)0x01, (byte)0x23);
}
assertEquals(success, true, "weakCompareAndSet byte");
byte x = (byte) vh.get(array, i);
assertEquals(x, (byte)0x23, "weakCompareAndSet byte value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(array, i, (byte)0x23, (byte)0x01);
}
assertEquals(success, true, "weakCompareAndSetAcquire byte");
byte x = (byte) vh.get(array, i);
assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(array, i, (byte)0x01, (byte)0x23);
}
assertEquals(success, true, "weakCompareAndSetRelease byte");
byte x = (byte) vh.get(array, i);
assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetVolatile(array, i, (byte)0x23, (byte)0x01);
}
assertEquals(success, true, "weakCompareAndSetVolatile byte");
byte x = (byte) vh.get(array, i);
assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte");
}
// Compare set and get
{
byte o = (byte) vh.getAndSet(array, i, (byte)0x23);
assertEquals(o, (byte)0x01, "getAndSet byte");
byte x = (byte) vh.get(array, i);
assertEquals(x, (byte)0x23, "getAndSet byte value");
}
vh.set(array, i, (byte)0x01);
// get and add, add and get
{
byte o = (byte) vh.getAndAdd(array, i, (byte)0x45);
assertEquals(o, (byte)0x01, "getAndAdd byte");
byte c = (byte) vh.addAndGet(array, i, (byte)0x45);
assertEquals(c, (byte)((byte)0x01 + (byte)0x45 + (byte)0x45), "getAndAdd byte value");
}
} }
} }
@ -597,49 +774,7 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest {
byte[] array = new byte[10]; byte[] array = new byte[10];
int i = 0; int i = 0;
checkUOE(() -> {
boolean r = vh.compareAndSet(array, i, (byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.compareAndExchangeVolatile(array, i, (byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.compareAndExchangeAcquire(array, i, (byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.compareAndExchangeRelease(array, i, (byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(array, i, (byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(array, i, (byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, i, (byte)1, (byte)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(array, i, (byte)1, (byte)2);
});
checkUOE(() -> {
byte r = (byte) vh.getAndSet(array, i, (byte)1);
});
checkUOE(() -> {
byte o = (byte) vh.getAndAdd(array, i, (byte)1);
});
checkUOE(() -> {
byte o = (byte) vh.addAndGet(array, i, (byte)1);
});
} }
static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable { static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
@ -653,7 +788,7 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.set(array, ci, (byte)1); vh.set(array, ci, (byte)0x01);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -661,7 +796,7 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.setVolatile(array, ci, (byte)1); vh.setVolatile(array, ci, (byte)0x01);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -669,7 +804,7 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.setRelease(array, ci, (byte)1); vh.setRelease(array, ci, (byte)0x01);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -677,10 +812,52 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.setOpaque(array, ci, (byte)1); vh.setOpaque(array, ci, (byte)0x01);
}); });
checkIOOBE(() -> {
boolean r = vh.compareAndSet(array, ci, (byte)0x01, (byte)0x23);
});
checkIOOBE(() -> {
byte r = (byte) vh.compareAndExchange(array, ci, (byte)0x23, (byte)0x01);
});
checkIOOBE(() -> {
byte r = (byte) vh.compareAndExchangeAcquire(array, ci, (byte)0x23, (byte)0x01);
});
checkIOOBE(() -> {
byte r = (byte) vh.compareAndExchangeRelease(array, ci, (byte)0x23, (byte)0x01);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSet(array, ci, (byte)0x01, (byte)0x23);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetVolatile(array, ci, (byte)0x01, (byte)0x23);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, ci, (byte)0x01, (byte)0x23);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetRelease(array, ci, (byte)0x01, (byte)0x23);
});
checkIOOBE(() -> {
byte o = (byte) vh.getAndSet(array, ci, (byte)0x01);
});
checkIOOBE(() -> {
byte o = (byte) vh.getAndAdd(array, ci, (byte)0x45);
});
checkIOOBE(() -> {
byte o = (byte) vh.addAndGet(array, ci, (byte)0x45);
});
} }
} }
} }

View file

@ -42,11 +42,11 @@ import java.util.List;
import static org.testng.Assert.*; import static org.testng.Assert.*;
public class VarHandleTestAccessChar extends VarHandleBaseTest { public class VarHandleTestAccessChar extends VarHandleBaseTest {
static final char static_final_v = 'a'; static final char static_final_v = '\u0123';
static char static_v; static char static_v;
final char final_v = 'a'; final char final_v = '\u0123';
char v; char v;
@ -99,18 +99,18 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET));
} }
@ -220,89 +220,47 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest {
// Plain // Plain
{ {
char x = (char) vh.get(recv); char x = (char) vh.get(recv);
assertEquals(x, 'a', "get char value"); assertEquals(x, '\u0123', "get char value");
} }
// Volatile // Volatile
{ {
char x = (char) vh.getVolatile(recv); char x = (char) vh.getVolatile(recv);
assertEquals(x, 'a', "getVolatile char value"); assertEquals(x, '\u0123', "getVolatile char value");
} }
// Lazy // Lazy
{ {
char x = (char) vh.getAcquire(recv); char x = (char) vh.getAcquire(recv);
assertEquals(x, 'a', "getRelease char value"); assertEquals(x, '\u0123', "getRelease char value");
} }
// Opaque // Opaque
{ {
char x = (char) vh.getOpaque(recv); char x = (char) vh.getOpaque(recv);
assertEquals(x, 'a', "getOpaque char value"); assertEquals(x, '\u0123', "getOpaque char value");
} }
} }
static void testInstanceFinalFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh) { static void testInstanceFinalFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh) {
checkUOE(() -> { checkUOE(() -> {
vh.set(recv, 'b'); vh.set(recv, '\u4567');
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setVolatile(recv, 'b'); vh.setVolatile(recv, '\u4567');
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setRelease(recv, 'b'); vh.setRelease(recv, '\u4567');
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setOpaque(recv, 'b'); vh.setOpaque(recv, '\u4567');
}); });
checkUOE(() -> {
boolean r = vh.compareAndSet(recv, 'a', 'b');
});
checkUOE(() -> {
char r = (char) vh.compareAndExchangeVolatile(recv, 'a', 'b');
});
checkUOE(() -> {
char r = (char) vh.compareAndExchangeAcquire(recv, 'a', 'b');
});
checkUOE(() -> {
char r = (char) vh.compareAndExchangeRelease(recv, 'a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(recv, 'a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(recv, 'a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(recv, 'a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(recv, 'a', 'b');
});
checkUOE(() -> {
char r = (char) vh.getAndSet(recv, 'a');
});
checkUOE(() -> {
char o = (char) vh.getAndAdd(recv, 'a');
});
checkUOE(() -> {
char o = (char) vh.addAndGet(recv, 'a');
});
} }
@ -310,249 +268,353 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest {
// Plain // Plain
{ {
char x = (char) vh.get(); char x = (char) vh.get();
assertEquals(x, 'a', "get char value"); assertEquals(x, '\u0123', "get char value");
} }
// Volatile // Volatile
{ {
char x = (char) vh.getVolatile(); char x = (char) vh.getVolatile();
assertEquals(x, 'a', "getVolatile char value"); assertEquals(x, '\u0123', "getVolatile char value");
} }
// Lazy // Lazy
{ {
char x = (char) vh.getAcquire(); char x = (char) vh.getAcquire();
assertEquals(x, 'a', "getRelease char value"); assertEquals(x, '\u0123', "getRelease char value");
} }
// Opaque // Opaque
{ {
char x = (char) vh.getOpaque(); char x = (char) vh.getOpaque();
assertEquals(x, 'a', "getOpaque char value"); assertEquals(x, '\u0123', "getOpaque char value");
} }
} }
static void testStaticFinalFieldUnsupported(VarHandle vh) { static void testStaticFinalFieldUnsupported(VarHandle vh) {
checkUOE(() -> { checkUOE(() -> {
vh.set('b'); vh.set('\u4567');
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setVolatile('b'); vh.setVolatile('\u4567');
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setRelease('b'); vh.setRelease('\u4567');
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setOpaque('b'); vh.setOpaque('\u4567');
}); });
checkUOE(() -> {
boolean r = vh.compareAndSet('a', 'b');
});
checkUOE(() -> {
char r = (char) vh.compareAndExchangeVolatile('a', 'b');
});
checkUOE(() -> {
char r = (char) vh.compareAndExchangeAcquire('a', 'b');
});
checkUOE(() -> {
char r = (char) vh.compareAndExchangeRelease('a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet('a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile('a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire('a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease('a', 'b');
});
checkUOE(() -> {
char r = (char) vh.getAndSet('a');
});
checkUOE(() -> {
char o = (char) vh.getAndAdd('a');
});
checkUOE(() -> {
char o = (char) vh.addAndGet('a');
});
} }
static void testInstanceField(VarHandleTestAccessChar recv, VarHandle vh) { static void testInstanceField(VarHandleTestAccessChar recv, VarHandle vh) {
// Plain // Plain
{ {
vh.set(recv, 'a'); vh.set(recv, '\u0123');
char x = (char) vh.get(recv); char x = (char) vh.get(recv);
assertEquals(x, 'a', "set char value"); assertEquals(x, '\u0123', "set char value");
} }
// Volatile // Volatile
{ {
vh.setVolatile(recv, 'b'); vh.setVolatile(recv, '\u4567');
char x = (char) vh.getVolatile(recv); char x = (char) vh.getVolatile(recv);
assertEquals(x, 'b', "setVolatile char value"); assertEquals(x, '\u4567', "setVolatile char value");
} }
// Lazy // Lazy
{ {
vh.setRelease(recv, 'a'); vh.setRelease(recv, '\u0123');
char x = (char) vh.getAcquire(recv); char x = (char) vh.getAcquire(recv);
assertEquals(x, 'a', "setRelease char value"); assertEquals(x, '\u0123', "setRelease char value");
} }
// Opaque // Opaque
{ {
vh.setOpaque(recv, 'b'); vh.setOpaque(recv, '\u4567');
char x = (char) vh.getOpaque(recv); char x = (char) vh.getOpaque(recv);
assertEquals(x, 'b', "setOpaque char value"); assertEquals(x, '\u4567', "setOpaque char value");
} }
vh.set(recv, '\u0123');
// Compare
{
boolean r = vh.compareAndSet(recv, '\u0123', '\u4567');
assertEquals(r, true, "success compareAndSet char");
char x = (char) vh.get(recv);
assertEquals(x, '\u4567', "success compareAndSet char value");
}
{
boolean r = vh.compareAndSet(recv, '\u0123', '\u89AB');
assertEquals(r, false, "failing compareAndSet char");
char x = (char) vh.get(recv);
assertEquals(x, '\u4567', "failing compareAndSet char value");
}
{
char r = (char) vh.compareAndExchange(recv, '\u4567', '\u0123');
assertEquals(r, '\u4567', "success compareAndExchange char");
char x = (char) vh.get(recv);
assertEquals(x, '\u0123', "success compareAndExchange char value");
}
{
char r = (char) vh.compareAndExchange(recv, '\u4567', '\u89AB');
assertEquals(r, '\u0123', "failing compareAndExchange char");
char x = (char) vh.get(recv);
assertEquals(x, '\u0123', "failing compareAndExchange char value");
}
{
char r = (char) vh.compareAndExchangeAcquire(recv, '\u0123', '\u4567');
assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
char x = (char) vh.get(recv);
assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
}
{
char r = (char) vh.compareAndExchangeAcquire(recv, '\u0123', '\u89AB');
assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
char x = (char) vh.get(recv);
assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
}
{
char r = (char) vh.compareAndExchangeRelease(recv, '\u4567', '\u0123');
assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
char x = (char) vh.get(recv);
assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
}
{
char r = (char) vh.compareAndExchangeRelease(recv, '\u4567', '\u89AB');
assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
char x = (char) vh.get(recv);
assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(recv, '\u0123', '\u4567');
}
assertEquals(success, true, "weakCompareAndSet char");
char x = (char) vh.get(recv);
assertEquals(x, '\u4567', "weakCompareAndSet char value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(recv, '\u4567', '\u0123');
}
assertEquals(success, true, "weakCompareAndSetAcquire char");
char x = (char) vh.get(recv);
assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(recv, '\u0123', '\u4567');
}
assertEquals(success, true, "weakCompareAndSetRelease char");
char x = (char) vh.get(recv);
assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetVolatile(recv, '\u4567', '\u0123');
}
assertEquals(success, true, "weakCompareAndSetVolatile char");
char x = (char) vh.get(recv);
assertEquals(x, '\u0123', "weakCompareAndSetVolatile char value");
}
// Compare set and get
{
char o = (char) vh.getAndSet(recv, '\u4567');
assertEquals(o, '\u0123', "getAndSet char");
char x = (char) vh.get(recv);
assertEquals(x, '\u4567', "getAndSet char value");
}
vh.set(recv, '\u0123');
// get and add, add and get
{
char o = (char) vh.getAndAdd(recv, '\u89AB');
assertEquals(o, '\u0123', "getAndAdd char");
char c = (char) vh.addAndGet(recv, '\u89AB');
assertEquals(c, (char)('\u0123' + '\u89AB' + '\u89AB'), "getAndAdd char value");
}
} }
static void testInstanceFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh) { static void testInstanceFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh) {
checkUOE(() -> {
boolean r = vh.compareAndSet(recv, 'a', 'b');
});
checkUOE(() -> {
char r = (char) vh.compareAndExchangeVolatile(recv, 'a', 'b');
});
checkUOE(() -> {
char r = (char) vh.compareAndExchangeAcquire(recv, 'a', 'b');
});
checkUOE(() -> {
char r = (char) vh.compareAndExchangeRelease(recv, 'a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(recv, 'a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(recv, 'a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(recv, 'a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(recv, 'a', 'b');
});
checkUOE(() -> {
char r = (char) vh.getAndSet(recv, 'a');
});
checkUOE(() -> {
char o = (char) vh.getAndAdd(recv, 'a');
});
checkUOE(() -> {
char o = (char) vh.addAndGet(recv, 'a');
});
} }
static void testStaticField(VarHandle vh) { static void testStaticField(VarHandle vh) {
// Plain // Plain
{ {
vh.set('a'); vh.set('\u0123');
char x = (char) vh.get(); char x = (char) vh.get();
assertEquals(x, 'a', "set char value"); assertEquals(x, '\u0123', "set char value");
} }
// Volatile // Volatile
{ {
vh.setVolatile('b'); vh.setVolatile('\u4567');
char x = (char) vh.getVolatile(); char x = (char) vh.getVolatile();
assertEquals(x, 'b', "setVolatile char value"); assertEquals(x, '\u4567', "setVolatile char value");
} }
// Lazy // Lazy
{ {
vh.setRelease('a'); vh.setRelease('\u0123');
char x = (char) vh.getAcquire(); char x = (char) vh.getAcquire();
assertEquals(x, 'a', "setRelease char value"); assertEquals(x, '\u0123', "setRelease char value");
} }
// Opaque // Opaque
{ {
vh.setOpaque('b'); vh.setOpaque('\u4567');
char x = (char) vh.getOpaque(); char x = (char) vh.getOpaque();
assertEquals(x, 'b', "setOpaque char value"); assertEquals(x, '\u4567', "setOpaque char value");
} }
vh.set('\u0123');
// Compare
{
boolean r = vh.compareAndSet('\u0123', '\u4567');
assertEquals(r, true, "success compareAndSet char");
char x = (char) vh.get();
assertEquals(x, '\u4567', "success compareAndSet char value");
}
{
boolean r = vh.compareAndSet('\u0123', '\u89AB');
assertEquals(r, false, "failing compareAndSet char");
char x = (char) vh.get();
assertEquals(x, '\u4567', "failing compareAndSet char value");
}
{
char r = (char) vh.compareAndExchange('\u4567', '\u0123');
assertEquals(r, '\u4567', "success compareAndExchange char");
char x = (char) vh.get();
assertEquals(x, '\u0123', "success compareAndExchange char value");
}
{
char r = (char) vh.compareAndExchange('\u4567', '\u89AB');
assertEquals(r, '\u0123', "failing compareAndExchange char");
char x = (char) vh.get();
assertEquals(x, '\u0123', "failing compareAndExchange char value");
}
{
char r = (char) vh.compareAndExchangeAcquire('\u0123', '\u4567');
assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
char x = (char) vh.get();
assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
}
{
char r = (char) vh.compareAndExchangeAcquire('\u0123', '\u89AB');
assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
char x = (char) vh.get();
assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
}
{
char r = (char) vh.compareAndExchangeRelease('\u4567', '\u0123');
assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
char x = (char) vh.get();
assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
}
{
char r = (char) vh.compareAndExchangeRelease('\u4567', '\u89AB');
assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
char x = (char) vh.get();
assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet('\u0123', '\u4567');
}
assertEquals(success, true, "weakCompareAndSet char");
char x = (char) vh.get();
assertEquals(x, '\u4567', "weakCompareAndSet char value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire('\u4567', '\u0123');
}
assertEquals(success, true, "weakCompareAndSetAcquire char");
char x = (char) vh.get();
assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease('\u0123', '\u4567');
}
assertEquals(success, true, "weakCompareAndSetRelease char");
char x = (char) vh.get();
assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease('\u4567', '\u0123');
}
assertEquals(success, true, "weakCompareAndSetVolatile char");
char x = (char) vh.get();
assertEquals(x, '\u0123', "weakCompareAndSetVolatile char");
}
// Compare set and get
{
char o = (char) vh.getAndSet('\u4567');
assertEquals(o, '\u0123', "getAndSet char");
char x = (char) vh.get();
assertEquals(x, '\u4567', "getAndSet char value");
}
vh.set('\u0123');
// get and add, add and get
{
char o = (char) vh.getAndAdd( '\u89AB');
assertEquals(o, '\u0123', "getAndAdd char");
char c = (char) vh.addAndGet('\u89AB');
assertEquals(c, (char)('\u0123' + '\u89AB' + '\u89AB'), "getAndAdd char value");
}
} }
static void testStaticFieldUnsupported(VarHandle vh) { static void testStaticFieldUnsupported(VarHandle vh) {
checkUOE(() -> {
boolean r = vh.compareAndSet('a', 'b');
});
checkUOE(() -> {
char r = (char) vh.compareAndExchangeVolatile('a', 'b');
});
checkUOE(() -> {
char r = (char) vh.compareAndExchangeAcquire('a', 'b');
});
checkUOE(() -> {
char r = (char) vh.compareAndExchangeRelease('a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet('a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile('a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire('a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease('a', 'b');
});
checkUOE(() -> {
char r = (char) vh.getAndSet('a');
});
checkUOE(() -> {
char o = (char) vh.getAndAdd('a');
});
checkUOE(() -> {
char o = (char) vh.addAndGet('a');
});
} }
@ -562,34 +624,149 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest {
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
// Plain // Plain
{ {
vh.set(array, i, 'a'); vh.set(array, i, '\u0123');
char x = (char) vh.get(array, i); char x = (char) vh.get(array, i);
assertEquals(x, 'a', "get char value"); assertEquals(x, '\u0123', "get char value");
} }
// Volatile // Volatile
{ {
vh.setVolatile(array, i, 'b'); vh.setVolatile(array, i, '\u4567');
char x = (char) vh.getVolatile(array, i); char x = (char) vh.getVolatile(array, i);
assertEquals(x, 'b', "setVolatile char value"); assertEquals(x, '\u4567', "setVolatile char value");
} }
// Lazy // Lazy
{ {
vh.setRelease(array, i, 'a'); vh.setRelease(array, i, '\u0123');
char x = (char) vh.getAcquire(array, i); char x = (char) vh.getAcquire(array, i);
assertEquals(x, 'a', "setRelease char value"); assertEquals(x, '\u0123', "setRelease char value");
} }
// Opaque // Opaque
{ {
vh.setOpaque(array, i, 'b'); vh.setOpaque(array, i, '\u4567');
char x = (char) vh.getOpaque(array, i); char x = (char) vh.getOpaque(array, i);
assertEquals(x, 'b', "setOpaque char value"); assertEquals(x, '\u4567', "setOpaque char value");
} }
vh.set(array, i, '\u0123');
// Compare
{
boolean r = vh.compareAndSet(array, i, '\u0123', '\u4567');
assertEquals(r, true, "success compareAndSet char");
char x = (char) vh.get(array, i);
assertEquals(x, '\u4567', "success compareAndSet char value");
}
{
boolean r = vh.compareAndSet(array, i, '\u0123', '\u89AB');
assertEquals(r, false, "failing compareAndSet char");
char x = (char) vh.get(array, i);
assertEquals(x, '\u4567', "failing compareAndSet char value");
}
{
char r = (char) vh.compareAndExchange(array, i, '\u4567', '\u0123');
assertEquals(r, '\u4567', "success compareAndExchange char");
char x = (char) vh.get(array, i);
assertEquals(x, '\u0123', "success compareAndExchange char value");
}
{
char r = (char) vh.compareAndExchange(array, i, '\u4567', '\u89AB');
assertEquals(r, '\u0123', "failing compareAndExchange char");
char x = (char) vh.get(array, i);
assertEquals(x, '\u0123', "failing compareAndExchange char value");
}
{
char r = (char) vh.compareAndExchangeAcquire(array, i, '\u0123', '\u4567');
assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
char x = (char) vh.get(array, i);
assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
}
{
char r = (char) vh.compareAndExchangeAcquire(array, i, '\u0123', '\u89AB');
assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
char x = (char) vh.get(array, i);
assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
}
{
char r = (char) vh.compareAndExchangeRelease(array, i, '\u4567', '\u0123');
assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
char x = (char) vh.get(array, i);
assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
}
{
char r = (char) vh.compareAndExchangeRelease(array, i, '\u4567', '\u89AB');
assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
char x = (char) vh.get(array, i);
assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(array, i, '\u0123', '\u4567');
}
assertEquals(success, true, "weakCompareAndSet char");
char x = (char) vh.get(array, i);
assertEquals(x, '\u4567', "weakCompareAndSet char value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(array, i, '\u4567', '\u0123');
}
assertEquals(success, true, "weakCompareAndSetAcquire char");
char x = (char) vh.get(array, i);
assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(array, i, '\u0123', '\u4567');
}
assertEquals(success, true, "weakCompareAndSetRelease char");
char x = (char) vh.get(array, i);
assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetVolatile(array, i, '\u4567', '\u0123');
}
assertEquals(success, true, "weakCompareAndSetVolatile char");
char x = (char) vh.get(array, i);
assertEquals(x, '\u0123', "weakCompareAndSetVolatile char");
}
// Compare set and get
{
char o = (char) vh.getAndSet(array, i, '\u4567');
assertEquals(o, '\u0123', "getAndSet char");
char x = (char) vh.get(array, i);
assertEquals(x, '\u4567', "getAndSet char value");
}
vh.set(array, i, '\u0123');
// get and add, add and get
{
char o = (char) vh.getAndAdd(array, i, '\u89AB');
assertEquals(o, '\u0123', "getAndAdd char");
char c = (char) vh.addAndGet(array, i, '\u89AB');
assertEquals(c, (char)('\u0123' + '\u89AB' + '\u89AB'), "getAndAdd char value");
}
} }
} }
@ -597,49 +774,7 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest {
char[] array = new char[10]; char[] array = new char[10];
int i = 0; int i = 0;
checkUOE(() -> {
boolean r = vh.compareAndSet(array, i, 'a', 'b');
});
checkUOE(() -> {
char r = (char) vh.compareAndExchangeVolatile(array, i, 'a', 'b');
});
checkUOE(() -> {
char r = (char) vh.compareAndExchangeAcquire(array, i, 'a', 'b');
});
checkUOE(() -> {
char r = (char) vh.compareAndExchangeRelease(array, i, 'a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(array, i, 'a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(array, i, 'a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, i, 'a', 'b');
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(array, i, 'a', 'b');
});
checkUOE(() -> {
char r = (char) vh.getAndSet(array, i, 'a');
});
checkUOE(() -> {
char o = (char) vh.getAndAdd(array, i, 'a');
});
checkUOE(() -> {
char o = (char) vh.addAndGet(array, i, 'a');
});
} }
static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable { static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
@ -653,7 +788,7 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.set(array, ci, 'a'); vh.set(array, ci, '\u0123');
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -661,7 +796,7 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.setVolatile(array, ci, 'a'); vh.setVolatile(array, ci, '\u0123');
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -669,7 +804,7 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.setRelease(array, ci, 'a'); vh.setRelease(array, ci, '\u0123');
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -677,10 +812,52 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.setOpaque(array, ci, 'a'); vh.setOpaque(array, ci, '\u0123');
}); });
checkIOOBE(() -> {
boolean r = vh.compareAndSet(array, ci, '\u0123', '\u4567');
});
checkIOOBE(() -> {
char r = (char) vh.compareAndExchange(array, ci, '\u4567', '\u0123');
});
checkIOOBE(() -> {
char r = (char) vh.compareAndExchangeAcquire(array, ci, '\u4567', '\u0123');
});
checkIOOBE(() -> {
char r = (char) vh.compareAndExchangeRelease(array, ci, '\u4567', '\u0123');
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSet(array, ci, '\u0123', '\u4567');
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetVolatile(array, ci, '\u0123', '\u4567');
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, ci, '\u0123', '\u4567');
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetRelease(array, ci, '\u0123', '\u4567');
});
checkIOOBE(() -> {
char o = (char) vh.getAndSet(array, ci, '\u0123');
});
checkIOOBE(() -> {
char o = (char) vh.getAndAdd(array, ci, '\u89AB');
});
checkIOOBE(() -> {
char o = (char) vh.addAndGet(array, ci, '\u89AB');
});
} }
} }
} }

View file

@ -99,18 +99,18 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET));
} }
@ -260,49 +260,7 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
vh.setOpaque(recv, 2.0d); vh.setOpaque(recv, 2.0d);
}); });
checkUOE(() -> {
boolean r = vh.compareAndSet(recv, 1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.compareAndExchangeVolatile(recv, 1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.compareAndExchangeAcquire(recv, 1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.compareAndExchangeRelease(recv, 1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(recv, 1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(recv, 1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(recv, 1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(recv, 1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.getAndSet(recv, 1.0d);
});
checkUOE(() -> {
double o = (double) vh.getAndAdd(recv, 1.0d);
});
checkUOE(() -> {
double o = (double) vh.addAndGet(recv, 1.0d);
});
} }
@ -350,49 +308,7 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
vh.setOpaque(2.0d); vh.setOpaque(2.0d);
}); });
checkUOE(() -> {
boolean r = vh.compareAndSet(1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.compareAndExchangeVolatile(1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.compareAndExchangeAcquire(1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.compareAndExchangeRelease(1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.getAndSet(1.0d);
});
checkUOE(() -> {
double o = (double) vh.getAndAdd(1.0d);
});
checkUOE(() -> {
double o = (double) vh.addAndGet(1.0d);
});
} }
@ -426,53 +342,126 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
assertEquals(x, 2.0d, "setOpaque double value"); assertEquals(x, 2.0d, "setOpaque double value");
} }
vh.set(recv, 1.0d);
// Compare
{
boolean r = vh.compareAndSet(recv, 1.0d, 2.0d);
assertEquals(r, true, "success compareAndSet double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "success compareAndSet double value");
}
{
boolean r = vh.compareAndSet(recv, 1.0d, 3.0d);
assertEquals(r, false, "failing compareAndSet double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "failing compareAndSet double value");
}
{
double r = (double) vh.compareAndExchange(recv, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchange double");
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "success compareAndExchange double value");
}
{
double r = (double) vh.compareAndExchange(recv, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchange double");
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "failing compareAndExchange double value");
}
{
double r = (double) vh.compareAndExchangeAcquire(recv, 1.0d, 2.0d);
assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
}
{
double r = (double) vh.compareAndExchangeAcquire(recv, 1.0d, 3.0d);
assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
}
{
double r = (double) vh.compareAndExchangeRelease(recv, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
}
{
double r = (double) vh.compareAndExchangeRelease(recv, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(recv, 1.0d, 2.0d);
}
assertEquals(success, true, "weakCompareAndSet double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "weakCompareAndSet double value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(recv, 2.0d, 1.0d);
}
assertEquals(success, true, "weakCompareAndSetAcquire double");
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "weakCompareAndSetAcquire double");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(recv, 1.0d, 2.0d);
}
assertEquals(success, true, "weakCompareAndSetRelease double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "weakCompareAndSetRelease double");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetVolatile(recv, 2.0d, 1.0d);
}
assertEquals(success, true, "weakCompareAndSetVolatile double");
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "weakCompareAndSetVolatile double value");
}
// Compare set and get
{
double o = (double) vh.getAndSet(recv, 2.0d);
assertEquals(o, 1.0d, "getAndSet double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "getAndSet double value");
}
vh.set(recv, 1.0d);
// get and add, add and get
{
double o = (double) vh.getAndAdd(recv, 3.0d);
assertEquals(o, 1.0d, "getAndAdd double");
double c = (double) vh.addAndGet(recv, 3.0d);
assertEquals(c, (double)(1.0d + 3.0d + 3.0d), "getAndAdd double value");
}
} }
static void testInstanceFieldUnsupported(VarHandleTestAccessDouble recv, VarHandle vh) { static void testInstanceFieldUnsupported(VarHandleTestAccessDouble recv, VarHandle vh) {
checkUOE(() -> {
boolean r = vh.compareAndSet(recv, 1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.compareAndExchangeVolatile(recv, 1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.compareAndExchangeAcquire(recv, 1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.compareAndExchangeRelease(recv, 1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(recv, 1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(recv, 1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(recv, 1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(recv, 1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.getAndSet(recv, 1.0d);
});
checkUOE(() -> {
double o = (double) vh.getAndAdd(recv, 1.0d);
});
checkUOE(() -> {
double o = (double) vh.addAndGet(recv, 1.0d);
});
} }
@ -506,53 +495,126 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
assertEquals(x, 2.0d, "setOpaque double value"); assertEquals(x, 2.0d, "setOpaque double value");
} }
vh.set(1.0d);
// Compare
{
boolean r = vh.compareAndSet(1.0d, 2.0d);
assertEquals(r, true, "success compareAndSet double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "success compareAndSet double value");
}
{
boolean r = vh.compareAndSet(1.0d, 3.0d);
assertEquals(r, false, "failing compareAndSet double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "failing compareAndSet double value");
}
{
double r = (double) vh.compareAndExchange(2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchange double");
double x = (double) vh.get();
assertEquals(x, 1.0d, "success compareAndExchange double value");
}
{
double r = (double) vh.compareAndExchange(2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchange double");
double x = (double) vh.get();
assertEquals(x, 1.0d, "failing compareAndExchange double value");
}
{
double r = (double) vh.compareAndExchangeAcquire(1.0d, 2.0d);
assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
}
{
double r = (double) vh.compareAndExchangeAcquire(1.0d, 3.0d);
assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
}
{
double r = (double) vh.compareAndExchangeRelease(2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
double x = (double) vh.get();
assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
}
{
double r = (double) vh.compareAndExchangeRelease(2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
double x = (double) vh.get();
assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(1.0d, 2.0d);
}
assertEquals(success, true, "weakCompareAndSet double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "weakCompareAndSet double value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(2.0d, 1.0d);
}
assertEquals(success, true, "weakCompareAndSetAcquire double");
double x = (double) vh.get();
assertEquals(x, 1.0d, "weakCompareAndSetAcquire double");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(1.0d, 2.0d);
}
assertEquals(success, true, "weakCompareAndSetRelease double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "weakCompareAndSetRelease double");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(2.0d, 1.0d);
}
assertEquals(success, true, "weakCompareAndSetVolatile double");
double x = (double) vh.get();
assertEquals(x, 1.0d, "weakCompareAndSetVolatile double");
}
// Compare set and get
{
double o = (double) vh.getAndSet(2.0d);
assertEquals(o, 1.0d, "getAndSet double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "getAndSet double value");
}
vh.set(1.0d);
// get and add, add and get
{
double o = (double) vh.getAndAdd( 3.0d);
assertEquals(o, 1.0d, "getAndAdd double");
double c = (double) vh.addAndGet(3.0d);
assertEquals(c, (double)(1.0d + 3.0d + 3.0d), "getAndAdd double value");
}
} }
static void testStaticFieldUnsupported(VarHandle vh) { static void testStaticFieldUnsupported(VarHandle vh) {
checkUOE(() -> {
boolean r = vh.compareAndSet(1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.compareAndExchangeVolatile(1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.compareAndExchangeAcquire(1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.compareAndExchangeRelease(1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.getAndSet(1.0d);
});
checkUOE(() -> {
double o = (double) vh.getAndAdd(1.0d);
});
checkUOE(() -> {
double o = (double) vh.addAndGet(1.0d);
});
} }
@ -589,7 +651,122 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
assertEquals(x, 2.0d, "setOpaque double value"); assertEquals(x, 2.0d, "setOpaque double value");
} }
vh.set(array, i, 1.0d);
// Compare
{
boolean r = vh.compareAndSet(array, i, 1.0d, 2.0d);
assertEquals(r, true, "success compareAndSet double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "success compareAndSet double value");
}
{
boolean r = vh.compareAndSet(array, i, 1.0d, 3.0d);
assertEquals(r, false, "failing compareAndSet double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "failing compareAndSet double value");
}
{
double r = (double) vh.compareAndExchange(array, i, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchange double");
double x = (double) vh.get(array, i);
assertEquals(x, 1.0d, "success compareAndExchange double value");
}
{
double r = (double) vh.compareAndExchange(array, i, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchange double");
double x = (double) vh.get(array, i);
assertEquals(x, 1.0d, "failing compareAndExchange double value");
}
{
double r = (double) vh.compareAndExchangeAcquire(array, i, 1.0d, 2.0d);
assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
}
{
double r = (double) vh.compareAndExchangeAcquire(array, i, 1.0d, 3.0d);
assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
}
{
double r = (double) vh.compareAndExchangeRelease(array, i, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
double x = (double) vh.get(array, i);
assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
}
{
double r = (double) vh.compareAndExchangeRelease(array, i, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
double x = (double) vh.get(array, i);
assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(array, i, 1.0d, 2.0d);
}
assertEquals(success, true, "weakCompareAndSet double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "weakCompareAndSet double value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(array, i, 2.0d, 1.0d);
}
assertEquals(success, true, "weakCompareAndSetAcquire double");
double x = (double) vh.get(array, i);
assertEquals(x, 1.0d, "weakCompareAndSetAcquire double");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(array, i, 1.0d, 2.0d);
}
assertEquals(success, true, "weakCompareAndSetRelease double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "weakCompareAndSetRelease double");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetVolatile(array, i, 2.0d, 1.0d);
}
assertEquals(success, true, "weakCompareAndSetVolatile double");
double x = (double) vh.get(array, i);
assertEquals(x, 1.0d, "weakCompareAndSetVolatile double");
}
// Compare set and get
{
double o = (double) vh.getAndSet(array, i, 2.0d);
assertEquals(o, 1.0d, "getAndSet double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "getAndSet double value");
}
vh.set(array, i, 1.0d);
// get and add, add and get
{
double o = (double) vh.getAndAdd(array, i, 3.0d);
assertEquals(o, 1.0d, "getAndAdd double");
double c = (double) vh.addAndGet(array, i, 3.0d);
assertEquals(c, (double)(1.0d + 3.0d + 3.0d), "getAndAdd double value");
}
} }
} }
@ -597,49 +774,7 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
double[] array = new double[10]; double[] array = new double[10];
int i = 0; int i = 0;
checkUOE(() -> {
boolean r = vh.compareAndSet(array, i, 1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.compareAndExchangeVolatile(array, i, 1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.compareAndExchangeAcquire(array, i, 1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.compareAndExchangeRelease(array, i, 1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(array, i, 1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(array, i, 1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, i, 1.0d, 2.0d);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(array, i, 1.0d, 2.0d);
});
checkUOE(() -> {
double r = (double) vh.getAndSet(array, i, 1.0d);
});
checkUOE(() -> {
double o = (double) vh.getAndAdd(array, i, 1.0d);
});
checkUOE(() -> {
double o = (double) vh.addAndGet(array, i, 1.0d);
});
} }
static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable { static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
@ -680,7 +815,49 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
vh.setOpaque(array, ci, 1.0d); vh.setOpaque(array, ci, 1.0d);
}); });
checkIOOBE(() -> {
boolean r = vh.compareAndSet(array, ci, 1.0d, 2.0d);
});
checkIOOBE(() -> {
double r = (double) vh.compareAndExchange(array, ci, 2.0d, 1.0d);
});
checkIOOBE(() -> {
double r = (double) vh.compareAndExchangeAcquire(array, ci, 2.0d, 1.0d);
});
checkIOOBE(() -> {
double r = (double) vh.compareAndExchangeRelease(array, ci, 2.0d, 1.0d);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSet(array, ci, 1.0d, 2.0d);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetVolatile(array, ci, 1.0d, 2.0d);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, ci, 1.0d, 2.0d);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetRelease(array, ci, 1.0d, 2.0d);
});
checkIOOBE(() -> {
double o = (double) vh.getAndSet(array, ci, 1.0d);
});
checkIOOBE(() -> {
double o = (double) vh.getAndAdd(array, ci, 3.0d);
});
checkIOOBE(() -> {
double o = (double) vh.addAndGet(array, ci, 3.0d);
});
} }
} }
} }

View file

@ -99,18 +99,18 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET));
} }
@ -260,49 +260,7 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
vh.setOpaque(recv, 2.0f); vh.setOpaque(recv, 2.0f);
}); });
checkUOE(() -> {
boolean r = vh.compareAndSet(recv, 1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.compareAndExchangeVolatile(recv, 1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.compareAndExchangeRelease(recv, 1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(recv, 1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(recv, 1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(recv, 1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(recv, 1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.getAndSet(recv, 1.0f);
});
checkUOE(() -> {
float o = (float) vh.getAndAdd(recv, 1.0f);
});
checkUOE(() -> {
float o = (float) vh.addAndGet(recv, 1.0f);
});
} }
@ -350,49 +308,7 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
vh.setOpaque(2.0f); vh.setOpaque(2.0f);
}); });
checkUOE(() -> {
boolean r = vh.compareAndSet(1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.compareAndExchangeVolatile(1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.compareAndExchangeAcquire(1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.compareAndExchangeRelease(1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.getAndSet(1.0f);
});
checkUOE(() -> {
float o = (float) vh.getAndAdd(1.0f);
});
checkUOE(() -> {
float o = (float) vh.addAndGet(1.0f);
});
} }
@ -426,53 +342,126 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
assertEquals(x, 2.0f, "setOpaque float value"); assertEquals(x, 2.0f, "setOpaque float value");
} }
vh.set(recv, 1.0f);
// Compare
{
boolean r = vh.compareAndSet(recv, 1.0f, 2.0f);
assertEquals(r, true, "success compareAndSet float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "success compareAndSet float value");
}
{
boolean r = vh.compareAndSet(recv, 1.0f, 3.0f);
assertEquals(r, false, "failing compareAndSet float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "failing compareAndSet float value");
}
{
float r = (float) vh.compareAndExchange(recv, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchange float");
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "success compareAndExchange float value");
}
{
float r = (float) vh.compareAndExchange(recv, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchange float");
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "failing compareAndExchange float value");
}
{
float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 2.0f);
assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
}
{
float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 3.0f);
assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
}
{
float r = (float) vh.compareAndExchangeRelease(recv, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
}
{
float r = (float) vh.compareAndExchangeRelease(recv, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(recv, 1.0f, 2.0f);
}
assertEquals(success, true, "weakCompareAndSet float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "weakCompareAndSet float value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(recv, 2.0f, 1.0f);
}
assertEquals(success, true, "weakCompareAndSetAcquire float");
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "weakCompareAndSetAcquire float");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(recv, 1.0f, 2.0f);
}
assertEquals(success, true, "weakCompareAndSetRelease float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "weakCompareAndSetRelease float");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetVolatile(recv, 2.0f, 1.0f);
}
assertEquals(success, true, "weakCompareAndSetVolatile float");
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "weakCompareAndSetVolatile float value");
}
// Compare set and get
{
float o = (float) vh.getAndSet(recv, 2.0f);
assertEquals(o, 1.0f, "getAndSet float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "getAndSet float value");
}
vh.set(recv, 1.0f);
// get and add, add and get
{
float o = (float) vh.getAndAdd(recv, 3.0f);
assertEquals(o, 1.0f, "getAndAdd float");
float c = (float) vh.addAndGet(recv, 3.0f);
assertEquals(c, (float)(1.0f + 3.0f + 3.0f), "getAndAdd float value");
}
} }
static void testInstanceFieldUnsupported(VarHandleTestAccessFloat recv, VarHandle vh) { static void testInstanceFieldUnsupported(VarHandleTestAccessFloat recv, VarHandle vh) {
checkUOE(() -> {
boolean r = vh.compareAndSet(recv, 1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.compareAndExchangeVolatile(recv, 1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.compareAndExchangeRelease(recv, 1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(recv, 1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(recv, 1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(recv, 1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(recv, 1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.getAndSet(recv, 1.0f);
});
checkUOE(() -> {
float o = (float) vh.getAndAdd(recv, 1.0f);
});
checkUOE(() -> {
float o = (float) vh.addAndGet(recv, 1.0f);
});
} }
@ -506,53 +495,126 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
assertEquals(x, 2.0f, "setOpaque float value"); assertEquals(x, 2.0f, "setOpaque float value");
} }
vh.set(1.0f);
// Compare
{
boolean r = vh.compareAndSet(1.0f, 2.0f);
assertEquals(r, true, "success compareAndSet float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "success compareAndSet float value");
}
{
boolean r = vh.compareAndSet(1.0f, 3.0f);
assertEquals(r, false, "failing compareAndSet float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "failing compareAndSet float value");
}
{
float r = (float) vh.compareAndExchange(2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchange float");
float x = (float) vh.get();
assertEquals(x, 1.0f, "success compareAndExchange float value");
}
{
float r = (float) vh.compareAndExchange(2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchange float");
float x = (float) vh.get();
assertEquals(x, 1.0f, "failing compareAndExchange float value");
}
{
float r = (float) vh.compareAndExchangeAcquire(1.0f, 2.0f);
assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
}
{
float r = (float) vh.compareAndExchangeAcquire(1.0f, 3.0f);
assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
}
{
float r = (float) vh.compareAndExchangeRelease(2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
float x = (float) vh.get();
assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
}
{
float r = (float) vh.compareAndExchangeRelease(2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
float x = (float) vh.get();
assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(1.0f, 2.0f);
}
assertEquals(success, true, "weakCompareAndSet float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "weakCompareAndSet float value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(2.0f, 1.0f);
}
assertEquals(success, true, "weakCompareAndSetAcquire float");
float x = (float) vh.get();
assertEquals(x, 1.0f, "weakCompareAndSetAcquire float");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(1.0f, 2.0f);
}
assertEquals(success, true, "weakCompareAndSetRelease float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "weakCompareAndSetRelease float");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(2.0f, 1.0f);
}
assertEquals(success, true, "weakCompareAndSetVolatile float");
float x = (float) vh.get();
assertEquals(x, 1.0f, "weakCompareAndSetVolatile float");
}
// Compare set and get
{
float o = (float) vh.getAndSet(2.0f);
assertEquals(o, 1.0f, "getAndSet float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "getAndSet float value");
}
vh.set(1.0f);
// get and add, add and get
{
float o = (float) vh.getAndAdd( 3.0f);
assertEquals(o, 1.0f, "getAndAdd float");
float c = (float) vh.addAndGet(3.0f);
assertEquals(c, (float)(1.0f + 3.0f + 3.0f), "getAndAdd float value");
}
} }
static void testStaticFieldUnsupported(VarHandle vh) { static void testStaticFieldUnsupported(VarHandle vh) {
checkUOE(() -> {
boolean r = vh.compareAndSet(1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.compareAndExchangeVolatile(1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.compareAndExchangeAcquire(1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.compareAndExchangeRelease(1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.getAndSet(1.0f);
});
checkUOE(() -> {
float o = (float) vh.getAndAdd(1.0f);
});
checkUOE(() -> {
float o = (float) vh.addAndGet(1.0f);
});
} }
@ -589,7 +651,122 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
assertEquals(x, 2.0f, "setOpaque float value"); assertEquals(x, 2.0f, "setOpaque float value");
} }
vh.set(array, i, 1.0f);
// Compare
{
boolean r = vh.compareAndSet(array, i, 1.0f, 2.0f);
assertEquals(r, true, "success compareAndSet float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "success compareAndSet float value");
}
{
boolean r = vh.compareAndSet(array, i, 1.0f, 3.0f);
assertEquals(r, false, "failing compareAndSet float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "failing compareAndSet float value");
}
{
float r = (float) vh.compareAndExchange(array, i, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchange float");
float x = (float) vh.get(array, i);
assertEquals(x, 1.0f, "success compareAndExchange float value");
}
{
float r = (float) vh.compareAndExchange(array, i, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchange float");
float x = (float) vh.get(array, i);
assertEquals(x, 1.0f, "failing compareAndExchange float value");
}
{
float r = (float) vh.compareAndExchangeAcquire(array, i, 1.0f, 2.0f);
assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
}
{
float r = (float) vh.compareAndExchangeAcquire(array, i, 1.0f, 3.0f);
assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
}
{
float r = (float) vh.compareAndExchangeRelease(array, i, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
float x = (float) vh.get(array, i);
assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
}
{
float r = (float) vh.compareAndExchangeRelease(array, i, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
float x = (float) vh.get(array, i);
assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(array, i, 1.0f, 2.0f);
}
assertEquals(success, true, "weakCompareAndSet float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "weakCompareAndSet float value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(array, i, 2.0f, 1.0f);
}
assertEquals(success, true, "weakCompareAndSetAcquire float");
float x = (float) vh.get(array, i);
assertEquals(x, 1.0f, "weakCompareAndSetAcquire float");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(array, i, 1.0f, 2.0f);
}
assertEquals(success, true, "weakCompareAndSetRelease float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "weakCompareAndSetRelease float");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetVolatile(array, i, 2.0f, 1.0f);
}
assertEquals(success, true, "weakCompareAndSetVolatile float");
float x = (float) vh.get(array, i);
assertEquals(x, 1.0f, "weakCompareAndSetVolatile float");
}
// Compare set and get
{
float o = (float) vh.getAndSet(array, i, 2.0f);
assertEquals(o, 1.0f, "getAndSet float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "getAndSet float value");
}
vh.set(array, i, 1.0f);
// get and add, add and get
{
float o = (float) vh.getAndAdd(array, i, 3.0f);
assertEquals(o, 1.0f, "getAndAdd float");
float c = (float) vh.addAndGet(array, i, 3.0f);
assertEquals(c, (float)(1.0f + 3.0f + 3.0f), "getAndAdd float value");
}
} }
} }
@ -597,49 +774,7 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
float[] array = new float[10]; float[] array = new float[10];
int i = 0; int i = 0;
checkUOE(() -> {
boolean r = vh.compareAndSet(array, i, 1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.compareAndExchangeVolatile(array, i, 1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.compareAndExchangeAcquire(array, i, 1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.compareAndExchangeRelease(array, i, 1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(array, i, 1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(array, i, 1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, i, 1.0f, 2.0f);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(array, i, 1.0f, 2.0f);
});
checkUOE(() -> {
float r = (float) vh.getAndSet(array, i, 1.0f);
});
checkUOE(() -> {
float o = (float) vh.getAndAdd(array, i, 1.0f);
});
checkUOE(() -> {
float o = (float) vh.addAndGet(array, i, 1.0f);
});
} }
static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable { static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
@ -680,7 +815,49 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
vh.setOpaque(array, ci, 1.0f); vh.setOpaque(array, ci, 1.0f);
}); });
checkIOOBE(() -> {
boolean r = vh.compareAndSet(array, ci, 1.0f, 2.0f);
});
checkIOOBE(() -> {
float r = (float) vh.compareAndExchange(array, ci, 2.0f, 1.0f);
});
checkIOOBE(() -> {
float r = (float) vh.compareAndExchangeAcquire(array, ci, 2.0f, 1.0f);
});
checkIOOBE(() -> {
float r = (float) vh.compareAndExchangeRelease(array, ci, 2.0f, 1.0f);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSet(array, ci, 1.0f, 2.0f);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetVolatile(array, ci, 1.0f, 2.0f);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, ci, 1.0f, 2.0f);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetRelease(array, ci, 1.0f, 2.0f);
});
checkIOOBE(() -> {
float o = (float) vh.getAndSet(array, ci, 1.0f);
});
checkIOOBE(() -> {
float o = (float) vh.getAndAdd(array, ci, 3.0f);
});
checkIOOBE(() -> {
float o = (float) vh.addAndGet(array, ci, 3.0f);
});
} }
} }
} }

View file

@ -42,11 +42,11 @@ import java.util.List;
import static org.testng.Assert.*; import static org.testng.Assert.*;
public class VarHandleTestAccessInt extends VarHandleBaseTest { public class VarHandleTestAccessInt extends VarHandleBaseTest {
static final int static_final_v = 1; static final int static_final_v = 0x01234567;
static int static_v; static int static_v;
final int final_v = 1; final int final_v = 0x01234567;
int v; int v;
@ -100,7 +100,7 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
@ -220,44 +220,44 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest {
// Plain // Plain
{ {
int x = (int) vh.get(recv); int x = (int) vh.get(recv);
assertEquals(x, 1, "get int value"); assertEquals(x, 0x01234567, "get int value");
} }
// Volatile // Volatile
{ {
int x = (int) vh.getVolatile(recv); int x = (int) vh.getVolatile(recv);
assertEquals(x, 1, "getVolatile int value"); assertEquals(x, 0x01234567, "getVolatile int value");
} }
// Lazy // Lazy
{ {
int x = (int) vh.getAcquire(recv); int x = (int) vh.getAcquire(recv);
assertEquals(x, 1, "getRelease int value"); assertEquals(x, 0x01234567, "getRelease int value");
} }
// Opaque // Opaque
{ {
int x = (int) vh.getOpaque(recv); int x = (int) vh.getOpaque(recv);
assertEquals(x, 1, "getOpaque int value"); assertEquals(x, 0x01234567, "getOpaque int value");
} }
} }
static void testInstanceFinalFieldUnsupported(VarHandleTestAccessInt recv, VarHandle vh) { static void testInstanceFinalFieldUnsupported(VarHandleTestAccessInt recv, VarHandle vh) {
checkUOE(() -> { checkUOE(() -> {
vh.set(recv, 2); vh.set(recv, 0x89ABCDEF);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setVolatile(recv, 2); vh.setVolatile(recv, 0x89ABCDEF);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setRelease(recv, 2); vh.setRelease(recv, 0x89ABCDEF);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setOpaque(recv, 2); vh.setOpaque(recv, 0x89ABCDEF);
}); });
@ -268,44 +268,44 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest {
// Plain // Plain
{ {
int x = (int) vh.get(); int x = (int) vh.get();
assertEquals(x, 1, "get int value"); assertEquals(x, 0x01234567, "get int value");
} }
// Volatile // Volatile
{ {
int x = (int) vh.getVolatile(); int x = (int) vh.getVolatile();
assertEquals(x, 1, "getVolatile int value"); assertEquals(x, 0x01234567, "getVolatile int value");
} }
// Lazy // Lazy
{ {
int x = (int) vh.getAcquire(); int x = (int) vh.getAcquire();
assertEquals(x, 1, "getRelease int value"); assertEquals(x, 0x01234567, "getRelease int value");
} }
// Opaque // Opaque
{ {
int x = (int) vh.getOpaque(); int x = (int) vh.getOpaque();
assertEquals(x, 1, "getOpaque int value"); assertEquals(x, 0x01234567, "getOpaque int value");
} }
} }
static void testStaticFinalFieldUnsupported(VarHandle vh) { static void testStaticFinalFieldUnsupported(VarHandle vh) {
checkUOE(() -> { checkUOE(() -> {
vh.set(2); vh.set(0x89ABCDEF);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setVolatile(2); vh.setVolatile(0x89ABCDEF);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setRelease(2); vh.setRelease(0x89ABCDEF);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setOpaque(2); vh.setOpaque(0x89ABCDEF);
}); });
@ -315,148 +315,148 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest {
static void testInstanceField(VarHandleTestAccessInt recv, VarHandle vh) { static void testInstanceField(VarHandleTestAccessInt recv, VarHandle vh) {
// Plain // Plain
{ {
vh.set(recv, 1); vh.set(recv, 0x01234567);
int x = (int) vh.get(recv); int x = (int) vh.get(recv);
assertEquals(x, 1, "set int value"); assertEquals(x, 0x01234567, "set int value");
} }
// Volatile // Volatile
{ {
vh.setVolatile(recv, 2); vh.setVolatile(recv, 0x89ABCDEF);
int x = (int) vh.getVolatile(recv); int x = (int) vh.getVolatile(recv);
assertEquals(x, 2, "setVolatile int value"); assertEquals(x, 0x89ABCDEF, "setVolatile int value");
} }
// Lazy // Lazy
{ {
vh.setRelease(recv, 1); vh.setRelease(recv, 0x01234567);
int x = (int) vh.getAcquire(recv); int x = (int) vh.getAcquire(recv);
assertEquals(x, 1, "setRelease int value"); assertEquals(x, 0x01234567, "setRelease int value");
} }
// Opaque // Opaque
{ {
vh.setOpaque(recv, 2); vh.setOpaque(recv, 0x89ABCDEF);
int x = (int) vh.getOpaque(recv); int x = (int) vh.getOpaque(recv);
assertEquals(x, 2, "setOpaque int value"); assertEquals(x, 0x89ABCDEF, "setOpaque int value");
} }
vh.set(recv, 1); vh.set(recv, 0x01234567);
// Compare // Compare
{ {
boolean r = vh.compareAndSet(recv, 1, 2); boolean r = vh.compareAndSet(recv, 0x01234567, 0x89ABCDEF);
assertEquals(r, true, "success compareAndSet int"); assertEquals(r, true, "success compareAndSet int");
int x = (int) vh.get(recv); int x = (int) vh.get(recv);
assertEquals(x, 2, "success compareAndSet int value"); assertEquals(x, 0x89ABCDEF, "success compareAndSet int value");
} }
{ {
boolean r = vh.compareAndSet(recv, 1, 3); boolean r = vh.compareAndSet(recv, 0x01234567, 0xCAFEBABE);
assertEquals(r, false, "failing compareAndSet int"); assertEquals(r, false, "failing compareAndSet int");
int x = (int) vh.get(recv); int x = (int) vh.get(recv);
assertEquals(x, 2, "failing compareAndSet int value"); assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value");
} }
{ {
int r = (int) vh.compareAndExchangeVolatile(recv, 2, 1); int r = (int) vh.compareAndExchange(recv, 0x89ABCDEF, 0x01234567);
assertEquals(r, 2, "success compareAndExchangeVolatile int"); assertEquals(r, 0x89ABCDEF, "success compareAndExchange int");
int x = (int) vh.get(recv); int x = (int) vh.get(recv);
assertEquals(x, 1, "success compareAndExchangeVolatile int value"); assertEquals(x, 0x01234567, "success compareAndExchange int value");
} }
{ {
int r = (int) vh.compareAndExchangeVolatile(recv, 2, 3); int r = (int) vh.compareAndExchange(recv, 0x89ABCDEF, 0xCAFEBABE);
assertEquals(r, 1, "failing compareAndExchangeVolatile int"); assertEquals(r, 0x01234567, "failing compareAndExchange int");
int x = (int) vh.get(recv); int x = (int) vh.get(recv);
assertEquals(x, 1, "failing compareAndExchangeVolatile int value"); assertEquals(x, 0x01234567, "failing compareAndExchange int value");
} }
{ {
int r = (int) vh.compareAndExchangeAcquire(recv, 1, 2); int r = (int) vh.compareAndExchangeAcquire(recv, 0x01234567, 0x89ABCDEF);
assertEquals(r, 1, "success compareAndExchangeAcquire int"); assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int");
int x = (int) vh.get(recv); int x = (int) vh.get(recv);
assertEquals(x, 2, "success compareAndExchangeAcquire int value"); assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value");
} }
{ {
int r = (int) vh.compareAndExchangeAcquire(recv, 1, 3); int r = (int) vh.compareAndExchangeAcquire(recv, 0x01234567, 0xCAFEBABE);
assertEquals(r, 2, "failing compareAndExchangeAcquire int"); assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int");
int x = (int) vh.get(recv); int x = (int) vh.get(recv);
assertEquals(x, 2, "failing compareAndExchangeAcquire int value"); assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value");
} }
{ {
int r = (int) vh.compareAndExchangeRelease(recv, 2, 1); int r = (int) vh.compareAndExchangeRelease(recv, 0x89ABCDEF, 0x01234567);
assertEquals(r, 2, "success compareAndExchangeRelease int"); assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int");
int x = (int) vh.get(recv); int x = (int) vh.get(recv);
assertEquals(x, 1, "success compareAndExchangeRelease int value"); assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value");
} }
{ {
int r = (int) vh.compareAndExchangeRelease(recv, 2, 3); int r = (int) vh.compareAndExchangeRelease(recv, 0x89ABCDEF, 0xCAFEBABE);
assertEquals(r, 1, "failing compareAndExchangeRelease int"); assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int");
int x = (int) vh.get(recv); int x = (int) vh.get(recv);
assertEquals(x, 1, "failing compareAndExchangeRelease int value"); assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(recv, 1, 2); success = vh.weakCompareAndSet(recv, 0x01234567, 0x89ABCDEF);
} }
assertEquals(success, true, "weakCompareAndSet int"); assertEquals(success, true, "weakCompareAndSet int");
int x = (int) vh.get(recv); int x = (int) vh.get(recv);
assertEquals(x, 2, "weakCompareAndSet int value"); assertEquals(x, 0x89ABCDEF, "weakCompareAndSet int value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(recv, 2, 1); success = vh.weakCompareAndSetAcquire(recv, 0x89ABCDEF, 0x01234567);
} }
assertEquals(success, true, "weakCompareAndSetAcquire int"); assertEquals(success, true, "weakCompareAndSetAcquire int");
int x = (int) vh.get(recv); int x = (int) vh.get(recv);
assertEquals(x, 1, "weakCompareAndSetAcquire int"); assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(recv, 1, 2); success = vh.weakCompareAndSetRelease(recv, 0x01234567, 0x89ABCDEF);
} }
assertEquals(success, true, "weakCompareAndSetRelease int"); assertEquals(success, true, "weakCompareAndSetRelease int");
int x = (int) vh.get(recv); int x = (int) vh.get(recv);
assertEquals(x, 2, "weakCompareAndSetRelease int"); assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetVolatile(recv, 2, 1); success = vh.weakCompareAndSetVolatile(recv, 0x89ABCDEF, 0x01234567);
} }
assertEquals(success, true, "weakCompareAndSetVolatile int"); assertEquals(success, true, "weakCompareAndSetVolatile int");
int x = (int) vh.get(recv); int x = (int) vh.get(recv);
assertEquals(x, 1, "weakCompareAndSetVolatile int value"); assertEquals(x, 0x01234567, "weakCompareAndSetVolatile int value");
} }
// Compare set and get // Compare set and get
{ {
int o = (int) vh.getAndSet(recv, 2); int o = (int) vh.getAndSet(recv, 0x89ABCDEF);
assertEquals(o, 1, "getAndSet int"); assertEquals(o, 0x01234567, "getAndSet int");
int x = (int) vh.get(recv); int x = (int) vh.get(recv);
assertEquals(x, 2, "getAndSet int value"); assertEquals(x, 0x89ABCDEF, "getAndSet int value");
} }
vh.set(recv, 1); vh.set(recv, 0x01234567);
// get and add, add and get // get and add, add and get
{ {
int o = (int) vh.getAndAdd(recv, 3); int o = (int) vh.getAndAdd(recv, 0xCAFEBABE);
assertEquals(o, 1, "getAndAdd int"); assertEquals(o, 0x01234567, "getAndAdd int");
int c = (int) vh.addAndGet(recv, 3); int c = (int) vh.addAndGet(recv, 0xCAFEBABE);
assertEquals(c, 1 + 3 + 3, "getAndAdd int value"); assertEquals(c, (int)(0x01234567 + 0xCAFEBABE + 0xCAFEBABE), "getAndAdd int value");
} }
} }
@ -468,148 +468,148 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest {
static void testStaticField(VarHandle vh) { static void testStaticField(VarHandle vh) {
// Plain // Plain
{ {
vh.set(1); vh.set(0x01234567);
int x = (int) vh.get(); int x = (int) vh.get();
assertEquals(x, 1, "set int value"); assertEquals(x, 0x01234567, "set int value");
} }
// Volatile // Volatile
{ {
vh.setVolatile(2); vh.setVolatile(0x89ABCDEF);
int x = (int) vh.getVolatile(); int x = (int) vh.getVolatile();
assertEquals(x, 2, "setVolatile int value"); assertEquals(x, 0x89ABCDEF, "setVolatile int value");
} }
// Lazy // Lazy
{ {
vh.setRelease(1); vh.setRelease(0x01234567);
int x = (int) vh.getAcquire(); int x = (int) vh.getAcquire();
assertEquals(x, 1, "setRelease int value"); assertEquals(x, 0x01234567, "setRelease int value");
} }
// Opaque // Opaque
{ {
vh.setOpaque(2); vh.setOpaque(0x89ABCDEF);
int x = (int) vh.getOpaque(); int x = (int) vh.getOpaque();
assertEquals(x, 2, "setOpaque int value"); assertEquals(x, 0x89ABCDEF, "setOpaque int value");
} }
vh.set(1); vh.set(0x01234567);
// Compare // Compare
{ {
boolean r = vh.compareAndSet(1, 2); boolean r = vh.compareAndSet(0x01234567, 0x89ABCDEF);
assertEquals(r, true, "success compareAndSet int"); assertEquals(r, true, "success compareAndSet int");
int x = (int) vh.get(); int x = (int) vh.get();
assertEquals(x, 2, "success compareAndSet int value"); assertEquals(x, 0x89ABCDEF, "success compareAndSet int value");
} }
{ {
boolean r = vh.compareAndSet(1, 3); boolean r = vh.compareAndSet(0x01234567, 0xCAFEBABE);
assertEquals(r, false, "failing compareAndSet int"); assertEquals(r, false, "failing compareAndSet int");
int x = (int) vh.get(); int x = (int) vh.get();
assertEquals(x, 2, "failing compareAndSet int value"); assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value");
} }
{ {
int r = (int) vh.compareAndExchangeVolatile(2, 1); int r = (int) vh.compareAndExchange(0x89ABCDEF, 0x01234567);
assertEquals(r, 2, "success compareAndExchangeVolatile int"); assertEquals(r, 0x89ABCDEF, "success compareAndExchange int");
int x = (int) vh.get(); int x = (int) vh.get();
assertEquals(x, 1, "success compareAndExchangeVolatile int value"); assertEquals(x, 0x01234567, "success compareAndExchange int value");
} }
{ {
int r = (int) vh.compareAndExchangeVolatile(2, 3); int r = (int) vh.compareAndExchange(0x89ABCDEF, 0xCAFEBABE);
assertEquals(r, 1, "failing compareAndExchangeVolatile int"); assertEquals(r, 0x01234567, "failing compareAndExchange int");
int x = (int) vh.get(); int x = (int) vh.get();
assertEquals(x, 1, "failing compareAndExchangeVolatile int value"); assertEquals(x, 0x01234567, "failing compareAndExchange int value");
} }
{ {
int r = (int) vh.compareAndExchangeAcquire(1, 2); int r = (int) vh.compareAndExchangeAcquire(0x01234567, 0x89ABCDEF);
assertEquals(r, 1, "success compareAndExchangeAcquire int"); assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int");
int x = (int) vh.get(); int x = (int) vh.get();
assertEquals(x, 2, "success compareAndExchangeAcquire int value"); assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value");
} }
{ {
int r = (int) vh.compareAndExchangeAcquire(1, 3); int r = (int) vh.compareAndExchangeAcquire(0x01234567, 0xCAFEBABE);
assertEquals(r, 2, "failing compareAndExchangeAcquire int"); assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int");
int x = (int) vh.get(); int x = (int) vh.get();
assertEquals(x, 2, "failing compareAndExchangeAcquire int value"); assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value");
} }
{ {
int r = (int) vh.compareAndExchangeRelease(2, 1); int r = (int) vh.compareAndExchangeRelease(0x89ABCDEF, 0x01234567);
assertEquals(r, 2, "success compareAndExchangeRelease int"); assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int");
int x = (int) vh.get(); int x = (int) vh.get();
assertEquals(x, 1, "success compareAndExchangeRelease int value"); assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value");
} }
{ {
int r = (int) vh.compareAndExchangeRelease(2, 3); int r = (int) vh.compareAndExchangeRelease(0x89ABCDEF, 0xCAFEBABE);
assertEquals(r, 1, "failing compareAndExchangeRelease int"); assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int");
int x = (int) vh.get(); int x = (int) vh.get();
assertEquals(x, 1, "failing compareAndExchangeRelease int value"); assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(1, 2); success = vh.weakCompareAndSet(0x01234567, 0x89ABCDEF);
} }
assertEquals(success, true, "weakCompareAndSet int"); assertEquals(success, true, "weakCompareAndSet int");
int x = (int) vh.get(); int x = (int) vh.get();
assertEquals(x, 2, "weakCompareAndSet int value"); assertEquals(x, 0x89ABCDEF, "weakCompareAndSet int value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(2, 1); success = vh.weakCompareAndSetAcquire(0x89ABCDEF, 0x01234567);
} }
assertEquals(success, true, "weakCompareAndSetAcquire int"); assertEquals(success, true, "weakCompareAndSetAcquire int");
int x = (int) vh.get(); int x = (int) vh.get();
assertEquals(x, 1, "weakCompareAndSetAcquire int"); assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(1, 2); success = vh.weakCompareAndSetRelease(0x01234567, 0x89ABCDEF);
} }
assertEquals(success, true, "weakCompareAndSetRelease int"); assertEquals(success, true, "weakCompareAndSetRelease int");
int x = (int) vh.get(); int x = (int) vh.get();
assertEquals(x, 2, "weakCompareAndSetRelease int"); assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(2, 1); success = vh.weakCompareAndSetRelease(0x89ABCDEF, 0x01234567);
} }
assertEquals(success, true, "weakCompareAndSetVolatile int"); assertEquals(success, true, "weakCompareAndSetVolatile int");
int x = (int) vh.get(); int x = (int) vh.get();
assertEquals(x, 1, "weakCompareAndSetVolatile int"); assertEquals(x, 0x01234567, "weakCompareAndSetVolatile int");
} }
// Compare set and get // Compare set and get
{ {
int o = (int) vh.getAndSet(2); int o = (int) vh.getAndSet(0x89ABCDEF);
assertEquals(o, 1, "getAndSet int"); assertEquals(o, 0x01234567, "getAndSet int");
int x = (int) vh.get(); int x = (int) vh.get();
assertEquals(x, 2, "getAndSet int value"); assertEquals(x, 0x89ABCDEF, "getAndSet int value");
} }
vh.set(1); vh.set(0x01234567);
// get and add, add and get // get and add, add and get
{ {
int o = (int) vh.getAndAdd( 3); int o = (int) vh.getAndAdd( 0xCAFEBABE);
assertEquals(o, 1, "getAndAdd int"); assertEquals(o, 0x01234567, "getAndAdd int");
int c = (int) vh.addAndGet(3); int c = (int) vh.addAndGet(0xCAFEBABE);
assertEquals(c, 1 + 3 + 3, "getAndAdd int value"); assertEquals(c, (int)(0x01234567 + 0xCAFEBABE + 0xCAFEBABE), "getAndAdd int value");
} }
} }
@ -624,148 +624,148 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest {
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
// Plain // Plain
{ {
vh.set(array, i, 1); vh.set(array, i, 0x01234567);
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, 1, "get int value"); assertEquals(x, 0x01234567, "get int value");
} }
// Volatile // Volatile
{ {
vh.setVolatile(array, i, 2); vh.setVolatile(array, i, 0x89ABCDEF);
int x = (int) vh.getVolatile(array, i); int x = (int) vh.getVolatile(array, i);
assertEquals(x, 2, "setVolatile int value"); assertEquals(x, 0x89ABCDEF, "setVolatile int value");
} }
// Lazy // Lazy
{ {
vh.setRelease(array, i, 1); vh.setRelease(array, i, 0x01234567);
int x = (int) vh.getAcquire(array, i); int x = (int) vh.getAcquire(array, i);
assertEquals(x, 1, "setRelease int value"); assertEquals(x, 0x01234567, "setRelease int value");
} }
// Opaque // Opaque
{ {
vh.setOpaque(array, i, 2); vh.setOpaque(array, i, 0x89ABCDEF);
int x = (int) vh.getOpaque(array, i); int x = (int) vh.getOpaque(array, i);
assertEquals(x, 2, "setOpaque int value"); assertEquals(x, 0x89ABCDEF, "setOpaque int value");
} }
vh.set(array, i, 1); vh.set(array, i, 0x01234567);
// Compare // Compare
{ {
boolean r = vh.compareAndSet(array, i, 1, 2); boolean r = vh.compareAndSet(array, i, 0x01234567, 0x89ABCDEF);
assertEquals(r, true, "success compareAndSet int"); assertEquals(r, true, "success compareAndSet int");
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, 2, "success compareAndSet int value"); assertEquals(x, 0x89ABCDEF, "success compareAndSet int value");
} }
{ {
boolean r = vh.compareAndSet(array, i, 1, 3); boolean r = vh.compareAndSet(array, i, 0x01234567, 0xCAFEBABE);
assertEquals(r, false, "failing compareAndSet int"); assertEquals(r, false, "failing compareAndSet int");
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, 2, "failing compareAndSet int value"); assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value");
} }
{ {
int r = (int) vh.compareAndExchangeVolatile(array, i, 2, 1); int r = (int) vh.compareAndExchange(array, i, 0x89ABCDEF, 0x01234567);
assertEquals(r, 2, "success compareAndExchangeVolatile int"); assertEquals(r, 0x89ABCDEF, "success compareAndExchange int");
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, 1, "success compareAndExchangeVolatile int value"); assertEquals(x, 0x01234567, "success compareAndExchange int value");
} }
{ {
int r = (int) vh.compareAndExchangeVolatile(array, i, 2, 3); int r = (int) vh.compareAndExchange(array, i, 0x89ABCDEF, 0xCAFEBABE);
assertEquals(r, 1, "failing compareAndExchangeVolatile int"); assertEquals(r, 0x01234567, "failing compareAndExchange int");
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, 1, "failing compareAndExchangeVolatile int value"); assertEquals(x, 0x01234567, "failing compareAndExchange int value");
} }
{ {
int r = (int) vh.compareAndExchangeAcquire(array, i, 1, 2); int r = (int) vh.compareAndExchangeAcquire(array, i, 0x01234567, 0x89ABCDEF);
assertEquals(r, 1, "success compareAndExchangeAcquire int"); assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int");
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, 2, "success compareAndExchangeAcquire int value"); assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value");
} }
{ {
int r = (int) vh.compareAndExchangeAcquire(array, i, 1, 3); int r = (int) vh.compareAndExchangeAcquire(array, i, 0x01234567, 0xCAFEBABE);
assertEquals(r, 2, "failing compareAndExchangeAcquire int"); assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int");
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, 2, "failing compareAndExchangeAcquire int value"); assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value");
} }
{ {
int r = (int) vh.compareAndExchangeRelease(array, i, 2, 1); int r = (int) vh.compareAndExchangeRelease(array, i, 0x89ABCDEF, 0x01234567);
assertEquals(r, 2, "success compareAndExchangeRelease int"); assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int");
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, 1, "success compareAndExchangeRelease int value"); assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value");
} }
{ {
int r = (int) vh.compareAndExchangeRelease(array, i, 2, 3); int r = (int) vh.compareAndExchangeRelease(array, i, 0x89ABCDEF, 0xCAFEBABE);
assertEquals(r, 1, "failing compareAndExchangeRelease int"); assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int");
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, 1, "failing compareAndExchangeRelease int value"); assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(array, i, 1, 2); success = vh.weakCompareAndSet(array, i, 0x01234567, 0x89ABCDEF);
} }
assertEquals(success, true, "weakCompareAndSet int"); assertEquals(success, true, "weakCompareAndSet int");
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, 2, "weakCompareAndSet int value"); assertEquals(x, 0x89ABCDEF, "weakCompareAndSet int value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(array, i, 2, 1); success = vh.weakCompareAndSetAcquire(array, i, 0x89ABCDEF, 0x01234567);
} }
assertEquals(success, true, "weakCompareAndSetAcquire int"); assertEquals(success, true, "weakCompareAndSetAcquire int");
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, 1, "weakCompareAndSetAcquire int"); assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(array, i, 1, 2); success = vh.weakCompareAndSetRelease(array, i, 0x01234567, 0x89ABCDEF);
} }
assertEquals(success, true, "weakCompareAndSetRelease int"); assertEquals(success, true, "weakCompareAndSetRelease int");
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, 2, "weakCompareAndSetRelease int"); assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetVolatile(array, i, 2, 1); success = vh.weakCompareAndSetVolatile(array, i, 0x89ABCDEF, 0x01234567);
} }
assertEquals(success, true, "weakCompareAndSetVolatile int"); assertEquals(success, true, "weakCompareAndSetVolatile int");
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, 1, "weakCompareAndSetVolatile int"); assertEquals(x, 0x01234567, "weakCompareAndSetVolatile int");
} }
// Compare set and get // Compare set and get
{ {
int o = (int) vh.getAndSet(array, i, 2); int o = (int) vh.getAndSet(array, i, 0x89ABCDEF);
assertEquals(o, 1, "getAndSet int"); assertEquals(o, 0x01234567, "getAndSet int");
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, 2, "getAndSet int value"); assertEquals(x, 0x89ABCDEF, "getAndSet int value");
} }
vh.set(array, i, 1); vh.set(array, i, 0x01234567);
// get and add, add and get // get and add, add and get
{ {
int o = (int) vh.getAndAdd(array, i, 3); int o = (int) vh.getAndAdd(array, i, 0xCAFEBABE);
assertEquals(o, 1, "getAndAdd int"); assertEquals(o, 0x01234567, "getAndAdd int");
int c = (int) vh.addAndGet(array, i, 3); int c = (int) vh.addAndGet(array, i, 0xCAFEBABE);
assertEquals(c, 1 + 3 + 3, "getAndAdd int value"); assertEquals(c, (int)(0x01234567 + 0xCAFEBABE + 0xCAFEBABE), "getAndAdd int value");
} }
} }
} }
@ -788,7 +788,7 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.set(array, ci, 1); vh.set(array, ci, 0x01234567);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -796,7 +796,7 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.setVolatile(array, ci, 1); vh.setVolatile(array, ci, 0x01234567);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -804,7 +804,7 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.setRelease(array, ci, 1); vh.setRelease(array, ci, 0x01234567);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -812,51 +812,51 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.setOpaque(array, ci, 1); vh.setOpaque(array, ci, 0x01234567);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
boolean r = vh.compareAndSet(array, ci, 1, 2); boolean r = vh.compareAndSet(array, ci, 0x01234567, 0x89ABCDEF);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
int r = (int) vh.compareAndExchangeVolatile(array, ci, 2, 1); int r = (int) vh.compareAndExchange(array, ci, 0x89ABCDEF, 0x01234567);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
int r = (int) vh.compareAndExchangeAcquire(array, ci, 2, 1); int r = (int) vh.compareAndExchangeAcquire(array, ci, 0x89ABCDEF, 0x01234567);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
int r = (int) vh.compareAndExchangeRelease(array, ci, 2, 1); int r = (int) vh.compareAndExchangeRelease(array, ci, 0x89ABCDEF, 0x01234567);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
boolean r = vh.weakCompareAndSet(array, ci, 1, 2); boolean r = vh.weakCompareAndSet(array, ci, 0x01234567, 0x89ABCDEF);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetVolatile(array, ci, 1, 2); boolean r = vh.weakCompareAndSetVolatile(array, ci, 0x01234567, 0x89ABCDEF);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, ci, 1, 2); boolean r = vh.weakCompareAndSetAcquire(array, ci, 0x01234567, 0x89ABCDEF);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetRelease(array, ci, 1, 2); boolean r = vh.weakCompareAndSetRelease(array, ci, 0x01234567, 0x89ABCDEF);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
int o = (int) vh.getAndSet(array, ci, 1); int o = (int) vh.getAndSet(array, ci, 0x01234567);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
int o = (int) vh.getAndAdd(array, ci, 3); int o = (int) vh.getAndAdd(array, ci, 0xCAFEBABE);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
int o = (int) vh.addAndGet(array, ci, 3); int o = (int) vh.addAndGet(array, ci, 0xCAFEBABE);
}); });
} }
} }

View file

@ -42,11 +42,11 @@ import java.util.List;
import static org.testng.Assert.*; import static org.testng.Assert.*;
public class VarHandleTestAccessLong extends VarHandleBaseTest { public class VarHandleTestAccessLong extends VarHandleBaseTest {
static final long static_final_v = 1L; static final long static_final_v = 0x0123456789ABCDEFL;
static long static_v; static long static_v;
final long final_v = 1L; final long final_v = 0x0123456789ABCDEFL;
long v; long v;
@ -100,7 +100,7 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
@ -220,44 +220,44 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest {
// Plain // Plain
{ {
long x = (long) vh.get(recv); long x = (long) vh.get(recv);
assertEquals(x, 1L, "get long value"); assertEquals(x, 0x0123456789ABCDEFL, "get long value");
} }
// Volatile // Volatile
{ {
long x = (long) vh.getVolatile(recv); long x = (long) vh.getVolatile(recv);
assertEquals(x, 1L, "getVolatile long value"); assertEquals(x, 0x0123456789ABCDEFL, "getVolatile long value");
} }
// Lazy // Lazy
{ {
long x = (long) vh.getAcquire(recv); long x = (long) vh.getAcquire(recv);
assertEquals(x, 1L, "getRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "getRelease long value");
} }
// Opaque // Opaque
{ {
long x = (long) vh.getOpaque(recv); long x = (long) vh.getOpaque(recv);
assertEquals(x, 1L, "getOpaque long value"); assertEquals(x, 0x0123456789ABCDEFL, "getOpaque long value");
} }
} }
static void testInstanceFinalFieldUnsupported(VarHandleTestAccessLong recv, VarHandle vh) { static void testInstanceFinalFieldUnsupported(VarHandleTestAccessLong recv, VarHandle vh) {
checkUOE(() -> { checkUOE(() -> {
vh.set(recv, 2L); vh.set(recv, 0xCAFEBABECAFEBABEL);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setVolatile(recv, 2L); vh.setVolatile(recv, 0xCAFEBABECAFEBABEL);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setRelease(recv, 2L); vh.setRelease(recv, 0xCAFEBABECAFEBABEL);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setOpaque(recv, 2L); vh.setOpaque(recv, 0xCAFEBABECAFEBABEL);
}); });
@ -268,44 +268,44 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest {
// Plain // Plain
{ {
long x = (long) vh.get(); long x = (long) vh.get();
assertEquals(x, 1L, "get long value"); assertEquals(x, 0x0123456789ABCDEFL, "get long value");
} }
// Volatile // Volatile
{ {
long x = (long) vh.getVolatile(); long x = (long) vh.getVolatile();
assertEquals(x, 1L, "getVolatile long value"); assertEquals(x, 0x0123456789ABCDEFL, "getVolatile long value");
} }
// Lazy // Lazy
{ {
long x = (long) vh.getAcquire(); long x = (long) vh.getAcquire();
assertEquals(x, 1L, "getRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "getRelease long value");
} }
// Opaque // Opaque
{ {
long x = (long) vh.getOpaque(); long x = (long) vh.getOpaque();
assertEquals(x, 1L, "getOpaque long value"); assertEquals(x, 0x0123456789ABCDEFL, "getOpaque long value");
} }
} }
static void testStaticFinalFieldUnsupported(VarHandle vh) { static void testStaticFinalFieldUnsupported(VarHandle vh) {
checkUOE(() -> { checkUOE(() -> {
vh.set(2L); vh.set(0xCAFEBABECAFEBABEL);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setVolatile(2L); vh.setVolatile(0xCAFEBABECAFEBABEL);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setRelease(2L); vh.setRelease(0xCAFEBABECAFEBABEL);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setOpaque(2L); vh.setOpaque(0xCAFEBABECAFEBABEL);
}); });
@ -315,148 +315,148 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest {
static void testInstanceField(VarHandleTestAccessLong recv, VarHandle vh) { static void testInstanceField(VarHandleTestAccessLong recv, VarHandle vh) {
// Plain // Plain
{ {
vh.set(recv, 1L); vh.set(recv, 0x0123456789ABCDEFL);
long x = (long) vh.get(recv); long x = (long) vh.get(recv);
assertEquals(x, 1L, "set long value"); assertEquals(x, 0x0123456789ABCDEFL, "set long value");
} }
// Volatile // Volatile
{ {
vh.setVolatile(recv, 2L); vh.setVolatile(recv, 0xCAFEBABECAFEBABEL);
long x = (long) vh.getVolatile(recv); long x = (long) vh.getVolatile(recv);
assertEquals(x, 2L, "setVolatile long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
} }
// Lazy // Lazy
{ {
vh.setRelease(recv, 1L); vh.setRelease(recv, 0x0123456789ABCDEFL);
long x = (long) vh.getAcquire(recv); long x = (long) vh.getAcquire(recv);
assertEquals(x, 1L, "setRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
} }
// Opaque // Opaque
{ {
vh.setOpaque(recv, 2L); vh.setOpaque(recv, 0xCAFEBABECAFEBABEL);
long x = (long) vh.getOpaque(recv); long x = (long) vh.getOpaque(recv);
assertEquals(x, 2L, "setOpaque long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
} }
vh.set(recv, 1L); vh.set(recv, 0x0123456789ABCDEFL);
// Compare // Compare
{ {
boolean r = vh.compareAndSet(recv, 1L, 2L); boolean r = vh.compareAndSet(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
assertEquals(r, true, "success compareAndSet long"); assertEquals(r, true, "success compareAndSet long");
long x = (long) vh.get(recv); long x = (long) vh.get(recv);
assertEquals(x, 2L, "success compareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
} }
{ {
boolean r = vh.compareAndSet(recv, 1L, 3L); boolean r = vh.compareAndSet(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, false, "failing compareAndSet long"); assertEquals(r, false, "failing compareAndSet long");
long x = (long) vh.get(recv); long x = (long) vh.get(recv);
assertEquals(x, 2L, "failing compareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
} }
{ {
long r = (long) vh.compareAndExchangeVolatile(recv, 2L, 1L); long r = (long) vh.compareAndExchange(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
assertEquals(r, 2L, "success compareAndExchangeVolatile long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
long x = (long) vh.get(recv); long x = (long) vh.get(recv);
assertEquals(x, 1L, "success compareAndExchangeVolatile long value"); assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
} }
{ {
long r = (long) vh.compareAndExchangeVolatile(recv, 2L, 3L); long r = (long) vh.compareAndExchange(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 1L, "failing compareAndExchangeVolatile long"); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
long x = (long) vh.get(recv); long x = (long) vh.get(recv);
assertEquals(x, 1L, "failing compareAndExchangeVolatile long value"); assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
} }
{ {
long r = (long) vh.compareAndExchangeAcquire(recv, 1L, 2L); long r = (long) vh.compareAndExchangeAcquire(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
assertEquals(r, 1L, "success compareAndExchangeAcquire long"); assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
long x = (long) vh.get(recv); long x = (long) vh.get(recv);
assertEquals(x, 2L, "success compareAndExchangeAcquire long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
} }
{ {
long r = (long) vh.compareAndExchangeAcquire(recv, 1L, 3L); long r = (long) vh.compareAndExchangeAcquire(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 2L, "failing compareAndExchangeAcquire long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
long x = (long) vh.get(recv); long x = (long) vh.get(recv);
assertEquals(x, 2L, "failing compareAndExchangeAcquire long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
} }
{ {
long r = (long) vh.compareAndExchangeRelease(recv, 2L, 1L); long r = (long) vh.compareAndExchangeRelease(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
assertEquals(r, 2L, "success compareAndExchangeRelease long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
long x = (long) vh.get(recv); long x = (long) vh.get(recv);
assertEquals(x, 1L, "success compareAndExchangeRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
} }
{ {
long r = (long) vh.compareAndExchangeRelease(recv, 2L, 3L); long r = (long) vh.compareAndExchangeRelease(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 1L, "failing compareAndExchangeRelease long"); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
long x = (long) vh.get(recv); long x = (long) vh.get(recv);
assertEquals(x, 1L, "failing compareAndExchangeRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(recv, 1L, 2L); success = vh.weakCompareAndSet(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
} }
assertEquals(success, true, "weakCompareAndSet long"); assertEquals(success, true, "weakCompareAndSet long");
long x = (long) vh.get(recv); long x = (long) vh.get(recv);
assertEquals(x, 2L, "weakCompareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSet long value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(recv, 2L, 1L); success = vh.weakCompareAndSetAcquire(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
} }
assertEquals(success, true, "weakCompareAndSetAcquire long"); assertEquals(success, true, "weakCompareAndSetAcquire long");
long x = (long) vh.get(recv); long x = (long) vh.get(recv);
assertEquals(x, 1L, "weakCompareAndSetAcquire long"); assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(recv, 1L, 2L); success = vh.weakCompareAndSetRelease(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
} }
assertEquals(success, true, "weakCompareAndSetRelease long"); assertEquals(success, true, "weakCompareAndSetRelease long");
long x = (long) vh.get(recv); long x = (long) vh.get(recv);
assertEquals(x, 2L, "weakCompareAndSetRelease long"); assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetVolatile(recv, 2L, 1L); success = vh.weakCompareAndSetVolatile(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
} }
assertEquals(success, true, "weakCompareAndSetVolatile long"); assertEquals(success, true, "weakCompareAndSetVolatile long");
long x = (long) vh.get(recv); long x = (long) vh.get(recv);
assertEquals(x, 1L, "weakCompareAndSetVolatile long value"); assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetVolatile long value");
} }
// Compare set and get // Compare set and get
{ {
long o = (long) vh.getAndSet(recv, 2L); long o = (long) vh.getAndSet(recv, 0xCAFEBABECAFEBABEL);
assertEquals(o, 1L, "getAndSet long"); assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
long x = (long) vh.get(recv); long x = (long) vh.get(recv);
assertEquals(x, 2L, "getAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
} }
vh.set(recv, 1L); vh.set(recv, 0x0123456789ABCDEFL);
// get and add, add and get // get and add, add and get
{ {
long o = (long) vh.getAndAdd(recv, 3L); long o = (long) vh.getAndAdd(recv, 0xDEADBEEFDEADBEEFL);
assertEquals(o, 1L, "getAndAdd long"); assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
long c = (long) vh.addAndGet(recv, 3L); long c = (long) vh.addAndGet(recv, 0xDEADBEEFDEADBEEFL);
assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); assertEquals(c, (long)(0x0123456789ABCDEFL + 0xDEADBEEFDEADBEEFL + 0xDEADBEEFDEADBEEFL), "getAndAdd long value");
} }
} }
@ -468,148 +468,148 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest {
static void testStaticField(VarHandle vh) { static void testStaticField(VarHandle vh) {
// Plain // Plain
{ {
vh.set(1L); vh.set(0x0123456789ABCDEFL);
long x = (long) vh.get(); long x = (long) vh.get();
assertEquals(x, 1L, "set long value"); assertEquals(x, 0x0123456789ABCDEFL, "set long value");
} }
// Volatile // Volatile
{ {
vh.setVolatile(2L); vh.setVolatile(0xCAFEBABECAFEBABEL);
long x = (long) vh.getVolatile(); long x = (long) vh.getVolatile();
assertEquals(x, 2L, "setVolatile long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
} }
// Lazy // Lazy
{ {
vh.setRelease(1L); vh.setRelease(0x0123456789ABCDEFL);
long x = (long) vh.getAcquire(); long x = (long) vh.getAcquire();
assertEquals(x, 1L, "setRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
} }
// Opaque // Opaque
{ {
vh.setOpaque(2L); vh.setOpaque(0xCAFEBABECAFEBABEL);
long x = (long) vh.getOpaque(); long x = (long) vh.getOpaque();
assertEquals(x, 2L, "setOpaque long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
} }
vh.set(1L); vh.set(0x0123456789ABCDEFL);
// Compare // Compare
{ {
boolean r = vh.compareAndSet(1L, 2L); boolean r = vh.compareAndSet(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
assertEquals(r, true, "success compareAndSet long"); assertEquals(r, true, "success compareAndSet long");
long x = (long) vh.get(); long x = (long) vh.get();
assertEquals(x, 2L, "success compareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
} }
{ {
boolean r = vh.compareAndSet(1L, 3L); boolean r = vh.compareAndSet(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, false, "failing compareAndSet long"); assertEquals(r, false, "failing compareAndSet long");
long x = (long) vh.get(); long x = (long) vh.get();
assertEquals(x, 2L, "failing compareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
} }
{ {
long r = (long) vh.compareAndExchangeVolatile(2L, 1L); long r = (long) vh.compareAndExchange(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
assertEquals(r, 2L, "success compareAndExchangeVolatile long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
long x = (long) vh.get(); long x = (long) vh.get();
assertEquals(x, 1L, "success compareAndExchangeVolatile long value"); assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
} }
{ {
long r = (long) vh.compareAndExchangeVolatile(2L, 3L); long r = (long) vh.compareAndExchange(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 1L, "failing compareAndExchangeVolatile long"); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
long x = (long) vh.get(); long x = (long) vh.get();
assertEquals(x, 1L, "failing compareAndExchangeVolatile long value"); assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
} }
{ {
long r = (long) vh.compareAndExchangeAcquire(1L, 2L); long r = (long) vh.compareAndExchangeAcquire(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
assertEquals(r, 1L, "success compareAndExchangeAcquire long"); assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
long x = (long) vh.get(); long x = (long) vh.get();
assertEquals(x, 2L, "success compareAndExchangeAcquire long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
} }
{ {
long r = (long) vh.compareAndExchangeAcquire(1L, 3L); long r = (long) vh.compareAndExchangeAcquire(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 2L, "failing compareAndExchangeAcquire long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
long x = (long) vh.get(); long x = (long) vh.get();
assertEquals(x, 2L, "failing compareAndExchangeAcquire long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
} }
{ {
long r = (long) vh.compareAndExchangeRelease(2L, 1L); long r = (long) vh.compareAndExchangeRelease(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
assertEquals(r, 2L, "success compareAndExchangeRelease long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
long x = (long) vh.get(); long x = (long) vh.get();
assertEquals(x, 1L, "success compareAndExchangeRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
} }
{ {
long r = (long) vh.compareAndExchangeRelease(2L, 3L); long r = (long) vh.compareAndExchangeRelease(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 1L, "failing compareAndExchangeRelease long"); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
long x = (long) vh.get(); long x = (long) vh.get();
assertEquals(x, 1L, "failing compareAndExchangeRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(1L, 2L); success = vh.weakCompareAndSet(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
} }
assertEquals(success, true, "weakCompareAndSet long"); assertEquals(success, true, "weakCompareAndSet long");
long x = (long) vh.get(); long x = (long) vh.get();
assertEquals(x, 2L, "weakCompareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSet long value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(2L, 1L); success = vh.weakCompareAndSetAcquire(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
} }
assertEquals(success, true, "weakCompareAndSetAcquire long"); assertEquals(success, true, "weakCompareAndSetAcquire long");
long x = (long) vh.get(); long x = (long) vh.get();
assertEquals(x, 1L, "weakCompareAndSetAcquire long"); assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(1L, 2L); success = vh.weakCompareAndSetRelease(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
} }
assertEquals(success, true, "weakCompareAndSetRelease long"); assertEquals(success, true, "weakCompareAndSetRelease long");
long x = (long) vh.get(); long x = (long) vh.get();
assertEquals(x, 2L, "weakCompareAndSetRelease long"); assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(2L, 1L); success = vh.weakCompareAndSetRelease(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
} }
assertEquals(success, true, "weakCompareAndSetVolatile long"); assertEquals(success, true, "weakCompareAndSetVolatile long");
long x = (long) vh.get(); long x = (long) vh.get();
assertEquals(x, 1L, "weakCompareAndSetVolatile long"); assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetVolatile long");
} }
// Compare set and get // Compare set and get
{ {
long o = (long) vh.getAndSet(2L); long o = (long) vh.getAndSet(0xCAFEBABECAFEBABEL);
assertEquals(o, 1L, "getAndSet long"); assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
long x = (long) vh.get(); long x = (long) vh.get();
assertEquals(x, 2L, "getAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
} }
vh.set(1L); vh.set(0x0123456789ABCDEFL);
// get and add, add and get // get and add, add and get
{ {
long o = (long) vh.getAndAdd( 3L); long o = (long) vh.getAndAdd( 0xDEADBEEFDEADBEEFL);
assertEquals(o, 1L, "getAndAdd long"); assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
long c = (long) vh.addAndGet(3L); long c = (long) vh.addAndGet(0xDEADBEEFDEADBEEFL);
assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); assertEquals(c, (long)(0x0123456789ABCDEFL + 0xDEADBEEFDEADBEEFL + 0xDEADBEEFDEADBEEFL), "getAndAdd long value");
} }
} }
@ -624,148 +624,148 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest {
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
// Plain // Plain
{ {
vh.set(array, i, 1L); vh.set(array, i, 0x0123456789ABCDEFL);
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, 1L, "get long value"); assertEquals(x, 0x0123456789ABCDEFL, "get long value");
} }
// Volatile // Volatile
{ {
vh.setVolatile(array, i, 2L); vh.setVolatile(array, i, 0xCAFEBABECAFEBABEL);
long x = (long) vh.getVolatile(array, i); long x = (long) vh.getVolatile(array, i);
assertEquals(x, 2L, "setVolatile long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
} }
// Lazy // Lazy
{ {
vh.setRelease(array, i, 1L); vh.setRelease(array, i, 0x0123456789ABCDEFL);
long x = (long) vh.getAcquire(array, i); long x = (long) vh.getAcquire(array, i);
assertEquals(x, 1L, "setRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
} }
// Opaque // Opaque
{ {
vh.setOpaque(array, i, 2L); vh.setOpaque(array, i, 0xCAFEBABECAFEBABEL);
long x = (long) vh.getOpaque(array, i); long x = (long) vh.getOpaque(array, i);
assertEquals(x, 2L, "setOpaque long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
} }
vh.set(array, i, 1L); vh.set(array, i, 0x0123456789ABCDEFL);
// Compare // Compare
{ {
boolean r = vh.compareAndSet(array, i, 1L, 2L); boolean r = vh.compareAndSet(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
assertEquals(r, true, "success compareAndSet long"); assertEquals(r, true, "success compareAndSet long");
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, 2L, "success compareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
} }
{ {
boolean r = vh.compareAndSet(array, i, 1L, 3L); boolean r = vh.compareAndSet(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, false, "failing compareAndSet long"); assertEquals(r, false, "failing compareAndSet long");
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, 2L, "failing compareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
} }
{ {
long r = (long) vh.compareAndExchangeVolatile(array, i, 2L, 1L); long r = (long) vh.compareAndExchange(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
assertEquals(r, 2L, "success compareAndExchangeVolatile long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, 1L, "success compareAndExchangeVolatile long value"); assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
} }
{ {
long r = (long) vh.compareAndExchangeVolatile(array, i, 2L, 3L); long r = (long) vh.compareAndExchange(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 1L, "failing compareAndExchangeVolatile long"); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, 1L, "failing compareAndExchangeVolatile long value"); assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
} }
{ {
long r = (long) vh.compareAndExchangeAcquire(array, i, 1L, 2L); long r = (long) vh.compareAndExchangeAcquire(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
assertEquals(r, 1L, "success compareAndExchangeAcquire long"); assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, 2L, "success compareAndExchangeAcquire long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
} }
{ {
long r = (long) vh.compareAndExchangeAcquire(array, i, 1L, 3L); long r = (long) vh.compareAndExchangeAcquire(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 2L, "failing compareAndExchangeAcquire long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, 2L, "failing compareAndExchangeAcquire long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
} }
{ {
long r = (long) vh.compareAndExchangeRelease(array, i, 2L, 1L); long r = (long) vh.compareAndExchangeRelease(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
assertEquals(r, 2L, "success compareAndExchangeRelease long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, 1L, "success compareAndExchangeRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
} }
{ {
long r = (long) vh.compareAndExchangeRelease(array, i, 2L, 3L); long r = (long) vh.compareAndExchangeRelease(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 1L, "failing compareAndExchangeRelease long"); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, 1L, "failing compareAndExchangeRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(array, i, 1L, 2L); success = vh.weakCompareAndSet(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
} }
assertEquals(success, true, "weakCompareAndSet long"); assertEquals(success, true, "weakCompareAndSet long");
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, 2L, "weakCompareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSet long value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(array, i, 2L, 1L); success = vh.weakCompareAndSetAcquire(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
} }
assertEquals(success, true, "weakCompareAndSetAcquire long"); assertEquals(success, true, "weakCompareAndSetAcquire long");
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, 1L, "weakCompareAndSetAcquire long"); assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(array, i, 1L, 2L); success = vh.weakCompareAndSetRelease(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
} }
assertEquals(success, true, "weakCompareAndSetRelease long"); assertEquals(success, true, "weakCompareAndSetRelease long");
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, 2L, "weakCompareAndSetRelease long"); assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetVolatile(array, i, 2L, 1L); success = vh.weakCompareAndSetVolatile(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
} }
assertEquals(success, true, "weakCompareAndSetVolatile long"); assertEquals(success, true, "weakCompareAndSetVolatile long");
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, 1L, "weakCompareAndSetVolatile long"); assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetVolatile long");
} }
// Compare set and get // Compare set and get
{ {
long o = (long) vh.getAndSet(array, i, 2L); long o = (long) vh.getAndSet(array, i, 0xCAFEBABECAFEBABEL);
assertEquals(o, 1L, "getAndSet long"); assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, 2L, "getAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
} }
vh.set(array, i, 1L); vh.set(array, i, 0x0123456789ABCDEFL);
// get and add, add and get // get and add, add and get
{ {
long o = (long) vh.getAndAdd(array, i, 3L); long o = (long) vh.getAndAdd(array, i, 0xDEADBEEFDEADBEEFL);
assertEquals(o, 1L, "getAndAdd long"); assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
long c = (long) vh.addAndGet(array, i, 3L); long c = (long) vh.addAndGet(array, i, 0xDEADBEEFDEADBEEFL);
assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); assertEquals(c, (long)(0x0123456789ABCDEFL + 0xDEADBEEFDEADBEEFL + 0xDEADBEEFDEADBEEFL), "getAndAdd long value");
} }
} }
} }
@ -788,7 +788,7 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.set(array, ci, 1L); vh.set(array, ci, 0x0123456789ABCDEFL);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -796,7 +796,7 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.setVolatile(array, ci, 1L); vh.setVolatile(array, ci, 0x0123456789ABCDEFL);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -804,7 +804,7 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.setRelease(array, ci, 1L); vh.setRelease(array, ci, 0x0123456789ABCDEFL);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -812,51 +812,51 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.setOpaque(array, ci, 1L); vh.setOpaque(array, ci, 0x0123456789ABCDEFL);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
boolean r = vh.compareAndSet(array, ci, 1L, 2L); boolean r = vh.compareAndSet(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
long r = (long) vh.compareAndExchangeVolatile(array, ci, 2L, 1L); long r = (long) vh.compareAndExchange(array, ci, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
long r = (long) vh.compareAndExchangeAcquire(array, ci, 2L, 1L); long r = (long) vh.compareAndExchangeAcquire(array, ci, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
long r = (long) vh.compareAndExchangeRelease(array, ci, 2L, 1L); long r = (long) vh.compareAndExchangeRelease(array, ci, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
boolean r = vh.weakCompareAndSet(array, ci, 1L, 2L); boolean r = vh.weakCompareAndSet(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetVolatile(array, ci, 1L, 2L); boolean r = vh.weakCompareAndSetVolatile(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, ci, 1L, 2L); boolean r = vh.weakCompareAndSetAcquire(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetRelease(array, ci, 1L, 2L); boolean r = vh.weakCompareAndSetRelease(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
long o = (long) vh.getAndSet(array, ci, 1L); long o = (long) vh.getAndSet(array, ci, 0x0123456789ABCDEFL);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
long o = (long) vh.getAndAdd(array, ci, 3L); long o = (long) vh.getAndAdd(array, ci, 0xDEADBEEFDEADBEEFL);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
long o = (long) vh.addAndGet(array, ci, 3L); long o = (long) vh.addAndGet(array, ci, 0xDEADBEEFDEADBEEFL);
}); });
} }
} }

View file

@ -42,11 +42,11 @@ import java.util.List;
import static org.testng.Assert.*; import static org.testng.Assert.*;
public class VarHandleTestAccessShort extends VarHandleBaseTest { public class VarHandleTestAccessShort extends VarHandleBaseTest {
static final short static_final_v = (short)1; static final short static_final_v = (short)0x0123;
static short static_v; static short static_v;
final short final_v = (short)1; final short final_v = (short)0x0123;
short v; short v;
@ -99,18 +99,18 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET));
} }
@ -220,89 +220,47 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest {
// Plain // Plain
{ {
short x = (short) vh.get(recv); short x = (short) vh.get(recv);
assertEquals(x, (short)1, "get short value"); assertEquals(x, (short)0x0123, "get short value");
} }
// Volatile // Volatile
{ {
short x = (short) vh.getVolatile(recv); short x = (short) vh.getVolatile(recv);
assertEquals(x, (short)1, "getVolatile short value"); assertEquals(x, (short)0x0123, "getVolatile short value");
} }
// Lazy // Lazy
{ {
short x = (short) vh.getAcquire(recv); short x = (short) vh.getAcquire(recv);
assertEquals(x, (short)1, "getRelease short value"); assertEquals(x, (short)0x0123, "getRelease short value");
} }
// Opaque // Opaque
{ {
short x = (short) vh.getOpaque(recv); short x = (short) vh.getOpaque(recv);
assertEquals(x, (short)1, "getOpaque short value"); assertEquals(x, (short)0x0123, "getOpaque short value");
} }
} }
static void testInstanceFinalFieldUnsupported(VarHandleTestAccessShort recv, VarHandle vh) { static void testInstanceFinalFieldUnsupported(VarHandleTestAccessShort recv, VarHandle vh) {
checkUOE(() -> { checkUOE(() -> {
vh.set(recv, (short)2); vh.set(recv, (short)0x4567);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setVolatile(recv, (short)2); vh.setVolatile(recv, (short)0x4567);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setRelease(recv, (short)2); vh.setRelease(recv, (short)0x4567);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setOpaque(recv, (short)2); vh.setOpaque(recv, (short)0x4567);
}); });
checkUOE(() -> {
boolean r = vh.compareAndSet(recv, (short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.compareAndExchangeVolatile(recv, (short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.compareAndExchangeAcquire(recv, (short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.compareAndExchangeRelease(recv, (short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(recv, (short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(recv, (short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(recv, (short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(recv, (short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.getAndSet(recv, (short)1);
});
checkUOE(() -> {
short o = (short) vh.getAndAdd(recv, (short)1);
});
checkUOE(() -> {
short o = (short) vh.addAndGet(recv, (short)1);
});
} }
@ -310,249 +268,353 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest {
// Plain // Plain
{ {
short x = (short) vh.get(); short x = (short) vh.get();
assertEquals(x, (short)1, "get short value"); assertEquals(x, (short)0x0123, "get short value");
} }
// Volatile // Volatile
{ {
short x = (short) vh.getVolatile(); short x = (short) vh.getVolatile();
assertEquals(x, (short)1, "getVolatile short value"); assertEquals(x, (short)0x0123, "getVolatile short value");
} }
// Lazy // Lazy
{ {
short x = (short) vh.getAcquire(); short x = (short) vh.getAcquire();
assertEquals(x, (short)1, "getRelease short value"); assertEquals(x, (short)0x0123, "getRelease short value");
} }
// Opaque // Opaque
{ {
short x = (short) vh.getOpaque(); short x = (short) vh.getOpaque();
assertEquals(x, (short)1, "getOpaque short value"); assertEquals(x, (short)0x0123, "getOpaque short value");
} }
} }
static void testStaticFinalFieldUnsupported(VarHandle vh) { static void testStaticFinalFieldUnsupported(VarHandle vh) {
checkUOE(() -> { checkUOE(() -> {
vh.set((short)2); vh.set((short)0x4567);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setVolatile((short)2); vh.setVolatile((short)0x4567);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setRelease((short)2); vh.setRelease((short)0x4567);
}); });
checkUOE(() -> { checkUOE(() -> {
vh.setOpaque((short)2); vh.setOpaque((short)0x4567);
}); });
checkUOE(() -> {
boolean r = vh.compareAndSet((short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.compareAndExchangeVolatile((short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.compareAndExchangeAcquire((short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.compareAndExchangeRelease((short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet((short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile((short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire((short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease((short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.getAndSet((short)1);
});
checkUOE(() -> {
short o = (short) vh.getAndAdd((short)1);
});
checkUOE(() -> {
short o = (short) vh.addAndGet((short)1);
});
} }
static void testInstanceField(VarHandleTestAccessShort recv, VarHandle vh) { static void testInstanceField(VarHandleTestAccessShort recv, VarHandle vh) {
// Plain // Plain
{ {
vh.set(recv, (short)1); vh.set(recv, (short)0x0123);
short x = (short) vh.get(recv); short x = (short) vh.get(recv);
assertEquals(x, (short)1, "set short value"); assertEquals(x, (short)0x0123, "set short value");
} }
// Volatile // Volatile
{ {
vh.setVolatile(recv, (short)2); vh.setVolatile(recv, (short)0x4567);
short x = (short) vh.getVolatile(recv); short x = (short) vh.getVolatile(recv);
assertEquals(x, (short)2, "setVolatile short value"); assertEquals(x, (short)0x4567, "setVolatile short value");
} }
// Lazy // Lazy
{ {
vh.setRelease(recv, (short)1); vh.setRelease(recv, (short)0x0123);
short x = (short) vh.getAcquire(recv); short x = (short) vh.getAcquire(recv);
assertEquals(x, (short)1, "setRelease short value"); assertEquals(x, (short)0x0123, "setRelease short value");
} }
// Opaque // Opaque
{ {
vh.setOpaque(recv, (short)2); vh.setOpaque(recv, (short)0x4567);
short x = (short) vh.getOpaque(recv); short x = (short) vh.getOpaque(recv);
assertEquals(x, (short)2, "setOpaque short value"); assertEquals(x, (short)0x4567, "setOpaque short value");
} }
vh.set(recv, (short)0x0123);
// Compare
{
boolean r = vh.compareAndSet(recv, (short)0x0123, (short)0x4567);
assertEquals(r, true, "success compareAndSet short");
short x = (short) vh.get(recv);
assertEquals(x, (short)0x4567, "success compareAndSet short value");
}
{
boolean r = vh.compareAndSet(recv, (short)0x0123, (short)0x89AB);
assertEquals(r, false, "failing compareAndSet short");
short x = (short) vh.get(recv);
assertEquals(x, (short)0x4567, "failing compareAndSet short value");
}
{
short r = (short) vh.compareAndExchange(recv, (short)0x4567, (short)0x0123);
assertEquals(r, (short)0x4567, "success compareAndExchange short");
short x = (short) vh.get(recv);
assertEquals(x, (short)0x0123, "success compareAndExchange short value");
}
{
short r = (short) vh.compareAndExchange(recv, (short)0x4567, (short)0x89AB);
assertEquals(r, (short)0x0123, "failing compareAndExchange short");
short x = (short) vh.get(recv);
assertEquals(x, (short)0x0123, "failing compareAndExchange short value");
}
{
short r = (short) vh.compareAndExchangeAcquire(recv, (short)0x0123, (short)0x4567);
assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short");
short x = (short) vh.get(recv);
assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value");
}
{
short r = (short) vh.compareAndExchangeAcquire(recv, (short)0x0123, (short)0x89AB);
assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short");
short x = (short) vh.get(recv);
assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value");
}
{
short r = (short) vh.compareAndExchangeRelease(recv, (short)0x4567, (short)0x0123);
assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short");
short x = (short) vh.get(recv);
assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value");
}
{
short r = (short) vh.compareAndExchangeRelease(recv, (short)0x4567, (short)0x89AB);
assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short");
short x = (short) vh.get(recv);
assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(recv, (short)0x0123, (short)0x4567);
}
assertEquals(success, true, "weakCompareAndSet short");
short x = (short) vh.get(recv);
assertEquals(x, (short)0x4567, "weakCompareAndSet short value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(recv, (short)0x4567, (short)0x0123);
}
assertEquals(success, true, "weakCompareAndSetAcquire short");
short x = (short) vh.get(recv);
assertEquals(x, (short)0x0123, "weakCompareAndSetAcquire short");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(recv, (short)0x0123, (short)0x4567);
}
assertEquals(success, true, "weakCompareAndSetRelease short");
short x = (short) vh.get(recv);
assertEquals(x, (short)0x4567, "weakCompareAndSetRelease short");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetVolatile(recv, (short)0x4567, (short)0x0123);
}
assertEquals(success, true, "weakCompareAndSetVolatile short");
short x = (short) vh.get(recv);
assertEquals(x, (short)0x0123, "weakCompareAndSetVolatile short value");
}
// Compare set and get
{
short o = (short) vh.getAndSet(recv, (short)0x4567);
assertEquals(o, (short)0x0123, "getAndSet short");
short x = (short) vh.get(recv);
assertEquals(x, (short)0x4567, "getAndSet short value");
}
vh.set(recv, (short)0x0123);
// get and add, add and get
{
short o = (short) vh.getAndAdd(recv, (short)0x89AB);
assertEquals(o, (short)0x0123, "getAndAdd short");
short c = (short) vh.addAndGet(recv, (short)0x89AB);
assertEquals(c, (short)((short)0x0123 + (short)0x89AB + (short)0x89AB), "getAndAdd short value");
}
} }
static void testInstanceFieldUnsupported(VarHandleTestAccessShort recv, VarHandle vh) { static void testInstanceFieldUnsupported(VarHandleTestAccessShort recv, VarHandle vh) {
checkUOE(() -> {
boolean r = vh.compareAndSet(recv, (short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.compareAndExchangeVolatile(recv, (short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.compareAndExchangeAcquire(recv, (short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.compareAndExchangeRelease(recv, (short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(recv, (short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(recv, (short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(recv, (short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(recv, (short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.getAndSet(recv, (short)1);
});
checkUOE(() -> {
short o = (short) vh.getAndAdd(recv, (short)1);
});
checkUOE(() -> {
short o = (short) vh.addAndGet(recv, (short)1);
});
} }
static void testStaticField(VarHandle vh) { static void testStaticField(VarHandle vh) {
// Plain // Plain
{ {
vh.set((short)1); vh.set((short)0x0123);
short x = (short) vh.get(); short x = (short) vh.get();
assertEquals(x, (short)1, "set short value"); assertEquals(x, (short)0x0123, "set short value");
} }
// Volatile // Volatile
{ {
vh.setVolatile((short)2); vh.setVolatile((short)0x4567);
short x = (short) vh.getVolatile(); short x = (short) vh.getVolatile();
assertEquals(x, (short)2, "setVolatile short value"); assertEquals(x, (short)0x4567, "setVolatile short value");
} }
// Lazy // Lazy
{ {
vh.setRelease((short)1); vh.setRelease((short)0x0123);
short x = (short) vh.getAcquire(); short x = (short) vh.getAcquire();
assertEquals(x, (short)1, "setRelease short value"); assertEquals(x, (short)0x0123, "setRelease short value");
} }
// Opaque // Opaque
{ {
vh.setOpaque((short)2); vh.setOpaque((short)0x4567);
short x = (short) vh.getOpaque(); short x = (short) vh.getOpaque();
assertEquals(x, (short)2, "setOpaque short value"); assertEquals(x, (short)0x4567, "setOpaque short value");
} }
vh.set((short)0x0123);
// Compare
{
boolean r = vh.compareAndSet((short)0x0123, (short)0x4567);
assertEquals(r, true, "success compareAndSet short");
short x = (short) vh.get();
assertEquals(x, (short)0x4567, "success compareAndSet short value");
}
{
boolean r = vh.compareAndSet((short)0x0123, (short)0x89AB);
assertEquals(r, false, "failing compareAndSet short");
short x = (short) vh.get();
assertEquals(x, (short)0x4567, "failing compareAndSet short value");
}
{
short r = (short) vh.compareAndExchange((short)0x4567, (short)0x0123);
assertEquals(r, (short)0x4567, "success compareAndExchange short");
short x = (short) vh.get();
assertEquals(x, (short)0x0123, "success compareAndExchange short value");
}
{
short r = (short) vh.compareAndExchange((short)0x4567, (short)0x89AB);
assertEquals(r, (short)0x0123, "failing compareAndExchange short");
short x = (short) vh.get();
assertEquals(x, (short)0x0123, "failing compareAndExchange short value");
}
{
short r = (short) vh.compareAndExchangeAcquire((short)0x0123, (short)0x4567);
assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short");
short x = (short) vh.get();
assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value");
}
{
short r = (short) vh.compareAndExchangeAcquire((short)0x0123, (short)0x89AB);
assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short");
short x = (short) vh.get();
assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value");
}
{
short r = (short) vh.compareAndExchangeRelease((short)0x4567, (short)0x0123);
assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short");
short x = (short) vh.get();
assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value");
}
{
short r = (short) vh.compareAndExchangeRelease((short)0x4567, (short)0x89AB);
assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short");
short x = (short) vh.get();
assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet((short)0x0123, (short)0x4567);
}
assertEquals(success, true, "weakCompareAndSet short");
short x = (short) vh.get();
assertEquals(x, (short)0x4567, "weakCompareAndSet short value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire((short)0x4567, (short)0x0123);
}
assertEquals(success, true, "weakCompareAndSetAcquire short");
short x = (short) vh.get();
assertEquals(x, (short)0x0123, "weakCompareAndSetAcquire short");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease((short)0x0123, (short)0x4567);
}
assertEquals(success, true, "weakCompareAndSetRelease short");
short x = (short) vh.get();
assertEquals(x, (short)0x4567, "weakCompareAndSetRelease short");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease((short)0x4567, (short)0x0123);
}
assertEquals(success, true, "weakCompareAndSetVolatile short");
short x = (short) vh.get();
assertEquals(x, (short)0x0123, "weakCompareAndSetVolatile short");
}
// Compare set and get
{
short o = (short) vh.getAndSet((short)0x4567);
assertEquals(o, (short)0x0123, "getAndSet short");
short x = (short) vh.get();
assertEquals(x, (short)0x4567, "getAndSet short value");
}
vh.set((short)0x0123);
// get and add, add and get
{
short o = (short) vh.getAndAdd( (short)0x89AB);
assertEquals(o, (short)0x0123, "getAndAdd short");
short c = (short) vh.addAndGet((short)0x89AB);
assertEquals(c, (short)((short)0x0123 + (short)0x89AB + (short)0x89AB), "getAndAdd short value");
}
} }
static void testStaticFieldUnsupported(VarHandle vh) { static void testStaticFieldUnsupported(VarHandle vh) {
checkUOE(() -> {
boolean r = vh.compareAndSet((short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.compareAndExchangeVolatile((short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.compareAndExchangeAcquire((short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.compareAndExchangeRelease((short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet((short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile((short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire((short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease((short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.getAndSet((short)1);
});
checkUOE(() -> {
short o = (short) vh.getAndAdd((short)1);
});
checkUOE(() -> {
short o = (short) vh.addAndGet((short)1);
});
} }
@ -562,34 +624,149 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest {
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
// Plain // Plain
{ {
vh.set(array, i, (short)1); vh.set(array, i, (short)0x0123);
short x = (short) vh.get(array, i); short x = (short) vh.get(array, i);
assertEquals(x, (short)1, "get short value"); assertEquals(x, (short)0x0123, "get short value");
} }
// Volatile // Volatile
{ {
vh.setVolatile(array, i, (short)2); vh.setVolatile(array, i, (short)0x4567);
short x = (short) vh.getVolatile(array, i); short x = (short) vh.getVolatile(array, i);
assertEquals(x, (short)2, "setVolatile short value"); assertEquals(x, (short)0x4567, "setVolatile short value");
} }
// Lazy // Lazy
{ {
vh.setRelease(array, i, (short)1); vh.setRelease(array, i, (short)0x0123);
short x = (short) vh.getAcquire(array, i); short x = (short) vh.getAcquire(array, i);
assertEquals(x, (short)1, "setRelease short value"); assertEquals(x, (short)0x0123, "setRelease short value");
} }
// Opaque // Opaque
{ {
vh.setOpaque(array, i, (short)2); vh.setOpaque(array, i, (short)0x4567);
short x = (short) vh.getOpaque(array, i); short x = (short) vh.getOpaque(array, i);
assertEquals(x, (short)2, "setOpaque short value"); assertEquals(x, (short)0x4567, "setOpaque short value");
} }
vh.set(array, i, (short)0x0123);
// Compare
{
boolean r = vh.compareAndSet(array, i, (short)0x0123, (short)0x4567);
assertEquals(r, true, "success compareAndSet short");
short x = (short) vh.get(array, i);
assertEquals(x, (short)0x4567, "success compareAndSet short value");
}
{
boolean r = vh.compareAndSet(array, i, (short)0x0123, (short)0x89AB);
assertEquals(r, false, "failing compareAndSet short");
short x = (short) vh.get(array, i);
assertEquals(x, (short)0x4567, "failing compareAndSet short value");
}
{
short r = (short) vh.compareAndExchange(array, i, (short)0x4567, (short)0x0123);
assertEquals(r, (short)0x4567, "success compareAndExchange short");
short x = (short) vh.get(array, i);
assertEquals(x, (short)0x0123, "success compareAndExchange short value");
}
{
short r = (short) vh.compareAndExchange(array, i, (short)0x4567, (short)0x89AB);
assertEquals(r, (short)0x0123, "failing compareAndExchange short");
short x = (short) vh.get(array, i);
assertEquals(x, (short)0x0123, "failing compareAndExchange short value");
}
{
short r = (short) vh.compareAndExchangeAcquire(array, i, (short)0x0123, (short)0x4567);
assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short");
short x = (short) vh.get(array, i);
assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value");
}
{
short r = (short) vh.compareAndExchangeAcquire(array, i, (short)0x0123, (short)0x89AB);
assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short");
short x = (short) vh.get(array, i);
assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value");
}
{
short r = (short) vh.compareAndExchangeRelease(array, i, (short)0x4567, (short)0x0123);
assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short");
short x = (short) vh.get(array, i);
assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value");
}
{
short r = (short) vh.compareAndExchangeRelease(array, i, (short)0x4567, (short)0x89AB);
assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short");
short x = (short) vh.get(array, i);
assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSet(array, i, (short)0x0123, (short)0x4567);
}
assertEquals(success, true, "weakCompareAndSet short");
short x = (short) vh.get(array, i);
assertEquals(x, (short)0x4567, "weakCompareAndSet short value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetAcquire(array, i, (short)0x4567, (short)0x0123);
}
assertEquals(success, true, "weakCompareAndSetAcquire short");
short x = (short) vh.get(array, i);
assertEquals(x, (short)0x0123, "weakCompareAndSetAcquire short");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetRelease(array, i, (short)0x0123, (short)0x4567);
}
assertEquals(success, true, "weakCompareAndSetRelease short");
short x = (short) vh.get(array, i);
assertEquals(x, (short)0x4567, "weakCompareAndSetRelease short");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = vh.weakCompareAndSetVolatile(array, i, (short)0x4567, (short)0x0123);
}
assertEquals(success, true, "weakCompareAndSetVolatile short");
short x = (short) vh.get(array, i);
assertEquals(x, (short)0x0123, "weakCompareAndSetVolatile short");
}
// Compare set and get
{
short o = (short) vh.getAndSet(array, i, (short)0x4567);
assertEquals(o, (short)0x0123, "getAndSet short");
short x = (short) vh.get(array, i);
assertEquals(x, (short)0x4567, "getAndSet short value");
}
vh.set(array, i, (short)0x0123);
// get and add, add and get
{
short o = (short) vh.getAndAdd(array, i, (short)0x89AB);
assertEquals(o, (short)0x0123, "getAndAdd short");
short c = (short) vh.addAndGet(array, i, (short)0x89AB);
assertEquals(c, (short)((short)0x0123 + (short)0x89AB + (short)0x89AB), "getAndAdd short value");
}
} }
} }
@ -597,49 +774,7 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest {
short[] array = new short[10]; short[] array = new short[10];
int i = 0; int i = 0;
checkUOE(() -> {
boolean r = vh.compareAndSet(array, i, (short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.compareAndExchangeVolatile(array, i, (short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.compareAndExchangeAcquire(array, i, (short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.compareAndExchangeRelease(array, i, (short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSet(array, i, (short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetVolatile(array, i, (short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, i, (short)1, (short)2);
});
checkUOE(() -> {
boolean r = vh.weakCompareAndSetRelease(array, i, (short)1, (short)2);
});
checkUOE(() -> {
short r = (short) vh.getAndSet(array, i, (short)1);
});
checkUOE(() -> {
short o = (short) vh.getAndAdd(array, i, (short)1);
});
checkUOE(() -> {
short o = (short) vh.addAndGet(array, i, (short)1);
});
} }
static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable { static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
@ -653,7 +788,7 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.set(array, ci, (short)1); vh.set(array, ci, (short)0x0123);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -661,7 +796,7 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.setVolatile(array, ci, (short)1); vh.setVolatile(array, ci, (short)0x0123);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -669,7 +804,7 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.setRelease(array, ci, (short)1); vh.setRelease(array, ci, (short)0x0123);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -677,10 +812,52 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
vh.setOpaque(array, ci, (short)1); vh.setOpaque(array, ci, (short)0x0123);
}); });
checkIOOBE(() -> {
boolean r = vh.compareAndSet(array, ci, (short)0x0123, (short)0x4567);
});
checkIOOBE(() -> {
short r = (short) vh.compareAndExchange(array, ci, (short)0x4567, (short)0x0123);
});
checkIOOBE(() -> {
short r = (short) vh.compareAndExchangeAcquire(array, ci, (short)0x4567, (short)0x0123);
});
checkIOOBE(() -> {
short r = (short) vh.compareAndExchangeRelease(array, ci, (short)0x4567, (short)0x0123);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSet(array, ci, (short)0x0123, (short)0x4567);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetVolatile(array, ci, (short)0x0123, (short)0x4567);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, ci, (short)0x0123, (short)0x4567);
});
checkIOOBE(() -> {
boolean r = vh.weakCompareAndSetRelease(array, ci, (short)0x0123, (short)0x4567);
});
checkIOOBE(() -> {
short o = (short) vh.getAndSet(array, ci, (short)0x0123);
});
checkIOOBE(() -> {
short o = (short) vh.getAndAdd(array, ci, (short)0x89AB);
});
checkIOOBE(() -> {
short o = (short) vh.addAndGet(array, ci, (short)0x89AB);
});
} }
} }
} }

View file

@ -100,7 +100,7 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
@ -374,17 +374,17 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
} }
{ {
String r = (String) vh.compareAndExchangeVolatile(recv, "bar", "foo"); String r = (String) vh.compareAndExchange(recv, "bar", "foo");
assertEquals(r, "bar", "success compareAndExchangeVolatile String"); assertEquals(r, "bar", "success compareAndExchange String");
String x = (String) vh.get(recv); String x = (String) vh.get(recv);
assertEquals(x, "foo", "success compareAndExchangeVolatile String value"); assertEquals(x, "foo", "success compareAndExchange String value");
} }
{ {
String r = (String) vh.compareAndExchangeVolatile(recv, "bar", "baz"); String r = (String) vh.compareAndExchange(recv, "bar", "baz");
assertEquals(r, "foo", "failing compareAndExchangeVolatile String"); assertEquals(r, "foo", "failing compareAndExchange String");
String x = (String) vh.get(recv); String x = (String) vh.get(recv);
assertEquals(x, "foo", "failing compareAndExchangeVolatile String value"); assertEquals(x, "foo", "failing compareAndExchange String value");
} }
{ {
@ -525,17 +525,17 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
} }
{ {
String r = (String) vh.compareAndExchangeVolatile("bar", "foo"); String r = (String) vh.compareAndExchange("bar", "foo");
assertEquals(r, "bar", "success compareAndExchangeVolatile String"); assertEquals(r, "bar", "success compareAndExchange String");
String x = (String) vh.get(); String x = (String) vh.get();
assertEquals(x, "foo", "success compareAndExchangeVolatile String value"); assertEquals(x, "foo", "success compareAndExchange String value");
} }
{ {
String r = (String) vh.compareAndExchangeVolatile("bar", "baz"); String r = (String) vh.compareAndExchange("bar", "baz");
assertEquals(r, "foo", "failing compareAndExchangeVolatile String"); assertEquals(r, "foo", "failing compareAndExchange String");
String x = (String) vh.get(); String x = (String) vh.get();
assertEquals(x, "foo", "failing compareAndExchangeVolatile String value"); assertEquals(x, "foo", "failing compareAndExchange String value");
} }
{ {
@ -679,17 +679,17 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
} }
{ {
String r = (String) vh.compareAndExchangeVolatile(array, i, "bar", "foo"); String r = (String) vh.compareAndExchange(array, i, "bar", "foo");
assertEquals(r, "bar", "success compareAndExchangeVolatile String"); assertEquals(r, "bar", "success compareAndExchange String");
String x = (String) vh.get(array, i); String x = (String) vh.get(array, i);
assertEquals(x, "foo", "success compareAndExchangeVolatile String value"); assertEquals(x, "foo", "success compareAndExchange String value");
} }
{ {
String r = (String) vh.compareAndExchangeVolatile(array, i, "bar", "baz"); String r = (String) vh.compareAndExchange(array, i, "bar", "baz");
assertEquals(r, "foo", "failing compareAndExchangeVolatile String"); assertEquals(r, "foo", "failing compareAndExchange String");
String x = (String) vh.get(array, i); String x = (String) vh.get(array, i);
assertEquals(x, "foo", "failing compareAndExchangeVolatile String value"); assertEquals(x, "foo", "failing compareAndExchange String value");
} }
{ {
@ -828,7 +828,7 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
String r = (String) vh.compareAndExchangeVolatile(array, ci, "bar", "foo"); String r = (String) vh.compareAndExchange(array, ci, "bar", "foo");
}); });
checkIOOBE(() -> { checkIOOBE(() -> {

View file

@ -89,7 +89,7 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
@ -189,7 +189,7 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest {
}); });
checkUOE(() -> { checkUOE(() -> {
char r = (char) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); char r = (char) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkUOE(() -> { checkUOE(() -> {
@ -258,7 +258,7 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest {
}); });
checkUOE(() -> { checkUOE(() -> {
char r = (char) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); char r = (char) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkUOE(() -> { checkUOE(() -> {
@ -303,7 +303,7 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest {
}); });
checkUOE(() -> { checkUOE(() -> {
char r = (char) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); char r = (char) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkUOE(() -> { checkUOE(() -> {

View file

@ -89,7 +89,7 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
@ -224,7 +224,7 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
}); });
checkROBE(() -> { checkROBE(() -> {
double r = (double) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); double r = (double) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkROBE(() -> { checkROBE(() -> {
@ -321,7 +321,7 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
double r = (double) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); double r = (double) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -406,7 +406,7 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
double r = (double) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); double r = (double) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -482,7 +482,7 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
}); });
checkISE(() -> { checkISE(() -> {
double r = (double) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); double r = (double) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkISE(() -> { checkISE(() -> {
@ -561,7 +561,7 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
}); });
checkISE(() -> { checkISE(() -> {
double r = (double) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); double r = (double) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkISE(() -> { checkISE(() -> {
@ -656,17 +656,17 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
} }
{ {
double r = (double) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_1); double r = (double) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchangeVolatile double"); assertEquals(r, VALUE_2, "success compareAndExchange double");
double x = (double) vh.get(array, i); double x = (double) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchangeVolatile double value"); assertEquals(x, VALUE_1, "success compareAndExchange double value");
} }
{ {
double r = (double) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_3); double r = (double) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchangeVolatile double"); assertEquals(r, VALUE_1, "failing compareAndExchange double");
double x = (double) vh.get(array, i); double x = (double) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchangeVolatile double value"); assertEquals(x, VALUE_1, "failing compareAndExchange double value");
} }
{ {
@ -805,17 +805,17 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
} }
{ {
double r = (double) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_1); double r = (double) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchangeVolatile double"); assertEquals(r, VALUE_2, "success compareAndExchange double");
double x = (double) vh.get(array, i); double x = (double) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchangeVolatile double value"); assertEquals(x, VALUE_1, "success compareAndExchange double value");
} }
{ {
double r = (double) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_3); double r = (double) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchangeVolatile double"); assertEquals(r, VALUE_1, "failing compareAndExchange double");
double x = (double) vh.get(array, i); double x = (double) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchangeVolatile double value"); assertEquals(x, VALUE_1, "failing compareAndExchange double value");
} }
{ {

View file

@ -89,7 +89,7 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
@ -224,7 +224,7 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
}); });
checkROBE(() -> { checkROBE(() -> {
float r = (float) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); float r = (float) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkROBE(() -> { checkROBE(() -> {
@ -321,7 +321,7 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
float r = (float) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); float r = (float) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -406,7 +406,7 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
float r = (float) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); float r = (float) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -482,7 +482,7 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
}); });
checkISE(() -> { checkISE(() -> {
float r = (float) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); float r = (float) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkISE(() -> { checkISE(() -> {
@ -561,7 +561,7 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
}); });
checkISE(() -> { checkISE(() -> {
float r = (float) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); float r = (float) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkISE(() -> { checkISE(() -> {
@ -656,17 +656,17 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
} }
{ {
float r = (float) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_1); float r = (float) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchangeVolatile float"); assertEquals(r, VALUE_2, "success compareAndExchange float");
float x = (float) vh.get(array, i); float x = (float) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchangeVolatile float value"); assertEquals(x, VALUE_1, "success compareAndExchange float value");
} }
{ {
float r = (float) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_3); float r = (float) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchangeVolatile float"); assertEquals(r, VALUE_1, "failing compareAndExchange float");
float x = (float) vh.get(array, i); float x = (float) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchangeVolatile float value"); assertEquals(x, VALUE_1, "failing compareAndExchange float value");
} }
{ {
@ -805,17 +805,17 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
} }
{ {
float r = (float) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_1); float r = (float) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchangeVolatile float"); assertEquals(r, VALUE_2, "success compareAndExchange float");
float x = (float) vh.get(array, i); float x = (float) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchangeVolatile float value"); assertEquals(x, VALUE_1, "success compareAndExchange float value");
} }
{ {
float r = (float) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_3); float r = (float) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchangeVolatile float"); assertEquals(r, VALUE_1, "failing compareAndExchange float");
float x = (float) vh.get(array, i); float x = (float) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchangeVolatile float value"); assertEquals(x, VALUE_1, "failing compareAndExchange float value");
} }
{ {

View file

@ -89,7 +89,7 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
@ -217,7 +217,7 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
}); });
checkROBE(() -> { checkROBE(() -> {
int r = (int) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); int r = (int) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkROBE(() -> { checkROBE(() -> {
@ -307,7 +307,7 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
int r = (int) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); int r = (int) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -399,7 +399,7 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
int r = (int) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); int r = (int) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -482,7 +482,7 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
}); });
checkISE(() -> { checkISE(() -> {
int r = (int) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); int r = (int) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkISE(() -> { checkISE(() -> {
@ -568,7 +568,7 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
}); });
checkISE(() -> { checkISE(() -> {
int r = (int) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); int r = (int) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkISE(() -> { checkISE(() -> {
@ -670,17 +670,17 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
} }
{ {
int r = (int) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_1); int r = (int) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchangeVolatile int"); assertEquals(r, VALUE_2, "success compareAndExchange int");
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchangeVolatile int value"); assertEquals(x, VALUE_1, "success compareAndExchange int value");
} }
{ {
int r = (int) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_3); int r = (int) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchangeVolatile int"); assertEquals(r, VALUE_1, "failing compareAndExchange int");
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchangeVolatile int value"); assertEquals(x, VALUE_1, "failing compareAndExchange int value");
} }
{ {
@ -828,17 +828,17 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
} }
{ {
int r = (int) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_1); int r = (int) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchangeVolatile int"); assertEquals(r, VALUE_2, "success compareAndExchange int");
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchangeVolatile int value"); assertEquals(x, VALUE_1, "success compareAndExchange int value");
} }
{ {
int r = (int) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_3); int r = (int) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchangeVolatile int"); assertEquals(r, VALUE_1, "failing compareAndExchange int");
int x = (int) vh.get(array, i); int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchangeVolatile int value"); assertEquals(x, VALUE_1, "failing compareAndExchange int value");
} }
{ {

View file

@ -89,7 +89,7 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
@ -217,7 +217,7 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
}); });
checkROBE(() -> { checkROBE(() -> {
long r = (long) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); long r = (long) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkROBE(() -> { checkROBE(() -> {
@ -307,7 +307,7 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
long r = (long) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); long r = (long) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -399,7 +399,7 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
long r = (long) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); long r = (long) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -482,7 +482,7 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
}); });
checkISE(() -> { checkISE(() -> {
long r = (long) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); long r = (long) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkISE(() -> { checkISE(() -> {
@ -568,7 +568,7 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
}); });
checkISE(() -> { checkISE(() -> {
long r = (long) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); long r = (long) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkISE(() -> { checkISE(() -> {
@ -670,17 +670,17 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
} }
{ {
long r = (long) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_1); long r = (long) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchangeVolatile long"); assertEquals(r, VALUE_2, "success compareAndExchange long");
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchangeVolatile long value"); assertEquals(x, VALUE_1, "success compareAndExchange long value");
} }
{ {
long r = (long) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_3); long r = (long) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchangeVolatile long"); assertEquals(r, VALUE_1, "failing compareAndExchange long");
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchangeVolatile long value"); assertEquals(x, VALUE_1, "failing compareAndExchange long value");
} }
{ {
@ -828,17 +828,17 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
} }
{ {
long r = (long) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_1); long r = (long) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchangeVolatile long"); assertEquals(r, VALUE_2, "success compareAndExchange long");
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchangeVolatile long value"); assertEquals(x, VALUE_1, "success compareAndExchange long value");
} }
{ {
long r = (long) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_3); long r = (long) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchangeVolatile long"); assertEquals(r, VALUE_1, "failing compareAndExchange long");
long x = (long) vh.get(array, i); long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchangeVolatile long value"); assertEquals(x, VALUE_1, "failing compareAndExchange long value");
} }
{ {

View file

@ -89,7 +89,7 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
@ -189,7 +189,7 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest {
}); });
checkUOE(() -> { checkUOE(() -> {
short r = (short) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); short r = (short) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkUOE(() -> { checkUOE(() -> {
@ -258,7 +258,7 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest {
}); });
checkUOE(() -> { checkUOE(() -> {
short r = (short) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); short r = (short) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkUOE(() -> { checkUOE(() -> {
@ -303,7 +303,7 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest {
}); });
checkUOE(() -> { checkUOE(() -> {
short r = (short) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); short r = (short) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkUOE(() -> { checkUOE(() -> {

View file

@ -148,27 +148,116 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
assertEquals(x, false, "setOpaque boolean value"); assertEquals(x, false, "setOpaque boolean value");
} }
hs.get(TestAccessMode.SET).invokeExact(recv, true);
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, true, false);
assertEquals(r, true, "success compareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, false, "success compareAndSet boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, true, false);
assertEquals(r, false, "failing compareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, false, "failing compareAndSet boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, false, true);
assertEquals(r, false, "success compareAndExchange boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, true, "success compareAndExchange boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, false, false);
assertEquals(r, true, "failing compareAndExchange boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, true, "failing compareAndExchange boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, true, false);
assertEquals(r, true, "success compareAndExchangeAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, true, false);
assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, false, true);
assertEquals(r, false, "success compareAndExchangeRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, true, "success compareAndExchangeRelease boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, false, false);
assertEquals(r, true, "failing compareAndExchangeRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, true, false);
}
assertEquals(success, true, "weakCompareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, false, "weakCompareAndSet boolean value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, false, true);
}
assertEquals(success, true, "weakCompareAndSetAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, true, "weakCompareAndSetAcquire boolean");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, true, false);
}
assertEquals(success, true, "weakCompareAndSetRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, false, "weakCompareAndSetRelease boolean");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, false, true);
}
assertEquals(success, true, "weakCompareAndSetVolatile boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, true, "weakCompareAndSetVolatile boolean");
}
// Compare set and get
{
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, false);
assertEquals(o, true, "getAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, false, "getAndSet boolean value");
}
} }
static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessBoolean recv, Handles hs) throws Throwable { static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessBoolean recv, Handles hs) throws Throwable {
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(recv, true, false);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(recv, true, false);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(recv, true);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> { checkUOE(am, () -> {
@ -208,27 +297,116 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
assertEquals(x, false, "setOpaque boolean value"); assertEquals(x, false, "setOpaque boolean value");
} }
hs.get(TestAccessMode.SET).invokeExact(true);
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(true, false);
assertEquals(r, true, "success compareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "success compareAndSet boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(true, false);
assertEquals(r, false, "failing compareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "failing compareAndSet boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(false, true);
assertEquals(r, false, "success compareAndExchange boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, true, "success compareAndExchange boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(false, false);
assertEquals(r, true, "failing compareAndExchange boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, true, "failing compareAndExchange boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(true, false);
assertEquals(r, true, "success compareAndExchangeAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(true, false);
assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(false, true);
assertEquals(r, false, "success compareAndExchangeRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, true, "success compareAndExchangeRelease boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(false, false);
assertEquals(r, true, "failing compareAndExchangeRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(true, false);
}
assertEquals(success, true, "weakCompareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "weakCompareAndSet boolean value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(false, true);
}
assertEquals(success, true, "weakCompareAndSetAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, true, "weakCompareAndSetAcquire boolean");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(true, false);
}
assertEquals(success, true, "weakCompareAndSetRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "weakCompareAndSetRelease boolean");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(false, true);
}
assertEquals(success, true, "weakCompareAndSetVolatile boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, true, "weakCompareAndSetVolatile boolean");
}
// Compare set and get
{
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact( false);
assertEquals(o, true, "getAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "getAndSet boolean value");
}
} }
static void testStaticFieldUnsupported(Handles hs) throws Throwable { static void testStaticFieldUnsupported(Handles hs) throws Throwable {
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(true, false);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(true, false);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(true);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> { checkUOE(am, () -> {
@ -271,6 +449,112 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
assertEquals(x, false, "setOpaque boolean value"); assertEquals(x, false, "setOpaque boolean value");
} }
hs.get(TestAccessMode.SET).invokeExact(array, i, true);
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, true, false);
assertEquals(r, true, "success compareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "success compareAndSet boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, true, false);
assertEquals(r, false, "failing compareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "failing compareAndSet boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, false, true);
assertEquals(r, false, "success compareAndExchange boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, true, "success compareAndExchange boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, false, false);
assertEquals(r, true, "failing compareAndExchange boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, true, "failing compareAndExchange boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, true, false);
assertEquals(r, true, "success compareAndExchangeAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, true, false);
assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, false, true);
assertEquals(r, false, "success compareAndExchangeRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, true, "success compareAndExchangeRelease boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, false, false);
assertEquals(r, true, "failing compareAndExchangeRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, true, false);
}
assertEquals(success, true, "weakCompareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "weakCompareAndSet boolean value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, false, true);
}
assertEquals(success, true, "weakCompareAndSetAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, true, "weakCompareAndSetAcquire boolean");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, true, false);
}
assertEquals(success, true, "weakCompareAndSetRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "weakCompareAndSetRelease boolean");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, false, true);
}
assertEquals(success, true, "weakCompareAndSetVolatile boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, true, "weakCompareAndSetVolatile boolean");
}
// Compare set and get
{
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, false);
assertEquals(o, true, "getAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "getAndSet boolean value");
}
} }
} }
@ -279,23 +563,6 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
boolean[] array = new boolean[10]; boolean[] array = new boolean[10];
final int i = 0; final int i = 0;
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(array, i, true, false);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(array, i, true, false);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(array, i, true);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> { checkUOE(am, () -> {
@ -322,6 +589,23 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
}); });
} }
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkIOOBE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(array, ci, true, false);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkIOOBE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(array, ci, false, true);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkIOOBE(am, () -> {
boolean o = (boolean) hs.get(am).invokeExact(array, ci, true);
});
}
} }
} }

View file

@ -39,11 +39,11 @@ import java.util.List;
import static org.testng.Assert.*; import static org.testng.Assert.*;
public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest {
static final byte static_final_v = (byte)1; static final byte static_final_v = (byte)0x01;
static byte static_v; static byte static_v;
final byte final_v = (byte)1; final byte final_v = (byte)0x01;
byte v; byte v;
@ -121,120 +121,306 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest {
static void testInstanceField(VarHandleTestMethodHandleAccessByte recv, Handles hs) throws Throwable { static void testInstanceField(VarHandleTestMethodHandleAccessByte recv, Handles hs) throws Throwable {
// Plain // Plain
{ {
hs.get(TestAccessMode.SET).invokeExact(recv, (byte)1); hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (byte)1, "set byte value"); assertEquals(x, (byte)0x01, "set byte value");
} }
// Volatile // Volatile
{ {
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, (byte)2); hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, (byte)0x23);
byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
assertEquals(x, (byte)2, "setVolatile byte value"); assertEquals(x, (byte)0x23, "setVolatile byte value");
} }
// Lazy // Lazy
{ {
hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, (byte)1); hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, (byte)0x01);
byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
assertEquals(x, (byte)1, "setRelease byte value"); assertEquals(x, (byte)0x01, "setRelease byte value");
} }
// Opaque // Opaque
{ {
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, (byte)2); hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, (byte)0x23);
byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
assertEquals(x, (byte)2, "setOpaque byte value"); assertEquals(x, (byte)0x23, "setOpaque byte value");
} }
hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (byte)0x01, (byte)0x23);
assertEquals(r, true, "success compareAndSet byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (byte)0x23, "success compareAndSet byte value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (byte)0x01, (byte)0x45);
assertEquals(r, false, "failing compareAndSet byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (byte)0x23, (byte)0x01);
assertEquals(r, (byte)0x23, "success compareAndExchange byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (byte)0x01, "success compareAndExchange byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (byte)0x23, (byte)0x45);
assertEquals(r, (byte)0x01, "failing compareAndExchange byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (byte)0x01, "failing compareAndExchange byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (byte)0x01, (byte)0x23);
assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (byte)0x01, (byte)0x45);
assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (byte)0x23, (byte)0x01);
assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (byte)0x23, (byte)0x45);
assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, (byte)0x01, (byte)0x23);
}
assertEquals(success, true, "weakCompareAndSet byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (byte)0x23, "weakCompareAndSet byte value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, (byte)0x23, (byte)0x01);
}
assertEquals(success, true, "weakCompareAndSetAcquire byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, (byte)0x01, (byte)0x23);
}
assertEquals(success, true, "weakCompareAndSetRelease byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, (byte)0x23, (byte)0x01);
}
assertEquals(success, true, "weakCompareAndSetVolatile byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte");
}
// Compare set and get
{
byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, (byte)0x23);
assertEquals(o, (byte)0x01, "getAndSet byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (byte)0x23, "getAndSet byte value");
}
hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
// get and add, add and get
{
byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, (byte)0x45);
assertEquals(o, (byte)0x01, "getAndAdd byte");
byte c = (byte) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, (byte)0x45);
assertEquals(c, (byte)((byte)0x01 + (byte)0x45 + (byte)0x45), "getAndAdd byte value");
}
} }
static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessByte recv, Handles hs) throws Throwable { static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessByte recv, Handles hs) throws Throwable {
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(recv, (byte)1, (byte)2);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
byte r = (byte) hs.get(am).invokeExact(recv, (byte)1, (byte)2);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
byte r = (byte) hs.get(am).invokeExact(recv, (byte)1);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> {
byte r = (byte) hs.get(am).invokeExact(recv, (byte)1);
});
}
} }
static void testStaticField(Handles hs) throws Throwable { static void testStaticField(Handles hs) throws Throwable {
// Plain // Plain
{ {
hs.get(TestAccessMode.SET).invokeExact((byte)1); hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (byte)1, "set byte value"); assertEquals(x, (byte)0x01, "set byte value");
} }
// Volatile // Volatile
{ {
hs.get(TestAccessMode.SET_VOLATILE).invokeExact((byte)2); hs.get(TestAccessMode.SET_VOLATILE).invokeExact((byte)0x23);
byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
assertEquals(x, (byte)2, "setVolatile byte value"); assertEquals(x, (byte)0x23, "setVolatile byte value");
} }
// Lazy // Lazy
{ {
hs.get(TestAccessMode.SET_RELEASE).invokeExact((byte)1); hs.get(TestAccessMode.SET_RELEASE).invokeExact((byte)0x01);
byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
assertEquals(x, (byte)1, "setRelease byte value"); assertEquals(x, (byte)0x01, "setRelease byte value");
} }
// Opaque // Opaque
{ {
hs.get(TestAccessMode.SET_OPAQUE).invokeExact((byte)2); hs.get(TestAccessMode.SET_OPAQUE).invokeExact((byte)0x23);
byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
assertEquals(x, (byte)2, "setOpaque byte value"); assertEquals(x, (byte)0x23, "setOpaque byte value");
} }
hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((byte)0x01, (byte)0x23);
assertEquals(r, true, "success compareAndSet byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (byte)0x23, "success compareAndSet byte value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((byte)0x01, (byte)0x45);
assertEquals(r, false, "failing compareAndSet byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((byte)0x23, (byte)0x01);
assertEquals(r, (byte)0x23, "success compareAndExchange byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (byte)0x01, "success compareAndExchange byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((byte)0x23, (byte)0x45);
assertEquals(r, (byte)0x01, "failing compareAndExchange byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (byte)0x01, "failing compareAndExchange byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((byte)0x01, (byte)0x23);
assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((byte)0x01, (byte)0x45);
assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((byte)0x23, (byte)0x01);
assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((byte)0x23, (byte)0x45);
assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact((byte)0x01, (byte)0x23);
}
assertEquals(success, true, "weakCompareAndSet byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (byte)0x23, "weakCompareAndSet byte value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact((byte)0x23, (byte)0x01);
}
assertEquals(success, true, "weakCompareAndSetAcquire byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact((byte)0x01, (byte)0x23);
}
assertEquals(success, true, "weakCompareAndSetRelease byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact((byte)0x23, (byte)0x01);
}
assertEquals(success, true, "weakCompareAndSetVolatile byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte");
}
// Compare set and get
{
byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact( (byte)0x23);
assertEquals(o, (byte)0x01, "getAndSet byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (byte)0x23, "getAndSet byte value");
}
hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
// get and add, add and get
{
byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( (byte)0x45);
assertEquals(o, (byte)0x01, "getAndAdd byte");
byte c = (byte) hs.get(TestAccessMode.ADD_AND_GET).invokeExact((byte)0x45);
assertEquals(c, (byte)((byte)0x01 + (byte)0x45 + (byte)0x45), "getAndAdd byte value");
}
} }
static void testStaticFieldUnsupported(Handles hs) throws Throwable { static void testStaticFieldUnsupported(Handles hs) throws Throwable {
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact((byte)1, (byte)2);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
byte r = (byte) hs.get(am).invokeExact((byte)1, (byte)2);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
byte r = (byte) hs.get(am).invokeExact((byte)1);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> {
byte r = (byte) hs.get(am).invokeExact((byte)1);
});
}
} }
@ -244,34 +430,149 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest {
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
// Plain // Plain
{ {
hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)1); hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (byte)1, "get byte value"); assertEquals(x, (byte)0x01, "get byte value");
} }
// Volatile // Volatile
{ {
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, (byte)2); hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, (byte)0x23);
byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
assertEquals(x, (byte)2, "setVolatile byte value"); assertEquals(x, (byte)0x23, "setVolatile byte value");
} }
// Lazy // Lazy
{ {
hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, (byte)1); hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, (byte)0x01);
byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
assertEquals(x, (byte)1, "setRelease byte value"); assertEquals(x, (byte)0x01, "setRelease byte value");
} }
// Opaque // Opaque
{ {
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, (byte)2); hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, (byte)0x23);
byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
assertEquals(x, (byte)2, "setOpaque byte value"); assertEquals(x, (byte)0x23, "setOpaque byte value");
} }
hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (byte)0x01, (byte)0x23);
assertEquals(r, true, "success compareAndSet byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (byte)0x23, "success compareAndSet byte value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (byte)0x01, (byte)0x45);
assertEquals(r, false, "failing compareAndSet byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (byte)0x23, (byte)0x01);
assertEquals(r, (byte)0x23, "success compareAndExchange byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (byte)0x01, "success compareAndExchange byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (byte)0x23, (byte)0x45);
assertEquals(r, (byte)0x01, "failing compareAndExchange byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (byte)0x01, "failing compareAndExchange byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (byte)0x01, (byte)0x23);
assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (byte)0x01, (byte)0x45);
assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (byte)0x23, (byte)0x01);
assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
}
{
byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (byte)0x23, (byte)0x45);
assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, (byte)0x01, (byte)0x23);
}
assertEquals(success, true, "weakCompareAndSet byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (byte)0x23, "weakCompareAndSet byte value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, (byte)0x23, (byte)0x01);
}
assertEquals(success, true, "weakCompareAndSetAcquire byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, (byte)0x01, (byte)0x23);
}
assertEquals(success, true, "weakCompareAndSetRelease byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, (byte)0x23, (byte)0x01);
}
assertEquals(success, true, "weakCompareAndSetVolatile byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte");
}
// Compare set and get
{
byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, (byte)0x23);
assertEquals(o, (byte)0x01, "getAndSet byte");
byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (byte)0x23, "getAndSet byte value");
}
hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
// get and add, add and get
{
byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, (byte)0x45);
assertEquals(o, (byte)0x01, "getAndAdd byte");
byte c = (byte) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, (byte)0x45);
assertEquals(c, (byte)((byte)0x01 + (byte)0x45 + (byte)0x45), "getAndAdd byte value");
}
} }
} }
@ -279,29 +580,7 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest {
byte[] array = new byte[10]; byte[] array = new byte[10];
final int i = 0; final int i = 0;
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(array, i, (byte)1, (byte)2);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
byte r = (byte) hs.get(am).invokeExact(array, i, (byte)1, (byte)2);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
byte r = (byte) hs.get(am).invokeExact(array, i, (byte)1);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> {
byte o = (byte) hs.get(am).invokeExact(array, i, (byte)1);
});
}
} }
static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
@ -318,11 +597,33 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest {
for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
checkIOOBE(am, () -> { checkIOOBE(am, () -> {
hs.get(am).invokeExact(array, ci, (byte)1); hs.get(am).invokeExact(array, ci, (byte)0x01);
}); });
} }
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkIOOBE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(array, ci, (byte)0x01, (byte)0x23);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkIOOBE(am, () -> {
byte r = (byte) hs.get(am).invokeExact(array, ci, (byte)0x23, (byte)0x01);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkIOOBE(am, () -> {
byte o = (byte) hs.get(am).invokeExact(array, ci, (byte)0x01);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkIOOBE(am, () -> {
byte o = (byte) hs.get(am).invokeExact(array, ci, (byte)0x45);
});
}
} }
} }
} }

View file

@ -39,11 +39,11 @@ import java.util.List;
import static org.testng.Assert.*; import static org.testng.Assert.*;
public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest {
static final char static_final_v = 'a'; static final char static_final_v = '\u0123';
static char static_v; static char static_v;
final char final_v = 'a'; final char final_v = '\u0123';
char v; char v;
@ -121,120 +121,306 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest {
static void testInstanceField(VarHandleTestMethodHandleAccessChar recv, Handles hs) throws Throwable { static void testInstanceField(VarHandleTestMethodHandleAccessChar recv, Handles hs) throws Throwable {
// Plain // Plain
{ {
hs.get(TestAccessMode.SET).invokeExact(recv, 'a'); hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123');
char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 'a', "set char value"); assertEquals(x, '\u0123', "set char value");
} }
// Volatile // Volatile
{ {
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 'b'); hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, '\u4567');
char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
assertEquals(x, 'b', "setVolatile char value"); assertEquals(x, '\u4567', "setVolatile char value");
} }
// Lazy // Lazy
{ {
hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 'a'); hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, '\u0123');
char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
assertEquals(x, 'a', "setRelease char value"); assertEquals(x, '\u0123', "setRelease char value");
} }
// Opaque // Opaque
{ {
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 'b'); hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, '\u4567');
char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
assertEquals(x, 'b', "setOpaque char value"); assertEquals(x, '\u4567', "setOpaque char value");
} }
hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123');
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, '\u0123', '\u4567');
assertEquals(r, true, "success compareAndSet char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, '\u4567', "success compareAndSet char value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, '\u0123', '\u89AB');
assertEquals(r, false, "failing compareAndSet char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, '\u4567', "failing compareAndSet char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, '\u4567', '\u0123');
assertEquals(r, '\u4567', "success compareAndExchange char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, '\u0123', "success compareAndExchange char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, '\u4567', '\u89AB');
assertEquals(r, '\u0123', "failing compareAndExchange char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, '\u0123', "failing compareAndExchange char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, '\u0123', '\u4567');
assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, '\u0123', '\u89AB');
assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, '\u4567', '\u0123');
assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, '\u4567', '\u89AB');
assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, '\u0123', '\u4567');
}
assertEquals(success, true, "weakCompareAndSet char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, '\u4567', "weakCompareAndSet char value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, '\u4567', '\u0123');
}
assertEquals(success, true, "weakCompareAndSetAcquire char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, '\u0123', '\u4567');
}
assertEquals(success, true, "weakCompareAndSetRelease char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, '\u4567', '\u0123');
}
assertEquals(success, true, "weakCompareAndSetVolatile char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, '\u0123', "weakCompareAndSetVolatile char");
}
// Compare set and get
{
char o = (char) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, '\u4567');
assertEquals(o, '\u0123', "getAndSet char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, '\u4567', "getAndSet char value");
}
hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123');
// get and add, add and get
{
char o = (char) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, '\u89AB');
assertEquals(o, '\u0123', "getAndAdd char");
char c = (char) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, '\u89AB');
assertEquals(c, (char)('\u0123' + '\u89AB' + '\u89AB'), "getAndAdd char value");
}
} }
static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessChar recv, Handles hs) throws Throwable { static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessChar recv, Handles hs) throws Throwable {
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(recv, 'a', 'b');
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
char r = (char) hs.get(am).invokeExact(recv, 'a', 'b');
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
char r = (char) hs.get(am).invokeExact(recv, 'a');
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> {
char r = (char) hs.get(am).invokeExact(recv, 'a');
});
}
} }
static void testStaticField(Handles hs) throws Throwable { static void testStaticField(Handles hs) throws Throwable {
// Plain // Plain
{ {
hs.get(TestAccessMode.SET).invokeExact('a'); hs.get(TestAccessMode.SET).invokeExact('\u0123');
char x = (char) hs.get(TestAccessMode.GET).invokeExact(); char x = (char) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 'a', "set char value"); assertEquals(x, '\u0123', "set char value");
} }
// Volatile // Volatile
{ {
hs.get(TestAccessMode.SET_VOLATILE).invokeExact('b'); hs.get(TestAccessMode.SET_VOLATILE).invokeExact('\u4567');
char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
assertEquals(x, 'b', "setVolatile char value"); assertEquals(x, '\u4567', "setVolatile char value");
} }
// Lazy // Lazy
{ {
hs.get(TestAccessMode.SET_RELEASE).invokeExact('a'); hs.get(TestAccessMode.SET_RELEASE).invokeExact('\u0123');
char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
assertEquals(x, 'a', "setRelease char value"); assertEquals(x, '\u0123', "setRelease char value");
} }
// Opaque // Opaque
{ {
hs.get(TestAccessMode.SET_OPAQUE).invokeExact('b'); hs.get(TestAccessMode.SET_OPAQUE).invokeExact('\u4567');
char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
assertEquals(x, 'b', "setOpaque char value"); assertEquals(x, '\u4567', "setOpaque char value");
} }
hs.get(TestAccessMode.SET).invokeExact('\u0123');
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact('\u0123', '\u4567');
assertEquals(r, true, "success compareAndSet char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, '\u4567', "success compareAndSet char value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact('\u0123', '\u89AB');
assertEquals(r, false, "failing compareAndSet char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, '\u4567', "failing compareAndSet char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact('\u4567', '\u0123');
assertEquals(r, '\u4567', "success compareAndExchange char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, '\u0123', "success compareAndExchange char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact('\u4567', '\u89AB');
assertEquals(r, '\u0123', "failing compareAndExchange char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, '\u0123', "failing compareAndExchange char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact('\u0123', '\u4567');
assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact('\u0123', '\u89AB');
assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact('\u4567', '\u0123');
assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact('\u4567', '\u89AB');
assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact('\u0123', '\u4567');
}
assertEquals(success, true, "weakCompareAndSet char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, '\u4567', "weakCompareAndSet char value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact('\u4567', '\u0123');
}
assertEquals(success, true, "weakCompareAndSetAcquire char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact('\u0123', '\u4567');
}
assertEquals(success, true, "weakCompareAndSetRelease char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact('\u4567', '\u0123');
}
assertEquals(success, true, "weakCompareAndSetVolatile char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, '\u0123', "weakCompareAndSetVolatile char");
}
// Compare set and get
{
char o = (char) hs.get(TestAccessMode.GET_AND_SET).invokeExact( '\u4567');
assertEquals(o, '\u0123', "getAndSet char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, '\u4567', "getAndSet char value");
}
hs.get(TestAccessMode.SET).invokeExact('\u0123');
// get and add, add and get
{
char o = (char) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( '\u89AB');
assertEquals(o, '\u0123', "getAndAdd char");
char c = (char) hs.get(TestAccessMode.ADD_AND_GET).invokeExact('\u89AB');
assertEquals(c, (char)('\u0123' + '\u89AB' + '\u89AB'), "getAndAdd char value");
}
} }
static void testStaticFieldUnsupported(Handles hs) throws Throwable { static void testStaticFieldUnsupported(Handles hs) throws Throwable {
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact('a', 'b');
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
char r = (char) hs.get(am).invokeExact('a', 'b');
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
char r = (char) hs.get(am).invokeExact('a');
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> {
char r = (char) hs.get(am).invokeExact('a');
});
}
} }
@ -244,34 +430,149 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest {
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
// Plain // Plain
{ {
hs.get(TestAccessMode.SET).invokeExact(array, i, 'a'); hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 'a', "get char value"); assertEquals(x, '\u0123', "get char value");
} }
// Volatile // Volatile
{ {
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 'b'); hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, '\u4567');
char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
assertEquals(x, 'b', "setVolatile char value"); assertEquals(x, '\u4567', "setVolatile char value");
} }
// Lazy // Lazy
{ {
hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 'a'); hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, '\u0123');
char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
assertEquals(x, 'a', "setRelease char value"); assertEquals(x, '\u0123', "setRelease char value");
} }
// Opaque // Opaque
{ {
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 'b'); hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, '\u4567');
char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
assertEquals(x, 'b', "setOpaque char value"); assertEquals(x, '\u4567', "setOpaque char value");
} }
hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, '\u0123', '\u4567');
assertEquals(r, true, "success compareAndSet char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, '\u4567', "success compareAndSet char value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, '\u0123', '\u89AB');
assertEquals(r, false, "failing compareAndSet char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, '\u4567', "failing compareAndSet char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, '\u4567', '\u0123');
assertEquals(r, '\u4567', "success compareAndExchange char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, '\u0123', "success compareAndExchange char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, '\u4567', '\u89AB');
assertEquals(r, '\u0123', "failing compareAndExchange char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, '\u0123', "failing compareAndExchange char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, '\u0123', '\u4567');
assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, '\u0123', '\u89AB');
assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, '\u4567', '\u0123');
assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
}
{
char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, '\u4567', '\u89AB');
assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, '\u0123', '\u4567');
}
assertEquals(success, true, "weakCompareAndSet char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, '\u4567', "weakCompareAndSet char value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, '\u4567', '\u0123');
}
assertEquals(success, true, "weakCompareAndSetAcquire char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, '\u0123', '\u4567');
}
assertEquals(success, true, "weakCompareAndSetRelease char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, '\u4567', '\u0123');
}
assertEquals(success, true, "weakCompareAndSetVolatile char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, '\u0123', "weakCompareAndSetVolatile char");
}
// Compare set and get
{
char o = (char) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, '\u4567');
assertEquals(o, '\u0123', "getAndSet char");
char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, '\u4567', "getAndSet char value");
}
hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
// get and add, add and get
{
char o = (char) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, '\u89AB');
assertEquals(o, '\u0123', "getAndAdd char");
char c = (char) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, '\u89AB');
assertEquals(c, (char)('\u0123' + '\u89AB' + '\u89AB'), "getAndAdd char value");
}
} }
} }
@ -279,29 +580,7 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest {
char[] array = new char[10]; char[] array = new char[10];
final int i = 0; final int i = 0;
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(array, i, 'a', 'b');
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
char r = (char) hs.get(am).invokeExact(array, i, 'a', 'b');
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
char r = (char) hs.get(am).invokeExact(array, i, 'a');
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> {
char o = (char) hs.get(am).invokeExact(array, i, 'a');
});
}
} }
static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
@ -318,11 +597,33 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest {
for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
checkIOOBE(am, () -> { checkIOOBE(am, () -> {
hs.get(am).invokeExact(array, ci, 'a'); hs.get(am).invokeExact(array, ci, '\u0123');
}); });
} }
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkIOOBE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(array, ci, '\u0123', '\u4567');
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkIOOBE(am, () -> {
char r = (char) hs.get(am).invokeExact(array, ci, '\u4567', '\u0123');
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkIOOBE(am, () -> {
char o = (char) hs.get(am).invokeExact(array, ci, '\u0123');
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkIOOBE(am, () -> {
char o = (char) hs.get(am).invokeExact(array, ci, '\u89AB');
});
}
} }
} }
} }

View file

@ -148,33 +148,126 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
assertEquals(x, 2.0d, "setOpaque double value"); assertEquals(x, 2.0d, "setOpaque double value");
} }
hs.get(TestAccessMode.SET).invokeExact(recv, 1.0d);
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0d, 2.0d);
assertEquals(r, true, "success compareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0d, "success compareAndSet double value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0d, 3.0d);
assertEquals(r, false, "failing compareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0d, "failing compareAndSet double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchange double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0d, "success compareAndExchange double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchange double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0d, "failing compareAndExchange double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0d, 2.0d);
assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0d, 3.0d);
assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 1.0d, 2.0d);
}
assertEquals(success, true, "weakCompareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0d, "weakCompareAndSet double value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 2.0d, 1.0d);
}
assertEquals(success, true, "weakCompareAndSetAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0d, "weakCompareAndSetAcquire double");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 1.0d, 2.0d);
}
assertEquals(success, true, "weakCompareAndSetRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0d, "weakCompareAndSetRelease double");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, 2.0d, 1.0d);
}
assertEquals(success, true, "weakCompareAndSetVolatile double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0d, "weakCompareAndSetVolatile double");
}
// Compare set and get
{
double o = (double) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 2.0d);
assertEquals(o, 1.0d, "getAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0d, "getAndSet double value");
}
hs.get(TestAccessMode.SET).invokeExact(recv, 1.0d);
// get and add, add and get
{
double o = (double) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 3.0d);
assertEquals(o, 1.0d, "getAndAdd double");
double c = (double) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, 3.0d);
assertEquals(c, (double)(1.0d + 3.0d + 3.0d), "getAndAdd double value");
}
} }
static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessDouble recv, Handles hs) throws Throwable { static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessDouble recv, Handles hs) throws Throwable {
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(recv, 1.0d, 2.0d);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
double r = (double) hs.get(am).invokeExact(recv, 1.0d, 2.0d);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
double r = (double) hs.get(am).invokeExact(recv, 1.0d);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> {
double r = (double) hs.get(am).invokeExact(recv, 1.0d);
});
}
} }
@ -208,33 +301,126 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
assertEquals(x, 2.0d, "setOpaque double value"); assertEquals(x, 2.0d, "setOpaque double value");
} }
hs.get(TestAccessMode.SET).invokeExact(1.0d);
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0d, 2.0d);
assertEquals(r, true, "success compareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "success compareAndSet double value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0d, 3.0d);
assertEquals(r, false, "failing compareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "failing compareAndSet double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchange double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0d, "success compareAndExchange double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchange double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0d, "failing compareAndExchange double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0d, 2.0d);
assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0d, 3.0d);
assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(1.0d, 2.0d);
}
assertEquals(success, true, "weakCompareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "weakCompareAndSet double value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(2.0d, 1.0d);
}
assertEquals(success, true, "weakCompareAndSetAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0d, "weakCompareAndSetAcquire double");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(1.0d, 2.0d);
}
assertEquals(success, true, "weakCompareAndSetRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "weakCompareAndSetRelease double");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(2.0d, 1.0d);
}
assertEquals(success, true, "weakCompareAndSetVolatile double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0d, "weakCompareAndSetVolatile double");
}
// Compare set and get
{
double o = (double) hs.get(TestAccessMode.GET_AND_SET).invokeExact( 2.0d);
assertEquals(o, 1.0d, "getAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "getAndSet double value");
}
hs.get(TestAccessMode.SET).invokeExact(1.0d);
// get and add, add and get
{
double o = (double) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( 3.0d);
assertEquals(o, 1.0d, "getAndAdd double");
double c = (double) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(3.0d);
assertEquals(c, (double)(1.0d + 3.0d + 3.0d), "getAndAdd double value");
}
} }
static void testStaticFieldUnsupported(Handles hs) throws Throwable { static void testStaticFieldUnsupported(Handles hs) throws Throwable {
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(1.0d, 2.0d);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
double r = (double) hs.get(am).invokeExact(1.0d, 2.0d);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
double r = (double) hs.get(am).invokeExact(1.0d);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> {
double r = (double) hs.get(am).invokeExact(1.0d);
});
}
} }
@ -271,7 +457,122 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
assertEquals(x, 2.0d, "setOpaque double value"); assertEquals(x, 2.0d, "setOpaque double value");
} }
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d);
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0d, 2.0d);
assertEquals(r, true, "success compareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "success compareAndSet double value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0d, 3.0d);
assertEquals(r, false, "failing compareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "failing compareAndSet double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchange double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0d, "success compareAndExchange double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchange double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0d, "failing compareAndExchange double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0d, 2.0d);
assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0d, 3.0d);
assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 1.0d, 2.0d);
}
assertEquals(success, true, "weakCompareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "weakCompareAndSet double value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 2.0d, 1.0d);
}
assertEquals(success, true, "weakCompareAndSetAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0d, "weakCompareAndSetAcquire double");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, 1.0d, 2.0d);
}
assertEquals(success, true, "weakCompareAndSetRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "weakCompareAndSetRelease double");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, 2.0d, 1.0d);
}
assertEquals(success, true, "weakCompareAndSetVolatile double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0d, "weakCompareAndSetVolatile double");
}
// Compare set and get
{
double o = (double) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 2.0d);
assertEquals(o, 1.0d, "getAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "getAndSet double value");
}
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d);
// get and add, add and get
{
double o = (double) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 3.0d);
assertEquals(o, 1.0d, "getAndAdd double");
double c = (double) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, 3.0d);
assertEquals(c, (double)(1.0d + 3.0d + 3.0d), "getAndAdd double value");
}
} }
} }
@ -279,29 +580,7 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
double[] array = new double[10]; double[] array = new double[10];
final int i = 0; final int i = 0;
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(array, i, 1.0d, 2.0d);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
double r = (double) hs.get(am).invokeExact(array, i, 1.0d, 2.0d);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
double r = (double) hs.get(am).invokeExact(array, i, 1.0d);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> {
double o = (double) hs.get(am).invokeExact(array, i, 1.0d);
});
}
} }
static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
@ -322,7 +601,29 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
}); });
} }
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkIOOBE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(array, ci, 1.0d, 2.0d);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkIOOBE(am, () -> {
double r = (double) hs.get(am).invokeExact(array, ci, 2.0d, 1.0d);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkIOOBE(am, () -> {
double o = (double) hs.get(am).invokeExact(array, ci, 1.0d);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkIOOBE(am, () -> {
double o = (double) hs.get(am).invokeExact(array, ci, 3.0d);
});
}
} }
} }
} }

View file

@ -148,33 +148,126 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
assertEquals(x, 2.0f, "setOpaque float value"); assertEquals(x, 2.0f, "setOpaque float value");
} }
hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f);
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0f, 2.0f);
assertEquals(r, true, "success compareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0f, "success compareAndSet float value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0f, 3.0f);
assertEquals(r, false, "failing compareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0f, "failing compareAndSet float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchange float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0f, "success compareAndExchange float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchange float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0f, "failing compareAndExchange float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0f, 2.0f);
assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0f, 3.0f);
assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 1.0f, 2.0f);
}
assertEquals(success, true, "weakCompareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0f, "weakCompareAndSet float value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 2.0f, 1.0f);
}
assertEquals(success, true, "weakCompareAndSetAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0f, "weakCompareAndSetAcquire float");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 1.0f, 2.0f);
}
assertEquals(success, true, "weakCompareAndSetRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0f, "weakCompareAndSetRelease float");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, 2.0f, 1.0f);
}
assertEquals(success, true, "weakCompareAndSetVolatile float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0f, "weakCompareAndSetVolatile float");
}
// Compare set and get
{
float o = (float) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 2.0f);
assertEquals(o, 1.0f, "getAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0f, "getAndSet float value");
}
hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f);
// get and add, add and get
{
float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 3.0f);
assertEquals(o, 1.0f, "getAndAdd float");
float c = (float) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, 3.0f);
assertEquals(c, (float)(1.0f + 3.0f + 3.0f), "getAndAdd float value");
}
} }
static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessFloat recv, Handles hs) throws Throwable { static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessFloat recv, Handles hs) throws Throwable {
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(recv, 1.0f, 2.0f);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
float r = (float) hs.get(am).invokeExact(recv, 1.0f, 2.0f);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
float r = (float) hs.get(am).invokeExact(recv, 1.0f);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> {
float r = (float) hs.get(am).invokeExact(recv, 1.0f);
});
}
} }
@ -208,33 +301,126 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
assertEquals(x, 2.0f, "setOpaque float value"); assertEquals(x, 2.0f, "setOpaque float value");
} }
hs.get(TestAccessMode.SET).invokeExact(1.0f);
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0f, 2.0f);
assertEquals(r, true, "success compareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "success compareAndSet float value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0f, 3.0f);
assertEquals(r, false, "failing compareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "failing compareAndSet float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchange float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0f, "success compareAndExchange float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchange float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0f, "failing compareAndExchange float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0f, 2.0f);
assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0f, 3.0f);
assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(1.0f, 2.0f);
}
assertEquals(success, true, "weakCompareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "weakCompareAndSet float value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(2.0f, 1.0f);
}
assertEquals(success, true, "weakCompareAndSetAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0f, "weakCompareAndSetAcquire float");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(1.0f, 2.0f);
}
assertEquals(success, true, "weakCompareAndSetRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "weakCompareAndSetRelease float");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(2.0f, 1.0f);
}
assertEquals(success, true, "weakCompareAndSetVolatile float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0f, "weakCompareAndSetVolatile float");
}
// Compare set and get
{
float o = (float) hs.get(TestAccessMode.GET_AND_SET).invokeExact( 2.0f);
assertEquals(o, 1.0f, "getAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "getAndSet float value");
}
hs.get(TestAccessMode.SET).invokeExact(1.0f);
// get and add, add and get
{
float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( 3.0f);
assertEquals(o, 1.0f, "getAndAdd float");
float c = (float) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(3.0f);
assertEquals(c, (float)(1.0f + 3.0f + 3.0f), "getAndAdd float value");
}
} }
static void testStaticFieldUnsupported(Handles hs) throws Throwable { static void testStaticFieldUnsupported(Handles hs) throws Throwable {
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(1.0f, 2.0f);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
float r = (float) hs.get(am).invokeExact(1.0f, 2.0f);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
float r = (float) hs.get(am).invokeExact(1.0f);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> {
float r = (float) hs.get(am).invokeExact(1.0f);
});
}
} }
@ -271,7 +457,122 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
assertEquals(x, 2.0f, "setOpaque float value"); assertEquals(x, 2.0f, "setOpaque float value");
} }
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0f, 2.0f);
assertEquals(r, true, "success compareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "success compareAndSet float value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0f, 3.0f);
assertEquals(r, false, "failing compareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "failing compareAndSet float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchange float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0f, "success compareAndExchange float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchange float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0f, "failing compareAndExchange float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0f, 2.0f);
assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0f, 3.0f);
assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 1.0f, 2.0f);
}
assertEquals(success, true, "weakCompareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "weakCompareAndSet float value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 2.0f, 1.0f);
}
assertEquals(success, true, "weakCompareAndSetAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0f, "weakCompareAndSetAcquire float");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, 1.0f, 2.0f);
}
assertEquals(success, true, "weakCompareAndSetRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "weakCompareAndSetRelease float");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, 2.0f, 1.0f);
}
assertEquals(success, true, "weakCompareAndSetVolatile float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0f, "weakCompareAndSetVolatile float");
}
// Compare set and get
{
float o = (float) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 2.0f);
assertEquals(o, 1.0f, "getAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "getAndSet float value");
}
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
// get and add, add and get
{
float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 3.0f);
assertEquals(o, 1.0f, "getAndAdd float");
float c = (float) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, 3.0f);
assertEquals(c, (float)(1.0f + 3.0f + 3.0f), "getAndAdd float value");
}
} }
} }
@ -279,29 +580,7 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
float[] array = new float[10]; float[] array = new float[10];
final int i = 0; final int i = 0;
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(array, i, 1.0f, 2.0f);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
float r = (float) hs.get(am).invokeExact(array, i, 1.0f, 2.0f);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
float r = (float) hs.get(am).invokeExact(array, i, 1.0f);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> {
float o = (float) hs.get(am).invokeExact(array, i, 1.0f);
});
}
} }
static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
@ -322,7 +601,29 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
}); });
} }
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkIOOBE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(array, ci, 1.0f, 2.0f);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkIOOBE(am, () -> {
float r = (float) hs.get(am).invokeExact(array, ci, 2.0f, 1.0f);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkIOOBE(am, () -> {
float o = (float) hs.get(am).invokeExact(array, ci, 1.0f);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkIOOBE(am, () -> {
float o = (float) hs.get(am).invokeExact(array, ci, 3.0f);
});
}
} }
} }
} }

View file

@ -39,11 +39,11 @@ import java.util.List;
import static org.testng.Assert.*; import static org.testng.Assert.*;
public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest {
static final int static_final_v = 1; static final int static_final_v = 0x01234567;
static int static_v; static int static_v;
final int final_v = 1; final int final_v = 0x01234567;
int v; int v;
@ -121,148 +121,148 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest {
static void testInstanceField(VarHandleTestMethodHandleAccessInt recv, Handles hs) throws Throwable { static void testInstanceField(VarHandleTestMethodHandleAccessInt recv, Handles hs) throws Throwable {
// Plain // Plain
{ {
hs.get(TestAccessMode.SET).invokeExact(recv, 1); hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567);
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1, "set int value"); assertEquals(x, 0x01234567, "set int value");
} }
// Volatile // Volatile
{ {
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 2); hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 0x89ABCDEF);
int x = (int) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); int x = (int) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
assertEquals(x, 2, "setVolatile int value"); assertEquals(x, 0x89ABCDEF, "setVolatile int value");
} }
// Lazy // Lazy
{ {
hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 1); hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 0x01234567);
int x = (int) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); int x = (int) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
assertEquals(x, 1, "setRelease int value"); assertEquals(x, 0x01234567, "setRelease int value");
} }
// Opaque // Opaque
{ {
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 2); hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 0x89ABCDEF);
int x = (int) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); int x = (int) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
assertEquals(x, 2, "setOpaque int value"); assertEquals(x, 0x89ABCDEF, "setOpaque int value");
} }
hs.get(TestAccessMode.SET).invokeExact(recv, 1); hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567);
// Compare // Compare
{ {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1, 2); boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 0x01234567, 0x89ABCDEF);
assertEquals(r, true, "success compareAndSet int"); assertEquals(r, true, "success compareAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2, "success compareAndSet int value"); assertEquals(x, 0x89ABCDEF, "success compareAndSet int value");
} }
{ {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1, 3); boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 0x01234567, 0xCAFEBABE);
assertEquals(r, false, "failing compareAndSet int"); assertEquals(r, false, "failing compareAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2, "failing compareAndSet int value"); assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, 2, 1); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 0x89ABCDEF, 0x01234567);
assertEquals(r, 2, "success compareAndExchangeVolatile int"); assertEquals(r, 0x89ABCDEF, "success compareAndExchange int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1, "success compareAndExchangeVolatile int value"); assertEquals(x, 0x01234567, "success compareAndExchange int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, 2, 3); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 0x89ABCDEF, 0xCAFEBABE);
assertEquals(r, 1, "failing compareAndExchangeVolatile int"); assertEquals(r, 0x01234567, "failing compareAndExchange int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1, "failing compareAndExchangeVolatile int value"); assertEquals(x, 0x01234567, "failing compareAndExchange int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1, 2); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 0x01234567, 0x89ABCDEF);
assertEquals(r, 1, "success compareAndExchangeAcquire int"); assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2, "success compareAndExchangeAcquire int value"); assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1, 3); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 0x01234567, 0xCAFEBABE);
assertEquals(r, 2, "failing compareAndExchangeAcquire int"); assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2, "failing compareAndExchangeAcquire int value"); assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2, 1); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 0x89ABCDEF, 0x01234567);
assertEquals(r, 2, "success compareAndExchangeRelease int"); assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1, "success compareAndExchangeRelease int value"); assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2, 3); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 0x89ABCDEF, 0xCAFEBABE);
assertEquals(r, 1, "failing compareAndExchangeRelease int"); assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1, "failing compareAndExchangeRelease int value"); assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 1, 2); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 0x01234567, 0x89ABCDEF);
} }
assertEquals(success, true, "weakCompareAndSet int"); assertEquals(success, true, "weakCompareAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2, "weakCompareAndSet int value"); assertEquals(x, 0x89ABCDEF, "weakCompareAndSet int value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 2, 1); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 0x89ABCDEF, 0x01234567);
} }
assertEquals(success, true, "weakCompareAndSetAcquire int"); assertEquals(success, true, "weakCompareAndSetAcquire int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1, "weakCompareAndSetAcquire int"); assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 1, 2); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 0x01234567, 0x89ABCDEF);
} }
assertEquals(success, true, "weakCompareAndSetRelease int"); assertEquals(success, true, "weakCompareAndSetRelease int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2, "weakCompareAndSetRelease int"); assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, 2, 1); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, 0x89ABCDEF, 0x01234567);
} }
assertEquals(success, true, "weakCompareAndSetVolatile int"); assertEquals(success, true, "weakCompareAndSetVolatile int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1, "weakCompareAndSetVolatile int"); assertEquals(x, 0x01234567, "weakCompareAndSetVolatile int");
} }
// Compare set and get // Compare set and get
{ {
int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 2); int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 0x89ABCDEF);
assertEquals(o, 1, "getAndSet int"); assertEquals(o, 0x01234567, "getAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2, "getAndSet int value"); assertEquals(x, 0x89ABCDEF, "getAndSet int value");
} }
hs.get(TestAccessMode.SET).invokeExact(recv, 1); hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567);
// get and add, add and get // get and add, add and get
{ {
int o = (int) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 3); int o = (int) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 0xCAFEBABE);
assertEquals(o, 1, "getAndAdd int"); assertEquals(o, 0x01234567, "getAndAdd int");
int c = (int) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, 3); int c = (int) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, 0xCAFEBABE);
assertEquals(c, 1 + 3 + 3, "getAndAdd int value"); assertEquals(c, (int)(0x01234567 + 0xCAFEBABE + 0xCAFEBABE), "getAndAdd int value");
} }
} }
@ -274,148 +274,148 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest {
static void testStaticField(Handles hs) throws Throwable { static void testStaticField(Handles hs) throws Throwable {
// Plain // Plain
{ {
hs.get(TestAccessMode.SET).invokeExact(1); hs.get(TestAccessMode.SET).invokeExact(0x01234567);
int x = (int) hs.get(TestAccessMode.GET).invokeExact(); int x = (int) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1, "set int value"); assertEquals(x, 0x01234567, "set int value");
} }
// Volatile // Volatile
{ {
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(2); hs.get(TestAccessMode.SET_VOLATILE).invokeExact(0x89ABCDEF);
int x = (int) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); int x = (int) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
assertEquals(x, 2, "setVolatile int value"); assertEquals(x, 0x89ABCDEF, "setVolatile int value");
} }
// Lazy // Lazy
{ {
hs.get(TestAccessMode.SET_RELEASE).invokeExact(1); hs.get(TestAccessMode.SET_RELEASE).invokeExact(0x01234567);
int x = (int) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); int x = (int) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
assertEquals(x, 1, "setRelease int value"); assertEquals(x, 0x01234567, "setRelease int value");
} }
// Opaque // Opaque
{ {
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(2); hs.get(TestAccessMode.SET_OPAQUE).invokeExact(0x89ABCDEF);
int x = (int) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); int x = (int) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
assertEquals(x, 2, "setOpaque int value"); assertEquals(x, 0x89ABCDEF, "setOpaque int value");
} }
hs.get(TestAccessMode.SET).invokeExact(1); hs.get(TestAccessMode.SET).invokeExact(0x01234567);
// Compare // Compare
{ {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1, 2); boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(0x01234567, 0x89ABCDEF);
assertEquals(r, true, "success compareAndSet int"); assertEquals(r, true, "success compareAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(); int x = (int) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2, "success compareAndSet int value"); assertEquals(x, 0x89ABCDEF, "success compareAndSet int value");
} }
{ {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1, 3); boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(0x01234567, 0xCAFEBABE);
assertEquals(r, false, "failing compareAndSet int"); assertEquals(r, false, "failing compareAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(); int x = (int) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2, "failing compareAndSet int value"); assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(2, 1); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(0x89ABCDEF, 0x01234567);
assertEquals(r, 2, "success compareAndExchangeVolatile int"); assertEquals(r, 0x89ABCDEF, "success compareAndExchange int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(); int x = (int) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1, "success compareAndExchangeVolatile int value"); assertEquals(x, 0x01234567, "success compareAndExchange int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(2, 3); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(0x89ABCDEF, 0xCAFEBABE);
assertEquals(r, 1, "failing compareAndExchangeVolatile int"); assertEquals(r, 0x01234567, "failing compareAndExchange int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(); int x = (int) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1, "failing compareAndExchangeVolatile int value"); assertEquals(x, 0x01234567, "failing compareAndExchange int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1, 2); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(0x01234567, 0x89ABCDEF);
assertEquals(r, 1, "success compareAndExchangeAcquire int"); assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(); int x = (int) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2, "success compareAndExchangeAcquire int value"); assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1, 3); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(0x01234567, 0xCAFEBABE);
assertEquals(r, 2, "failing compareAndExchangeAcquire int"); assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(); int x = (int) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2, "failing compareAndExchangeAcquire int value"); assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2, 1); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(0x89ABCDEF, 0x01234567);
assertEquals(r, 2, "success compareAndExchangeRelease int"); assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(); int x = (int) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1, "success compareAndExchangeRelease int value"); assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2, 3); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(0x89ABCDEF, 0xCAFEBABE);
assertEquals(r, 1, "failing compareAndExchangeRelease int"); assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(); int x = (int) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1, "failing compareAndExchangeRelease int value"); assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(1, 2); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(0x01234567, 0x89ABCDEF);
} }
assertEquals(success, true, "weakCompareAndSet int"); assertEquals(success, true, "weakCompareAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(); int x = (int) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2, "weakCompareAndSet int value"); assertEquals(x, 0x89ABCDEF, "weakCompareAndSet int value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(2, 1); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(0x89ABCDEF, 0x01234567);
} }
assertEquals(success, true, "weakCompareAndSetAcquire int"); assertEquals(success, true, "weakCompareAndSetAcquire int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(); int x = (int) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1, "weakCompareAndSetAcquire int"); assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(1, 2); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(0x01234567, 0x89ABCDEF);
} }
assertEquals(success, true, "weakCompareAndSetRelease int"); assertEquals(success, true, "weakCompareAndSetRelease int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(); int x = (int) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2, "weakCompareAndSetRelease int"); assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(2, 1); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(0x89ABCDEF, 0x01234567);
} }
assertEquals(success, true, "weakCompareAndSetVolatile int"); assertEquals(success, true, "weakCompareAndSetVolatile int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(); int x = (int) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1, "weakCompareAndSetVolatile int"); assertEquals(x, 0x01234567, "weakCompareAndSetVolatile int");
} }
// Compare set and get // Compare set and get
{ {
int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact( 2); int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact( 0x89ABCDEF);
assertEquals(o, 1, "getAndSet int"); assertEquals(o, 0x01234567, "getAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(); int x = (int) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2, "getAndSet int value"); assertEquals(x, 0x89ABCDEF, "getAndSet int value");
} }
hs.get(TestAccessMode.SET).invokeExact(1); hs.get(TestAccessMode.SET).invokeExact(0x01234567);
// get and add, add and get // get and add, add and get
{ {
int o = (int) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( 3); int o = (int) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( 0xCAFEBABE);
assertEquals(o, 1, "getAndAdd int"); assertEquals(o, 0x01234567, "getAndAdd int");
int c = (int) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(3); int c = (int) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(0xCAFEBABE);
assertEquals(c, 1 + 3 + 3, "getAndAdd int value"); assertEquals(c, (int)(0x01234567 + 0xCAFEBABE + 0xCAFEBABE), "getAndAdd int value");
} }
} }
@ -430,148 +430,148 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest {
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
// Plain // Plain
{ {
hs.get(TestAccessMode.SET).invokeExact(array, i, 1); hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1, "get int value"); assertEquals(x, 0x01234567, "get int value");
} }
// Volatile // Volatile
{ {
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 2); hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 0x89ABCDEF);
int x = (int) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); int x = (int) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
assertEquals(x, 2, "setVolatile int value"); assertEquals(x, 0x89ABCDEF, "setVolatile int value");
} }
// Lazy // Lazy
{ {
hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 1); hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 0x01234567);
int x = (int) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); int x = (int) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
assertEquals(x, 1, "setRelease int value"); assertEquals(x, 0x01234567, "setRelease int value");
} }
// Opaque // Opaque
{ {
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 2); hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 0x89ABCDEF);
int x = (int) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); int x = (int) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
assertEquals(x, 2, "setOpaque int value"); assertEquals(x, 0x89ABCDEF, "setOpaque int value");
} }
hs.get(TestAccessMode.SET).invokeExact(array, i, 1); hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
// Compare // Compare
{ {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1, 2); boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 0x01234567, 0x89ABCDEF);
assertEquals(r, true, "success compareAndSet int"); assertEquals(r, true, "success compareAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2, "success compareAndSet int value"); assertEquals(x, 0x89ABCDEF, "success compareAndSet int value");
} }
{ {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1, 3); boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 0x01234567, 0xCAFEBABE);
assertEquals(r, false, "failing compareAndSet int"); assertEquals(r, false, "failing compareAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2, "failing compareAndSet int value"); assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, 2, 1); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 0x89ABCDEF, 0x01234567);
assertEquals(r, 2, "success compareAndExchangeVolatile int"); assertEquals(r, 0x89ABCDEF, "success compareAndExchange int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1, "success compareAndExchangeVolatile int value"); assertEquals(x, 0x01234567, "success compareAndExchange int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, 2, 3); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 0x89ABCDEF, 0xCAFEBABE);
assertEquals(r, 1, "failing compareAndExchangeVolatile int"); assertEquals(r, 0x01234567, "failing compareAndExchange int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1, "failing compareAndExchangeVolatile int value"); assertEquals(x, 0x01234567, "failing compareAndExchange int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1, 2); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 0x01234567, 0x89ABCDEF);
assertEquals(r, 1, "success compareAndExchangeAcquire int"); assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2, "success compareAndExchangeAcquire int value"); assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1, 3); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 0x01234567, 0xCAFEBABE);
assertEquals(r, 2, "failing compareAndExchangeAcquire int"); assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2, "failing compareAndExchangeAcquire int value"); assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2, 1); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 0x89ABCDEF, 0x01234567);
assertEquals(r, 2, "success compareAndExchangeRelease int"); assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1, "success compareAndExchangeRelease int value"); assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value");
} }
{ {
int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2, 3); int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 0x89ABCDEF, 0xCAFEBABE);
assertEquals(r, 1, "failing compareAndExchangeRelease int"); assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1, "failing compareAndExchangeRelease int value"); assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 1, 2); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 0x01234567, 0x89ABCDEF);
} }
assertEquals(success, true, "weakCompareAndSet int"); assertEquals(success, true, "weakCompareAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2, "weakCompareAndSet int value"); assertEquals(x, 0x89ABCDEF, "weakCompareAndSet int value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 2, 1); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 0x89ABCDEF, 0x01234567);
} }
assertEquals(success, true, "weakCompareAndSetAcquire int"); assertEquals(success, true, "weakCompareAndSetAcquire int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1, "weakCompareAndSetAcquire int"); assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, 1, 2); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, 0x01234567, 0x89ABCDEF);
} }
assertEquals(success, true, "weakCompareAndSetRelease int"); assertEquals(success, true, "weakCompareAndSetRelease int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2, "weakCompareAndSetRelease int"); assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, 2, 1); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, 0x89ABCDEF, 0x01234567);
} }
assertEquals(success, true, "weakCompareAndSetVolatile int"); assertEquals(success, true, "weakCompareAndSetVolatile int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1, "weakCompareAndSetVolatile int"); assertEquals(x, 0x01234567, "weakCompareAndSetVolatile int");
} }
// Compare set and get // Compare set and get
{ {
int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 2); int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 0x89ABCDEF);
assertEquals(o, 1, "getAndSet int"); assertEquals(o, 0x01234567, "getAndSet int");
int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2, "getAndSet int value"); assertEquals(x, 0x89ABCDEF, "getAndSet int value");
} }
hs.get(TestAccessMode.SET).invokeExact(array, i, 1); hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
// get and add, add and get // get and add, add and get
{ {
int o = (int) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 3); int o = (int) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 0xCAFEBABE);
assertEquals(o, 1, "getAndAdd int"); assertEquals(o, 0x01234567, "getAndAdd int");
int c = (int) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, 3); int c = (int) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, 0xCAFEBABE);
assertEquals(c, 1 + 3 + 3, "getAndAdd int value"); assertEquals(c, (int)(0x01234567 + 0xCAFEBABE + 0xCAFEBABE), "getAndAdd int value");
} }
} }
} }
@ -597,31 +597,31 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest {
for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
checkIOOBE(am, () -> { checkIOOBE(am, () -> {
hs.get(am).invokeExact(array, ci, 1); hs.get(am).invokeExact(array, ci, 0x01234567);
}); });
} }
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkIOOBE(am, () -> { checkIOOBE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(array, ci, 1, 2); boolean r = (boolean) hs.get(am).invokeExact(array, ci, 0x01234567, 0x89ABCDEF);
}); });
} }
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkIOOBE(am, () -> { checkIOOBE(am, () -> {
int r = (int) hs.get(am).invokeExact(array, ci, 2, 1); int r = (int) hs.get(am).invokeExact(array, ci, 0x89ABCDEF, 0x01234567);
}); });
} }
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkIOOBE(am, () -> { checkIOOBE(am, () -> {
int o = (int) hs.get(am).invokeExact(array, ci, 1); int o = (int) hs.get(am).invokeExact(array, ci, 0x01234567);
}); });
} }
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkIOOBE(am, () -> { checkIOOBE(am, () -> {
int o = (int) hs.get(am).invokeExact(array, ci, 3); int o = (int) hs.get(am).invokeExact(array, ci, 0xCAFEBABE);
}); });
} }
} }

View file

@ -39,11 +39,11 @@ import java.util.List;
import static org.testng.Assert.*; import static org.testng.Assert.*;
public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest {
static final long static_final_v = 1L; static final long static_final_v = 0x0123456789ABCDEFL;
static long static_v; static long static_v;
final long final_v = 1L; final long final_v = 0x0123456789ABCDEFL;
long v; long v;
@ -121,148 +121,148 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest {
static void testInstanceField(VarHandleTestMethodHandleAccessLong recv, Handles hs) throws Throwable { static void testInstanceField(VarHandleTestMethodHandleAccessLong recv, Handles hs) throws Throwable {
// Plain // Plain
{ {
hs.get(TestAccessMode.SET).invokeExact(recv, 1L); hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1L, "set long value"); assertEquals(x, 0x0123456789ABCDEFL, "set long value");
} }
// Volatile // Volatile
{ {
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 2L); hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
assertEquals(x, 2L, "setVolatile long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
} }
// Lazy // Lazy
{ {
hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 1L); hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 0x0123456789ABCDEFL);
long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
assertEquals(x, 1L, "setRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
} }
// Opaque // Opaque
{ {
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 2L); hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
assertEquals(x, 2L, "setOpaque long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
} }
hs.get(TestAccessMode.SET).invokeExact(recv, 1L); hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
// Compare // Compare
{ {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1L, 2L); boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
assertEquals(r, true, "success compareAndSet long"); assertEquals(r, true, "success compareAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2L, "success compareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
} }
{ {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1L, 3L); boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, false, "failing compareAndSet long"); assertEquals(r, false, "failing compareAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2L, "failing compareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, 2L, 1L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
assertEquals(r, 2L, "success compareAndExchangeVolatile long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1L, "success compareAndExchangeVolatile long value"); assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, 2L, 3L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 1L, "failing compareAndExchangeVolatile long"); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1L, "failing compareAndExchangeVolatile long value"); assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1L, 2L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
assertEquals(r, 1L, "success compareAndExchangeAcquire long"); assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2L, "success compareAndExchangeAcquire long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1L, 3L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 2L, "failing compareAndExchangeAcquire long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2L, "failing compareAndExchangeAcquire long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2L, 1L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
assertEquals(r, 2L, "success compareAndExchangeRelease long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1L, "success compareAndExchangeRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2L, 3L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 1L, "failing compareAndExchangeRelease long"); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1L, "failing compareAndExchangeRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 1L, 2L); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
} }
assertEquals(success, true, "weakCompareAndSet long"); assertEquals(success, true, "weakCompareAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2L, "weakCompareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSet long value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 2L, 1L); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
} }
assertEquals(success, true, "weakCompareAndSetAcquire long"); assertEquals(success, true, "weakCompareAndSetAcquire long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1L, "weakCompareAndSetAcquire long"); assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 1L, 2L); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
} }
assertEquals(success, true, "weakCompareAndSetRelease long"); assertEquals(success, true, "weakCompareAndSetRelease long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2L, "weakCompareAndSetRelease long"); assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, 2L, 1L); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
} }
assertEquals(success, true, "weakCompareAndSetVolatile long"); assertEquals(success, true, "weakCompareAndSetVolatile long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1L, "weakCompareAndSetVolatile long"); assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetVolatile long");
} }
// Compare set and get // Compare set and get
{ {
long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 2L); long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 0xCAFEBABECAFEBABEL);
assertEquals(o, 1L, "getAndSet long"); assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2L, "getAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
} }
hs.get(TestAccessMode.SET).invokeExact(recv, 1L); hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
// get and add, add and get // get and add, add and get
{ {
long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 3L); long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 0xDEADBEEFDEADBEEFL);
assertEquals(o, 1L, "getAndAdd long"); assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, 3L); long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, 0xDEADBEEFDEADBEEFL);
assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); assertEquals(c, (long)(0x0123456789ABCDEFL + 0xDEADBEEFDEADBEEFL + 0xDEADBEEFDEADBEEFL), "getAndAdd long value");
} }
} }
@ -274,148 +274,148 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest {
static void testStaticField(Handles hs) throws Throwable { static void testStaticField(Handles hs) throws Throwable {
// Plain // Plain
{ {
hs.get(TestAccessMode.SET).invokeExact(1L); hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); long x = (long) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1L, "set long value"); assertEquals(x, 0x0123456789ABCDEFL, "set long value");
} }
// Volatile // Volatile
{ {
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(2L); hs.get(TestAccessMode.SET_VOLATILE).invokeExact(0xCAFEBABECAFEBABEL);
long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
assertEquals(x, 2L, "setVolatile long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
} }
// Lazy // Lazy
{ {
hs.get(TestAccessMode.SET_RELEASE).invokeExact(1L); hs.get(TestAccessMode.SET_RELEASE).invokeExact(0x0123456789ABCDEFL);
long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
assertEquals(x, 1L, "setRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
} }
// Opaque // Opaque
{ {
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(2L); hs.get(TestAccessMode.SET_OPAQUE).invokeExact(0xCAFEBABECAFEBABEL);
long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
assertEquals(x, 2L, "setOpaque long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
} }
hs.get(TestAccessMode.SET).invokeExact(1L); hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
// Compare // Compare
{ {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1L, 2L); boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
assertEquals(r, true, "success compareAndSet long"); assertEquals(r, true, "success compareAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); long x = (long) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2L, "success compareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
} }
{ {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1L, 3L); boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, false, "failing compareAndSet long"); assertEquals(r, false, "failing compareAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); long x = (long) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2L, "failing compareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(2L, 1L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
assertEquals(r, 2L, "success compareAndExchangeVolatile long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); long x = (long) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1L, "success compareAndExchangeVolatile long value"); assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(2L, 3L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 1L, "failing compareAndExchangeVolatile long"); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); long x = (long) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1L, "failing compareAndExchangeVolatile long value"); assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1L, 2L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
assertEquals(r, 1L, "success compareAndExchangeAcquire long"); assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); long x = (long) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2L, "success compareAndExchangeAcquire long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1L, 3L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 2L, "failing compareAndExchangeAcquire long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); long x = (long) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2L, "failing compareAndExchangeAcquire long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2L, 1L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
assertEquals(r, 2L, "success compareAndExchangeRelease long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); long x = (long) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1L, "success compareAndExchangeRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2L, 3L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 1L, "failing compareAndExchangeRelease long"); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); long x = (long) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1L, "failing compareAndExchangeRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(1L, 2L); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
} }
assertEquals(success, true, "weakCompareAndSet long"); assertEquals(success, true, "weakCompareAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); long x = (long) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2L, "weakCompareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSet long value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(2L, 1L); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
} }
assertEquals(success, true, "weakCompareAndSetAcquire long"); assertEquals(success, true, "weakCompareAndSetAcquire long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); long x = (long) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1L, "weakCompareAndSetAcquire long"); assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(1L, 2L); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
} }
assertEquals(success, true, "weakCompareAndSetRelease long"); assertEquals(success, true, "weakCompareAndSetRelease long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); long x = (long) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2L, "weakCompareAndSetRelease long"); assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(2L, 1L); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
} }
assertEquals(success, true, "weakCompareAndSetVolatile long"); assertEquals(success, true, "weakCompareAndSetVolatile long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); long x = (long) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1L, "weakCompareAndSetVolatile long"); assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetVolatile long");
} }
// Compare set and get // Compare set and get
{ {
long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact( 2L); long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact( 0xCAFEBABECAFEBABEL);
assertEquals(o, 1L, "getAndSet long"); assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); long x = (long) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2L, "getAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
} }
hs.get(TestAccessMode.SET).invokeExact(1L); hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
// get and add, add and get // get and add, add and get
{ {
long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( 3L); long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( 0xDEADBEEFDEADBEEFL);
assertEquals(o, 1L, "getAndAdd long"); assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(3L); long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(0xDEADBEEFDEADBEEFL);
assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); assertEquals(c, (long)(0x0123456789ABCDEFL + 0xDEADBEEFDEADBEEFL + 0xDEADBEEFDEADBEEFL), "getAndAdd long value");
} }
} }
@ -430,148 +430,148 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest {
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
// Plain // Plain
{ {
hs.get(TestAccessMode.SET).invokeExact(array, i, 1L); hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1L, "get long value"); assertEquals(x, 0x0123456789ABCDEFL, "get long value");
} }
// Volatile // Volatile
{ {
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 2L); hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
assertEquals(x, 2L, "setVolatile long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
} }
// Lazy // Lazy
{ {
hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 1L); hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 0x0123456789ABCDEFL);
long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
assertEquals(x, 1L, "setRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
} }
// Opaque // Opaque
{ {
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 2L); hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
assertEquals(x, 2L, "setOpaque long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
} }
hs.get(TestAccessMode.SET).invokeExact(array, i, 1L); hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
// Compare // Compare
{ {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1L, 2L); boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
assertEquals(r, true, "success compareAndSet long"); assertEquals(r, true, "success compareAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2L, "success compareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
} }
{ {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1L, 3L); boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, false, "failing compareAndSet long"); assertEquals(r, false, "failing compareAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2L, "failing compareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, 2L, 1L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
assertEquals(r, 2L, "success compareAndExchangeVolatile long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1L, "success compareAndExchangeVolatile long value"); assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, 2L, 3L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 1L, "failing compareAndExchangeVolatile long"); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1L, "failing compareAndExchangeVolatile long value"); assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1L, 2L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
assertEquals(r, 1L, "success compareAndExchangeAcquire long"); assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2L, "success compareAndExchangeAcquire long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1L, 3L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 2L, "failing compareAndExchangeAcquire long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2L, "failing compareAndExchangeAcquire long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2L, 1L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
assertEquals(r, 2L, "success compareAndExchangeRelease long"); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1L, "success compareAndExchangeRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
} }
{ {
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2L, 3L); long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
assertEquals(r, 1L, "failing compareAndExchangeRelease long"); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1L, "failing compareAndExchangeRelease long value"); assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 1L, 2L); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
} }
assertEquals(success, true, "weakCompareAndSet long"); assertEquals(success, true, "weakCompareAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2L, "weakCompareAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSet long value");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 2L, 1L); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
} }
assertEquals(success, true, "weakCompareAndSetAcquire long"); assertEquals(success, true, "weakCompareAndSetAcquire long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1L, "weakCompareAndSetAcquire long"); assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, 1L, 2L); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
} }
assertEquals(success, true, "weakCompareAndSetRelease long"); assertEquals(success, true, "weakCompareAndSetRelease long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2L, "weakCompareAndSetRelease long"); assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
} }
{ {
boolean success = false; boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, 2L, 1L); success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
} }
assertEquals(success, true, "weakCompareAndSetVolatile long"); assertEquals(success, true, "weakCompareAndSetVolatile long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1L, "weakCompareAndSetVolatile long"); assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetVolatile long");
} }
// Compare set and get // Compare set and get
{ {
long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 2L); long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
assertEquals(o, 1L, "getAndSet long"); assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2L, "getAndSet long value"); assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
} }
hs.get(TestAccessMode.SET).invokeExact(array, i, 1L); hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
// get and add, add and get // get and add, add and get
{ {
long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 3L); long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 0xDEADBEEFDEADBEEFL);
assertEquals(o, 1L, "getAndAdd long"); assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, 3L); long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, 0xDEADBEEFDEADBEEFL);
assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); assertEquals(c, (long)(0x0123456789ABCDEFL + 0xDEADBEEFDEADBEEFL + 0xDEADBEEFDEADBEEFL), "getAndAdd long value");
} }
} }
} }
@ -597,31 +597,31 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest {
for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
checkIOOBE(am, () -> { checkIOOBE(am, () -> {
hs.get(am).invokeExact(array, ci, 1L); hs.get(am).invokeExact(array, ci, 0x0123456789ABCDEFL);
}); });
} }
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkIOOBE(am, () -> { checkIOOBE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(array, ci, 1L, 2L); boolean r = (boolean) hs.get(am).invokeExact(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
}); });
} }
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkIOOBE(am, () -> { checkIOOBE(am, () -> {
long r = (long) hs.get(am).invokeExact(array, ci, 2L, 1L); long r = (long) hs.get(am).invokeExact(array, ci, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
}); });
} }
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkIOOBE(am, () -> { checkIOOBE(am, () -> {
long o = (long) hs.get(am).invokeExact(array, ci, 1L); long o = (long) hs.get(am).invokeExact(array, ci, 0x0123456789ABCDEFL);
}); });
} }
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkIOOBE(am, () -> { checkIOOBE(am, () -> {
long o = (long) hs.get(am).invokeExact(array, ci, 3L); long o = (long) hs.get(am).invokeExact(array, ci, 0xDEADBEEFDEADBEEFL);
}); });
} }
} }

View file

@ -39,11 +39,11 @@ import java.util.List;
import static org.testng.Assert.*; import static org.testng.Assert.*;
public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest {
static final short static_final_v = (short)1; static final short static_final_v = (short)0x0123;
static short static_v; static short static_v;
final short final_v = (short)1; final short final_v = (short)0x0123;
short v; short v;
@ -121,120 +121,306 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest {
static void testInstanceField(VarHandleTestMethodHandleAccessShort recv, Handles hs) throws Throwable { static void testInstanceField(VarHandleTestMethodHandleAccessShort recv, Handles hs) throws Throwable {
// Plain // Plain
{ {
hs.get(TestAccessMode.SET).invokeExact(recv, (short)1); hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (short)1, "set short value"); assertEquals(x, (short)0x0123, "set short value");
} }
// Volatile // Volatile
{ {
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, (short)2); hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, (short)0x4567);
short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
assertEquals(x, (short)2, "setVolatile short value"); assertEquals(x, (short)0x4567, "setVolatile short value");
} }
// Lazy // Lazy
{ {
hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, (short)1); hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, (short)0x0123);
short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
assertEquals(x, (short)1, "setRelease short value"); assertEquals(x, (short)0x0123, "setRelease short value");
} }
// Opaque // Opaque
{ {
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, (short)2); hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, (short)0x4567);
short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
assertEquals(x, (short)2, "setOpaque short value"); assertEquals(x, (short)0x4567, "setOpaque short value");
} }
hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (short)0x0123, (short)0x4567);
assertEquals(r, true, "success compareAndSet short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (short)0x4567, "success compareAndSet short value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (short)0x0123, (short)0x89AB);
assertEquals(r, false, "failing compareAndSet short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (short)0x4567, "failing compareAndSet short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (short)0x4567, (short)0x0123);
assertEquals(r, (short)0x4567, "success compareAndExchange short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (short)0x0123, "success compareAndExchange short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (short)0x4567, (short)0x89AB);
assertEquals(r, (short)0x0123, "failing compareAndExchange short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (short)0x0123, "failing compareAndExchange short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (short)0x0123, (short)0x4567);
assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (short)0x0123, (short)0x89AB);
assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (short)0x4567, (short)0x0123);
assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (short)0x4567, (short)0x89AB);
assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, (short)0x0123, (short)0x4567);
}
assertEquals(success, true, "weakCompareAndSet short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (short)0x4567, "weakCompareAndSet short value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, (short)0x4567, (short)0x0123);
}
assertEquals(success, true, "weakCompareAndSetAcquire short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (short)0x0123, "weakCompareAndSetAcquire short");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, (short)0x0123, (short)0x4567);
}
assertEquals(success, true, "weakCompareAndSetRelease short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (short)0x4567, "weakCompareAndSetRelease short");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, (short)0x4567, (short)0x0123);
}
assertEquals(success, true, "weakCompareAndSetVolatile short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (short)0x0123, "weakCompareAndSetVolatile short");
}
// Compare set and get
{
short o = (short) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, (short)0x4567);
assertEquals(o, (short)0x0123, "getAndSet short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (short)0x4567, "getAndSet short value");
}
hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
// get and add, add and get
{
short o = (short) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, (short)0x89AB);
assertEquals(o, (short)0x0123, "getAndAdd short");
short c = (short) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, (short)0x89AB);
assertEquals(c, (short)((short)0x0123 + (short)0x89AB + (short)0x89AB), "getAndAdd short value");
}
} }
static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessShort recv, Handles hs) throws Throwable { static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessShort recv, Handles hs) throws Throwable {
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(recv, (short)1, (short)2);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
short r = (short) hs.get(am).invokeExact(recv, (short)1, (short)2);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
short r = (short) hs.get(am).invokeExact(recv, (short)1);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> {
short r = (short) hs.get(am).invokeExact(recv, (short)1);
});
}
} }
static void testStaticField(Handles hs) throws Throwable { static void testStaticField(Handles hs) throws Throwable {
// Plain // Plain
{ {
hs.get(TestAccessMode.SET).invokeExact((short)1); hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
short x = (short) hs.get(TestAccessMode.GET).invokeExact(); short x = (short) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (short)1, "set short value"); assertEquals(x, (short)0x0123, "set short value");
} }
// Volatile // Volatile
{ {
hs.get(TestAccessMode.SET_VOLATILE).invokeExact((short)2); hs.get(TestAccessMode.SET_VOLATILE).invokeExact((short)0x4567);
short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
assertEquals(x, (short)2, "setVolatile short value"); assertEquals(x, (short)0x4567, "setVolatile short value");
} }
// Lazy // Lazy
{ {
hs.get(TestAccessMode.SET_RELEASE).invokeExact((short)1); hs.get(TestAccessMode.SET_RELEASE).invokeExact((short)0x0123);
short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
assertEquals(x, (short)1, "setRelease short value"); assertEquals(x, (short)0x0123, "setRelease short value");
} }
// Opaque // Opaque
{ {
hs.get(TestAccessMode.SET_OPAQUE).invokeExact((short)2); hs.get(TestAccessMode.SET_OPAQUE).invokeExact((short)0x4567);
short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
assertEquals(x, (short)2, "setOpaque short value"); assertEquals(x, (short)0x4567, "setOpaque short value");
} }
hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((short)0x0123, (short)0x4567);
assertEquals(r, true, "success compareAndSet short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (short)0x4567, "success compareAndSet short value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((short)0x0123, (short)0x89AB);
assertEquals(r, false, "failing compareAndSet short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (short)0x4567, "failing compareAndSet short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((short)0x4567, (short)0x0123);
assertEquals(r, (short)0x4567, "success compareAndExchange short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (short)0x0123, "success compareAndExchange short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((short)0x4567, (short)0x89AB);
assertEquals(r, (short)0x0123, "failing compareAndExchange short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (short)0x0123, "failing compareAndExchange short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((short)0x0123, (short)0x4567);
assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((short)0x0123, (short)0x89AB);
assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((short)0x4567, (short)0x0123);
assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((short)0x4567, (short)0x89AB);
assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact((short)0x0123, (short)0x4567);
}
assertEquals(success, true, "weakCompareAndSet short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (short)0x4567, "weakCompareAndSet short value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact((short)0x4567, (short)0x0123);
}
assertEquals(success, true, "weakCompareAndSetAcquire short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (short)0x0123, "weakCompareAndSetAcquire short");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact((short)0x0123, (short)0x4567);
}
assertEquals(success, true, "weakCompareAndSetRelease short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (short)0x4567, "weakCompareAndSetRelease short");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact((short)0x4567, (short)0x0123);
}
assertEquals(success, true, "weakCompareAndSetVolatile short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (short)0x0123, "weakCompareAndSetVolatile short");
}
// Compare set and get
{
short o = (short) hs.get(TestAccessMode.GET_AND_SET).invokeExact( (short)0x4567);
assertEquals(o, (short)0x0123, "getAndSet short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (short)0x4567, "getAndSet short value");
}
hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
// get and add, add and get
{
short o = (short) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( (short)0x89AB);
assertEquals(o, (short)0x0123, "getAndAdd short");
short c = (short) hs.get(TestAccessMode.ADD_AND_GET).invokeExact((short)0x89AB);
assertEquals(c, (short)((short)0x0123 + (short)0x89AB + (short)0x89AB), "getAndAdd short value");
}
} }
static void testStaticFieldUnsupported(Handles hs) throws Throwable { static void testStaticFieldUnsupported(Handles hs) throws Throwable {
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact((short)1, (short)2);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
short r = (short) hs.get(am).invokeExact((short)1, (short)2);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
short r = (short) hs.get(am).invokeExact((short)1);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> {
short r = (short) hs.get(am).invokeExact((short)1);
});
}
} }
@ -244,34 +430,149 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest {
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
// Plain // Plain
{ {
hs.get(TestAccessMode.SET).invokeExact(array, i, (short)1); hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (short)1, "get short value"); assertEquals(x, (short)0x0123, "get short value");
} }
// Volatile // Volatile
{ {
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, (short)2); hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, (short)0x4567);
short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
assertEquals(x, (short)2, "setVolatile short value"); assertEquals(x, (short)0x4567, "setVolatile short value");
} }
// Lazy // Lazy
{ {
hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, (short)1); hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, (short)0x0123);
short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
assertEquals(x, (short)1, "setRelease short value"); assertEquals(x, (short)0x0123, "setRelease short value");
} }
// Opaque // Opaque
{ {
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, (short)2); hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, (short)0x4567);
short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
assertEquals(x, (short)2, "setOpaque short value"); assertEquals(x, (short)0x4567, "setOpaque short value");
} }
hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
// Compare
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (short)0x0123, (short)0x4567);
assertEquals(r, true, "success compareAndSet short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (short)0x4567, "success compareAndSet short value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (short)0x0123, (short)0x89AB);
assertEquals(r, false, "failing compareAndSet short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (short)0x4567, "failing compareAndSet short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (short)0x4567, (short)0x0123);
assertEquals(r, (short)0x4567, "success compareAndExchange short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (short)0x0123, "success compareAndExchange short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (short)0x4567, (short)0x89AB);
assertEquals(r, (short)0x0123, "failing compareAndExchange short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (short)0x0123, "failing compareAndExchange short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (short)0x0123, (short)0x4567);
assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (short)0x0123, (short)0x89AB);
assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (short)0x4567, (short)0x0123);
assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value");
}
{
short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (short)0x4567, (short)0x89AB);
assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, (short)0x0123, (short)0x4567);
}
assertEquals(success, true, "weakCompareAndSet short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (short)0x4567, "weakCompareAndSet short value");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, (short)0x4567, (short)0x0123);
}
assertEquals(success, true, "weakCompareAndSetAcquire short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (short)0x0123, "weakCompareAndSetAcquire short");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, (short)0x0123, (short)0x4567);
}
assertEquals(success, true, "weakCompareAndSetRelease short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (short)0x4567, "weakCompareAndSetRelease short");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, (short)0x4567, (short)0x0123);
}
assertEquals(success, true, "weakCompareAndSetVolatile short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (short)0x0123, "weakCompareAndSetVolatile short");
}
// Compare set and get
{
short o = (short) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, (short)0x4567);
assertEquals(o, (short)0x0123, "getAndSet short");
short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (short)0x4567, "getAndSet short value");
}
hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
// get and add, add and get
{
short o = (short) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, (short)0x89AB);
assertEquals(o, (short)0x0123, "getAndAdd short");
short c = (short) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, (short)0x89AB);
assertEquals(c, (short)((short)0x0123 + (short)0x89AB + (short)0x89AB), "getAndAdd short value");
}
} }
} }
@ -279,29 +580,7 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest {
short[] array = new short[10]; short[] array = new short[10];
final int i = 0; final int i = 0;
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkUOE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(array, i, (short)1, (short)2);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkUOE(am, () -> {
short r = (short) hs.get(am).invokeExact(array, i, (short)1, (short)2);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkUOE(am, () -> {
short r = (short) hs.get(am).invokeExact(array, i, (short)1);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkUOE(am, () -> {
short o = (short) hs.get(am).invokeExact(array, i, (short)1);
});
}
} }
static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
@ -318,11 +597,33 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest {
for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
checkIOOBE(am, () -> { checkIOOBE(am, () -> {
hs.get(am).invokeExact(array, ci, (short)1); hs.get(am).invokeExact(array, ci, (short)0x0123);
}); });
} }
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
checkIOOBE(am, () -> {
boolean r = (boolean) hs.get(am).invokeExact(array, ci, (short)0x0123, (short)0x4567);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
checkIOOBE(am, () -> {
short r = (short) hs.get(am).invokeExact(array, ci, (short)0x4567, (short)0x0123);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
checkIOOBE(am, () -> {
short o = (short) hs.get(am).invokeExact(array, ci, (short)0x0123);
});
}
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
checkIOOBE(am, () -> {
short o = (short) hs.get(am).invokeExact(array, ci, (short)0x89AB);
});
}
} }
} }
} }

View file

@ -166,17 +166,17 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
} }
{ {
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, "bar", "foo"); String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, "bar", "foo");
assertEquals(r, "bar", "success compareAndExchangeVolatile String"); assertEquals(r, "bar", "success compareAndExchange String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "foo", "success compareAndExchangeVolatile String value"); assertEquals(x, "foo", "success compareAndExchange String value");
} }
{ {
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, "bar", "baz"); String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, "bar", "baz");
assertEquals(r, "foo", "failing compareAndExchangeVolatile String"); assertEquals(r, "foo", "failing compareAndExchange String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "foo", "failing compareAndExchangeVolatile String value"); assertEquals(x, "foo", "failing compareAndExchange String value");
} }
{ {
@ -315,17 +315,17 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
} }
{ {
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact("bar", "foo"); String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact("bar", "foo");
assertEquals(r, "bar", "success compareAndExchangeVolatile String"); assertEquals(r, "bar", "success compareAndExchange String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(); String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "foo", "success compareAndExchangeVolatile String value"); assertEquals(x, "foo", "success compareAndExchange String value");
} }
{ {
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact("bar", "baz"); String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact("bar", "baz");
assertEquals(r, "foo", "failing compareAndExchangeVolatile String"); assertEquals(r, "foo", "failing compareAndExchange String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(); String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "foo", "failing compareAndExchangeVolatile String value"); assertEquals(x, "foo", "failing compareAndExchange String value");
} }
{ {
@ -467,17 +467,17 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
} }
{ {
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, "bar", "foo"); String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, "bar", "foo");
assertEquals(r, "bar", "success compareAndExchangeVolatile String"); assertEquals(r, "bar", "success compareAndExchange String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "foo", "success compareAndExchangeVolatile String value"); assertEquals(x, "foo", "success compareAndExchange String value");
} }
{ {
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, "bar", "baz"); String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, "bar", "baz");
assertEquals(r, "foo", "failing compareAndExchangeVolatile String"); assertEquals(r, "foo", "failing compareAndExchange String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "foo", "failing compareAndExchangeVolatile String value"); assertEquals(x, "foo", "failing compareAndExchange String value");
} }
{ {

View file

@ -454,40 +454,40 @@ public class VarHandleTestMethodTypeString extends VarHandleBaseTest {
}); });
// CompareAndExchangeVolatile // CompareAndExchange
// Incorrect argument types // Incorrect argument types
checkNPE(() -> { // null receiver checkNPE(() -> { // null receiver
String x = (String) vh.compareAndExchangeVolatile(null, "foo", "foo"); String x = (String) vh.compareAndExchange(null, "foo", "foo");
}); });
checkCCE(() -> { // receiver reference class checkCCE(() -> { // receiver reference class
String x = (String) vh.compareAndExchangeVolatile(Void.class, "foo", "foo"); String x = (String) vh.compareAndExchange(Void.class, "foo", "foo");
}); });
checkCCE(() -> { // expected reference class checkCCE(() -> { // expected reference class
String x = (String) vh.compareAndExchangeVolatile(recv, Void.class, "foo"); String x = (String) vh.compareAndExchange(recv, Void.class, "foo");
}); });
checkCCE(() -> { // actual reference class checkCCE(() -> { // actual reference class
String x = (String) vh.compareAndExchangeVolatile(recv, "foo", Void.class); String x = (String) vh.compareAndExchange(recv, "foo", Void.class);
}); });
checkWMTE(() -> { // reciever primitive class checkWMTE(() -> { // reciever primitive class
String x = (String) vh.compareAndExchangeVolatile(0, "foo", "foo"); String x = (String) vh.compareAndExchange(0, "foo", "foo");
}); });
// Incorrect return type // Incorrect return type
checkCCE(() -> { // reference class checkCCE(() -> { // reference class
Void r = (Void) vh.compareAndExchangeVolatile(recv, "foo", "foo"); Void r = (Void) vh.compareAndExchange(recv, "foo", "foo");
}); });
checkWMTE(() -> { // primitive class checkWMTE(() -> { // primitive class
boolean x = (boolean) vh.compareAndExchangeVolatile(recv, "foo", "foo"); boolean x = (boolean) vh.compareAndExchange(recv, "foo", "foo");
}); });
// Incorrect arity // Incorrect arity
checkWMTE(() -> { // 0 checkWMTE(() -> { // 0
String x = (String) vh.compareAndExchangeVolatile(); String x = (String) vh.compareAndExchange();
}); });
checkWMTE(() -> { // > checkWMTE(() -> { // >
String x = (String) vh.compareAndExchangeVolatile(recv, "foo", "foo", Void.class); String x = (String) vh.compareAndExchange(recv, "foo", "foo", Void.class);
}); });
// CompareAndExchangeVolatileAcquire // CompareAndExchangeAcquire
// Incorrect argument types // Incorrect argument types
checkNPE(() -> { // null receiver checkNPE(() -> { // null receiver
String x = (String) vh.compareAndExchangeAcquire(null, "foo", "foo"); String x = (String) vh.compareAndExchangeAcquire(null, "foo", "foo");
@ -957,27 +957,27 @@ public class VarHandleTestMethodTypeString extends VarHandleBaseTest {
}); });
// CompareAndExchangeVolatile // CompareAndExchange
// Incorrect argument types // Incorrect argument types
checkCCE(() -> { // expected reference class checkCCE(() -> { // expected reference class
String x = (String) vh.compareAndExchangeVolatile(Void.class, "foo"); String x = (String) vh.compareAndExchange(Void.class, "foo");
}); });
checkCCE(() -> { // actual reference class checkCCE(() -> { // actual reference class
String x = (String) vh.compareAndExchangeVolatile("foo", Void.class); String x = (String) vh.compareAndExchange("foo", Void.class);
}); });
// Incorrect return type // Incorrect return type
checkCCE(() -> { // reference class checkCCE(() -> { // reference class
Void r = (Void) vh.compareAndExchangeVolatile("foo", "foo"); Void r = (Void) vh.compareAndExchange("foo", "foo");
}); });
checkWMTE(() -> { // primitive class checkWMTE(() -> { // primitive class
boolean x = (boolean) vh.compareAndExchangeVolatile("foo", "foo"); boolean x = (boolean) vh.compareAndExchange("foo", "foo");
}); });
// Incorrect arity // Incorrect arity
checkWMTE(() -> { // 0 checkWMTE(() -> { // 0
String x = (String) vh.compareAndExchangeVolatile(); String x = (String) vh.compareAndExchange();
}); });
checkWMTE(() -> { // > checkWMTE(() -> { // >
String x = (String) vh.compareAndExchangeVolatile("foo", "foo", Void.class); String x = (String) vh.compareAndExchange("foo", "foo", Void.class);
}); });
@ -1539,39 +1539,39 @@ public class VarHandleTestMethodTypeString extends VarHandleBaseTest {
}); });
// CompareAndExchangeVolatile // CompareAndExchange
// Incorrect argument types // Incorrect argument types
checkNPE(() -> { // null receiver checkNPE(() -> { // null receiver
String x = (String) vh.compareAndExchangeVolatile(null, 0, "foo", "foo"); String x = (String) vh.compareAndExchange(null, 0, "foo", "foo");
}); });
checkCCE(() -> { // array reference class checkCCE(() -> { // array reference class
String x = (String) vh.compareAndExchangeVolatile(Void.class, 0, "foo", "foo"); String x = (String) vh.compareAndExchange(Void.class, 0, "foo", "foo");
}); });
checkCCE(() -> { // expected reference class checkCCE(() -> { // expected reference class
String x = (String) vh.compareAndExchangeVolatile(array, 0, Void.class, "foo"); String x = (String) vh.compareAndExchange(array, 0, Void.class, "foo");
}); });
checkCCE(() -> { // actual reference class checkCCE(() -> { // actual reference class
String x = (String) vh.compareAndExchangeVolatile(array, 0, "foo", Void.class); String x = (String) vh.compareAndExchange(array, 0, "foo", Void.class);
}); });
checkWMTE(() -> { // array primitive class checkWMTE(() -> { // array primitive class
String x = (String) vh.compareAndExchangeVolatile(0, 0, "foo", "foo"); String x = (String) vh.compareAndExchange(0, 0, "foo", "foo");
}); });
checkWMTE(() -> { // index reference class checkWMTE(() -> { // index reference class
String x = (String) vh.compareAndExchangeVolatile(array, Void.class, "foo", "foo"); String x = (String) vh.compareAndExchange(array, Void.class, "foo", "foo");
}); });
// Incorrect return type // Incorrect return type
checkCCE(() -> { // reference class checkCCE(() -> { // reference class
Void r = (Void) vh.compareAndExchangeVolatile(array, 0, "foo", "foo"); Void r = (Void) vh.compareAndExchange(array, 0, "foo", "foo");
}); });
checkWMTE(() -> { // primitive class checkWMTE(() -> { // primitive class
boolean x = (boolean) vh.compareAndExchangeVolatile(array, 0, "foo", "foo"); boolean x = (boolean) vh.compareAndExchange(array, 0, "foo", "foo");
}); });
// Incorrect arity // Incorrect arity
checkWMTE(() -> { // 0 checkWMTE(() -> { // 0
String x = (String) vh.compareAndExchangeVolatile(); String x = (String) vh.compareAndExchange();
}); });
checkWMTE(() -> { // > checkWMTE(() -> { // >
String x = (String) vh.compareAndExchangeVolatile(array, 0, "foo", "foo", Void.class); String x = (String) vh.compareAndExchange(array, 0, "foo", "foo", Void.class);
}); });

View file

@ -101,7 +101,7 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
#if[CAS] #if[CAS]
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
@ -111,7 +111,7 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
#else[CAS] #else[CAS]
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
@ -283,7 +283,7 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
}); });
checkUOE(() -> { checkUOE(() -> {
$type$ r = ($type$) vh.compareAndExchangeVolatile(recv, $value1$, $value2$); $type$ r = ($type$) vh.compareAndExchange(recv, $value1$, $value2$);
}); });
checkUOE(() -> { checkUOE(() -> {
@ -377,7 +377,7 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
}); });
checkUOE(() -> { checkUOE(() -> {
$type$ r = ($type$) vh.compareAndExchangeVolatile($value1$, $value2$); $type$ r = ($type$) vh.compareAndExchange($value1$, $value2$);
}); });
checkUOE(() -> { checkUOE(() -> {
@ -470,17 +470,17 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
} }
{ {
$type$ r = ($type$) vh.compareAndExchangeVolatile(recv, $value2$, $value1$); $type$ r = ($type$) vh.compareAndExchange(recv, $value2$, $value1$);
assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$"); assertEquals(r, $value2$, "success compareAndExchange $type$");
$type$ x = ($type$) vh.get(recv); $type$ x = ($type$) vh.get(recv);
assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value"); assertEquals(x, $value1$, "success compareAndExchange $type$ value");
} }
{ {
$type$ r = ($type$) vh.compareAndExchangeVolatile(recv, $value2$, $value3$); $type$ r = ($type$) vh.compareAndExchange(recv, $value2$, $value3$);
assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$"); assertEquals(r, $value1$, "failing compareAndExchange $type$");
$type$ x = ($type$) vh.get(recv); $type$ x = ($type$) vh.get(recv);
assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value"); assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
} }
{ {
@ -568,7 +568,7 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
$type$ o = ($type$) vh.getAndAdd(recv, $value3$); $type$ o = ($type$) vh.getAndAdd(recv, $value3$);
assertEquals(o, $value1$, "getAndAdd $type$"); assertEquals(o, $value1$, "getAndAdd $type$");
$type$ c = ($type$) vh.addAndGet(recv, $value3$); $type$ c = ($type$) vh.addAndGet(recv, $value3$);
assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value"); assertEquals(c, ($type$)($value1$ + $value3$ + $value3$), "getAndAdd $type$ value");
} }
#end[AtomicAdd] #end[AtomicAdd]
} }
@ -580,7 +580,7 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
}); });
checkUOE(() -> { checkUOE(() -> {
$type$ r = ($type$) vh.compareAndExchangeVolatile(recv, $value1$, $value2$); $type$ r = ($type$) vh.compareAndExchange(recv, $value1$, $value2$);
}); });
checkUOE(() -> { checkUOE(() -> {
@ -673,17 +673,17 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
} }
{ {
$type$ r = ($type$) vh.compareAndExchangeVolatile($value2$, $value1$); $type$ r = ($type$) vh.compareAndExchange($value2$, $value1$);
assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$"); assertEquals(r, $value2$, "success compareAndExchange $type$");
$type$ x = ($type$) vh.get(); $type$ x = ($type$) vh.get();
assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value"); assertEquals(x, $value1$, "success compareAndExchange $type$ value");
} }
{ {
$type$ r = ($type$) vh.compareAndExchangeVolatile($value2$, $value3$); $type$ r = ($type$) vh.compareAndExchange($value2$, $value3$);
assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$"); assertEquals(r, $value1$, "failing compareAndExchange $type$");
$type$ x = ($type$) vh.get(); $type$ x = ($type$) vh.get();
assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value"); assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
} }
{ {
@ -771,7 +771,7 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
$type$ o = ($type$) vh.getAndAdd( $value3$); $type$ o = ($type$) vh.getAndAdd( $value3$);
assertEquals(o, $value1$, "getAndAdd $type$"); assertEquals(o, $value1$, "getAndAdd $type$");
$type$ c = ($type$) vh.addAndGet($value3$); $type$ c = ($type$) vh.addAndGet($value3$);
assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value"); assertEquals(c, ($type$)($value1$ + $value3$ + $value3$), "getAndAdd $type$ value");
} }
#end[AtomicAdd] #end[AtomicAdd]
} }
@ -783,7 +783,7 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
}); });
checkUOE(() -> { checkUOE(() -> {
$type$ r = ($type$) vh.compareAndExchangeVolatile($value1$, $value2$); $type$ r = ($type$) vh.compareAndExchange($value1$, $value2$);
}); });
checkUOE(() -> { checkUOE(() -> {
@ -879,17 +879,17 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
} }
{ {
$type$ r = ($type$) vh.compareAndExchangeVolatile(array, i, $value2$, $value1$); $type$ r = ($type$) vh.compareAndExchange(array, i, $value2$, $value1$);
assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$"); assertEquals(r, $value2$, "success compareAndExchange $type$");
$type$ x = ($type$) vh.get(array, i); $type$ x = ($type$) vh.get(array, i);
assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value"); assertEquals(x, $value1$, "success compareAndExchange $type$ value");
} }
{ {
$type$ r = ($type$) vh.compareAndExchangeVolatile(array, i, $value2$, $value3$); $type$ r = ($type$) vh.compareAndExchange(array, i, $value2$, $value3$);
assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$"); assertEquals(r, $value1$, "failing compareAndExchange $type$");
$type$ x = ($type$) vh.get(array, i); $type$ x = ($type$) vh.get(array, i);
assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value"); assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
} }
{ {
@ -977,7 +977,7 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
$type$ o = ($type$) vh.getAndAdd(array, i, $value3$); $type$ o = ($type$) vh.getAndAdd(array, i, $value3$);
assertEquals(o, $value1$, "getAndAdd $type$"); assertEquals(o, $value1$, "getAndAdd $type$");
$type$ c = ($type$) vh.addAndGet(array, i, $value3$); $type$ c = ($type$) vh.addAndGet(array, i, $value3$);
assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value"); assertEquals(c, ($type$)($value1$ + $value3$ + $value3$), "getAndAdd $type$ value");
} }
#end[AtomicAdd] #end[AtomicAdd]
} }
@ -993,7 +993,7 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
}); });
checkUOE(() -> { checkUOE(() -> {
$type$ r = ($type$) vh.compareAndExchangeVolatile(array, i, $value1$, $value2$); $type$ r = ($type$) vh.compareAndExchange(array, i, $value1$, $value2$);
}); });
checkUOE(() -> { checkUOE(() -> {
@ -1080,7 +1080,7 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
$type$ r = ($type$) vh.compareAndExchangeVolatile(array, ci, $value2$, $value1$); $type$ r = ($type$) vh.compareAndExchange(array, ci, $value2$, $value1$);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {

View file

@ -90,7 +90,7 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
#if[CAS] #if[CAS]
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
@ -100,7 +100,7 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
#else[CAS] #else[CAS]
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
@ -207,7 +207,7 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
}); });
checkUOE(() -> { checkUOE(() -> {
$type$ r = ($type$) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkUOE(() -> { checkUOE(() -> {
@ -281,7 +281,7 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
}); });
checkROBE(() -> { checkROBE(() -> {
$type$ r = ($type$) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkROBE(() -> { checkROBE(() -> {
@ -318,7 +318,7 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
}); });
checkUOE(() -> { checkUOE(() -> {
$type$ r = ($type$) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkUOE(() -> { checkUOE(() -> {
@ -375,7 +375,7 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
}); });
checkUOE(() -> { checkUOE(() -> {
$type$ r = ($type$) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkUOE(() -> { checkUOE(() -> {
@ -465,7 +465,7 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
$type$ r = ($type$) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -561,7 +561,7 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
$type$ r = ($type$) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkIOOBE(() -> { checkIOOBE(() -> {
@ -648,7 +648,7 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
}); });
checkISE(() -> { checkISE(() -> {
$type$ r = ($type$) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkISE(() -> { checkISE(() -> {
@ -738,7 +738,7 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
}); });
checkISE(() -> { checkISE(() -> {
$type$ r = ($type$) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
}); });
checkISE(() -> { checkISE(() -> {
@ -844,17 +844,17 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
} }
{ {
$type$ r = ($type$) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_1); $type$ r = ($type$) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchangeVolatile $type$"); assertEquals(r, VALUE_2, "success compareAndExchange $type$");
$type$ x = ($type$) vh.get(array, i); $type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchangeVolatile $type$ value"); assertEquals(x, VALUE_1, "success compareAndExchange $type$ value");
} }
{ {
$type$ r = ($type$) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_3); $type$ r = ($type$) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchangeVolatile $type$"); assertEquals(r, VALUE_1, "failing compareAndExchange $type$");
$type$ x = ($type$) vh.get(array, i); $type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchangeVolatile $type$ value"); assertEquals(x, VALUE_1, "failing compareAndExchange $type$ value");
} }
{ {
@ -1006,17 +1006,17 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
} }
{ {
$type$ r = ($type$) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_1); $type$ r = ($type$) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchangeVolatile $type$"); assertEquals(r, VALUE_2, "success compareAndExchange $type$");
$type$ x = ($type$) vh.get(array, i); $type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchangeVolatile $type$ value"); assertEquals(x, VALUE_1, "success compareAndExchange $type$ value");
} }
{ {
$type$ r = ($type$) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_3); $type$ r = ($type$) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchangeVolatile $type$"); assertEquals(r, VALUE_1, "failing compareAndExchange $type$");
$type$ x = ($type$) vh.get(array, i); $type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchangeVolatile $type$ value"); assertEquals(x, VALUE_1, "failing compareAndExchange $type$ value");
} }
{ {

View file

@ -167,17 +167,17 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest {
} }
{ {
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, $value2$, $value1$); $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, $value2$, $value1$);
assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$"); assertEquals(r, $value2$, "success compareAndExchange $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value"); assertEquals(x, $value1$, "success compareAndExchange $type$ value");
} }
{ {
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, $value2$, $value3$); $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, $value2$, $value3$);
assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$"); assertEquals(r, $value1$, "failing compareAndExchange $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value"); assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
} }
{ {
@ -265,7 +265,7 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest {
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, $value3$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, $value3$);
assertEquals(o, $value1$, "getAndAdd $type$"); assertEquals(o, $value1$, "getAndAdd $type$");
$type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, $value3$); $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, $value3$);
assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value"); assertEquals(c, ($type$)($value1$ + $value3$ + $value3$), "getAndAdd $type$ value");
} }
#end[AtomicAdd] #end[AtomicAdd]
} }
@ -350,17 +350,17 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest {
} }
{ {
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value1$); $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact($value2$, $value1$);
assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$"); assertEquals(r, $value2$, "success compareAndExchange $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value"); assertEquals(x, $value1$, "success compareAndExchange $type$ value");
} }
{ {
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value3$); $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact($value2$, $value3$);
assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$"); assertEquals(r, $value1$, "failing compareAndExchange $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value"); assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
} }
{ {
@ -448,7 +448,7 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest {
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( $value3$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( $value3$);
assertEquals(o, $value1$, "getAndAdd $type$"); assertEquals(o, $value1$, "getAndAdd $type$");
$type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact($value3$); $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact($value3$);
assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value"); assertEquals(c, ($type$)($value1$ + $value3$ + $value3$), "getAndAdd $type$ value");
} }
#end[AtomicAdd] #end[AtomicAdd]
} }
@ -536,17 +536,17 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest {
} }
{ {
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value1$); $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, $value2$, $value1$);
assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$"); assertEquals(r, $value2$, "success compareAndExchange $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value"); assertEquals(x, $value1$, "success compareAndExchange $type$ value");
} }
{ {
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value3$); $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, $value2$, $value3$);
assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$"); assertEquals(r, $value1$, "failing compareAndExchange $type$");
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value"); assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
} }
{ {
@ -634,7 +634,7 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest {
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, $value3$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, $value3$);
assertEquals(o, $value1$, "getAndAdd $type$"); assertEquals(o, $value1$, "getAndAdd $type$");
$type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, $value3$); $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, $value3$);
assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value"); assertEquals(c, ($type$)($value1$ + $value3$ + $value3$), "getAndAdd $type$ value");
} }
#end[AtomicAdd] #end[AtomicAdd]
} }

View file

@ -455,40 +455,40 @@ public class VarHandleTestMethodType$Type$ extends VarHandleBaseTest {
}); });
// CompareAndExchangeVolatile // CompareAndExchange
// Incorrect argument types // Incorrect argument types
checkNPE(() -> { // null receiver checkNPE(() -> { // null receiver
$type$ x = ($type$) vh.compareAndExchangeVolatile(null, $value1$, $value1$); $type$ x = ($type$) vh.compareAndExchange(null, $value1$, $value1$);
}); });
checkCCE(() -> { // receiver reference class checkCCE(() -> { // receiver reference class
$type$ x = ($type$) vh.compareAndExchangeVolatile(Void.class, $value1$, $value1$); $type$ x = ($type$) vh.compareAndExchange(Void.class, $value1$, $value1$);
}); });
check{#if[String]?CCE:WMTE}(() -> { // expected reference class check{#if[String]?CCE:WMTE}(() -> { // expected reference class
$type$ x = ($type$) vh.compareAndExchangeVolatile(recv, Void.class, $value1$); $type$ x = ($type$) vh.compareAndExchange(recv, Void.class, $value1$);
}); });
check{#if[String]?CCE:WMTE}(() -> { // actual reference class check{#if[String]?CCE:WMTE}(() -> { // actual reference class
$type$ x = ($type$) vh.compareAndExchangeVolatile(recv, $value1$, Void.class); $type$ x = ($type$) vh.compareAndExchange(recv, $value1$, Void.class);
}); });
checkWMTE(() -> { // reciever primitive class checkWMTE(() -> { // reciever primitive class
$type$ x = ($type$) vh.compareAndExchangeVolatile(0, $value1$, $value1$); $type$ x = ($type$) vh.compareAndExchange(0, $value1$, $value1$);
}); });
// Incorrect return type // Incorrect return type
check{#if[String]?CCE:WMTE}(() -> { // reference class check{#if[String]?CCE:WMTE}(() -> { // reference class
Void r = (Void) vh.compareAndExchangeVolatile(recv, $value1$, $value1$); Void r = (Void) vh.compareAndExchange(recv, $value1$, $value1$);
}); });
checkWMTE(() -> { // primitive class checkWMTE(() -> { // primitive class
$wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeVolatile(recv, $value1$, $value1$); $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchange(recv, $value1$, $value1$);
}); });
// Incorrect arity // Incorrect arity
checkWMTE(() -> { // 0 checkWMTE(() -> { // 0
$type$ x = ($type$) vh.compareAndExchangeVolatile(); $type$ x = ($type$) vh.compareAndExchange();
}); });
checkWMTE(() -> { // > checkWMTE(() -> { // >
$type$ x = ($type$) vh.compareAndExchangeVolatile(recv, $value1$, $value1$, Void.class); $type$ x = ($type$) vh.compareAndExchange(recv, $value1$, $value1$, Void.class);
}); });
// CompareAndExchangeVolatileAcquire // CompareAndExchangeAcquire
// Incorrect argument types // Incorrect argument types
checkNPE(() -> { // null receiver checkNPE(() -> { // null receiver
$type$ x = ($type$) vh.compareAndExchangeAcquire(null, $value1$, $value1$); $type$ x = ($type$) vh.compareAndExchangeAcquire(null, $value1$, $value1$);
@ -1060,27 +1060,27 @@ public class VarHandleTestMethodType$Type$ extends VarHandleBaseTest {
}); });
// CompareAndExchangeVolatile // CompareAndExchange
// Incorrect argument types // Incorrect argument types
check{#if[String]?CCE:WMTE}(() -> { // expected reference class check{#if[String]?CCE:WMTE}(() -> { // expected reference class
$type$ x = ($type$) vh.compareAndExchangeVolatile(Void.class, $value1$); $type$ x = ($type$) vh.compareAndExchange(Void.class, $value1$);
}); });
check{#if[String]?CCE:WMTE}(() -> { // actual reference class check{#if[String]?CCE:WMTE}(() -> { // actual reference class
$type$ x = ($type$) vh.compareAndExchangeVolatile($value1$, Void.class); $type$ x = ($type$) vh.compareAndExchange($value1$, Void.class);
}); });
// Incorrect return type // Incorrect return type
check{#if[String]?CCE:WMTE}(() -> { // reference class check{#if[String]?CCE:WMTE}(() -> { // reference class
Void r = (Void) vh.compareAndExchangeVolatile($value1$, $value1$); Void r = (Void) vh.compareAndExchange($value1$, $value1$);
}); });
checkWMTE(() -> { // primitive class checkWMTE(() -> { // primitive class
$wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeVolatile($value1$, $value1$); $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchange($value1$, $value1$);
}); });
// Incorrect arity // Incorrect arity
checkWMTE(() -> { // 0 checkWMTE(() -> { // 0
$type$ x = ($type$) vh.compareAndExchangeVolatile(); $type$ x = ($type$) vh.compareAndExchange();
}); });
checkWMTE(() -> { // > checkWMTE(() -> { // >
$type$ x = ($type$) vh.compareAndExchangeVolatile($value1$, $value1$, Void.class); $type$ x = ($type$) vh.compareAndExchange($value1$, $value1$, Void.class);
}); });
@ -1715,39 +1715,39 @@ public class VarHandleTestMethodType$Type$ extends VarHandleBaseTest {
}); });
// CompareAndExchangeVolatile // CompareAndExchange
// Incorrect argument types // Incorrect argument types
checkNPE(() -> { // null receiver checkNPE(() -> { // null receiver
$type$ x = ($type$) vh.compareAndExchangeVolatile(null, 0, $value1$, $value1$); $type$ x = ($type$) vh.compareAndExchange(null, 0, $value1$, $value1$);
}); });
checkCCE(() -> { // array reference class checkCCE(() -> { // array reference class
$type$ x = ($type$) vh.compareAndExchangeVolatile(Void.class, 0, $value1$, $value1$); $type$ x = ($type$) vh.compareAndExchange(Void.class, 0, $value1$, $value1$);
}); });
check{#if[String]?CCE:WMTE}(() -> { // expected reference class check{#if[String]?CCE:WMTE}(() -> { // expected reference class
$type$ x = ($type$) vh.compareAndExchangeVolatile(array, 0, Void.class, $value1$); $type$ x = ($type$) vh.compareAndExchange(array, 0, Void.class, $value1$);
}); });
check{#if[String]?CCE:WMTE}(() -> { // actual reference class check{#if[String]?CCE:WMTE}(() -> { // actual reference class
$type$ x = ($type$) vh.compareAndExchangeVolatile(array, 0, $value1$, Void.class); $type$ x = ($type$) vh.compareAndExchange(array, 0, $value1$, Void.class);
}); });
checkWMTE(() -> { // array primitive class checkWMTE(() -> { // array primitive class
$type$ x = ($type$) vh.compareAndExchangeVolatile(0, 0, $value1$, $value1$); $type$ x = ($type$) vh.compareAndExchange(0, 0, $value1$, $value1$);
}); });
checkWMTE(() -> { // index reference class checkWMTE(() -> { // index reference class
$type$ x = ($type$) vh.compareAndExchangeVolatile(array, Void.class, $value1$, $value1$); $type$ x = ($type$) vh.compareAndExchange(array, Void.class, $value1$, $value1$);
}); });
// Incorrect return type // Incorrect return type
check{#if[String]?CCE:WMTE}(() -> { // reference class check{#if[String]?CCE:WMTE}(() -> { // reference class
Void r = (Void) vh.compareAndExchangeVolatile(array, 0, $value1$, $value1$); Void r = (Void) vh.compareAndExchange(array, 0, $value1$, $value1$);
}); });
checkWMTE(() -> { // primitive class checkWMTE(() -> { // primitive class
$wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeVolatile(array, 0, $value1$, $value1$); $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchange(array, 0, $value1$, $value1$);
}); });
// Incorrect arity // Incorrect arity
checkWMTE(() -> { // 0 checkWMTE(() -> { // 0
$type$ x = ($type$) vh.compareAndExchangeVolatile(); $type$ x = ($type$) vh.compareAndExchange();
}); });
checkWMTE(() -> { // > checkWMTE(() -> { // >
$type$ x = ($type$) vh.compareAndExchangeVolatile(array, 0, $value1$, $value1$, Void.class); $type$ x = ($type$) vh.compareAndExchange(array, 0, $value1$, $value1$, Void.class);
}); });

View file

@ -14,14 +14,10 @@ do
Type="$(tr '[:lower:]' '[:upper:]' <<< ${type:0:1})${type:1}" Type="$(tr '[:lower:]' '[:upper:]' <<< ${type:0:1})${type:1}"
args="-K$type -Dtype=$type -DType=$Type" args="-K$type -Dtype=$type -DType=$Type"
case $type in args="$args -KCAS"
String|int|long)
args="$args -KCAS"
;;
esac
case $type in case $type in
int|long) byte|short|char|int|long|float|double)
args="$args -KAtomicAdd" args="$args -KAtomicAdd"
;; ;;
esac esac
@ -36,29 +32,29 @@ do
wrong_primitive_type=int wrong_primitive_type=int
;; ;;
byte) byte)
value1=(byte)1 value1=(byte)0x01
value2=(byte)2 value2=(byte)0x23
value3=(byte)3 value3=(byte)0x45
;; ;;
short) short)
value1=(short)1 value1=(short)0x0123
value2=(short)2 value2=(short)0x4567
value3=(short)3 value3=(short)0x89AB
;; ;;
char) char)
value1=\'a\' value1=\'\\\\u0123\'
value2=\'b\' value2=\'\\\\u4567\'
value3=\'c\' value3=\'\\\\u89AB\'
;; ;;
int) int)
value1=1 value1=0x01234567
value2=2 value2=0x89ABCDEF
value3=3 value3=0xCAFEBABE
;; ;;
long) long)
value1=1L value1=0x0123456789ABCDEFL
value2=2L value2=0xCAFEBABECAFEBABEL
value3=3L value3=0xDEADBEEFDEADBEEFL
;; ;;
float) float)
value1=1.0f value1=1.0f