8158039: VarHandle float/double field/array access should support CAS/set/add atomics

Reviewed-by: shade, vlivanov, darcy
This commit is contained in:
Paul Sandoz 2016-06-20 17:57:19 +02:00
parent e663206d07
commit 734dbe4089
10 changed files with 4463 additions and 642 deletions

View file

@ -38,11 +38,9 @@ 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 Boolean Byte Short Char Int Long), ) $1_ARGS += -KCAS
$1_ARGS += -KCAS
endif
ifneq ($$(findstring $$($1_Type), Byte Short Char Int Long), ) ifneq ($$(findstring $$($1_Type), Byte Short Char Int Long Float Double), )
$1_ARGS += -KAtomicAdd $1_ARGS += -KAtomicAdd
endif endif

View file

@ -1208,21 +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 boolean},
* {@code byte}, {@code short}, {@code char}, {@code int},
* {@code long} or a reference type, then atomic update access modes
* are unsupported. (Future major platform releases of the JDK may
* support additional types for certain currently unsupported access
* modes.)
* <li>if the field type is anything other than {@code byte}, * <li>if the field type is anything other than {@code byte},
* {@code short}, {@code char}, {@code int} or {@code long}, then * {@code short}, {@code char}, {@code int} or {@code long},
* numeric atomic update access modes are unsupported. * {@code float}, or {@code double} then numeric atomic update
* access modes are unsupported.
* </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
@ -1305,21 +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 boolean},
* {@code byte}, {@code short}, {@code char}, {@code int},
* {@code long} or a reference type, then atomic update access modes
* are unsupported. (Future major platform releases of the JDK may
* support additional types for certain currently unsupported access
* modes.)
* <li>if the field type is anything other than {@code byte}, * <li>if the field type is anything other than {@code byte},
* {@code short}, {@code char}, {@code int} or {@code long}, then * {@code short}, {@code char}, {@code int} or {@code long},
* numeric atomic update access modes are unsupported. * {@code float}, or {@code double}, then numeric atomic update
* access modes are unsupported.
* </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}
@ -1588,21 +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 boolean},
* {@code byte}, {@code short}, {@code char}, {@code int},
* {@code long} or a reference type, then atomic update access modes
* are unsupported. (Future major platform releases of the JDK may
* support additional types for certain currently unsupported access
* modes.)
* <li>if the field type is anything other than {@code byte}, * <li>if the field type is anything other than {@code byte},
* {@code short}, {@code char}, {@code int} or {@code long}, then * {@code short}, {@code char}, {@code int} or {@code long},
* numeric atomic update access modes are unsupported. * {@code float}, or {@code double} then numeric atomic update
* access modes are unsupported.
* </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
@ -2294,16 +2360,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 field type is anything other than {@code boolean},
* {@code byte}, {@code short}, {@code char}, {@code int},
* {@code long} or a reference type, then atomic update access modes
* are unsupported. (Future major platform releases of the JDK may
* support additional types for certain currently unsupported access
* modes.)
* <li>if the component type is anything other than {@code byte}, * <li>if the component type is anything other than {@code byte},
* {@code short}, {@code char}, {@code int} or {@code long}, then * {@code short}, {@code char}, {@code int} or {@code long},
* numeric atomic update access modes are unsupported. * {@code float}, or {@code double} then numeric atomic update access
* modes are unsupported.
* </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
@ -2367,16 +2455,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
@ -2453,16 +2536,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

@ -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.
@ -1679,6 +1677,174 @@ public final class Unsafe {
return weakCompareAndSwapByte(o, offset, bool2byte(expected), bool2byte(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}.
@ -2161,10 +2327,41 @@ public final class Unsafe {
return v; return v;
} }
@ForceInline
public final char getAndAddChar(Object o, long offset, char delta) { public final char getAndAddChar(Object o, long offset, char delta) {
return (char) getAndAddShort(o, offset, (short) 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;
}
/** /**
* Atomically exchanges the given value with the current value of * Atomically exchanges the given value with the current value of
* a field or array element within the given object {@code o} * a field or array element within the given object {@code o}
@ -2234,6 +2431,7 @@ public final class Unsafe {
return v; return v;
} }
@ForceInline
public final boolean getAndSetBoolean(Object o, long offset, boolean newValue) { public final boolean getAndSetBoolean(Object o, long offset, boolean newValue) {
return byte2bool(getAndSetByte(o, offset, bool2byte(newValue))); return byte2bool(getAndSetByte(o, offset, bool2byte(newValue)));
} }
@ -2247,10 +2445,23 @@ public final class Unsafe {
return v; return v;
} }
@ForceInline
public final char getAndSetChar(Object o, long offset, char newValue) { public final char getAndSetChar(Object o, long offset, char newValue) {
return s2c(getAndSetShort(o, offset, c2s(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
* stores after the fence; a "LoadLoad plus LoadStore barrier". * stores after the fence; a "LoadLoad plus LoadStore barrier".

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_VOLATILE));
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.compareAndExchangeVolatile(recv, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeVolatile double");
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "success compareAndExchangeVolatile double value");
}
{
double r = (double) vh.compareAndExchangeVolatile(recv, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeVolatile double");
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "failing compareAndExchangeVolatile 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.compareAndExchangeVolatile(2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeVolatile double");
double x = (double) vh.get();
assertEquals(x, 1.0d, "success compareAndExchangeVolatile double value");
}
{
double r = (double) vh.compareAndExchangeVolatile(2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeVolatile double");
double x = (double) vh.get();
assertEquals(x, 1.0d, "failing compareAndExchangeVolatile 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.compareAndExchangeVolatile(array, i, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeVolatile double");
double x = (double) vh.get(array, i);
assertEquals(x, 1.0d, "success compareAndExchangeVolatile double value");
}
{
double r = (double) vh.compareAndExchangeVolatile(array, i, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeVolatile double");
double x = (double) vh.get(array, i);
assertEquals(x, 1.0d, "failing compareAndExchangeVolatile 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.compareAndExchangeVolatile(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_VOLATILE));
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.compareAndExchangeVolatile(recv, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeVolatile float");
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "success compareAndExchangeVolatile float value");
}
{
float r = (float) vh.compareAndExchangeVolatile(recv, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeVolatile float");
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "failing compareAndExchangeVolatile 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.compareAndExchangeVolatile(2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeVolatile float");
float x = (float) vh.get();
assertEquals(x, 1.0f, "success compareAndExchangeVolatile float value");
}
{
float r = (float) vh.compareAndExchangeVolatile(2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeVolatile float");
float x = (float) vh.get();
assertEquals(x, 1.0f, "failing compareAndExchangeVolatile 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.compareAndExchangeVolatile(array, i, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeVolatile float");
float x = (float) vh.get(array, i);
assertEquals(x, 1.0f, "success compareAndExchangeVolatile float value");
}
{
float r = (float) vh.compareAndExchangeVolatile(array, i, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeVolatile float");
float x = (float) vh.get(array, i);
assertEquals(x, 1.0f, "failing compareAndExchangeVolatile 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.compareAndExchangeVolatile(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

@ -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_VOLATILE).invokeExact(recv, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeVolatile double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0d, "success compareAndExchangeVolatile double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeVolatile double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0d, "failing compareAndExchangeVolatile 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_VOLATILE).invokeExact(2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeVolatile double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0d, "success compareAndExchangeVolatile double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeVolatile double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0d, "failing compareAndExchangeVolatile 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_VOLATILE).invokeExact(array, i, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeVolatile double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0d, "success compareAndExchangeVolatile double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeVolatile double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0d, "failing compareAndExchangeVolatile 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_VOLATILE).invokeExact(recv, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeVolatile float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0f, "success compareAndExchangeVolatile float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeVolatile float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0f, "failing compareAndExchangeVolatile 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_VOLATILE).invokeExact(2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeVolatile float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0f, "success compareAndExchangeVolatile float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeVolatile float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0f, "failing compareAndExchangeVolatile 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_VOLATILE).invokeExact(array, i, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeVolatile float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0f, "success compareAndExchangeVolatile float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeVolatile float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0f, "failing compareAndExchangeVolatile 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

@ -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|boolean|byte|short|char|int|long)
args="$args -KCAS"
;;
esac
case $type in case $type in
byte|short|char|int|long) byte|short|char|int|long|float|double)
args="$args -KAtomicAdd" args="$args -KAtomicAdd"
;; ;;
esac esac