Merge "Reverting checks after toArray() calls"
diff --git a/EXPECTED_UPSTREAM b/EXPECTED_UPSTREAM
index db5254f..982b3e0 100644
--- a/EXPECTED_UPSTREAM
+++ b/EXPECTED_UPSTREAM
@@ -1782,6 +1782,55 @@
ojluni/src/test/java/io/Reader/NullReader.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/io/Reader/NullReader.java
ojluni/src/test/java/io/Reader/TransferTo.java,jdk11u/jdk-11+28,test/jdk/java/io/Reader/TransferTo.java
ojluni/src/test/java/io/Writer/NullWriter.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/io/Writer/NullWriter.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleBaseByteArrayTest.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleBaseByteArrayTest.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleBaseTest.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleBaseTest.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleMethodReferenceTest.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleMethodReferenceTest.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessBoolean.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessBoolean.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessByte.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessByte.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessChar.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessChar.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessDouble.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessDouble.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessFloat.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessFloat.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessInt.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessInt.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessLong.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessLong.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessModeMethodNames.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessModeMethodNames.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessShort.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessShort.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessString.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessString.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsChar.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsChar.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsDouble.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsDouble.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsFloat.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsFloat.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsInt.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsInt.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsLong.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsLong.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsShort.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsShort.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessBoolean.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessBoolean.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessByte.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessByte.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessChar.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessChar.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessDouble.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessDouble.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessFloat.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessFloat.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessInt.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessInt.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessLong.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessLong.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessShort.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessShort.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessString.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessString.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeBoolean.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeBoolean.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeByte.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeByte.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeChar.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeChar.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeDouble.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeDouble.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeFloat.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeFloat.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeInt.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeInt.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeLong.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeLong.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeShort.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeShort.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeString.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeString.java
+ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestReflection.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/VarHandleTestReflection.java
+ojluni/src/test/java/lang/invoke/VarHandles/X-VarHandleTestAccess.java.template,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestAccess.java.template
+ojluni/src/test/java/lang/invoke/VarHandles/X-VarHandleTestByteArrayView.java.template,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestByteArrayView.java.template
+ojluni/src/test/java/lang/invoke/VarHandles/X-VarHandleTestMethodHandleAccess.java.template,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestMethodHandleAccess.java.template
+ojluni/src/test/java/lang/invoke/VarHandles/X-VarHandleTestMethodType.java.template,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestMethodType.java.template
+ojluni/src/test/java/lang/invoke/VarHandles/accessibility/TestFieldLookupAccessibility.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/accessibility/TestFieldLookupAccessibility.java
+ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/A.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/accessibility/pkg/A.java
+ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/B_extends_A.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/accessibility/pkg/B_extends_A.java
+ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/C.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/accessibility/pkg/C.java
+ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/subpkg/B_extends_A.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/accessibility/pkg/subpkg/B_extends_A.java
+ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/subpkg/C.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/accessibility/pkg/subpkg/C.java
+ojluni/src/test/java/lang/invoke/VarHandles/generate-vh-tests.sh,jdk11u/jdk-11.0.13-ga,test/jdk/java/lang/invoke/VarHandles/generate-vh-tests.sh
ojluni/src/test/java/math/BigDecimal/AddTests.java,jdk11u/jdk-11+28,test/jdk/java/math/BigDecimal/AddTests.java
ojluni/src/test/java/math/BigDecimal/CompareToTests.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/math/BigDecimal/CompareToTests.java
ojluni/src/test/java/math/BigDecimal/Constructor.java,jdk11u/jdk-11+28,test/jdk/java/math/BigDecimal/Constructor.java
diff --git a/JavaLibrary.bp b/JavaLibrary.bp
index 4da15c1..24295f8 100644
--- a/JavaLibrary.bp
+++ b/JavaLibrary.bp
@@ -697,6 +697,9 @@
"ojluni/src/test/java/**/*.java",
"ojluni/src/test/javax/**/*.java",
],
+ exclude_srcs: [
+ "ojluni/src/test/java/lang/invoke/VarHandles/**/*.java",
+ ],
java_resource_dirs: [
"ojluni/src/test/java",
"ojluni/src/test/resources",
@@ -753,10 +756,12 @@
// and won't actually run, and
// 2.) util/stream/boot*. Those directories contain classes in the package java.util.stream;
// excluding them means we don't need patch_module: "java.base"
+ // 3.) java.lang.invoke.VarHandles. A few issues to clear out then address b/203822478.
exclude_srcs: [
"**/DeserializeMethodTest.java",
"**/SerializedLambdaTest.java",
"ojluni/src/test/java/util/stream/boot*/**/*",
+ "ojluni/src/test/java/lang/invoke/VarHandles/**/*.java",
],
java_resource_dirs: [
"ojluni/src/test/java",
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleBaseByteArrayTest.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleBaseByteArrayTest.java
new file mode 100644
index 0000000..6d90d77
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleBaseByteArrayTest.java
@@ -0,0 +1,362 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+
+import java.lang.invoke.VarHandle;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.function.Function;
+
+public abstract class VarHandleBaseByteArrayTest extends VarHandleBaseTest {
+
+ enum MemoryMode {
+ ALIGNED(0, false), UNALIGNED(0, true),
+ BIG_ENDIAN(1, false), LITTLE_ENDIAN(1, true),
+ READ_WRITE(2, false), READ_ONLY(2, true),;
+
+ final int bit;
+ final int value;
+
+ MemoryMode(int bit, boolean value) {
+ this.bit = bit;
+ this.value = value ? 1 << bit : 0;
+ }
+
+ boolean isSet(int bitSet) {
+ return (bitSet & (1 << bit)) == value;
+ }
+
+ static int bitSet(MemoryMode... modes) {
+ if (modes == null) return 0;
+
+ int set = 0;
+ for (MemoryMode m : modes) {
+ set = (set & ~(1 << m.bit)) | m.value;
+ }
+ return set;
+ }
+
+ static EnumSet<MemoryMode> enumSet(int bitSet) {
+ EnumSet<MemoryMode> es = EnumSet.noneOf(MemoryMode.class);
+ for (MemoryMode m : values()) {
+ if (m.isSet(bitSet)) {
+ es.add(m);
+ }
+ }
+ return es;
+ }
+ }
+
+ static class Source<T> {
+ final T s;
+ final int memoryModes;
+
+ public Source(T s, MemoryMode... modes) {
+ this.s = s;
+ memoryModes = MemoryMode.bitSet(modes);
+ }
+
+ @Override
+ public String toString() {
+ return s.getClass().getCanonicalName() + " " + MemoryMode.enumSet(memoryModes);
+ }
+ }
+
+ static abstract class ByteArrayViewSource<T> extends Source<T> {
+ public ByteArrayViewSource(T t, MemoryMode... modes) {
+ super(t, modes);
+ }
+
+ abstract void fill(byte value);
+
+ abstract void fill(byte[] values);
+ }
+
+ static class ByteArraySource extends ByteArrayViewSource<byte[]> {
+ public ByteArraySource(byte[] bytes, MemoryMode... modes) {
+ super(bytes, modes);
+ }
+
+ void fill(byte value) {
+ Arrays.fill(s, value);
+ }
+
+ void fill(byte[] values) {
+ for (int i = 0; i < s.length; i++) {
+ s[i] = values[i % values.length];
+ }
+ }
+ }
+
+ static class ByteBufferSource extends ByteArrayViewSource<ByteBuffer> {
+ public ByteBufferSource(ByteBuffer buffer, MemoryMode... modes) {
+ super(buffer, modes);
+ }
+
+ void fill(byte value) {
+ for (int i = 0; i < s.limit(); i++) {
+ s.put(i, value);
+ }
+ }
+
+ void fill(byte[] values) {
+ for (int i = 0; i < s.limit(); i++) {
+ s.put(i, values[i % values.length]);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return s + " " + MemoryMode.enumSet(memoryModes);
+ }
+ }
+
+ static class ByteBufferReadOnlySource extends ByteBufferSource {
+ final ByteBuffer rwSource;
+
+ public ByteBufferReadOnlySource(ByteBuffer roBuffer, ByteBuffer rwSource, MemoryMode... modes) {
+ super(roBuffer, modes);
+ this.rwSource = rwSource;
+ }
+
+ void fill(byte value) {
+ for (int i = 0; i < rwSource.limit(); i++) {
+ rwSource.put(i, value);
+ }
+ }
+
+ void fill(byte[] values) {
+ for (int i = 0; i < rwSource.limit(); i++) {
+ rwSource.put(i, values[i % values.length]);
+ }
+ }
+ }
+
+ static class VarHandleSource extends Source<VarHandle> {
+ VarHandleSource(VarHandle vh, MemoryMode... modes) {
+ super(vh, modes);
+ }
+
+ boolean matches(ByteArrayViewSource<?> bav) {
+ return s.coordinateTypes().get(0).isAssignableFrom(bav.s.getClass());
+ }
+
+ @Override
+ public String toString() {
+ return " VarHandle " + MemoryMode.enumSet(memoryModes);
+ }
+ }
+
+ static class VarHandleSourceAccessTestCase extends AccessTestCase<VarHandleSource> {
+ final ByteArrayViewSource<?> bs;
+ final VarHandleSource vhs;
+
+ VarHandleSourceAccessTestCase(String desc, ByteArrayViewSource<?> bs, VarHandleSource vhs, AccessTestAction<VarHandleSource> ata) {
+ this(desc, bs, vhs, ata, true);
+ }
+
+ VarHandleSourceAccessTestCase(String desc, ByteArrayViewSource<?> bs, VarHandleSource vhs, AccessTestAction<VarHandleSource> ata, boolean loop) {
+ super(vhs + " -> " + bs + " " + desc, ata, loop);
+ this.bs = bs;
+ this.vhs = vhs;
+ }
+
+ @Override
+ VarHandleSource get() {
+ return vhs;
+ }
+ }
+
+
+ static double rotateLeft(double i, int distance) {
+ return Double.longBitsToDouble(
+ Long.rotateLeft(Double.doubleToRawLongBits(i), distance));
+ }
+
+ static double rotateRight(double i, int distance) {
+ return Double.longBitsToDouble(
+ Long.rotateRight(Double.doubleToRawLongBits(i), distance));
+ }
+
+ static float rotateLeft(float i, int distance) {
+ return Float.intBitsToFloat(
+ Integer.rotateLeft(Float.floatToRawIntBits(i), distance));
+ }
+
+ static float rotateRight(float i, int distance) {
+ return Float.intBitsToFloat(
+ Integer.rotateRight(Float.floatToRawIntBits(i), distance));
+ }
+
+ static long rotateLeft(long i, int distance) {
+ return Long.rotateLeft(i, distance);
+ }
+
+ static long rotateRight(long i, int distance) {
+ return Long.rotateRight(i, distance);
+ }
+
+ static int rotateLeft(int i, int distance) {
+ return Integer.rotateLeft(i, distance);
+ }
+
+ static int rotateRight(int i, int distance) {
+ return Integer.rotateRight(i, distance);
+ }
+
+ static short rotateLeft(short i, int distance) {
+ int v = (i << 16) | i;
+ v = Integer.rotateLeft(v, distance);
+ return (short) v;
+ }
+
+ static short rotateRight(short i, int distance) {
+ int v = (i << 16) | i;
+ v = Integer.rotateRight(v, distance);
+ return (short) v;
+ }
+
+ static char rotateLeft(char i, int distance) {
+ int v = (i << 16) | i;
+ v = Integer.rotateLeft(v, distance);
+ return (char) v;
+ }
+
+ static char rotateRight(char i, int distance) {
+ int v = (i << 16) | i;
+ v = Integer.rotateRight(v, distance);
+ return (char) v;
+ }
+
+ static final int LENGTH_BYTES = 32;
+
+ byte[] array;
+
+ List<ByteArrayViewSource<?>> bavss;
+
+ List<VarHandleSource> vhss;
+
+ public void setupByteSources() {
+ array = new byte[LENGTH_BYTES];
+
+ // Native endianess
+ MemoryMode ne = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN
+ ? MemoryMode.BIG_ENDIAN : MemoryMode.LITTLE_ENDIAN;
+
+ bavss = new ArrayList<>();
+
+ // byte[] source
+ ByteArraySource a =
+ new ByteArraySource(array,
+ ne, MemoryMode.READ_WRITE);
+ bavss.add(a);
+
+
+ // Combinations of ByteBuffer sources
+ ByteBufferSource hbb =
+ new ByteBufferSource(ByteBuffer.wrap(array),
+ MemoryMode.ALIGNED, ne, MemoryMode.READ_WRITE);
+ bavss.add(hbb);
+ ByteBufferReadOnlySource hbb_ro =
+ new ByteBufferReadOnlySource(hbb.s.asReadOnlyBuffer(), hbb.s,
+ MemoryMode.ALIGNED, ne, MemoryMode.READ_ONLY);
+ bavss.add(hbb_ro);
+
+ ByteBufferSource hbb_offset_aligned =
+ new ByteBufferSource(ByteBuffer.wrap(array, array.length / 4, array.length / 2).slice(),
+ MemoryMode.ALIGNED, ne, MemoryMode.READ_WRITE);
+ bavss.add(hbb_offset_aligned);
+ ByteBufferReadOnlySource hbb_offset_aligned_ro =
+ new ByteBufferReadOnlySource(hbb_offset_aligned.s.asReadOnlyBuffer(), hbb_offset_aligned.s,
+ MemoryMode.ALIGNED, ne, MemoryMode.READ_ONLY);
+ bavss.add(hbb_offset_aligned_ro);
+
+ ByteBufferSource hbb_offset_unaligned =
+ new ByteBufferSource(ByteBuffer.wrap(array, array.length / 4 - 1, array.length / 2).slice(),
+ MemoryMode.UNALIGNED, ne, MemoryMode.READ_WRITE);
+ bavss.add(hbb_offset_unaligned);
+ ByteBufferReadOnlySource hbb_offset_unaligned_ro =
+ new ByteBufferReadOnlySource(hbb_offset_unaligned.s.asReadOnlyBuffer(), hbb_offset_unaligned.s,
+ MemoryMode.UNALIGNED, ne, MemoryMode.READ_ONLY);
+ bavss.add(hbb_offset_unaligned_ro);
+
+
+ ByteBufferSource dbb =
+ new ByteBufferSource(ByteBuffer.allocateDirect(array.length),
+ MemoryMode.ALIGNED, ne, MemoryMode.READ_WRITE);
+ bavss.add(dbb);
+ ByteBufferReadOnlySource dbb_ro =
+ new ByteBufferReadOnlySource(dbb.s.asReadOnlyBuffer(), dbb.s,
+ MemoryMode.ALIGNED, ne, MemoryMode.READ_ONLY);
+ bavss.add(dbb_ro);
+
+ ByteBufferSource dbb_offset_aligned =
+ new ByteBufferSource(dbb.s.slice().position(array.length / 4).limit(array.length / 4 + array.length / 2).slice(),
+ MemoryMode.ALIGNED, ne, MemoryMode.READ_WRITE);
+ bavss.add(dbb_offset_aligned);
+ ByteBufferReadOnlySource dbb_offset_aligned_ro =
+ new ByteBufferReadOnlySource(dbb_offset_aligned.s.asReadOnlyBuffer(), dbb_offset_aligned.s,
+ MemoryMode.ALIGNED, ne, MemoryMode.READ_ONLY);
+ bavss.add(dbb_offset_aligned_ro);
+
+ ByteBufferSource dbb_offset_unaligned =
+ new ByteBufferSource(dbb.s.slice().position(array.length / 4 - 1).limit(array.length / 4 - 1 + array.length / 2).slice(),
+ MemoryMode.UNALIGNED, ne, MemoryMode.READ_WRITE);
+ bavss.add(dbb_offset_unaligned);
+ ByteBufferReadOnlySource dbb_offset_unaligned_ro =
+ new ByteBufferReadOnlySource(dbb_offset_unaligned.s.asReadOnlyBuffer(), dbb_offset_unaligned.s,
+ MemoryMode.UNALIGNED, ne, MemoryMode.READ_ONLY);
+ bavss.add(dbb_offset_unaligned_ro);
+ }
+
+ @BeforeClass
+ public void setup() {
+ setupByteSources();
+ setupVarHandleSources();
+ }
+
+ abstract void setupVarHandleSources();
+
+
+ @DataProvider
+ public Object[][] varHandlesProvider() throws Exception {
+ return vhss.stream().map(cvh -> new Object[]{cvh}).toArray(Object[][]::new);
+ }
+
+ @DataProvider
+ public Object[][] typesProvider() throws Exception {
+ List<java.lang.Class<?>> aepts = Arrays.asList(byte[].class, int.class);
+ List<java.lang.Class<?>> bbpts = Arrays.asList(ByteBuffer.class, int.class);
+
+ Function<VarHandle, List<Class<?>>> vhToPts = vh ->
+ vh.coordinateTypes().get(0) == byte[].class ? aepts : bbpts;
+
+ return vhss.stream().map(vh -> new Object[]{vh.s, vhToPts.apply(vh.s)}).toArray(Object[][]::new);
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleBaseTest.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleBaseTest.java
new file mode 100644
index 0000000..7792df8
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleBaseTest.java
@@ -0,0 +1,493 @@
+/*
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandleInfo;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.invoke.VarHandle;
+import java.lang.invoke.WrongMethodTypeException;
+import java.lang.reflect.Method;
+import java.nio.ReadOnlyBufferException;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import static java.util.stream.Collectors.toList;
+import static org.testng.Assert.*;
+
+abstract class VarHandleBaseTest {
+ static final int ITERS = Integer.getInteger("iters", 1);
+ static final int WEAK_ATTEMPTS = Integer.getInteger("weakAttempts", 10);
+
+ interface ThrowingRunnable {
+ void run() throws Throwable;
+ }
+
+ static void checkUOE(ThrowingRunnable r) {
+ checkWithThrowable(UnsupportedOperationException.class, null, r);
+ }
+
+ static void checkUOE(Object message, ThrowingRunnable r) {
+ checkWithThrowable(UnsupportedOperationException.class, message, r);
+ }
+
+ static void checkROBE(ThrowingRunnable r) {
+ checkWithThrowable(ReadOnlyBufferException.class, null, r);
+ }
+
+ static void checkROBE(Object message, ThrowingRunnable r) {
+ checkWithThrowable(ReadOnlyBufferException.class, message, r);
+ }
+
+ static void checkIOOBE(ThrowingRunnable r) {
+ checkWithThrowable(IndexOutOfBoundsException.class, null, r);
+ }
+
+ static void checkIOOBE(Object message, ThrowingRunnable r) {
+ checkWithThrowable(IndexOutOfBoundsException.class, message, r);
+ }
+
+ static void checkASE(ThrowingRunnable r) {
+ checkWithThrowable(ArrayStoreException.class, null, r);
+ }
+
+ static void checkASE(Object message, ThrowingRunnable r) {
+ checkWithThrowable(ArrayStoreException.class, message, r);
+ }
+
+ static void checkISE(ThrowingRunnable r) {
+ checkWithThrowable(IllegalStateException.class, null, r);
+ }
+
+ static void checkISE(Object message, ThrowingRunnable r) {
+ checkWithThrowable(IllegalStateException.class, message, r);
+ }
+
+ static void checkIAE(ThrowingRunnable r) {
+ checkWithThrowable(IllegalAccessException.class, null, r);
+ }
+
+ static void checkIAE(Object message, ThrowingRunnable r) {
+ checkWithThrowable(IllegalAccessException.class, message, r);
+ }
+
+ static void checkWMTE(ThrowingRunnable r) {
+ checkWithThrowable(WrongMethodTypeException.class, null, r);
+ }
+
+ static void checkWMTE(Object message, ThrowingRunnable r) {
+ checkWithThrowable(WrongMethodTypeException.class, message, r);
+ }
+
+ static void checkCCE(ThrowingRunnable r) {
+ checkWithThrowable(ClassCastException.class, null, r);
+ }
+
+ static void checkCCE(Object message, ThrowingRunnable r) {
+ checkWithThrowable(ClassCastException.class, message, r);
+ }
+
+ static void checkNPE(ThrowingRunnable r) {
+ checkWithThrowable(NullPointerException.class, null, r);
+ }
+
+ static void checkNPE(Object message, ThrowingRunnable r) {
+ checkWithThrowable(NullPointerException.class, message, r);
+ }
+
+ static void checkWithThrowable(Class<? extends Throwable> re,
+ Object message,
+ ThrowingRunnable r) {
+ Throwable _e = null;
+ try {
+ r.run();
+ }
+ catch (Throwable e) {
+ _e = e;
+ }
+ message = message == null ? "" : message + ". ";
+ assertNotNull(_e, String.format("%sNo throwable thrown. Expected %s", message, re));
+ assertTrue(re.isInstance(_e), String.format("%sIncorrect throwable thrown, %s. Expected %s", message, _e, re));
+ }
+
+
+ enum TestAccessType {
+ GET,
+ SET,
+ COMPARE_AND_SET,
+ COMPARE_AND_EXCHANGE,
+ GET_AND_SET,
+ GET_AND_ADD,
+ GET_AND_BITWISE;
+ }
+
+ enum TestAccessMode {
+ GET(TestAccessType.GET),
+ SET(TestAccessType.SET),
+ GET_VOLATILE(TestAccessType.GET),
+ SET_VOLATILE(TestAccessType.SET),
+ GET_ACQUIRE(TestAccessType.GET),
+ SET_RELEASE(TestAccessType.SET),
+ GET_OPAQUE(TestAccessType.GET),
+ SET_OPAQUE(TestAccessType.SET),
+ COMPARE_AND_SET(TestAccessType.COMPARE_AND_SET),
+ COMPARE_AND_EXCHANGE(TestAccessType.COMPARE_AND_EXCHANGE),
+ COMPARE_AND_EXCHANGE_ACQUIRE(TestAccessType.COMPARE_AND_EXCHANGE),
+ COMPARE_AND_EXCHANGE_RELEASE(TestAccessType.COMPARE_AND_EXCHANGE),
+ WEAK_COMPARE_AND_SET_PLAIN(TestAccessType.COMPARE_AND_SET),
+ WEAK_COMPARE_AND_SET(TestAccessType.COMPARE_AND_SET),
+ WEAK_COMPARE_AND_SET_ACQUIRE(TestAccessType.COMPARE_AND_SET),
+ WEAK_COMPARE_AND_SET_RELEASE(TestAccessType.COMPARE_AND_SET),
+ GET_AND_SET(TestAccessType.GET_AND_SET),
+ GET_AND_SET_ACQUIRE(TestAccessType.GET_AND_SET),
+ GET_AND_SET_RELEASE(TestAccessType.GET_AND_SET),
+ GET_AND_ADD(TestAccessType.GET_AND_ADD),
+ GET_AND_ADD_ACQUIRE(TestAccessType.GET_AND_ADD),
+ GET_AND_ADD_RELEASE(TestAccessType.GET_AND_ADD),
+ GET_AND_BITWISE_OR(TestAccessType.GET_AND_BITWISE),
+ GET_AND_BITWISE_OR_ACQUIRE(TestAccessType.GET_AND_BITWISE),
+ GET_AND_BITWISE_OR_RELEASE(TestAccessType.GET_AND_BITWISE),
+ GET_AND_BITWISE_AND(TestAccessType.GET_AND_BITWISE),
+ GET_AND_BITWISE_AND_ACQUIRE(TestAccessType.GET_AND_BITWISE),
+ GET_AND_BITWISE_AND_RELEASE(TestAccessType.GET_AND_BITWISE),
+ GET_AND_BITWISE_XOR(TestAccessType.GET_AND_BITWISE),
+ GET_AND_BITWISE_XOR_ACQUIRE(TestAccessType.GET_AND_BITWISE),
+ GET_AND_BITWISE_XOR_RELEASE(TestAccessType.GET_AND_BITWISE),
+ ;
+
+ final TestAccessType at;
+ final boolean isPolyMorphicInReturnType;
+ final Class<?> returnType;
+
+ TestAccessMode(TestAccessType at) {
+ this.at = at;
+
+ try {
+ VarHandle.AccessMode vh_am = toAccessMode();
+ Method m = VarHandle.class.getMethod(vh_am.methodName(), Object[].class);
+ this.returnType = m.getReturnType();
+ isPolyMorphicInReturnType = returnType != Object.class;
+ }
+ catch (Exception e) {
+ throw new Error(e);
+ }
+ }
+
+ boolean isOfType(TestAccessType at) {
+ return this.at == at;
+ }
+
+ VarHandle.AccessMode toAccessMode() {
+ return VarHandle.AccessMode.valueOf(name());
+ }
+ }
+
+ static List<TestAccessMode> testAccessModes() {
+ return Stream.of(TestAccessMode.values()).collect(toList());
+ }
+
+ static List<TestAccessMode> testAccessModesOfType(TestAccessType... ats) {
+ Stream<TestAccessMode> s = Stream.of(TestAccessMode.values());
+ return s.filter(e -> Stream.of(ats).anyMatch(e::isOfType))
+ .collect(toList());
+ }
+
+ static List<VarHandle.AccessMode> accessModes() {
+ return Stream.of(VarHandle.AccessMode.values()).collect(toList());
+ }
+
+ static List<VarHandle.AccessMode> accessModesOfType(TestAccessType... ats) {
+ Stream<TestAccessMode> s = Stream.of(TestAccessMode.values());
+ return s.filter(e -> Stream.of(ats).anyMatch(e::isOfType))
+ .map(TestAccessMode::toAccessMode)
+ .collect(toList());
+ }
+
+ static MethodHandle toMethodHandle(VarHandle vh, TestAccessMode tam, MethodType mt) {
+ return vh.toMethodHandle(tam.toAccessMode());
+ }
+
+ static MethodHandle findVirtual(VarHandle vh, TestAccessMode tam, MethodType mt) {
+ MethodHandle mh;
+ try {
+ mh = MethodHandles.publicLookup().
+ findVirtual(VarHandle.class,
+ tam.toAccessMode().methodName(),
+ mt);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return bind(vh, mh, mt);
+ }
+
+ static MethodHandle varHandleInvoker(VarHandle vh, TestAccessMode tam, MethodType mt) {
+ MethodHandle mh = MethodHandles.varHandleInvoker(
+ tam.toAccessMode(),
+ mt);
+
+ return bind(vh, mh, mt);
+ }
+
+ static MethodHandle varHandleExactInvoker(VarHandle vh, TestAccessMode tam, MethodType mt) {
+ MethodHandle mh = MethodHandles.varHandleExactInvoker(
+ tam.toAccessMode(),
+ mt);
+
+ return bind(vh, mh, mt);
+ }
+
+ private static MethodHandle bind(VarHandle vh, MethodHandle mh, MethodType emt) {
+ assertEquals(mh.type(), emt.insertParameterTypes(0, VarHandle.class),
+ "MethodHandle type differs from access mode type");
+
+ MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh);
+ assertEquals(info.getMethodType(), emt,
+ "MethodHandleInfo method type differs from access mode type");
+
+ return mh.bindTo(vh);
+ }
+
+ private interface TriFunction<T, U, V, R> {
+ R apply(T t, U u, V v);
+ }
+
+ enum VarHandleToMethodHandle {
+ VAR_HANDLE_TO_METHOD_HANDLE(
+ "VarHandle.toMethodHandle",
+ true,
+ VarHandleBaseTest::toMethodHandle),
+ METHOD_HANDLES_LOOKUP_FIND_VIRTUAL(
+ "Lookup.findVirtual",
+ false,
+ VarHandleBaseTest::findVirtual),
+ METHOD_HANDLES_VAR_HANDLE_INVOKER(
+ "MethodHandles.varHandleInvoker",
+ false,
+ VarHandleBaseTest::varHandleInvoker),
+ METHOD_HANDLES_VAR_HANDLE_EXACT_INVOKER(
+ "MethodHandles.varHandleExactInvoker",
+ true,
+ VarHandleBaseTest::varHandleExactInvoker);
+
+ final String desc;
+ final boolean isExact;
+ final TriFunction<VarHandle, TestAccessMode, MethodType, MethodHandle> f;
+
+ VarHandleToMethodHandle(String desc, boolean isExact,
+ TriFunction<VarHandle, TestAccessMode, MethodType, MethodHandle> f) {
+ this.desc = desc;
+ this.f = f;
+ this.isExact = isExact;
+ }
+
+ MethodHandle apply(VarHandle vh, TestAccessMode am, MethodType mt) {
+ return f.apply(vh, am, mt);
+ }
+
+ @Override
+ public String toString() {
+ return desc;
+ }
+ }
+
+ static class Handles {
+ static class AccessModeAndType {
+ final TestAccessMode tam;
+ final MethodType t;
+
+ public AccessModeAndType(TestAccessMode tam, MethodType t) {
+ this.tam = tam;
+ this.t = t;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ AccessModeAndType x = (AccessModeAndType) o;
+
+ if (tam != x.tam) return false;
+ if (t != null ? !t.equals(x.t) : x.t != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = tam != null ? tam.hashCode() : 0;
+ result = 31 * result + (t != null ? t.hashCode() : 0);
+ return result;
+ }
+ }
+
+ final VarHandle vh;
+ final VarHandleToMethodHandle f;
+ final EnumMap<TestAccessMode, MethodType> amToType;
+ final Map<AccessModeAndType, MethodHandle> amToHandle;
+
+ Handles(VarHandle vh, VarHandleToMethodHandle f) throws Exception {
+ this.vh = vh;
+ this.f = f;
+ this.amToHandle = new HashMap<>();
+
+ amToType = new EnumMap<>(TestAccessMode.class);
+ for (TestAccessMode am : testAccessModes()) {
+ amToType.put(am, vh.accessModeType(am.toAccessMode()));
+ }
+ }
+
+ MethodHandle get(TestAccessMode am) {
+ return get(am, amToType.get(am));
+ }
+
+ MethodHandle get(TestAccessMode am, MethodType mt) {
+ AccessModeAndType amt = new AccessModeAndType(am, mt);
+ return amToHandle.computeIfAbsent(
+ amt, k -> f.apply(vh, am, mt));
+ }
+
+ Class<? extends Throwable> getWMTEOOrOther(Class<? extends Throwable> c) {
+ return f.isExact ? WrongMethodTypeException.class : c;
+ }
+
+ void checkWMTEOrCCE(ThrowingRunnable r) {
+ checkWithThrowable(getWMTEOOrOther(ClassCastException.class), null, r);
+ }
+
+ }
+
+ interface AccessTestAction<T> {
+ void action(T t) throws Throwable;
+ }
+
+ static abstract class AccessTestCase<T> {
+ final String desc;
+ final AccessTestAction<T> ata;
+ final boolean loop;
+
+ AccessTestCase(String desc, AccessTestAction<T> ata, boolean loop) {
+ this.desc = desc;
+ this.ata = ata;
+ this.loop = loop;
+ }
+
+ boolean requiresLoop() {
+ return loop;
+ }
+
+ abstract T get() throws Exception;
+
+ void testAccess(T t) throws Throwable {
+ ata.action(t);
+ }
+
+ @Override
+ public String toString() {
+ return desc;
+ }
+ }
+
+ static class VarHandleAccessTestCase extends AccessTestCase<VarHandle> {
+ final VarHandle vh;
+
+ VarHandleAccessTestCase(String desc, VarHandle vh, AccessTestAction<VarHandle> ata) {
+ this(desc, vh, ata, true);
+ }
+
+ VarHandleAccessTestCase(String desc, VarHandle vh, AccessTestAction<VarHandle> ata, boolean loop) {
+ super("VarHandle -> " + desc, ata, loop);
+ this.vh = vh;
+ }
+
+ @Override
+ VarHandle get() {
+ return vh;
+ }
+ }
+
+ static class MethodHandleAccessTestCase extends AccessTestCase<Handles> {
+ final VarHandle vh;
+ final VarHandleToMethodHandle f;
+
+ MethodHandleAccessTestCase(String desc, VarHandle vh, VarHandleToMethodHandle f, AccessTestAction<Handles> ata) {
+ this(desc, vh, f, ata, true);
+ }
+
+ MethodHandleAccessTestCase(String desc, VarHandle vh, VarHandleToMethodHandle f, AccessTestAction<Handles> ata, boolean loop) {
+ super("VarHandle -> " + f.toString() + " -> " + desc, ata, loop);
+ this.vh = vh;
+ this.f = f;
+ }
+
+ @Override
+ Handles get() throws Exception {
+ return new Handles(vh, f);
+ }
+ }
+
+ static void testTypes(VarHandle vh) {
+ List<Class<?>> pts = vh.coordinateTypes();
+
+ for (TestAccessMode accessMode : testAccessModes()) {
+ MethodType amt = vh.accessModeType(accessMode.toAccessMode());
+
+ assertEquals(amt.parameterList().subList(0, pts.size()), pts);
+ }
+
+ for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.GET)) {
+ MethodType mt = vh.accessModeType(testAccessMode.toAccessMode());
+ assertEquals(mt.returnType(), vh.varType());
+ assertEquals(mt.parameterList(), pts);
+ }
+
+ for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.SET)) {
+ MethodType mt = vh.accessModeType(testAccessMode.toAccessMode());
+ assertEquals(mt.returnType(), void.class);
+ assertEquals(mt.parameterType(mt.parameterCount() - 1), vh.varType());
+ }
+
+ for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ MethodType mt = vh.accessModeType(testAccessMode.toAccessMode());
+ assertEquals(mt.returnType(), boolean.class);
+ assertEquals(mt.parameterType(mt.parameterCount() - 1), vh.varType());
+ assertEquals(mt.parameterType(mt.parameterCount() - 2), vh.varType());
+ }
+
+ for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ MethodType mt = vh.accessModeType(testAccessMode.toAccessMode());
+ assertEquals(mt.returnType(), vh.varType());
+ assertEquals(mt.parameterType(mt.parameterCount() - 1), vh.varType());
+ assertEquals(mt.parameterType(mt.parameterCount() - 2), vh.varType());
+ }
+
+ for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.GET_AND_SET, TestAccessType.GET_AND_ADD)) {
+ MethodType mt = vh.accessModeType(testAccessMode.toAccessMode());
+ assertEquals(mt.returnType(), vh.varType());
+ assertEquals(mt.parameterType(mt.parameterCount() - 1), vh.varType());
+ }
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleMethodReferenceTest.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleMethodReferenceTest.java
new file mode 100644
index 0000000..02de5a3
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleMethodReferenceTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8195650
+ * @summary Test linking of method references to VarHandle access methods.
+ * @run testng VarHandleMethodReferenceTest
+ */
+
+import org.testng.annotations.Test;
+
+import java.lang.invoke.*;
+
+public class VarHandleMethodReferenceTest {
+
+ interface R {
+ void apply();
+ }
+
+ @Test
+ public void testMethodReferences() {
+ VarHandle vh = MethodHandles.arrayElementVarHandle(int[].class);
+
+ // The compilation of these method references will result in the
+ // placement of MethodHandles in the constant pool that reference
+ // VarHandle signature polymorphic methods.
+ // When those constant method handles are loaded the VarHandle invoker
+ // mechanism will be used where the first argument to invocation will be
+ // the bound VarHandle instance
+
+ // VarHandle invokers are tested by other test classes so here it
+ // is just necessary to check that functional objects can be successfully
+ // obtained, it does not matter about the signature of the functional
+ // interface
+
+ R r;
+ r = vh::get;
+ r = vh::set;
+ r = vh::getVolatile;
+ r = vh::setVolatile;
+ r = vh::getOpaque;
+ r = vh::setOpaque;
+ r = vh::getAcquire;
+ r = vh::setRelease;
+
+ r = vh::compareAndSet;
+ r = vh::compareAndExchange;
+ r = vh::compareAndExchangeAcquire;
+ r = vh::compareAndExchangeRelease;
+ r = vh::weakCompareAndSetPlain;
+ r = vh::weakCompareAndSet;
+ r = vh::weakCompareAndSetAcquire;
+ r = vh::weakCompareAndSetRelease;
+
+ r = vh::getAndSet;
+ r = vh::getAndSetAcquire;
+ r = vh::getAndSetRelease;
+ r = vh::getAndAdd;
+ r = vh::getAndAddAcquire;
+ r = vh::getAndAddRelease;
+ r = vh::getAndBitwiseOr;
+ r = vh::getAndBitwiseOrAcquire;
+ r = vh::getAndBitwiseOrRelease;
+ r = vh::getAndBitwiseAnd;
+ r = vh::getAndBitwiseAndAcquire;
+ r = vh::getAndBitwiseAndRelease;
+ r = vh::getAndBitwiseXor;
+ r = vh::getAndBitwiseXorAcquire;
+ r = vh::getAndBitwiseXorRelease;
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessBoolean.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessBoolean.java
new file mode 100644
index 0000000..ea85761
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessBoolean.java
@@ -0,0 +1,1260 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessBoolean
+ * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessBoolean
+ * @run testng/othervm -Diters=20000 VarHandleTestAccessBoolean
+ * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestAccessBoolean
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestAccessBoolean extends VarHandleBaseTest {
+ static final boolean static_final_v = true;
+
+ static boolean static_v;
+
+ final boolean final_v = true;
+
+ boolean v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessBoolean.class, "final_v", boolean.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessBoolean.class, "v", boolean.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessBoolean.class, "static_final_v", boolean.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessBoolean.class, "static_v", boolean.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(boolean[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] varHandlesProvider() throws Exception {
+ List<VarHandle> vhs = new ArrayList<>();
+ vhs.add(vhField);
+ vhs.add(vhStaticField);
+ vhs.add(vhArray);
+
+ return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "varHandlesProvider")
+ public void testIsAccessModeSupported(VarHandle vh) {
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+ }
+
+
+ @DataProvider
+ public Object[][] typesProvider() throws Exception {
+ List<Object[]> types = new ArrayList<>();
+ types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessBoolean.class)});
+ types.add(new Object[] {vhStaticField, Arrays.asList()});
+ types.add(new Object[] {vhArray, Arrays.asList(boolean[].class, int.class)});
+
+ return types.stream().toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "typesProvider")
+ public void testTypes(VarHandle vh, List<Class<?>> pts) {
+ assertEquals(vh.varType(), boolean.class);
+
+ assertEquals(vh.coordinateTypes(), pts);
+
+ testTypes(vh);
+ }
+
+
+ @Test
+ public void testLookupInstanceToStatic() {
+ checkIAE("Lookup of static final field to instance final field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessBoolean.class, "final_v", boolean.class);
+ });
+
+ checkIAE("Lookup of static field to instance field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessBoolean.class, "v", boolean.class);
+ });
+ }
+
+ @Test
+ public void testLookupStaticToInstance() {
+ checkIAE("Lookup of instance final field to static final field", () -> {
+ MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessBoolean.class, "static_final_v", boolean.class);
+ });
+
+ checkIAE("Lookup of instance field to static field", () -> {
+ vhStaticField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessBoolean.class, "static_v", boolean.class);
+ });
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance final field",
+ vhFinalField, vh -> testInstanceFinalField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
+ vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static final field",
+ vhStaticFinalField, VarHandleTestAccessBoolean::testStaticFinalField));
+ cases.add(new VarHandleAccessTestCase("Static final field unsupported",
+ vhStaticFinalField, VarHandleTestAccessBoolean::testStaticFinalFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance field unsupported",
+ vhField, vh -> testInstanceFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestAccessBoolean::testStaticField));
+ cases.add(new VarHandleAccessTestCase("Static field unsupported",
+ vhStaticField, VarHandleTestAccessBoolean::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestAccessBoolean::testArray));
+ cases.add(new VarHandleAccessTestCase("Array unsupported",
+ vhArray, VarHandleTestAccessBoolean::testArrayUnsupported,
+ false));
+ cases.add(new VarHandleAccessTestCase("Array index out of bounds",
+ vhArray, VarHandleTestAccessBoolean::testArrayIndexOutOfBounds,
+ false));
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+
+
+ static void testInstanceFinalField(VarHandleTestAccessBoolean recv, VarHandle vh) {
+ // Plain
+ {
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, true, "get boolean value");
+ }
+
+
+ // Volatile
+ {
+ boolean x = (boolean) vh.getVolatile(recv);
+ assertEquals(x, true, "getVolatile boolean value");
+ }
+
+ // Lazy
+ {
+ boolean x = (boolean) vh.getAcquire(recv);
+ assertEquals(x, true, "getRelease boolean value");
+ }
+
+ // Opaque
+ {
+ boolean x = (boolean) vh.getOpaque(recv);
+ assertEquals(x, true, "getOpaque boolean value");
+ }
+ }
+
+ static void testInstanceFinalFieldUnsupported(VarHandleTestAccessBoolean recv, VarHandle vh) {
+ checkUOE(() -> {
+ vh.set(recv, false);
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile(recv, false);
+ });
+
+ checkUOE(() -> {
+ vh.setRelease(recv, false);
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque(recv, false);
+ });
+
+
+ checkUOE(() -> {
+ boolean o = (boolean) vh.getAndAdd(recv, true);
+ });
+
+ checkUOE(() -> {
+ boolean o = (boolean) vh.getAndAddAcquire(recv, true);
+ });
+
+ checkUOE(() -> {
+ boolean o = (boolean) vh.getAndAddRelease(recv, true);
+ });
+
+ }
+
+
+ static void testStaticFinalField(VarHandle vh) {
+ // Plain
+ {
+ boolean x = (boolean) vh.get();
+ assertEquals(x, true, "get boolean value");
+ }
+
+
+ // Volatile
+ {
+ boolean x = (boolean) vh.getVolatile();
+ assertEquals(x, true, "getVolatile boolean value");
+ }
+
+ // Lazy
+ {
+ boolean x = (boolean) vh.getAcquire();
+ assertEquals(x, true, "getRelease boolean value");
+ }
+
+ // Opaque
+ {
+ boolean x = (boolean) vh.getOpaque();
+ assertEquals(x, true, "getOpaque boolean value");
+ }
+ }
+
+ static void testStaticFinalFieldUnsupported(VarHandle vh) {
+ checkUOE(() -> {
+ vh.set(false);
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile(false);
+ });
+
+ checkUOE(() -> {
+ vh.setRelease(false);
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque(false);
+ });
+
+
+ checkUOE(() -> {
+ boolean o = (boolean) vh.getAndAdd(true);
+ });
+
+ checkUOE(() -> {
+ boolean o = (boolean) vh.getAndAddAcquire(true);
+ });
+
+ checkUOE(() -> {
+ boolean o = (boolean) vh.getAndAddRelease(true);
+ });
+
+ }
+
+
+ static void testInstanceField(VarHandleTestAccessBoolean recv, VarHandle vh) {
+ // Plain
+ {
+ vh.set(recv, true);
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, true, "set boolean value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(recv, false);
+ boolean x = (boolean) vh.getVolatile(recv);
+ assertEquals(x, false, "setVolatile boolean value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(recv, true);
+ boolean x = (boolean) vh.getAcquire(recv);
+ assertEquals(x, true, "setRelease boolean value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(recv, false);
+ boolean x = (boolean) vh.getOpaque(recv);
+ assertEquals(x, false, "setOpaque boolean value");
+ }
+
+ vh.set(recv, true);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(recv, true, false);
+ assertEquals(r, true, "success compareAndSet boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, false, "success compareAndSet boolean value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(recv, true, false);
+ assertEquals(r, false, "failing compareAndSet boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, false, "failing compareAndSet boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchange(recv, false, true);
+ assertEquals(r, false, "success compareAndExchange boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, true, "success compareAndExchange boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchange(recv, false, false);
+ assertEquals(r, true, "failing compareAndExchange boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, true, "failing compareAndExchange boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchangeAcquire(recv, true, false);
+ assertEquals(r, true, "success compareAndExchangeAcquire boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchangeAcquire(recv, true, false);
+ assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchangeRelease(recv, false, true);
+ assertEquals(r, false, "success compareAndExchangeRelease boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, true, "success compareAndExchangeRelease boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchangeRelease(recv, false, false);
+ assertEquals(r, true, "failing compareAndExchangeRelease boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(recv, true, false);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, false, "weakCompareAndSetPlain boolean value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(recv, false, true);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, true, "weakCompareAndSetAcquire boolean");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(recv, true, false);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, false, "weakCompareAndSetRelease boolean");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(recv, false, true);
+ }
+ assertEquals(success, true, "weakCompareAndSet boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, true, "weakCompareAndSet boolean value");
+ }
+
+ // Compare set and get
+ {
+ vh.set(recv, true);
+
+ boolean o = (boolean) vh.getAndSet(recv, false);
+ assertEquals(o, true, "getAndSet boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, false, "getAndSet boolean value");
+ }
+
+ {
+ vh.set(recv, true);
+
+ boolean o = (boolean) vh.getAndSetAcquire(recv, false);
+ assertEquals(o, true, "getAndSetAcquire boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, false, "getAndSetAcquire boolean value");
+ }
+
+ {
+ vh.set(recv, true);
+
+ boolean o = (boolean) vh.getAndSetRelease(recv, false);
+ assertEquals(o, true, "getAndSetRelease boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, false, "getAndSetRelease boolean value");
+ }
+
+
+ // get and bitwise or
+ {
+ vh.set(recv, true);
+
+ boolean o = (boolean) vh.getAndBitwiseOr(recv, false);
+ assertEquals(o, true, "getAndBitwiseOr boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOr boolean value");
+ }
+
+ {
+ vh.set(recv, true);
+
+ boolean o = (boolean) vh.getAndBitwiseOrAcquire(recv, false);
+ assertEquals(o, true, "getAndBitwiseOrAcquire boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOrAcquire boolean value");
+ }
+
+ {
+ vh.set(recv, true);
+
+ boolean o = (boolean) vh.getAndBitwiseOrRelease(recv, false);
+ assertEquals(o, true, "getAndBitwiseOrRelease boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOrRelease boolean value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(recv, true);
+
+ boolean o = (boolean) vh.getAndBitwiseAnd(recv, false);
+ assertEquals(o, true, "getAndBitwiseAnd boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAnd boolean value");
+ }
+
+ {
+ vh.set(recv, true);
+
+ boolean o = (boolean) vh.getAndBitwiseAndAcquire(recv, false);
+ assertEquals(o, true, "getAndBitwiseAndAcquire boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAndAcquire boolean value");
+ }
+
+ {
+ vh.set(recv, true);
+
+ boolean o = (boolean) vh.getAndBitwiseAndRelease(recv, false);
+ assertEquals(o, true, "getAndBitwiseAndRelease boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAndRelease boolean value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(recv, true);
+
+ boolean o = (boolean) vh.getAndBitwiseXor(recv, false);
+ assertEquals(o, true, "getAndBitwiseXor boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXor boolean value");
+ }
+
+ {
+ vh.set(recv, true);
+
+ boolean o = (boolean) vh.getAndBitwiseXorAcquire(recv, false);
+ assertEquals(o, true, "getAndBitwiseXorAcquire boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorAcquire boolean value");
+ }
+
+ {
+ vh.set(recv, true);
+
+ boolean o = (boolean) vh.getAndBitwiseXorRelease(recv, false);
+ assertEquals(o, true, "getAndBitwiseXorRelease boolean");
+ boolean x = (boolean) vh.get(recv);
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorRelease boolean value");
+ }
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestAccessBoolean recv, VarHandle vh) {
+
+ checkUOE(() -> {
+ boolean o = (boolean) vh.getAndAdd(recv, true);
+ });
+
+ checkUOE(() -> {
+ boolean o = (boolean) vh.getAndAddAcquire(recv, true);
+ });
+
+ checkUOE(() -> {
+ boolean o = (boolean) vh.getAndAddRelease(recv, true);
+ });
+
+ }
+
+
+ static void testStaticField(VarHandle vh) {
+ // Plain
+ {
+ vh.set(true);
+ boolean x = (boolean) vh.get();
+ assertEquals(x, true, "set boolean value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(false);
+ boolean x = (boolean) vh.getVolatile();
+ assertEquals(x, false, "setVolatile boolean value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(true);
+ boolean x = (boolean) vh.getAcquire();
+ assertEquals(x, true, "setRelease boolean value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(false);
+ boolean x = (boolean) vh.getOpaque();
+ assertEquals(x, false, "setOpaque boolean value");
+ }
+
+ vh.set(true);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(true, false);
+ assertEquals(r, true, "success compareAndSet boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, false, "success compareAndSet boolean value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(true, false);
+ assertEquals(r, false, "failing compareAndSet boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, false, "failing compareAndSet boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchange(false, true);
+ assertEquals(r, false, "success compareAndExchange boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, true, "success compareAndExchange boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchange(false, false);
+ assertEquals(r, true, "failing compareAndExchange boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, true, "failing compareAndExchange boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchangeAcquire(true, false);
+ assertEquals(r, true, "success compareAndExchangeAcquire boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchangeAcquire(true, false);
+ assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchangeRelease(false, true);
+ assertEquals(r, false, "success compareAndExchangeRelease boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, true, "success compareAndExchangeRelease boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchangeRelease(false, false);
+ assertEquals(r, true, "failing compareAndExchangeRelease boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(true, false);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, false, "weakCompareAndSetPlain boolean value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(false, true);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, true, "weakCompareAndSetAcquire boolean");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(true, false);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, false, "weakCompareAndSetRelease boolean");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(false, true);
+ }
+ assertEquals(success, true, "weakCompareAndSet boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, true, "weakCompareAndSet boolean");
+ }
+
+ // Compare set and get
+ {
+ vh.set(true);
+
+ boolean o = (boolean) vh.getAndSet(false);
+ assertEquals(o, true, "getAndSet boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, false, "getAndSet boolean value");
+ }
+
+ {
+ vh.set(true);
+
+ boolean o = (boolean) vh.getAndSetAcquire(false);
+ assertEquals(o, true, "getAndSetAcquire boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, false, "getAndSetAcquire boolean value");
+ }
+
+ {
+ vh.set(true);
+
+ boolean o = (boolean) vh.getAndSetRelease(false);
+ assertEquals(o, true, "getAndSetRelease boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, false, "getAndSetRelease boolean value");
+ }
+
+
+ // get and bitwise or
+ {
+ vh.set(true);
+
+ boolean o = (boolean) vh.getAndBitwiseOr(false);
+ assertEquals(o, true, "getAndBitwiseOr boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOr boolean value");
+ }
+
+ {
+ vh.set(true);
+
+ boolean o = (boolean) vh.getAndBitwiseOrAcquire(false);
+ assertEquals(o, true, "getAndBitwiseOrAcquire boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOrAcquire boolean value");
+ }
+
+ {
+ vh.set(true);
+
+ boolean o = (boolean) vh.getAndBitwiseOrRelease(false);
+ assertEquals(o, true, "getAndBitwiseOrRelease boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOrRelease boolean value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(true);
+
+ boolean o = (boolean) vh.getAndBitwiseAnd(false);
+ assertEquals(o, true, "getAndBitwiseAnd boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAnd boolean value");
+ }
+
+ {
+ vh.set(true);
+
+ boolean o = (boolean) vh.getAndBitwiseAndAcquire(false);
+ assertEquals(o, true, "getAndBitwiseAndAcquire boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAndAcquire boolean value");
+ }
+
+ {
+ vh.set(true);
+
+ boolean o = (boolean) vh.getAndBitwiseAndRelease(false);
+ assertEquals(o, true, "getAndBitwiseAndRelease boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAndRelease boolean value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(true);
+
+ boolean o = (boolean) vh.getAndBitwiseXor(false);
+ assertEquals(o, true, "getAndBitwiseXor boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXor boolean value");
+ }
+
+ {
+ vh.set(true);
+
+ boolean o = (boolean) vh.getAndBitwiseXorAcquire(false);
+ assertEquals(o, true, "getAndBitwiseXorAcquire boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorAcquire boolean value");
+ }
+
+ {
+ vh.set(true);
+
+ boolean o = (boolean) vh.getAndBitwiseXorRelease(false);
+ assertEquals(o, true, "getAndBitwiseXorRelease boolean");
+ boolean x = (boolean) vh.get();
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorRelease boolean value");
+ }
+ }
+
+ static void testStaticFieldUnsupported(VarHandle vh) {
+
+ checkUOE(() -> {
+ boolean o = (boolean) vh.getAndAdd(true);
+ });
+
+ checkUOE(() -> {
+ boolean o = (boolean) vh.getAndAddAcquire(true);
+ });
+
+ checkUOE(() -> {
+ boolean o = (boolean) vh.getAndAddRelease(true);
+ });
+
+ }
+
+
+ static void testArray(VarHandle vh) {
+ boolean[] array = new boolean[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ vh.set(array, i, true);
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, true, "get boolean value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(array, i, false);
+ boolean x = (boolean) vh.getVolatile(array, i);
+ assertEquals(x, false, "setVolatile boolean value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, true);
+ boolean x = (boolean) vh.getAcquire(array, i);
+ assertEquals(x, true, "setRelease boolean value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, false);
+ boolean x = (boolean) vh.getOpaque(array, i);
+ assertEquals(x, false, "setOpaque boolean value");
+ }
+
+ vh.set(array, i, true);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, true, false);
+ assertEquals(r, true, "success compareAndSet boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, false, "success compareAndSet boolean value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, true, false);
+ assertEquals(r, false, "failing compareAndSet boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, false, "failing compareAndSet boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchange(array, i, false, true);
+ assertEquals(r, false, "success compareAndExchange boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, true, "success compareAndExchange boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchange(array, i, false, false);
+ assertEquals(r, true, "failing compareAndExchange boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, true, "failing compareAndExchange boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchangeAcquire(array, i, true, false);
+ assertEquals(r, true, "success compareAndExchangeAcquire boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchangeAcquire(array, i, true, false);
+ assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchangeRelease(array, i, false, true);
+ assertEquals(r, false, "success compareAndExchangeRelease boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, true, "success compareAndExchangeRelease boolean value");
+ }
+
+ {
+ boolean r = (boolean) vh.compareAndExchangeRelease(array, i, false, false);
+ assertEquals(r, true, "failing compareAndExchangeRelease boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, true, false);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, false, "weakCompareAndSetPlain boolean value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, false, true);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, true, "weakCompareAndSetAcquire boolean");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, true, false);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, false, "weakCompareAndSetRelease boolean");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, false, true);
+ }
+ assertEquals(success, true, "weakCompareAndSet boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, true, "weakCompareAndSet boolean");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, true);
+
+ boolean o = (boolean) vh.getAndSet(array, i, false);
+ assertEquals(o, true, "getAndSet boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, false, "getAndSet boolean value");
+ }
+
+ {
+ vh.set(array, i, true);
+
+ boolean o = (boolean) vh.getAndSetAcquire(array, i, false);
+ assertEquals(o, true, "getAndSetAcquire boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, false, "getAndSetAcquire boolean value");
+ }
+
+ {
+ vh.set(array, i, true);
+
+ boolean o = (boolean) vh.getAndSetRelease(array, i, false);
+ assertEquals(o, true, "getAndSetRelease boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, false, "getAndSetRelease boolean value");
+ }
+
+
+ // get and bitwise or
+ {
+ vh.set(array, i, true);
+
+ boolean o = (boolean) vh.getAndBitwiseOr(array, i, false);
+ assertEquals(o, true, "getAndBitwiseOr boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOr boolean value");
+ }
+
+ {
+ vh.set(array, i, true);
+
+ boolean o = (boolean) vh.getAndBitwiseOrAcquire(array, i, false);
+ assertEquals(o, true, "getAndBitwiseOrAcquire boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOrAcquire boolean value");
+ }
+
+ {
+ vh.set(array, i, true);
+
+ boolean o = (boolean) vh.getAndBitwiseOrRelease(array, i, false);
+ assertEquals(o, true, "getAndBitwiseOrRelease boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOrRelease boolean value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(array, i, true);
+
+ boolean o = (boolean) vh.getAndBitwiseAnd(array, i, false);
+ assertEquals(o, true, "getAndBitwiseAnd boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAnd boolean value");
+ }
+
+ {
+ vh.set(array, i, true);
+
+ boolean o = (boolean) vh.getAndBitwiseAndAcquire(array, i, false);
+ assertEquals(o, true, "getAndBitwiseAndAcquire boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAndAcquire boolean value");
+ }
+
+ {
+ vh.set(array, i, true);
+
+ boolean o = (boolean) vh.getAndBitwiseAndRelease(array, i, false);
+ assertEquals(o, true, "getAndBitwiseAndRelease boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAndRelease boolean value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(array, i, true);
+
+ boolean o = (boolean) vh.getAndBitwiseXor(array, i, false);
+ assertEquals(o, true, "getAndBitwiseXor boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXor boolean value");
+ }
+
+ {
+ vh.set(array, i, true);
+
+ boolean o = (boolean) vh.getAndBitwiseXorAcquire(array, i, false);
+ assertEquals(o, true, "getAndBitwiseXorAcquire boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorAcquire boolean value");
+ }
+
+ {
+ vh.set(array, i, true);
+
+ boolean o = (boolean) vh.getAndBitwiseXorRelease(array, i, false);
+ assertEquals(o, true, "getAndBitwiseXorRelease boolean");
+ boolean x = (boolean) vh.get(array, i);
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorRelease boolean value");
+ }
+ }
+ }
+
+ static void testArrayUnsupported(VarHandle vh) {
+ boolean[] array = new boolean[10];
+
+ int i = 0;
+
+ checkUOE(() -> {
+ boolean o = (boolean) vh.getAndAdd(array, i, true);
+ });
+
+ checkUOE(() -> {
+ boolean o = (boolean) vh.getAndAddAcquire(array, i, true);
+ });
+
+ checkUOE(() -> {
+ boolean o = (boolean) vh.getAndAddRelease(array, i, true);
+ });
+
+ }
+
+ static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
+ boolean[] array = new boolean[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ boolean x = (boolean) vh.get(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.set(array, ci, true);
+ });
+
+ checkIOOBE(() -> {
+ boolean x = (boolean) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, true);
+ });
+
+ checkIOOBE(() -> {
+ boolean x = (boolean) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, true);
+ });
+
+ checkIOOBE(() -> {
+ boolean x = (boolean) vh.getOpaque(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, true);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, true, false);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = (boolean) vh.compareAndExchange(array, ci, false, true);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = (boolean) vh.compareAndExchangeAcquire(array, ci, false, true);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = (boolean) vh.compareAndExchangeRelease(array, ci, false, true);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, true, false);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, true, false);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, true, false);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, true, false);
+ });
+
+ checkIOOBE(() -> {
+ boolean o = (boolean) vh.getAndSet(array, ci, true);
+ });
+
+ checkIOOBE(() -> {
+ boolean o = (boolean) vh.getAndSetAcquire(array, ci, true);
+ });
+
+ checkIOOBE(() -> {
+ boolean o = (boolean) vh.getAndSetRelease(array, ci, true);
+ });
+
+
+ checkIOOBE(() -> {
+ boolean o = (boolean) vh.getAndBitwiseOr(array, ci, true);
+ });
+
+ checkIOOBE(() -> {
+ boolean o = (boolean) vh.getAndBitwiseOrAcquire(array, ci, true);
+ });
+
+ checkIOOBE(() -> {
+ boolean o = (boolean) vh.getAndBitwiseOrRelease(array, ci, true);
+ });
+
+ checkIOOBE(() -> {
+ boolean o = (boolean) vh.getAndBitwiseAnd(array, ci, true);
+ });
+
+ checkIOOBE(() -> {
+ boolean o = (boolean) vh.getAndBitwiseAndAcquire(array, ci, true);
+ });
+
+ checkIOOBE(() -> {
+ boolean o = (boolean) vh.getAndBitwiseAndRelease(array, ci, true);
+ });
+
+ checkIOOBE(() -> {
+ boolean o = (boolean) vh.getAndBitwiseXor(array, ci, true);
+ });
+
+ checkIOOBE(() -> {
+ boolean o = (boolean) vh.getAndBitwiseXorAcquire(array, ci, true);
+ });
+
+ checkIOOBE(() -> {
+ boolean o = (boolean) vh.getAndBitwiseXorRelease(array, ci, true);
+ });
+ }
+ }
+
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessByte.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessByte.java
new file mode 100644
index 0000000..033451a
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessByte.java
@@ -0,0 +1,1297 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessByte
+ * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessByte
+ * @run testng/othervm -Diters=20000 VarHandleTestAccessByte
+ * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestAccessByte
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestAccessByte extends VarHandleBaseTest {
+ static final byte static_final_v = (byte)0x01;
+
+ static byte static_v;
+
+ final byte final_v = (byte)0x01;
+
+ byte v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessByte.class, "final_v", byte.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessByte.class, "v", byte.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessByte.class, "static_final_v", byte.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessByte.class, "static_v", byte.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(byte[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] varHandlesProvider() throws Exception {
+ List<VarHandle> vhs = new ArrayList<>();
+ vhs.add(vhField);
+ vhs.add(vhStaticField);
+ vhs.add(vhArray);
+
+ return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "varHandlesProvider")
+ public void testIsAccessModeSupported(VarHandle vh) {
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+ }
+
+
+ @DataProvider
+ public Object[][] typesProvider() throws Exception {
+ List<Object[]> types = new ArrayList<>();
+ types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessByte.class)});
+ types.add(new Object[] {vhStaticField, Arrays.asList()});
+ types.add(new Object[] {vhArray, Arrays.asList(byte[].class, int.class)});
+
+ return types.stream().toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "typesProvider")
+ public void testTypes(VarHandle vh, List<Class<?>> pts) {
+ assertEquals(vh.varType(), byte.class);
+
+ assertEquals(vh.coordinateTypes(), pts);
+
+ testTypes(vh);
+ }
+
+
+ @Test
+ public void testLookupInstanceToStatic() {
+ checkIAE("Lookup of static final field to instance final field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessByte.class, "final_v", byte.class);
+ });
+
+ checkIAE("Lookup of static field to instance field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessByte.class, "v", byte.class);
+ });
+ }
+
+ @Test
+ public void testLookupStaticToInstance() {
+ checkIAE("Lookup of instance final field to static final field", () -> {
+ MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessByte.class, "static_final_v", byte.class);
+ });
+
+ checkIAE("Lookup of instance field to static field", () -> {
+ vhStaticField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessByte.class, "static_v", byte.class);
+ });
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance final field",
+ vhFinalField, vh -> testInstanceFinalField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
+ vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static final field",
+ vhStaticFinalField, VarHandleTestAccessByte::testStaticFinalField));
+ cases.add(new VarHandleAccessTestCase("Static final field unsupported",
+ vhStaticFinalField, VarHandleTestAccessByte::testStaticFinalFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance field unsupported",
+ vhField, vh -> testInstanceFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestAccessByte::testStaticField));
+ cases.add(new VarHandleAccessTestCase("Static field unsupported",
+ vhStaticField, VarHandleTestAccessByte::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestAccessByte::testArray));
+ cases.add(new VarHandleAccessTestCase("Array unsupported",
+ vhArray, VarHandleTestAccessByte::testArrayUnsupported,
+ false));
+ cases.add(new VarHandleAccessTestCase("Array index out of bounds",
+ vhArray, VarHandleTestAccessByte::testArrayIndexOutOfBounds,
+ false));
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+
+
+ static void testInstanceFinalField(VarHandleTestAccessByte recv, VarHandle vh) {
+ // Plain
+ {
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x01, "get byte value");
+ }
+
+
+ // Volatile
+ {
+ byte x = (byte) vh.getVolatile(recv);
+ assertEquals(x, (byte)0x01, "getVolatile byte value");
+ }
+
+ // Lazy
+ {
+ byte x = (byte) vh.getAcquire(recv);
+ assertEquals(x, (byte)0x01, "getRelease byte value");
+ }
+
+ // Opaque
+ {
+ byte x = (byte) vh.getOpaque(recv);
+ assertEquals(x, (byte)0x01, "getOpaque byte value");
+ }
+ }
+
+ static void testInstanceFinalFieldUnsupported(VarHandleTestAccessByte recv, VarHandle vh) {
+ checkUOE(() -> {
+ vh.set(recv, (byte)0x23);
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile(recv, (byte)0x23);
+ });
+
+ checkUOE(() -> {
+ vh.setRelease(recv, (byte)0x23);
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque(recv, (byte)0x23);
+ });
+
+
+
+ }
+
+
+ static void testStaticFinalField(VarHandle vh) {
+ // Plain
+ {
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)0x01, "get byte value");
+ }
+
+
+ // Volatile
+ {
+ byte x = (byte) vh.getVolatile();
+ assertEquals(x, (byte)0x01, "getVolatile byte value");
+ }
+
+ // Lazy
+ {
+ byte x = (byte) vh.getAcquire();
+ assertEquals(x, (byte)0x01, "getRelease byte value");
+ }
+
+ // Opaque
+ {
+ byte x = (byte) vh.getOpaque();
+ assertEquals(x, (byte)0x01, "getOpaque byte value");
+ }
+ }
+
+ static void testStaticFinalFieldUnsupported(VarHandle vh) {
+ checkUOE(() -> {
+ vh.set((byte)0x23);
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile((byte)0x23);
+ });
+
+ checkUOE(() -> {
+ vh.setRelease((byte)0x23);
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque((byte)0x23);
+ });
+
+
+
+ }
+
+
+ static void testInstanceField(VarHandleTestAccessByte recv, VarHandle vh) {
+ // Plain
+ {
+ vh.set(recv, (byte)0x01);
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x01, "set byte value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(recv, (byte)0x23);
+ byte x = (byte) vh.getVolatile(recv);
+ assertEquals(x, (byte)0x23, "setVolatile byte value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(recv, (byte)0x01);
+ byte x = (byte) vh.getAcquire(recv);
+ assertEquals(x, (byte)0x01, "setRelease byte value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(recv, (byte)0x23);
+ byte x = (byte) vh.getOpaque(recv);
+ assertEquals(x, (byte)0x23, "setOpaque byte value");
+ }
+
+ vh.set(recv, (byte)0x01);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(recv, (byte)0x01, (byte)0x23);
+ assertEquals(r, true, "success compareAndSet byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x23, "success compareAndSet byte value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(recv, (byte)0x01, (byte)0x45);
+ assertEquals(r, false, "failing compareAndSet byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchange(recv, (byte)0x23, (byte)0x01);
+ assertEquals(r, (byte)0x23, "success compareAndExchange byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x01, "success compareAndExchange byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchange(recv, (byte)0x23, (byte)0x45);
+ assertEquals(r, (byte)0x01, "failing compareAndExchange byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x01, "failing compareAndExchange byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchangeAcquire(recv, (byte)0x01, (byte)0x23);
+ assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchangeAcquire(recv, (byte)0x01, (byte)0x45);
+ assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchangeRelease(recv, (byte)0x23, (byte)0x01);
+ assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchangeRelease(recv, (byte)0x23, (byte)0x45);
+ assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(recv, (byte)0x01, (byte)0x23);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x23, "weakCompareAndSetPlain byte value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(recv, (byte)0x23, (byte)0x01);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(recv, (byte)0x01, (byte)0x23);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(recv, (byte)0x23, (byte)0x01);
+ }
+ assertEquals(success, true, "weakCompareAndSet byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x01, "weakCompareAndSet byte value");
+ }
+
+ // Compare set and get
+ {
+ vh.set(recv, (byte)0x01);
+
+ byte o = (byte) vh.getAndSet(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndSet byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x23, "getAndSet byte value");
+ }
+
+ {
+ vh.set(recv, (byte)0x01);
+
+ byte o = (byte) vh.getAndSetAcquire(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndSetAcquire byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x23, "getAndSetAcquire byte value");
+ }
+
+ {
+ vh.set(recv, (byte)0x01);
+
+ byte o = (byte) vh.getAndSetRelease(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndSetRelease byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)0x23, "getAndSetRelease byte value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(recv, (byte)0x01);
+
+ byte o = (byte) vh.getAndAdd(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAdd byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value");
+ }
+
+ {
+ vh.set(recv, (byte)0x01);
+
+ byte o = (byte) vh.getAndAddAcquire(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAddAcquire byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value");
+ }
+
+ {
+ vh.set(recv, (byte)0x01);
+
+ byte o = (byte) vh.getAndAddRelease(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAddReleasebyte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set(recv, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseOr(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOr byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value");
+ }
+
+ {
+ vh.set(recv, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseOrAcquire(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value");
+ }
+
+ {
+ vh.set(recv, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseOrRelease(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(recv, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseAnd(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value");
+ }
+
+ {
+ vh.set(recv, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseAndAcquire(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value");
+ }
+
+ {
+ vh.set(recv, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseAndRelease(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(recv, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseXor(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXor byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value");
+ }
+
+ {
+ vh.set(recv, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseXorAcquire(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value");
+ }
+
+ {
+ vh.set(recv, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseXorRelease(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte");
+ byte x = (byte) vh.get(recv);
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value");
+ }
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestAccessByte recv, VarHandle vh) {
+
+
+ }
+
+
+ static void testStaticField(VarHandle vh) {
+ // Plain
+ {
+ vh.set((byte)0x01);
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)0x01, "set byte value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile((byte)0x23);
+ byte x = (byte) vh.getVolatile();
+ assertEquals(x, (byte)0x23, "setVolatile byte value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease((byte)0x01);
+ byte x = (byte) vh.getAcquire();
+ assertEquals(x, (byte)0x01, "setRelease byte value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque((byte)0x23);
+ byte x = (byte) vh.getOpaque();
+ assertEquals(x, (byte)0x23, "setOpaque byte value");
+ }
+
+ vh.set((byte)0x01);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet((byte)0x01, (byte)0x23);
+ assertEquals(r, true, "success compareAndSet byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)0x23, "success compareAndSet byte value");
+ }
+
+ {
+ boolean r = vh.compareAndSet((byte)0x01, (byte)0x45);
+ assertEquals(r, false, "failing compareAndSet byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchange((byte)0x23, (byte)0x01);
+ assertEquals(r, (byte)0x23, "success compareAndExchange byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)0x01, "success compareAndExchange byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchange((byte)0x23, (byte)0x45);
+ assertEquals(r, (byte)0x01, "failing compareAndExchange byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)0x01, "failing compareAndExchange byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchangeAcquire((byte)0x01, (byte)0x23);
+ assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchangeAcquire((byte)0x01, (byte)0x45);
+ assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchangeRelease((byte)0x23, (byte)0x01);
+ assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchangeRelease((byte)0x23, (byte)0x45);
+ assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain((byte)0x01, (byte)0x23);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)0x23, "weakCompareAndSetPlain byte value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire((byte)0x23, (byte)0x01);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease((byte)0x01, (byte)0x23);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet((byte)0x23, (byte)0x01);
+ }
+ assertEquals(success, true, "weakCompareAndSet byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)0x01, "weakCompareAndSet byte");
+ }
+
+ // Compare set and get
+ {
+ vh.set((byte)0x01);
+
+ byte o = (byte) vh.getAndSet((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndSet byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)0x23, "getAndSet byte value");
+ }
+
+ {
+ vh.set((byte)0x01);
+
+ byte o = (byte) vh.getAndSetAcquire((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndSetAcquire byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)0x23, "getAndSetAcquire byte value");
+ }
+
+ {
+ vh.set((byte)0x01);
+
+ byte o = (byte) vh.getAndSetRelease((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndSetRelease byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)0x23, "getAndSetRelease byte value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set((byte)0x01);
+
+ byte o = (byte) vh.getAndAdd((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAdd byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value");
+ }
+
+ {
+ vh.set((byte)0x01);
+
+ byte o = (byte) vh.getAndAddAcquire((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAddAcquire byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value");
+ }
+
+ {
+ vh.set((byte)0x01);
+
+ byte o = (byte) vh.getAndAddRelease((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAddReleasebyte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set((byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseOr((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOr byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value");
+ }
+
+ {
+ vh.set((byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseOrAcquire((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value");
+ }
+
+ {
+ vh.set((byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseOrRelease((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set((byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseAnd((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value");
+ }
+
+ {
+ vh.set((byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseAndAcquire((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value");
+ }
+
+ {
+ vh.set((byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseAndRelease((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set((byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseXor((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXor byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value");
+ }
+
+ {
+ vh.set((byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseXorAcquire((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value");
+ }
+
+ {
+ vh.set((byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseXorRelease((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte");
+ byte x = (byte) vh.get();
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value");
+ }
+ }
+
+ static void testStaticFieldUnsupported(VarHandle vh) {
+
+
+ }
+
+
+ static void testArray(VarHandle vh) {
+ byte[] array = new byte[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ vh.set(array, i, (byte)0x01);
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)0x01, "get byte value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(array, i, (byte)0x23);
+ byte x = (byte) vh.getVolatile(array, i);
+ assertEquals(x, (byte)0x23, "setVolatile byte value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, (byte)0x01);
+ byte x = (byte) vh.getAcquire(array, i);
+ assertEquals(x, (byte)0x01, "setRelease byte value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, (byte)0x23);
+ byte x = (byte) vh.getOpaque(array, i);
+ assertEquals(x, (byte)0x23, "setOpaque byte value");
+ }
+
+ vh.set(array, i, (byte)0x01);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, (byte)0x01, (byte)0x23);
+ assertEquals(r, true, "success compareAndSet byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)0x23, "success compareAndSet byte value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, (byte)0x01, (byte)0x45);
+ assertEquals(r, false, "failing compareAndSet byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchange(array, i, (byte)0x23, (byte)0x01);
+ assertEquals(r, (byte)0x23, "success compareAndExchange byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)0x01, "success compareAndExchange byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchange(array, i, (byte)0x23, (byte)0x45);
+ assertEquals(r, (byte)0x01, "failing compareAndExchange byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)0x01, "failing compareAndExchange byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchangeAcquire(array, i, (byte)0x01, (byte)0x23);
+ assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchangeAcquire(array, i, (byte)0x01, (byte)0x45);
+ assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchangeRelease(array, i, (byte)0x23, (byte)0x01);
+ assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
+ }
+
+ {
+ byte r = (byte) vh.compareAndExchangeRelease(array, i, (byte)0x23, (byte)0x45);
+ assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, (byte)0x01, (byte)0x23);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)0x23, "weakCompareAndSetPlain byte value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, (byte)0x23, (byte)0x01);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, (byte)0x01, (byte)0x23);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, (byte)0x23, (byte)0x01);
+ }
+ assertEquals(success, true, "weakCompareAndSet byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)0x01, "weakCompareAndSet byte");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, (byte)0x01);
+
+ byte o = (byte) vh.getAndSet(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndSet byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)0x23, "getAndSet byte value");
+ }
+
+ {
+ vh.set(array, i, (byte)0x01);
+
+ byte o = (byte) vh.getAndSetAcquire(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndSetAcquire byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)0x23, "getAndSetAcquire byte value");
+ }
+
+ {
+ vh.set(array, i, (byte)0x01);
+
+ byte o = (byte) vh.getAndSetRelease(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndSetRelease byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)0x23, "getAndSetRelease byte value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(array, i, (byte)0x01);
+
+ byte o = (byte) vh.getAndAdd(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAdd byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value");
+ }
+
+ {
+ vh.set(array, i, (byte)0x01);
+
+ byte o = (byte) vh.getAndAddAcquire(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAddAcquire byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value");
+ }
+
+ {
+ vh.set(array, i, (byte)0x01);
+
+ byte o = (byte) vh.getAndAddRelease(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAddReleasebyte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set(array, i, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseOr(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOr byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value");
+ }
+
+ {
+ vh.set(array, i, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseOrAcquire(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value");
+ }
+
+ {
+ vh.set(array, i, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseOrRelease(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(array, i, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseAnd(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value");
+ }
+
+ {
+ vh.set(array, i, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseAndAcquire(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value");
+ }
+
+ {
+ vh.set(array, i, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseAndRelease(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(array, i, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseXor(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXor byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value");
+ }
+
+ {
+ vh.set(array, i, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseXorAcquire(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value");
+ }
+
+ {
+ vh.set(array, i, (byte)0x01);
+
+ byte o = (byte) vh.getAndBitwiseXorRelease(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte");
+ byte x = (byte) vh.get(array, i);
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value");
+ }
+ }
+ }
+
+ static void testArrayUnsupported(VarHandle vh) {
+ byte[] array = new byte[10];
+
+ int i = 0;
+
+
+ }
+
+ static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
+ byte[] array = new byte[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ byte x = (byte) vh.get(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.set(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte x = (byte) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte x = (byte) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte x = (byte) vh.getOpaque(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, (byte)0x01, (byte)0x23);
+ });
+
+ checkIOOBE(() -> {
+ byte r = (byte) vh.compareAndExchange(array, ci, (byte)0x23, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte r = (byte) vh.compareAndExchangeAcquire(array, ci, (byte)0x23, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte r = (byte) vh.compareAndExchangeRelease(array, ci, (byte)0x23, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, (byte)0x01, (byte)0x23);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, (byte)0x01, (byte)0x23);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, (byte)0x01, (byte)0x23);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, (byte)0x01, (byte)0x23);
+ });
+
+ checkIOOBE(() -> {
+ byte o = (byte) vh.getAndSet(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte o = (byte) vh.getAndSetAcquire(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte o = (byte) vh.getAndSetRelease(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte o = (byte) vh.getAndAdd(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte o = (byte) vh.getAndAddAcquire(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte o = (byte) vh.getAndAddRelease(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte o = (byte) vh.getAndBitwiseOr(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte o = (byte) vh.getAndBitwiseOrAcquire(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte o = (byte) vh.getAndBitwiseOrRelease(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte o = (byte) vh.getAndBitwiseAnd(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte o = (byte) vh.getAndBitwiseAndAcquire(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte o = (byte) vh.getAndBitwiseAndRelease(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte o = (byte) vh.getAndBitwiseXor(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte o = (byte) vh.getAndBitwiseXorAcquire(array, ci, (byte)0x01);
+ });
+
+ checkIOOBE(() -> {
+ byte o = (byte) vh.getAndBitwiseXorRelease(array, ci, (byte)0x01);
+ });
+ }
+ }
+
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessChar.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessChar.java
new file mode 100644
index 0000000..ecd685f
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessChar.java
@@ -0,0 +1,1297 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessChar
+ * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessChar
+ * @run testng/othervm -Diters=20000 VarHandleTestAccessChar
+ * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestAccessChar
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestAccessChar extends VarHandleBaseTest {
+ static final char static_final_v = '\u0123';
+
+ static char static_v;
+
+ final char final_v = '\u0123';
+
+ char v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessChar.class, "final_v", char.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessChar.class, "v", char.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessChar.class, "static_final_v", char.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessChar.class, "static_v", char.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(char[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] varHandlesProvider() throws Exception {
+ List<VarHandle> vhs = new ArrayList<>();
+ vhs.add(vhField);
+ vhs.add(vhStaticField);
+ vhs.add(vhArray);
+
+ return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "varHandlesProvider")
+ public void testIsAccessModeSupported(VarHandle vh) {
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+ }
+
+
+ @DataProvider
+ public Object[][] typesProvider() throws Exception {
+ List<Object[]> types = new ArrayList<>();
+ types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessChar.class)});
+ types.add(new Object[] {vhStaticField, Arrays.asList()});
+ types.add(new Object[] {vhArray, Arrays.asList(char[].class, int.class)});
+
+ return types.stream().toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "typesProvider")
+ public void testTypes(VarHandle vh, List<Class<?>> pts) {
+ assertEquals(vh.varType(), char.class);
+
+ assertEquals(vh.coordinateTypes(), pts);
+
+ testTypes(vh);
+ }
+
+
+ @Test
+ public void testLookupInstanceToStatic() {
+ checkIAE("Lookup of static final field to instance final field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessChar.class, "final_v", char.class);
+ });
+
+ checkIAE("Lookup of static field to instance field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessChar.class, "v", char.class);
+ });
+ }
+
+ @Test
+ public void testLookupStaticToInstance() {
+ checkIAE("Lookup of instance final field to static final field", () -> {
+ MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessChar.class, "static_final_v", char.class);
+ });
+
+ checkIAE("Lookup of instance field to static field", () -> {
+ vhStaticField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessChar.class, "static_v", char.class);
+ });
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance final field",
+ vhFinalField, vh -> testInstanceFinalField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
+ vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static final field",
+ vhStaticFinalField, VarHandleTestAccessChar::testStaticFinalField));
+ cases.add(new VarHandleAccessTestCase("Static final field unsupported",
+ vhStaticFinalField, VarHandleTestAccessChar::testStaticFinalFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance field unsupported",
+ vhField, vh -> testInstanceFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestAccessChar::testStaticField));
+ cases.add(new VarHandleAccessTestCase("Static field unsupported",
+ vhStaticField, VarHandleTestAccessChar::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestAccessChar::testArray));
+ cases.add(new VarHandleAccessTestCase("Array unsupported",
+ vhArray, VarHandleTestAccessChar::testArrayUnsupported,
+ false));
+ cases.add(new VarHandleAccessTestCase("Array index out of bounds",
+ vhArray, VarHandleTestAccessChar::testArrayIndexOutOfBounds,
+ false));
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+
+
+ static void testInstanceFinalField(VarHandleTestAccessChar recv, VarHandle vh) {
+ // Plain
+ {
+ char x = (char) vh.get(recv);
+ assertEquals(x, '\u0123', "get char value");
+ }
+
+
+ // Volatile
+ {
+ char x = (char) vh.getVolatile(recv);
+ assertEquals(x, '\u0123', "getVolatile char value");
+ }
+
+ // Lazy
+ {
+ char x = (char) vh.getAcquire(recv);
+ assertEquals(x, '\u0123', "getRelease char value");
+ }
+
+ // Opaque
+ {
+ char x = (char) vh.getOpaque(recv);
+ assertEquals(x, '\u0123', "getOpaque char value");
+ }
+ }
+
+ static void testInstanceFinalFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh) {
+ checkUOE(() -> {
+ vh.set(recv, '\u4567');
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile(recv, '\u4567');
+ });
+
+ checkUOE(() -> {
+ vh.setRelease(recv, '\u4567');
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque(recv, '\u4567');
+ });
+
+
+
+ }
+
+
+ static void testStaticFinalField(VarHandle vh) {
+ // Plain
+ {
+ char x = (char) vh.get();
+ assertEquals(x, '\u0123', "get char value");
+ }
+
+
+ // Volatile
+ {
+ char x = (char) vh.getVolatile();
+ assertEquals(x, '\u0123', "getVolatile char value");
+ }
+
+ // Lazy
+ {
+ char x = (char) vh.getAcquire();
+ assertEquals(x, '\u0123', "getRelease char value");
+ }
+
+ // Opaque
+ {
+ char x = (char) vh.getOpaque();
+ assertEquals(x, '\u0123', "getOpaque char value");
+ }
+ }
+
+ static void testStaticFinalFieldUnsupported(VarHandle vh) {
+ checkUOE(() -> {
+ vh.set('\u4567');
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile('\u4567');
+ });
+
+ checkUOE(() -> {
+ vh.setRelease('\u4567');
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque('\u4567');
+ });
+
+
+
+ }
+
+
+ static void testInstanceField(VarHandleTestAccessChar recv, VarHandle vh) {
+ // Plain
+ {
+ vh.set(recv, '\u0123');
+ char x = (char) vh.get(recv);
+ assertEquals(x, '\u0123', "set char value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(recv, '\u4567');
+ char x = (char) vh.getVolatile(recv);
+ assertEquals(x, '\u4567', "setVolatile char value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(recv, '\u0123');
+ char x = (char) vh.getAcquire(recv);
+ assertEquals(x, '\u0123', "setRelease char value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(recv, '\u4567');
+ char x = (char) vh.getOpaque(recv);
+ assertEquals(x, '\u4567', "setOpaque char value");
+ }
+
+ vh.set(recv, '\u0123');
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(recv, '\u0123', '\u4567');
+ assertEquals(r, true, "success compareAndSet char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, '\u4567', "success compareAndSet char value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(recv, '\u0123', '\u89AB');
+ assertEquals(r, false, "failing compareAndSet char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, '\u4567', "failing compareAndSet char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchange(recv, '\u4567', '\u0123');
+ assertEquals(r, '\u4567', "success compareAndExchange char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, '\u0123', "success compareAndExchange char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchange(recv, '\u4567', '\u89AB');
+ assertEquals(r, '\u0123', "failing compareAndExchange char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, '\u0123', "failing compareAndExchange char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchangeAcquire(recv, '\u0123', '\u4567');
+ assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchangeAcquire(recv, '\u0123', '\u89AB');
+ assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchangeRelease(recv, '\u4567', '\u0123');
+ assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchangeRelease(recv, '\u4567', '\u89AB');
+ assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(recv, '\u0123', '\u4567');
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, '\u4567', "weakCompareAndSetPlain char value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(recv, '\u4567', '\u0123');
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(recv, '\u0123', '\u4567');
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(recv, '\u4567', '\u0123');
+ }
+ assertEquals(success, true, "weakCompareAndSet char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, '\u0123', "weakCompareAndSet char value");
+ }
+
+ // Compare set and get
+ {
+ vh.set(recv, '\u0123');
+
+ char o = (char) vh.getAndSet(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndSet char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, '\u4567', "getAndSet char value");
+ }
+
+ {
+ vh.set(recv, '\u0123');
+
+ char o = (char) vh.getAndSetAcquire(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndSetAcquire char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, '\u4567', "getAndSetAcquire char value");
+ }
+
+ {
+ vh.set(recv, '\u0123');
+
+ char o = (char) vh.getAndSetRelease(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndSetRelease char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, '\u4567', "getAndSetRelease char value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(recv, '\u0123');
+
+ char o = (char) vh.getAndAdd(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndAdd char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value");
+ }
+
+ {
+ vh.set(recv, '\u0123');
+
+ char o = (char) vh.getAndAddAcquire(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndAddAcquire char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value");
+ }
+
+ {
+ vh.set(recv, '\u0123');
+
+ char o = (char) vh.getAndAddRelease(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndAddReleasechar");
+ char x = (char) vh.get(recv);
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set(recv, '\u0123');
+
+ char o = (char) vh.getAndBitwiseOr(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOr char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value");
+ }
+
+ {
+ vh.set(recv, '\u0123');
+
+ char o = (char) vh.getAndBitwiseOrAcquire(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value");
+ }
+
+ {
+ vh.set(recv, '\u0123');
+
+ char o = (char) vh.getAndBitwiseOrRelease(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOrRelease char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(recv, '\u0123');
+
+ char o = (char) vh.getAndBitwiseAnd(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAnd char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value");
+ }
+
+ {
+ vh.set(recv, '\u0123');
+
+ char o = (char) vh.getAndBitwiseAndAcquire(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value");
+ }
+
+ {
+ vh.set(recv, '\u0123');
+
+ char o = (char) vh.getAndBitwiseAndRelease(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAndRelease char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(recv, '\u0123');
+
+ char o = (char) vh.getAndBitwiseXor(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXor char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value");
+ }
+
+ {
+ vh.set(recv, '\u0123');
+
+ char o = (char) vh.getAndBitwiseXorAcquire(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value");
+ }
+
+ {
+ vh.set(recv, '\u0123');
+
+ char o = (char) vh.getAndBitwiseXorRelease(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXorRelease char");
+ char x = (char) vh.get(recv);
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value");
+ }
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh) {
+
+
+ }
+
+
+ static void testStaticField(VarHandle vh) {
+ // Plain
+ {
+ vh.set('\u0123');
+ char x = (char) vh.get();
+ assertEquals(x, '\u0123', "set char value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile('\u4567');
+ char x = (char) vh.getVolatile();
+ assertEquals(x, '\u4567', "setVolatile char value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease('\u0123');
+ char x = (char) vh.getAcquire();
+ assertEquals(x, '\u0123', "setRelease char value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque('\u4567');
+ char x = (char) vh.getOpaque();
+ assertEquals(x, '\u4567', "setOpaque char value");
+ }
+
+ vh.set('\u0123');
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet('\u0123', '\u4567');
+ assertEquals(r, true, "success compareAndSet char");
+ char x = (char) vh.get();
+ assertEquals(x, '\u4567', "success compareAndSet char value");
+ }
+
+ {
+ boolean r = vh.compareAndSet('\u0123', '\u89AB');
+ assertEquals(r, false, "failing compareAndSet char");
+ char x = (char) vh.get();
+ assertEquals(x, '\u4567', "failing compareAndSet char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchange('\u4567', '\u0123');
+ assertEquals(r, '\u4567', "success compareAndExchange char");
+ char x = (char) vh.get();
+ assertEquals(x, '\u0123', "success compareAndExchange char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchange('\u4567', '\u89AB');
+ assertEquals(r, '\u0123', "failing compareAndExchange char");
+ char x = (char) vh.get();
+ assertEquals(x, '\u0123', "failing compareAndExchange char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchangeAcquire('\u0123', '\u4567');
+ assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
+ char x = (char) vh.get();
+ assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchangeAcquire('\u0123', '\u89AB');
+ assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
+ char x = (char) vh.get();
+ assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchangeRelease('\u4567', '\u0123');
+ assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
+ char x = (char) vh.get();
+ assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchangeRelease('\u4567', '\u89AB');
+ assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
+ char x = (char) vh.get();
+ assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain('\u0123', '\u4567');
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain char");
+ char x = (char) vh.get();
+ assertEquals(x, '\u4567', "weakCompareAndSetPlain char value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire('\u4567', '\u0123');
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire char");
+ char x = (char) vh.get();
+ assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease('\u0123', '\u4567');
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease char");
+ char x = (char) vh.get();
+ assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet('\u4567', '\u0123');
+ }
+ assertEquals(success, true, "weakCompareAndSet char");
+ char x = (char) vh.get();
+ assertEquals(x, '\u0123', "weakCompareAndSet char");
+ }
+
+ // Compare set and get
+ {
+ vh.set('\u0123');
+
+ char o = (char) vh.getAndSet('\u4567');
+ assertEquals(o, '\u0123', "getAndSet char");
+ char x = (char) vh.get();
+ assertEquals(x, '\u4567', "getAndSet char value");
+ }
+
+ {
+ vh.set('\u0123');
+
+ char o = (char) vh.getAndSetAcquire('\u4567');
+ assertEquals(o, '\u0123', "getAndSetAcquire char");
+ char x = (char) vh.get();
+ assertEquals(x, '\u4567', "getAndSetAcquire char value");
+ }
+
+ {
+ vh.set('\u0123');
+
+ char o = (char) vh.getAndSetRelease('\u4567');
+ assertEquals(o, '\u0123', "getAndSetRelease char");
+ char x = (char) vh.get();
+ assertEquals(x, '\u4567', "getAndSetRelease char value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set('\u0123');
+
+ char o = (char) vh.getAndAdd('\u4567');
+ assertEquals(o, '\u0123', "getAndAdd char");
+ char x = (char) vh.get();
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value");
+ }
+
+ {
+ vh.set('\u0123');
+
+ char o = (char) vh.getAndAddAcquire('\u4567');
+ assertEquals(o, '\u0123', "getAndAddAcquire char");
+ char x = (char) vh.get();
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value");
+ }
+
+ {
+ vh.set('\u0123');
+
+ char o = (char) vh.getAndAddRelease('\u4567');
+ assertEquals(o, '\u0123', "getAndAddReleasechar");
+ char x = (char) vh.get();
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set('\u0123');
+
+ char o = (char) vh.getAndBitwiseOr('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOr char");
+ char x = (char) vh.get();
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value");
+ }
+
+ {
+ vh.set('\u0123');
+
+ char o = (char) vh.getAndBitwiseOrAcquire('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char");
+ char x = (char) vh.get();
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value");
+ }
+
+ {
+ vh.set('\u0123');
+
+ char o = (char) vh.getAndBitwiseOrRelease('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOrRelease char");
+ char x = (char) vh.get();
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set('\u0123');
+
+ char o = (char) vh.getAndBitwiseAnd('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAnd char");
+ char x = (char) vh.get();
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value");
+ }
+
+ {
+ vh.set('\u0123');
+
+ char o = (char) vh.getAndBitwiseAndAcquire('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char");
+ char x = (char) vh.get();
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value");
+ }
+
+ {
+ vh.set('\u0123');
+
+ char o = (char) vh.getAndBitwiseAndRelease('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAndRelease char");
+ char x = (char) vh.get();
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set('\u0123');
+
+ char o = (char) vh.getAndBitwiseXor('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXor char");
+ char x = (char) vh.get();
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value");
+ }
+
+ {
+ vh.set('\u0123');
+
+ char o = (char) vh.getAndBitwiseXorAcquire('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char");
+ char x = (char) vh.get();
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value");
+ }
+
+ {
+ vh.set('\u0123');
+
+ char o = (char) vh.getAndBitwiseXorRelease('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXorRelease char");
+ char x = (char) vh.get();
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value");
+ }
+ }
+
+ static void testStaticFieldUnsupported(VarHandle vh) {
+
+
+ }
+
+
+ static void testArray(VarHandle vh) {
+ char[] array = new char[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ vh.set(array, i, '\u0123');
+ char x = (char) vh.get(array, i);
+ assertEquals(x, '\u0123', "get char value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(array, i, '\u4567');
+ char x = (char) vh.getVolatile(array, i);
+ assertEquals(x, '\u4567', "setVolatile char value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, '\u0123');
+ char x = (char) vh.getAcquire(array, i);
+ assertEquals(x, '\u0123', "setRelease char value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, '\u4567');
+ char x = (char) vh.getOpaque(array, i);
+ assertEquals(x, '\u4567', "setOpaque char value");
+ }
+
+ vh.set(array, i, '\u0123');
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, '\u0123', '\u4567');
+ assertEquals(r, true, "success compareAndSet char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, '\u4567', "success compareAndSet char value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, '\u0123', '\u89AB');
+ assertEquals(r, false, "failing compareAndSet char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, '\u4567', "failing compareAndSet char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchange(array, i, '\u4567', '\u0123');
+ assertEquals(r, '\u4567', "success compareAndExchange char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, '\u0123', "success compareAndExchange char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchange(array, i, '\u4567', '\u89AB');
+ assertEquals(r, '\u0123', "failing compareAndExchange char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, '\u0123', "failing compareAndExchange char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchangeAcquire(array, i, '\u0123', '\u4567');
+ assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchangeAcquire(array, i, '\u0123', '\u89AB');
+ assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchangeRelease(array, i, '\u4567', '\u0123');
+ assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
+ }
+
+ {
+ char r = (char) vh.compareAndExchangeRelease(array, i, '\u4567', '\u89AB');
+ assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, '\u0123', '\u4567');
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, '\u4567', "weakCompareAndSetPlain char value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, '\u4567', '\u0123');
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, '\u0123', '\u4567');
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, '\u4567', '\u0123');
+ }
+ assertEquals(success, true, "weakCompareAndSet char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, '\u0123', "weakCompareAndSet char");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, '\u0123');
+
+ char o = (char) vh.getAndSet(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndSet char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, '\u4567', "getAndSet char value");
+ }
+
+ {
+ vh.set(array, i, '\u0123');
+
+ char o = (char) vh.getAndSetAcquire(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndSetAcquire char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, '\u4567', "getAndSetAcquire char value");
+ }
+
+ {
+ vh.set(array, i, '\u0123');
+
+ char o = (char) vh.getAndSetRelease(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndSetRelease char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, '\u4567', "getAndSetRelease char value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(array, i, '\u0123');
+
+ char o = (char) vh.getAndAdd(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndAdd char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value");
+ }
+
+ {
+ vh.set(array, i, '\u0123');
+
+ char o = (char) vh.getAndAddAcquire(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndAddAcquire char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value");
+ }
+
+ {
+ vh.set(array, i, '\u0123');
+
+ char o = (char) vh.getAndAddRelease(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndAddReleasechar");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set(array, i, '\u0123');
+
+ char o = (char) vh.getAndBitwiseOr(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOr char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value");
+ }
+
+ {
+ vh.set(array, i, '\u0123');
+
+ char o = (char) vh.getAndBitwiseOrAcquire(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value");
+ }
+
+ {
+ vh.set(array, i, '\u0123');
+
+ char o = (char) vh.getAndBitwiseOrRelease(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOrRelease char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(array, i, '\u0123');
+
+ char o = (char) vh.getAndBitwiseAnd(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAnd char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value");
+ }
+
+ {
+ vh.set(array, i, '\u0123');
+
+ char o = (char) vh.getAndBitwiseAndAcquire(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value");
+ }
+
+ {
+ vh.set(array, i, '\u0123');
+
+ char o = (char) vh.getAndBitwiseAndRelease(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAndRelease char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(array, i, '\u0123');
+
+ char o = (char) vh.getAndBitwiseXor(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXor char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value");
+ }
+
+ {
+ vh.set(array, i, '\u0123');
+
+ char o = (char) vh.getAndBitwiseXorAcquire(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value");
+ }
+
+ {
+ vh.set(array, i, '\u0123');
+
+ char o = (char) vh.getAndBitwiseXorRelease(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXorRelease char");
+ char x = (char) vh.get(array, i);
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value");
+ }
+ }
+ }
+
+ static void testArrayUnsupported(VarHandle vh) {
+ char[] array = new char[10];
+
+ int i = 0;
+
+
+ }
+
+ static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
+ char[] array = new char[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ char x = (char) vh.get(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.set(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char x = (char) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char x = (char) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char x = (char) vh.getOpaque(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, '\u0123', '\u4567');
+ });
+
+ checkIOOBE(() -> {
+ char r = (char) vh.compareAndExchange(array, ci, '\u4567', '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char r = (char) vh.compareAndExchangeAcquire(array, ci, '\u4567', '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char r = (char) vh.compareAndExchangeRelease(array, ci, '\u4567', '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, '\u0123', '\u4567');
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, '\u0123', '\u4567');
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, '\u0123', '\u4567');
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, '\u0123', '\u4567');
+ });
+
+ checkIOOBE(() -> {
+ char o = (char) vh.getAndSet(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char o = (char) vh.getAndSetAcquire(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char o = (char) vh.getAndSetRelease(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char o = (char) vh.getAndAdd(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char o = (char) vh.getAndAddAcquire(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char o = (char) vh.getAndAddRelease(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char o = (char) vh.getAndBitwiseOr(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char o = (char) vh.getAndBitwiseOrAcquire(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char o = (char) vh.getAndBitwiseOrRelease(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char o = (char) vh.getAndBitwiseAnd(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char o = (char) vh.getAndBitwiseAndAcquire(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char o = (char) vh.getAndBitwiseAndRelease(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char o = (char) vh.getAndBitwiseXor(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char o = (char) vh.getAndBitwiseXorAcquire(array, ci, '\u0123');
+ });
+
+ checkIOOBE(() -> {
+ char o = (char) vh.getAndBitwiseXorRelease(array, ci, '\u0123');
+ });
+ }
+ }
+
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessDouble.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessDouble.java
new file mode 100644
index 0000000..3aa12aa
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessDouble.java
@@ -0,0 +1,1188 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessDouble
+ * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessDouble
+ * @run testng/othervm -Diters=20000 VarHandleTestAccessDouble
+ * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestAccessDouble
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestAccessDouble extends VarHandleBaseTest {
+ static final double static_final_v = 1.0d;
+
+ static double static_v;
+
+ final double final_v = 1.0d;
+
+ double v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessDouble.class, "final_v", double.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessDouble.class, "v", double.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessDouble.class, "static_final_v", double.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessDouble.class, "static_v", double.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(double[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] varHandlesProvider() throws Exception {
+ List<VarHandle> vhs = new ArrayList<>();
+ vhs.add(vhField);
+ vhs.add(vhStaticField);
+ vhs.add(vhArray);
+
+ return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "varHandlesProvider")
+ public void testIsAccessModeSupported(VarHandle vh) {
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+ }
+
+
+ @DataProvider
+ public Object[][] typesProvider() throws Exception {
+ List<Object[]> types = new ArrayList<>();
+ types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessDouble.class)});
+ types.add(new Object[] {vhStaticField, Arrays.asList()});
+ types.add(new Object[] {vhArray, Arrays.asList(double[].class, int.class)});
+
+ return types.stream().toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "typesProvider")
+ public void testTypes(VarHandle vh, List<Class<?>> pts) {
+ assertEquals(vh.varType(), double.class);
+
+ assertEquals(vh.coordinateTypes(), pts);
+
+ testTypes(vh);
+ }
+
+
+ @Test
+ public void testLookupInstanceToStatic() {
+ checkIAE("Lookup of static final field to instance final field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessDouble.class, "final_v", double.class);
+ });
+
+ checkIAE("Lookup of static field to instance field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessDouble.class, "v", double.class);
+ });
+ }
+
+ @Test
+ public void testLookupStaticToInstance() {
+ checkIAE("Lookup of instance final field to static final field", () -> {
+ MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessDouble.class, "static_final_v", double.class);
+ });
+
+ checkIAE("Lookup of instance field to static field", () -> {
+ vhStaticField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessDouble.class, "static_v", double.class);
+ });
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance final field",
+ vhFinalField, vh -> testInstanceFinalField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
+ vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static final field",
+ vhStaticFinalField, VarHandleTestAccessDouble::testStaticFinalField));
+ cases.add(new VarHandleAccessTestCase("Static final field unsupported",
+ vhStaticFinalField, VarHandleTestAccessDouble::testStaticFinalFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance field unsupported",
+ vhField, vh -> testInstanceFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestAccessDouble::testStaticField));
+ cases.add(new VarHandleAccessTestCase("Static field unsupported",
+ vhStaticField, VarHandleTestAccessDouble::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestAccessDouble::testArray));
+ cases.add(new VarHandleAccessTestCase("Array unsupported",
+ vhArray, VarHandleTestAccessDouble::testArrayUnsupported,
+ false));
+ cases.add(new VarHandleAccessTestCase("Array index out of bounds",
+ vhArray, VarHandleTestAccessDouble::testArrayIndexOutOfBounds,
+ false));
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+
+
+ static void testInstanceFinalField(VarHandleTestAccessDouble recv, VarHandle vh) {
+ // Plain
+ {
+ double x = (double) vh.get(recv);
+ assertEquals(x, 1.0d, "get double value");
+ }
+
+
+ // Volatile
+ {
+ double x = (double) vh.getVolatile(recv);
+ assertEquals(x, 1.0d, "getVolatile double value");
+ }
+
+ // Lazy
+ {
+ double x = (double) vh.getAcquire(recv);
+ assertEquals(x, 1.0d, "getRelease double value");
+ }
+
+ // Opaque
+ {
+ double x = (double) vh.getOpaque(recv);
+ assertEquals(x, 1.0d, "getOpaque double value");
+ }
+ }
+
+ static void testInstanceFinalFieldUnsupported(VarHandleTestAccessDouble recv, VarHandle vh) {
+ checkUOE(() -> {
+ vh.set(recv, 2.0d);
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile(recv, 2.0d);
+ });
+
+ checkUOE(() -> {
+ vh.setRelease(recv, 2.0d);
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque(recv, 2.0d);
+ });
+
+
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOr(recv, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOrAcquire(recv, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOrRelease(recv, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAnd(recv, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAndAcquire(recv, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAndRelease(recv, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXor(recv, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXorAcquire(recv, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXorRelease(recv, 1.0d);
+ });
+ }
+
+
+ static void testStaticFinalField(VarHandle vh) {
+ // Plain
+ {
+ double x = (double) vh.get();
+ assertEquals(x, 1.0d, "get double value");
+ }
+
+
+ // Volatile
+ {
+ double x = (double) vh.getVolatile();
+ assertEquals(x, 1.0d, "getVolatile double value");
+ }
+
+ // Lazy
+ {
+ double x = (double) vh.getAcquire();
+ assertEquals(x, 1.0d, "getRelease double value");
+ }
+
+ // Opaque
+ {
+ double x = (double) vh.getOpaque();
+ assertEquals(x, 1.0d, "getOpaque double value");
+ }
+ }
+
+ static void testStaticFinalFieldUnsupported(VarHandle vh) {
+ checkUOE(() -> {
+ vh.set(2.0d);
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile(2.0d);
+ });
+
+ checkUOE(() -> {
+ vh.setRelease(2.0d);
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque(2.0d);
+ });
+
+
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOr(1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOrAcquire(1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOrRelease(1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAnd(1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAndAcquire(1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAndRelease(1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXor(1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXorAcquire(1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXorRelease(1.0d);
+ });
+ }
+
+
+ static void testInstanceField(VarHandleTestAccessDouble recv, VarHandle vh) {
+ // Plain
+ {
+ vh.set(recv, 1.0d);
+ double x = (double) vh.get(recv);
+ assertEquals(x, 1.0d, "set double value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(recv, 2.0d);
+ double x = (double) vh.getVolatile(recv);
+ assertEquals(x, 2.0d, "setVolatile double value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(recv, 1.0d);
+ double x = (double) vh.getAcquire(recv);
+ assertEquals(x, 1.0d, "setRelease double value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(recv, 2.0d);
+ double x = (double) vh.getOpaque(recv);
+ assertEquals(x, 2.0d, "setOpaque double value");
+ }
+
+ vh.set(recv, 1.0d);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(recv, 1.0d, 2.0d);
+ assertEquals(r, true, "success compareAndSet double");
+ double x = (double) vh.get(recv);
+ assertEquals(x, 2.0d, "success compareAndSet double value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(recv, 1.0d, 3.0d);
+ assertEquals(r, false, "failing compareAndSet double");
+ double x = (double) vh.get(recv);
+ assertEquals(x, 2.0d, "failing compareAndSet double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchange(recv, 2.0d, 1.0d);
+ assertEquals(r, 2.0d, "success compareAndExchange double");
+ double x = (double) vh.get(recv);
+ assertEquals(x, 1.0d, "success compareAndExchange double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchange(recv, 2.0d, 3.0d);
+ assertEquals(r, 1.0d, "failing compareAndExchange double");
+ double x = (double) vh.get(recv);
+ assertEquals(x, 1.0d, "failing compareAndExchange double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeAcquire(recv, 1.0d, 2.0d);
+ assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
+ double x = (double) vh.get(recv);
+ assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeAcquire(recv, 1.0d, 3.0d);
+ assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
+ double x = (double) vh.get(recv);
+ assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeRelease(recv, 2.0d, 1.0d);
+ assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
+ double x = (double) vh.get(recv);
+ assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeRelease(recv, 2.0d, 3.0d);
+ assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
+ double x = (double) vh.get(recv);
+ assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(recv, 1.0d, 2.0d);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain double");
+ double x = (double) vh.get(recv);
+ assertEquals(x, 2.0d, "weakCompareAndSetPlain 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.weakCompareAndSet(recv, 2.0d, 1.0d);
+ }
+ assertEquals(success, true, "weakCompareAndSet double");
+ double x = (double) vh.get(recv);
+ assertEquals(x, 1.0d, "weakCompareAndSet double value");
+ }
+
+ // Compare set and get
+ {
+ vh.set(recv, 1.0d);
+
+ 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);
+
+ double o = (double) vh.getAndSetAcquire(recv, 2.0d);
+ assertEquals(o, 1.0d, "getAndSetAcquire double");
+ double x = (double) vh.get(recv);
+ assertEquals(x, 2.0d, "getAndSetAcquire double value");
+ }
+
+ {
+ vh.set(recv, 1.0d);
+
+ double o = (double) vh.getAndSetRelease(recv, 2.0d);
+ assertEquals(o, 1.0d, "getAndSetRelease double");
+ double x = (double) vh.get(recv);
+ assertEquals(x, 2.0d, "getAndSetRelease double value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(recv, 1.0d);
+
+ double o = (double) vh.getAndAdd(recv, 2.0d);
+ assertEquals(o, 1.0d, "getAndAdd double");
+ double x = (double) vh.get(recv);
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value");
+ }
+
+ {
+ vh.set(recv, 1.0d);
+
+ double o = (double) vh.getAndAddAcquire(recv, 2.0d);
+ assertEquals(o, 1.0d, "getAndAddAcquire double");
+ double x = (double) vh.get(recv);
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value");
+ }
+
+ {
+ vh.set(recv, 1.0d);
+
+ double o = (double) vh.getAndAddRelease(recv, 2.0d);
+ assertEquals(o, 1.0d, "getAndAddReleasedouble");
+ double x = (double) vh.get(recv);
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value");
+ }
+
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestAccessDouble recv, VarHandle vh) {
+
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOr(recv, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOrAcquire(recv, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOrRelease(recv, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAnd(recv, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAndAcquire(recv, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAndRelease(recv, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXor(recv, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXorAcquire(recv, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXorRelease(recv, 1.0d);
+ });
+ }
+
+
+ static void testStaticField(VarHandle vh) {
+ // Plain
+ {
+ vh.set(1.0d);
+ double x = (double) vh.get();
+ assertEquals(x, 1.0d, "set double value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(2.0d);
+ double x = (double) vh.getVolatile();
+ assertEquals(x, 2.0d, "setVolatile double value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(1.0d);
+ double x = (double) vh.getAcquire();
+ assertEquals(x, 1.0d, "setRelease double value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(2.0d);
+ double x = (double) vh.getOpaque();
+ assertEquals(x, 2.0d, "setOpaque double value");
+ }
+
+ vh.set(1.0d);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(1.0d, 2.0d);
+ assertEquals(r, true, "success compareAndSet double");
+ double x = (double) vh.get();
+ assertEquals(x, 2.0d, "success compareAndSet double value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(1.0d, 3.0d);
+ assertEquals(r, false, "failing compareAndSet double");
+ double x = (double) vh.get();
+ assertEquals(x, 2.0d, "failing compareAndSet double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchange(2.0d, 1.0d);
+ assertEquals(r, 2.0d, "success compareAndExchange double");
+ double x = (double) vh.get();
+ assertEquals(x, 1.0d, "success compareAndExchange double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchange(2.0d, 3.0d);
+ assertEquals(r, 1.0d, "failing compareAndExchange double");
+ double x = (double) vh.get();
+ assertEquals(x, 1.0d, "failing compareAndExchange double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeAcquire(1.0d, 2.0d);
+ assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
+ double x = (double) vh.get();
+ assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeAcquire(1.0d, 3.0d);
+ assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
+ double x = (double) vh.get();
+ assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeRelease(2.0d, 1.0d);
+ assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
+ double x = (double) vh.get();
+ assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeRelease(2.0d, 3.0d);
+ assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
+ double x = (double) vh.get();
+ assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(1.0d, 2.0d);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain double");
+ double x = (double) vh.get();
+ assertEquals(x, 2.0d, "weakCompareAndSetPlain 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.weakCompareAndSet(2.0d, 1.0d);
+ }
+ assertEquals(success, true, "weakCompareAndSet double");
+ double x = (double) vh.get();
+ assertEquals(x, 1.0d, "weakCompareAndSet double");
+ }
+
+ // Compare set and get
+ {
+ vh.set(1.0d);
+
+ 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);
+
+ double o = (double) vh.getAndSetAcquire(2.0d);
+ assertEquals(o, 1.0d, "getAndSetAcquire double");
+ double x = (double) vh.get();
+ assertEquals(x, 2.0d, "getAndSetAcquire double value");
+ }
+
+ {
+ vh.set(1.0d);
+
+ double o = (double) vh.getAndSetRelease(2.0d);
+ assertEquals(o, 1.0d, "getAndSetRelease double");
+ double x = (double) vh.get();
+ assertEquals(x, 2.0d, "getAndSetRelease double value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(1.0d);
+
+ double o = (double) vh.getAndAdd(2.0d);
+ assertEquals(o, 1.0d, "getAndAdd double");
+ double x = (double) vh.get();
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value");
+ }
+
+ {
+ vh.set(1.0d);
+
+ double o = (double) vh.getAndAddAcquire(2.0d);
+ assertEquals(o, 1.0d, "getAndAddAcquire double");
+ double x = (double) vh.get();
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value");
+ }
+
+ {
+ vh.set(1.0d);
+
+ double o = (double) vh.getAndAddRelease(2.0d);
+ assertEquals(o, 1.0d, "getAndAddReleasedouble");
+ double x = (double) vh.get();
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value");
+ }
+
+ }
+
+ static void testStaticFieldUnsupported(VarHandle vh) {
+
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOr(1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOrAcquire(1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOrRelease(1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAnd(1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAndAcquire(1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAndRelease(1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXor(1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXorAcquire(1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXorRelease(1.0d);
+ });
+ }
+
+
+ static void testArray(VarHandle vh) {
+ double[] array = new double[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ vh.set(array, i, 1.0d);
+ double x = (double) vh.get(array, i);
+ assertEquals(x, 1.0d, "get double value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(array, i, 2.0d);
+ double x = (double) vh.getVolatile(array, i);
+ assertEquals(x, 2.0d, "setVolatile double value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, 1.0d);
+ double x = (double) vh.getAcquire(array, i);
+ assertEquals(x, 1.0d, "setRelease double value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, 2.0d);
+ double x = (double) vh.getOpaque(array, i);
+ assertEquals(x, 2.0d, "setOpaque double value");
+ }
+
+ vh.set(array, i, 1.0d);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, 1.0d, 2.0d);
+ assertEquals(r, true, "success compareAndSet double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, 2.0d, "success compareAndSet double value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, 1.0d, 3.0d);
+ assertEquals(r, false, "failing compareAndSet double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, 2.0d, "failing compareAndSet double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchange(array, i, 2.0d, 1.0d);
+ assertEquals(r, 2.0d, "success compareAndExchange double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, 1.0d, "success compareAndExchange double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchange(array, i, 2.0d, 3.0d);
+ assertEquals(r, 1.0d, "failing compareAndExchange double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, 1.0d, "failing compareAndExchange double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeAcquire(array, i, 1.0d, 2.0d);
+ assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeAcquire(array, i, 1.0d, 3.0d);
+ assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeRelease(array, i, 2.0d, 1.0d);
+ assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeRelease(array, i, 2.0d, 3.0d);
+ assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, 1.0d, 2.0d);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, 2.0d, "weakCompareAndSetPlain 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.weakCompareAndSet(array, i, 2.0d, 1.0d);
+ }
+ assertEquals(success, true, "weakCompareAndSet double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, 1.0d, "weakCompareAndSet double");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, 1.0d);
+
+ 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);
+
+ double o = (double) vh.getAndSetAcquire(array, i, 2.0d);
+ assertEquals(o, 1.0d, "getAndSetAcquire double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, 2.0d, "getAndSetAcquire double value");
+ }
+
+ {
+ vh.set(array, i, 1.0d);
+
+ double o = (double) vh.getAndSetRelease(array, i, 2.0d);
+ assertEquals(o, 1.0d, "getAndSetRelease double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, 2.0d, "getAndSetRelease double value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(array, i, 1.0d);
+
+ double o = (double) vh.getAndAdd(array, i, 2.0d);
+ assertEquals(o, 1.0d, "getAndAdd double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value");
+ }
+
+ {
+ vh.set(array, i, 1.0d);
+
+ double o = (double) vh.getAndAddAcquire(array, i, 2.0d);
+ assertEquals(o, 1.0d, "getAndAddAcquire double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value");
+ }
+
+ {
+ vh.set(array, i, 1.0d);
+
+ double o = (double) vh.getAndAddRelease(array, i, 2.0d);
+ assertEquals(o, 1.0d, "getAndAddReleasedouble");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value");
+ }
+
+ }
+ }
+
+ static void testArrayUnsupported(VarHandle vh) {
+ double[] array = new double[10];
+
+ int i = 0;
+
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOr(array, i, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOrAcquire(array, i, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOrRelease(array, i, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAnd(array, i, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAndAcquire(array, i, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAndRelease(array, i, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXor(array, i, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXorAcquire(array, i, 1.0d);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXorRelease(array, i, 1.0d);
+ });
+ }
+
+ static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
+ double[] array = new double[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ double x = (double) vh.get(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.set(array, ci, 1.0d);
+ });
+
+ checkIOOBE(() -> {
+ double x = (double) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, 1.0d);
+ });
+
+ checkIOOBE(() -> {
+ double x = (double) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, 1.0d);
+ });
+
+ checkIOOBE(() -> {
+ double x = (double) vh.getOpaque(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, 1.0d);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, 1.0d, 2.0d);
+ });
+
+ checkIOOBE(() -> {
+ double r = (double) vh.compareAndExchange(array, ci, 2.0d, 1.0d);
+ });
+
+ checkIOOBE(() -> {
+ double r = (double) vh.compareAndExchangeAcquire(array, ci, 2.0d, 1.0d);
+ });
+
+ checkIOOBE(() -> {
+ double r = (double) vh.compareAndExchangeRelease(array, ci, 2.0d, 1.0d);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, 1.0d, 2.0d);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(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.getAndSetAcquire(array, ci, 1.0d);
+ });
+
+ checkIOOBE(() -> {
+ double o = (double) vh.getAndSetRelease(array, ci, 1.0d);
+ });
+
+ checkIOOBE(() -> {
+ double o = (double) vh.getAndAdd(array, ci, 1.0d);
+ });
+
+ checkIOOBE(() -> {
+ double o = (double) vh.getAndAddAcquire(array, ci, 1.0d);
+ });
+
+ checkIOOBE(() -> {
+ double o = (double) vh.getAndAddRelease(array, ci, 1.0d);
+ });
+
+ }
+ }
+
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessFloat.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessFloat.java
new file mode 100644
index 0000000..81f19fb
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessFloat.java
@@ -0,0 +1,1188 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessFloat
+ * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessFloat
+ * @run testng/othervm -Diters=20000 VarHandleTestAccessFloat
+ * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestAccessFloat
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestAccessFloat extends VarHandleBaseTest {
+ static final float static_final_v = 1.0f;
+
+ static float static_v;
+
+ final float final_v = 1.0f;
+
+ float v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessFloat.class, "final_v", float.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessFloat.class, "v", float.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessFloat.class, "static_final_v", float.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessFloat.class, "static_v", float.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(float[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] varHandlesProvider() throws Exception {
+ List<VarHandle> vhs = new ArrayList<>();
+ vhs.add(vhField);
+ vhs.add(vhStaticField);
+ vhs.add(vhArray);
+
+ return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "varHandlesProvider")
+ public void testIsAccessModeSupported(VarHandle vh) {
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+ }
+
+
+ @DataProvider
+ public Object[][] typesProvider() throws Exception {
+ List<Object[]> types = new ArrayList<>();
+ types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessFloat.class)});
+ types.add(new Object[] {vhStaticField, Arrays.asList()});
+ types.add(new Object[] {vhArray, Arrays.asList(float[].class, int.class)});
+
+ return types.stream().toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "typesProvider")
+ public void testTypes(VarHandle vh, List<Class<?>> pts) {
+ assertEquals(vh.varType(), float.class);
+
+ assertEquals(vh.coordinateTypes(), pts);
+
+ testTypes(vh);
+ }
+
+
+ @Test
+ public void testLookupInstanceToStatic() {
+ checkIAE("Lookup of static final field to instance final field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessFloat.class, "final_v", float.class);
+ });
+
+ checkIAE("Lookup of static field to instance field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessFloat.class, "v", float.class);
+ });
+ }
+
+ @Test
+ public void testLookupStaticToInstance() {
+ checkIAE("Lookup of instance final field to static final field", () -> {
+ MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessFloat.class, "static_final_v", float.class);
+ });
+
+ checkIAE("Lookup of instance field to static field", () -> {
+ vhStaticField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessFloat.class, "static_v", float.class);
+ });
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance final field",
+ vhFinalField, vh -> testInstanceFinalField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
+ vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static final field",
+ vhStaticFinalField, VarHandleTestAccessFloat::testStaticFinalField));
+ cases.add(new VarHandleAccessTestCase("Static final field unsupported",
+ vhStaticFinalField, VarHandleTestAccessFloat::testStaticFinalFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance field unsupported",
+ vhField, vh -> testInstanceFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestAccessFloat::testStaticField));
+ cases.add(new VarHandleAccessTestCase("Static field unsupported",
+ vhStaticField, VarHandleTestAccessFloat::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestAccessFloat::testArray));
+ cases.add(new VarHandleAccessTestCase("Array unsupported",
+ vhArray, VarHandleTestAccessFloat::testArrayUnsupported,
+ false));
+ cases.add(new VarHandleAccessTestCase("Array index out of bounds",
+ vhArray, VarHandleTestAccessFloat::testArrayIndexOutOfBounds,
+ false));
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+
+
+ static void testInstanceFinalField(VarHandleTestAccessFloat recv, VarHandle vh) {
+ // Plain
+ {
+ float x = (float) vh.get(recv);
+ assertEquals(x, 1.0f, "get float value");
+ }
+
+
+ // Volatile
+ {
+ float x = (float) vh.getVolatile(recv);
+ assertEquals(x, 1.0f, "getVolatile float value");
+ }
+
+ // Lazy
+ {
+ float x = (float) vh.getAcquire(recv);
+ assertEquals(x, 1.0f, "getRelease float value");
+ }
+
+ // Opaque
+ {
+ float x = (float) vh.getOpaque(recv);
+ assertEquals(x, 1.0f, "getOpaque float value");
+ }
+ }
+
+ static void testInstanceFinalFieldUnsupported(VarHandleTestAccessFloat recv, VarHandle vh) {
+ checkUOE(() -> {
+ vh.set(recv, 2.0f);
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile(recv, 2.0f);
+ });
+
+ checkUOE(() -> {
+ vh.setRelease(recv, 2.0f);
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque(recv, 2.0f);
+ });
+
+
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOr(recv, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOrAcquire(recv, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOrRelease(recv, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAnd(recv, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAndAcquire(recv, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAndRelease(recv, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXor(recv, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXorAcquire(recv, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXorRelease(recv, 1.0f);
+ });
+ }
+
+
+ static void testStaticFinalField(VarHandle vh) {
+ // Plain
+ {
+ float x = (float) vh.get();
+ assertEquals(x, 1.0f, "get float value");
+ }
+
+
+ // Volatile
+ {
+ float x = (float) vh.getVolatile();
+ assertEquals(x, 1.0f, "getVolatile float value");
+ }
+
+ // Lazy
+ {
+ float x = (float) vh.getAcquire();
+ assertEquals(x, 1.0f, "getRelease float value");
+ }
+
+ // Opaque
+ {
+ float x = (float) vh.getOpaque();
+ assertEquals(x, 1.0f, "getOpaque float value");
+ }
+ }
+
+ static void testStaticFinalFieldUnsupported(VarHandle vh) {
+ checkUOE(() -> {
+ vh.set(2.0f);
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile(2.0f);
+ });
+
+ checkUOE(() -> {
+ vh.setRelease(2.0f);
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque(2.0f);
+ });
+
+
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOr(1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOrAcquire(1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOrRelease(1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAnd(1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAndAcquire(1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAndRelease(1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXor(1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXorAcquire(1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXorRelease(1.0f);
+ });
+ }
+
+
+ static void testInstanceField(VarHandleTestAccessFloat recv, VarHandle vh) {
+ // Plain
+ {
+ vh.set(recv, 1.0f);
+ float x = (float) vh.get(recv);
+ assertEquals(x, 1.0f, "set float value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(recv, 2.0f);
+ float x = (float) vh.getVolatile(recv);
+ assertEquals(x, 2.0f, "setVolatile float value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(recv, 1.0f);
+ float x = (float) vh.getAcquire(recv);
+ assertEquals(x, 1.0f, "setRelease float value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(recv, 2.0f);
+ float x = (float) vh.getOpaque(recv);
+ assertEquals(x, 2.0f, "setOpaque float value");
+ }
+
+ vh.set(recv, 1.0f);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(recv, 1.0f, 2.0f);
+ assertEquals(r, true, "success compareAndSet float");
+ float x = (float) vh.get(recv);
+ assertEquals(x, 2.0f, "success compareAndSet float value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(recv, 1.0f, 3.0f);
+ assertEquals(r, false, "failing compareAndSet float");
+ float x = (float) vh.get(recv);
+ assertEquals(x, 2.0f, "failing compareAndSet float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchange(recv, 2.0f, 1.0f);
+ assertEquals(r, 2.0f, "success compareAndExchange float");
+ float x = (float) vh.get(recv);
+ assertEquals(x, 1.0f, "success compareAndExchange float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchange(recv, 2.0f, 3.0f);
+ assertEquals(r, 1.0f, "failing compareAndExchange float");
+ float x = (float) vh.get(recv);
+ assertEquals(x, 1.0f, "failing compareAndExchange float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 2.0f);
+ assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
+ float x = (float) vh.get(recv);
+ assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 3.0f);
+ assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
+ float x = (float) vh.get(recv);
+ assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeRelease(recv, 2.0f, 1.0f);
+ assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
+ float x = (float) vh.get(recv);
+ assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeRelease(recv, 2.0f, 3.0f);
+ assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
+ float x = (float) vh.get(recv);
+ assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(recv, 1.0f, 2.0f);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain float");
+ float x = (float) vh.get(recv);
+ assertEquals(x, 2.0f, "weakCompareAndSetPlain 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.weakCompareAndSet(recv, 2.0f, 1.0f);
+ }
+ assertEquals(success, true, "weakCompareAndSet float");
+ float x = (float) vh.get(recv);
+ assertEquals(x, 1.0f, "weakCompareAndSet float value");
+ }
+
+ // Compare set and get
+ {
+ vh.set(recv, 1.0f);
+
+ 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);
+
+ float o = (float) vh.getAndSetAcquire(recv, 2.0f);
+ assertEquals(o, 1.0f, "getAndSetAcquire float");
+ float x = (float) vh.get(recv);
+ assertEquals(x, 2.0f, "getAndSetAcquire float value");
+ }
+
+ {
+ vh.set(recv, 1.0f);
+
+ float o = (float) vh.getAndSetRelease(recv, 2.0f);
+ assertEquals(o, 1.0f, "getAndSetRelease float");
+ float x = (float) vh.get(recv);
+ assertEquals(x, 2.0f, "getAndSetRelease float value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(recv, 1.0f);
+
+ float o = (float) vh.getAndAdd(recv, 2.0f);
+ assertEquals(o, 1.0f, "getAndAdd float");
+ float x = (float) vh.get(recv);
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
+ }
+
+ {
+ vh.set(recv, 1.0f);
+
+ float o = (float) vh.getAndAddAcquire(recv, 2.0f);
+ assertEquals(o, 1.0f, "getAndAddAcquire float");
+ float x = (float) vh.get(recv);
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
+ }
+
+ {
+ vh.set(recv, 1.0f);
+
+ float o = (float) vh.getAndAddRelease(recv, 2.0f);
+ assertEquals(o, 1.0f, "getAndAddReleasefloat");
+ float x = (float) vh.get(recv);
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
+ }
+
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestAccessFloat recv, VarHandle vh) {
+
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOr(recv, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOrAcquire(recv, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOrRelease(recv, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAnd(recv, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAndAcquire(recv, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAndRelease(recv, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXor(recv, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXorAcquire(recv, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXorRelease(recv, 1.0f);
+ });
+ }
+
+
+ static void testStaticField(VarHandle vh) {
+ // Plain
+ {
+ vh.set(1.0f);
+ float x = (float) vh.get();
+ assertEquals(x, 1.0f, "set float value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(2.0f);
+ float x = (float) vh.getVolatile();
+ assertEquals(x, 2.0f, "setVolatile float value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(1.0f);
+ float x = (float) vh.getAcquire();
+ assertEquals(x, 1.0f, "setRelease float value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(2.0f);
+ float x = (float) vh.getOpaque();
+ assertEquals(x, 2.0f, "setOpaque float value");
+ }
+
+ vh.set(1.0f);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(1.0f, 2.0f);
+ assertEquals(r, true, "success compareAndSet float");
+ float x = (float) vh.get();
+ assertEquals(x, 2.0f, "success compareAndSet float value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(1.0f, 3.0f);
+ assertEquals(r, false, "failing compareAndSet float");
+ float x = (float) vh.get();
+ assertEquals(x, 2.0f, "failing compareAndSet float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchange(2.0f, 1.0f);
+ assertEquals(r, 2.0f, "success compareAndExchange float");
+ float x = (float) vh.get();
+ assertEquals(x, 1.0f, "success compareAndExchange float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchange(2.0f, 3.0f);
+ assertEquals(r, 1.0f, "failing compareAndExchange float");
+ float x = (float) vh.get();
+ assertEquals(x, 1.0f, "failing compareAndExchange float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeAcquire(1.0f, 2.0f);
+ assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
+ float x = (float) vh.get();
+ assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeAcquire(1.0f, 3.0f);
+ assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
+ float x = (float) vh.get();
+ assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeRelease(2.0f, 1.0f);
+ assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
+ float x = (float) vh.get();
+ assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeRelease(2.0f, 3.0f);
+ assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
+ float x = (float) vh.get();
+ assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(1.0f, 2.0f);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain float");
+ float x = (float) vh.get();
+ assertEquals(x, 2.0f, "weakCompareAndSetPlain 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.weakCompareAndSet(2.0f, 1.0f);
+ }
+ assertEquals(success, true, "weakCompareAndSet float");
+ float x = (float) vh.get();
+ assertEquals(x, 1.0f, "weakCompareAndSet float");
+ }
+
+ // Compare set and get
+ {
+ vh.set(1.0f);
+
+ 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);
+
+ float o = (float) vh.getAndSetAcquire(2.0f);
+ assertEquals(o, 1.0f, "getAndSetAcquire float");
+ float x = (float) vh.get();
+ assertEquals(x, 2.0f, "getAndSetAcquire float value");
+ }
+
+ {
+ vh.set(1.0f);
+
+ float o = (float) vh.getAndSetRelease(2.0f);
+ assertEquals(o, 1.0f, "getAndSetRelease float");
+ float x = (float) vh.get();
+ assertEquals(x, 2.0f, "getAndSetRelease float value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(1.0f);
+
+ float o = (float) vh.getAndAdd(2.0f);
+ assertEquals(o, 1.0f, "getAndAdd float");
+ float x = (float) vh.get();
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
+ }
+
+ {
+ vh.set(1.0f);
+
+ float o = (float) vh.getAndAddAcquire(2.0f);
+ assertEquals(o, 1.0f, "getAndAddAcquire float");
+ float x = (float) vh.get();
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
+ }
+
+ {
+ vh.set(1.0f);
+
+ float o = (float) vh.getAndAddRelease(2.0f);
+ assertEquals(o, 1.0f, "getAndAddReleasefloat");
+ float x = (float) vh.get();
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
+ }
+
+ }
+
+ static void testStaticFieldUnsupported(VarHandle vh) {
+
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOr(1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOrAcquire(1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOrRelease(1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAnd(1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAndAcquire(1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAndRelease(1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXor(1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXorAcquire(1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXorRelease(1.0f);
+ });
+ }
+
+
+ static void testArray(VarHandle vh) {
+ float[] array = new float[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ vh.set(array, i, 1.0f);
+ float x = (float) vh.get(array, i);
+ assertEquals(x, 1.0f, "get float value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(array, i, 2.0f);
+ float x = (float) vh.getVolatile(array, i);
+ assertEquals(x, 2.0f, "setVolatile float value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, 1.0f);
+ float x = (float) vh.getAcquire(array, i);
+ assertEquals(x, 1.0f, "setRelease float value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, 2.0f);
+ float x = (float) vh.getOpaque(array, i);
+ assertEquals(x, 2.0f, "setOpaque float value");
+ }
+
+ vh.set(array, i, 1.0f);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, 1.0f, 2.0f);
+ assertEquals(r, true, "success compareAndSet float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, 2.0f, "success compareAndSet float value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, 1.0f, 3.0f);
+ assertEquals(r, false, "failing compareAndSet float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, 2.0f, "failing compareAndSet float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchange(array, i, 2.0f, 1.0f);
+ assertEquals(r, 2.0f, "success compareAndExchange float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, 1.0f, "success compareAndExchange float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchange(array, i, 2.0f, 3.0f);
+ assertEquals(r, 1.0f, "failing compareAndExchange float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, 1.0f, "failing compareAndExchange float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeAcquire(array, i, 1.0f, 2.0f);
+ assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeAcquire(array, i, 1.0f, 3.0f);
+ assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeRelease(array, i, 2.0f, 1.0f);
+ assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeRelease(array, i, 2.0f, 3.0f);
+ assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, 1.0f, 2.0f);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, 2.0f, "weakCompareAndSetPlain 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.weakCompareAndSet(array, i, 2.0f, 1.0f);
+ }
+ assertEquals(success, true, "weakCompareAndSet float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, 1.0f, "weakCompareAndSet float");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, 1.0f);
+
+ 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);
+
+ float o = (float) vh.getAndSetAcquire(array, i, 2.0f);
+ assertEquals(o, 1.0f, "getAndSetAcquire float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, 2.0f, "getAndSetAcquire float value");
+ }
+
+ {
+ vh.set(array, i, 1.0f);
+
+ float o = (float) vh.getAndSetRelease(array, i, 2.0f);
+ assertEquals(o, 1.0f, "getAndSetRelease float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, 2.0f, "getAndSetRelease float value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(array, i, 1.0f);
+
+ float o = (float) vh.getAndAdd(array, i, 2.0f);
+ assertEquals(o, 1.0f, "getAndAdd float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
+ }
+
+ {
+ vh.set(array, i, 1.0f);
+
+ float o = (float) vh.getAndAddAcquire(array, i, 2.0f);
+ assertEquals(o, 1.0f, "getAndAddAcquire float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
+ }
+
+ {
+ vh.set(array, i, 1.0f);
+
+ float o = (float) vh.getAndAddRelease(array, i, 2.0f);
+ assertEquals(o, 1.0f, "getAndAddReleasefloat");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
+ }
+
+ }
+ }
+
+ static void testArrayUnsupported(VarHandle vh) {
+ float[] array = new float[10];
+
+ int i = 0;
+
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOr(array, i, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOrAcquire(array, i, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOrRelease(array, i, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAnd(array, i, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAndAcquire(array, i, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAndRelease(array, i, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXor(array, i, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXorAcquire(array, i, 1.0f);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXorRelease(array, i, 1.0f);
+ });
+ }
+
+ static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
+ float[] array = new float[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ float x = (float) vh.get(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.set(array, ci, 1.0f);
+ });
+
+ checkIOOBE(() -> {
+ float x = (float) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, 1.0f);
+ });
+
+ checkIOOBE(() -> {
+ float x = (float) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, 1.0f);
+ });
+
+ checkIOOBE(() -> {
+ float x = (float) vh.getOpaque(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, 1.0f);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, 1.0f, 2.0f);
+ });
+
+ checkIOOBE(() -> {
+ float r = (float) vh.compareAndExchange(array, ci, 2.0f, 1.0f);
+ });
+
+ checkIOOBE(() -> {
+ float r = (float) vh.compareAndExchangeAcquire(array, ci, 2.0f, 1.0f);
+ });
+
+ checkIOOBE(() -> {
+ float r = (float) vh.compareAndExchangeRelease(array, ci, 2.0f, 1.0f);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, 1.0f, 2.0f);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(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.getAndSetAcquire(array, ci, 1.0f);
+ });
+
+ checkIOOBE(() -> {
+ float o = (float) vh.getAndSetRelease(array, ci, 1.0f);
+ });
+
+ checkIOOBE(() -> {
+ float o = (float) vh.getAndAdd(array, ci, 1.0f);
+ });
+
+ checkIOOBE(() -> {
+ float o = (float) vh.getAndAddAcquire(array, ci, 1.0f);
+ });
+
+ checkIOOBE(() -> {
+ float o = (float) vh.getAndAddRelease(array, ci, 1.0f);
+ });
+
+ }
+ }
+
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessInt.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessInt.java
new file mode 100644
index 0000000..bfa7665
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessInt.java
@@ -0,0 +1,1297 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessInt
+ * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessInt
+ * @run testng/othervm -Diters=20000 VarHandleTestAccessInt
+ * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestAccessInt
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestAccessInt extends VarHandleBaseTest {
+ static final int static_final_v = 0x01234567;
+
+ static int static_v;
+
+ final int final_v = 0x01234567;
+
+ int v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessInt.class, "final_v", int.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessInt.class, "v", int.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessInt.class, "static_final_v", int.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessInt.class, "static_v", int.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(int[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] varHandlesProvider() throws Exception {
+ List<VarHandle> vhs = new ArrayList<>();
+ vhs.add(vhField);
+ vhs.add(vhStaticField);
+ vhs.add(vhArray);
+
+ return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "varHandlesProvider")
+ public void testIsAccessModeSupported(VarHandle vh) {
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+ }
+
+
+ @DataProvider
+ public Object[][] typesProvider() throws Exception {
+ List<Object[]> types = new ArrayList<>();
+ types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessInt.class)});
+ types.add(new Object[] {vhStaticField, Arrays.asList()});
+ types.add(new Object[] {vhArray, Arrays.asList(int[].class, int.class)});
+
+ return types.stream().toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "typesProvider")
+ public void testTypes(VarHandle vh, List<Class<?>> pts) {
+ assertEquals(vh.varType(), int.class);
+
+ assertEquals(vh.coordinateTypes(), pts);
+
+ testTypes(vh);
+ }
+
+
+ @Test
+ public void testLookupInstanceToStatic() {
+ checkIAE("Lookup of static final field to instance final field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessInt.class, "final_v", int.class);
+ });
+
+ checkIAE("Lookup of static field to instance field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessInt.class, "v", int.class);
+ });
+ }
+
+ @Test
+ public void testLookupStaticToInstance() {
+ checkIAE("Lookup of instance final field to static final field", () -> {
+ MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessInt.class, "static_final_v", int.class);
+ });
+
+ checkIAE("Lookup of instance field to static field", () -> {
+ vhStaticField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessInt.class, "static_v", int.class);
+ });
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance final field",
+ vhFinalField, vh -> testInstanceFinalField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
+ vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static final field",
+ vhStaticFinalField, VarHandleTestAccessInt::testStaticFinalField));
+ cases.add(new VarHandleAccessTestCase("Static final field unsupported",
+ vhStaticFinalField, VarHandleTestAccessInt::testStaticFinalFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance field unsupported",
+ vhField, vh -> testInstanceFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestAccessInt::testStaticField));
+ cases.add(new VarHandleAccessTestCase("Static field unsupported",
+ vhStaticField, VarHandleTestAccessInt::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestAccessInt::testArray));
+ cases.add(new VarHandleAccessTestCase("Array unsupported",
+ vhArray, VarHandleTestAccessInt::testArrayUnsupported,
+ false));
+ cases.add(new VarHandleAccessTestCase("Array index out of bounds",
+ vhArray, VarHandleTestAccessInt::testArrayIndexOutOfBounds,
+ false));
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+
+
+ static void testInstanceFinalField(VarHandleTestAccessInt recv, VarHandle vh) {
+ // Plain
+ {
+ int x = (int) vh.get(recv);
+ assertEquals(x, 0x01234567, "get int value");
+ }
+
+
+ // Volatile
+ {
+ int x = (int) vh.getVolatile(recv);
+ assertEquals(x, 0x01234567, "getVolatile int value");
+ }
+
+ // Lazy
+ {
+ int x = (int) vh.getAcquire(recv);
+ assertEquals(x, 0x01234567, "getRelease int value");
+ }
+
+ // Opaque
+ {
+ int x = (int) vh.getOpaque(recv);
+ assertEquals(x, 0x01234567, "getOpaque int value");
+ }
+ }
+
+ static void testInstanceFinalFieldUnsupported(VarHandleTestAccessInt recv, VarHandle vh) {
+ checkUOE(() -> {
+ vh.set(recv, 0x89ABCDEF);
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile(recv, 0x89ABCDEF);
+ });
+
+ checkUOE(() -> {
+ vh.setRelease(recv, 0x89ABCDEF);
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque(recv, 0x89ABCDEF);
+ });
+
+
+
+ }
+
+
+ static void testStaticFinalField(VarHandle vh) {
+ // Plain
+ {
+ int x = (int) vh.get();
+ assertEquals(x, 0x01234567, "get int value");
+ }
+
+
+ // Volatile
+ {
+ int x = (int) vh.getVolatile();
+ assertEquals(x, 0x01234567, "getVolatile int value");
+ }
+
+ // Lazy
+ {
+ int x = (int) vh.getAcquire();
+ assertEquals(x, 0x01234567, "getRelease int value");
+ }
+
+ // Opaque
+ {
+ int x = (int) vh.getOpaque();
+ assertEquals(x, 0x01234567, "getOpaque int value");
+ }
+ }
+
+ static void testStaticFinalFieldUnsupported(VarHandle vh) {
+ checkUOE(() -> {
+ vh.set(0x89ABCDEF);
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile(0x89ABCDEF);
+ });
+
+ checkUOE(() -> {
+ vh.setRelease(0x89ABCDEF);
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque(0x89ABCDEF);
+ });
+
+
+
+ }
+
+
+ static void testInstanceField(VarHandleTestAccessInt recv, VarHandle vh) {
+ // Plain
+ {
+ vh.set(recv, 0x01234567);
+ int x = (int) vh.get(recv);
+ assertEquals(x, 0x01234567, "set int value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(recv, 0x89ABCDEF);
+ int x = (int) vh.getVolatile(recv);
+ assertEquals(x, 0x89ABCDEF, "setVolatile int value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(recv, 0x01234567);
+ int x = (int) vh.getAcquire(recv);
+ assertEquals(x, 0x01234567, "setRelease int value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(recv, 0x89ABCDEF);
+ int x = (int) vh.getOpaque(recv);
+ assertEquals(x, 0x89ABCDEF, "setOpaque int value");
+ }
+
+ vh.set(recv, 0x01234567);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(recv, 0x01234567, 0x89ABCDEF);
+ assertEquals(r, true, "success compareAndSet int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, 0x89ABCDEF, "success compareAndSet int value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(recv, 0x01234567, 0xCAFEBABE);
+ assertEquals(r, false, "failing compareAndSet int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchange(recv, 0x89ABCDEF, 0x01234567);
+ assertEquals(r, 0x89ABCDEF, "success compareAndExchange int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, 0x01234567, "success compareAndExchange int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchange(recv, 0x89ABCDEF, 0xCAFEBABE);
+ assertEquals(r, 0x01234567, "failing compareAndExchange int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, 0x01234567, "failing compareAndExchange int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeAcquire(recv, 0x01234567, 0x89ABCDEF);
+ assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeAcquire(recv, 0x01234567, 0xCAFEBABE);
+ assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeRelease(recv, 0x89ABCDEF, 0x01234567);
+ assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeRelease(recv, 0x89ABCDEF, 0xCAFEBABE);
+ assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(recv, 0x01234567, 0x89ABCDEF);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, 0x89ABCDEF, "weakCompareAndSetPlain int value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(recv, 0x89ABCDEF, 0x01234567);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(recv, 0x01234567, 0x89ABCDEF);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(recv, 0x89ABCDEF, 0x01234567);
+ }
+ assertEquals(success, true, "weakCompareAndSet int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, 0x01234567, "weakCompareAndSet int value");
+ }
+
+ // Compare set and get
+ {
+ vh.set(recv, 0x01234567);
+
+ int o = (int) vh.getAndSet(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndSet int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, 0x89ABCDEF, "getAndSet int value");
+ }
+
+ {
+ vh.set(recv, 0x01234567);
+
+ int o = (int) vh.getAndSetAcquire(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndSetAcquire int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, 0x89ABCDEF, "getAndSetAcquire int value");
+ }
+
+ {
+ vh.set(recv, 0x01234567);
+
+ int o = (int) vh.getAndSetRelease(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndSetRelease int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, 0x89ABCDEF, "getAndSetRelease int value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(recv, 0x01234567);
+
+ int o = (int) vh.getAndAdd(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAdd int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAdd int value");
+ }
+
+ {
+ vh.set(recv, 0x01234567);
+
+ int o = (int) vh.getAndAddAcquire(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAddAcquire int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddAcquire int value");
+ }
+
+ {
+ vh.set(recv, 0x01234567);
+
+ int o = (int) vh.getAndAddRelease(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAddReleaseint");
+ int x = (int) vh.get(recv);
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddRelease int value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set(recv, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseOr(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOr int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOr int value");
+ }
+
+ {
+ vh.set(recv, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseOrAcquire(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOrAcquire int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrAcquire int value");
+ }
+
+ {
+ vh.set(recv, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseOrRelease(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOrRelease int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrRelease int value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(recv, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseAnd(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAnd int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAnd int value");
+ }
+
+ {
+ vh.set(recv, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseAndAcquire(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAndAcquire int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndAcquire int value");
+ }
+
+ {
+ vh.set(recv, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseAndRelease(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAndRelease int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndRelease int value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(recv, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseXor(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXor int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXor int value");
+ }
+
+ {
+ vh.set(recv, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseXorAcquire(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXorAcquire int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorAcquire int value");
+ }
+
+ {
+ vh.set(recv, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseXorRelease(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXorRelease int");
+ int x = (int) vh.get(recv);
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorRelease int value");
+ }
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestAccessInt recv, VarHandle vh) {
+
+
+ }
+
+
+ static void testStaticField(VarHandle vh) {
+ // Plain
+ {
+ vh.set(0x01234567);
+ int x = (int) vh.get();
+ assertEquals(x, 0x01234567, "set int value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(0x89ABCDEF);
+ int x = (int) vh.getVolatile();
+ assertEquals(x, 0x89ABCDEF, "setVolatile int value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(0x01234567);
+ int x = (int) vh.getAcquire();
+ assertEquals(x, 0x01234567, "setRelease int value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(0x89ABCDEF);
+ int x = (int) vh.getOpaque();
+ assertEquals(x, 0x89ABCDEF, "setOpaque int value");
+ }
+
+ vh.set(0x01234567);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(0x01234567, 0x89ABCDEF);
+ assertEquals(r, true, "success compareAndSet int");
+ int x = (int) vh.get();
+ assertEquals(x, 0x89ABCDEF, "success compareAndSet int value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(0x01234567, 0xCAFEBABE);
+ assertEquals(r, false, "failing compareAndSet int");
+ int x = (int) vh.get();
+ assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchange(0x89ABCDEF, 0x01234567);
+ assertEquals(r, 0x89ABCDEF, "success compareAndExchange int");
+ int x = (int) vh.get();
+ assertEquals(x, 0x01234567, "success compareAndExchange int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchange(0x89ABCDEF, 0xCAFEBABE);
+ assertEquals(r, 0x01234567, "failing compareAndExchange int");
+ int x = (int) vh.get();
+ assertEquals(x, 0x01234567, "failing compareAndExchange int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeAcquire(0x01234567, 0x89ABCDEF);
+ assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int");
+ int x = (int) vh.get();
+ assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeAcquire(0x01234567, 0xCAFEBABE);
+ assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int");
+ int x = (int) vh.get();
+ assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeRelease(0x89ABCDEF, 0x01234567);
+ assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int");
+ int x = (int) vh.get();
+ assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeRelease(0x89ABCDEF, 0xCAFEBABE);
+ assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int");
+ int x = (int) vh.get();
+ assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(0x01234567, 0x89ABCDEF);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain int");
+ int x = (int) vh.get();
+ assertEquals(x, 0x89ABCDEF, "weakCompareAndSetPlain int value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(0x89ABCDEF, 0x01234567);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire int");
+ int x = (int) vh.get();
+ assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(0x01234567, 0x89ABCDEF);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease int");
+ int x = (int) vh.get();
+ assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(0x89ABCDEF, 0x01234567);
+ }
+ assertEquals(success, true, "weakCompareAndSet int");
+ int x = (int) vh.get();
+ assertEquals(x, 0x01234567, "weakCompareAndSet int");
+ }
+
+ // Compare set and get
+ {
+ vh.set(0x01234567);
+
+ int o = (int) vh.getAndSet(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndSet int");
+ int x = (int) vh.get();
+ assertEquals(x, 0x89ABCDEF, "getAndSet int value");
+ }
+
+ {
+ vh.set(0x01234567);
+
+ int o = (int) vh.getAndSetAcquire(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndSetAcquire int");
+ int x = (int) vh.get();
+ assertEquals(x, 0x89ABCDEF, "getAndSetAcquire int value");
+ }
+
+ {
+ vh.set(0x01234567);
+
+ int o = (int) vh.getAndSetRelease(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndSetRelease int");
+ int x = (int) vh.get();
+ assertEquals(x, 0x89ABCDEF, "getAndSetRelease int value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(0x01234567);
+
+ int o = (int) vh.getAndAdd(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAdd int");
+ int x = (int) vh.get();
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAdd int value");
+ }
+
+ {
+ vh.set(0x01234567);
+
+ int o = (int) vh.getAndAddAcquire(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAddAcquire int");
+ int x = (int) vh.get();
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddAcquire int value");
+ }
+
+ {
+ vh.set(0x01234567);
+
+ int o = (int) vh.getAndAddRelease(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAddReleaseint");
+ int x = (int) vh.get();
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddRelease int value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set(0x01234567);
+
+ int o = (int) vh.getAndBitwiseOr(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOr int");
+ int x = (int) vh.get();
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOr int value");
+ }
+
+ {
+ vh.set(0x01234567);
+
+ int o = (int) vh.getAndBitwiseOrAcquire(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOrAcquire int");
+ int x = (int) vh.get();
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrAcquire int value");
+ }
+
+ {
+ vh.set(0x01234567);
+
+ int o = (int) vh.getAndBitwiseOrRelease(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOrRelease int");
+ int x = (int) vh.get();
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrRelease int value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(0x01234567);
+
+ int o = (int) vh.getAndBitwiseAnd(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAnd int");
+ int x = (int) vh.get();
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAnd int value");
+ }
+
+ {
+ vh.set(0x01234567);
+
+ int o = (int) vh.getAndBitwiseAndAcquire(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAndAcquire int");
+ int x = (int) vh.get();
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndAcquire int value");
+ }
+
+ {
+ vh.set(0x01234567);
+
+ int o = (int) vh.getAndBitwiseAndRelease(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAndRelease int");
+ int x = (int) vh.get();
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndRelease int value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(0x01234567);
+
+ int o = (int) vh.getAndBitwiseXor(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXor int");
+ int x = (int) vh.get();
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXor int value");
+ }
+
+ {
+ vh.set(0x01234567);
+
+ int o = (int) vh.getAndBitwiseXorAcquire(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXorAcquire int");
+ int x = (int) vh.get();
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorAcquire int value");
+ }
+
+ {
+ vh.set(0x01234567);
+
+ int o = (int) vh.getAndBitwiseXorRelease(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXorRelease int");
+ int x = (int) vh.get();
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorRelease int value");
+ }
+ }
+
+ static void testStaticFieldUnsupported(VarHandle vh) {
+
+
+ }
+
+
+ static void testArray(VarHandle vh) {
+ int[] array = new int[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ vh.set(array, i, 0x01234567);
+ int x = (int) vh.get(array, i);
+ assertEquals(x, 0x01234567, "get int value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(array, i, 0x89ABCDEF);
+ int x = (int) vh.getVolatile(array, i);
+ assertEquals(x, 0x89ABCDEF, "setVolatile int value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, 0x01234567);
+ int x = (int) vh.getAcquire(array, i);
+ assertEquals(x, 0x01234567, "setRelease int value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, 0x89ABCDEF);
+ int x = (int) vh.getOpaque(array, i);
+ assertEquals(x, 0x89ABCDEF, "setOpaque int value");
+ }
+
+ vh.set(array, i, 0x01234567);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, 0x01234567, 0x89ABCDEF);
+ assertEquals(r, true, "success compareAndSet int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, 0x89ABCDEF, "success compareAndSet int value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, 0x01234567, 0xCAFEBABE);
+ assertEquals(r, false, "failing compareAndSet int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchange(array, i, 0x89ABCDEF, 0x01234567);
+ assertEquals(r, 0x89ABCDEF, "success compareAndExchange int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, 0x01234567, "success compareAndExchange int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchange(array, i, 0x89ABCDEF, 0xCAFEBABE);
+ assertEquals(r, 0x01234567, "failing compareAndExchange int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, 0x01234567, "failing compareAndExchange int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeAcquire(array, i, 0x01234567, 0x89ABCDEF);
+ assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeAcquire(array, i, 0x01234567, 0xCAFEBABE);
+ assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeRelease(array, i, 0x89ABCDEF, 0x01234567);
+ assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeRelease(array, i, 0x89ABCDEF, 0xCAFEBABE);
+ assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, 0x01234567, 0x89ABCDEF);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, 0x89ABCDEF, "weakCompareAndSetPlain int value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, 0x89ABCDEF, 0x01234567);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, 0x01234567, 0x89ABCDEF);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, 0x89ABCDEF, 0x01234567);
+ }
+ assertEquals(success, true, "weakCompareAndSet int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, 0x01234567, "weakCompareAndSet int");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, 0x01234567);
+
+ int o = (int) vh.getAndSet(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndSet int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, 0x89ABCDEF, "getAndSet int value");
+ }
+
+ {
+ vh.set(array, i, 0x01234567);
+
+ int o = (int) vh.getAndSetAcquire(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndSetAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, 0x89ABCDEF, "getAndSetAcquire int value");
+ }
+
+ {
+ vh.set(array, i, 0x01234567);
+
+ int o = (int) vh.getAndSetRelease(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndSetRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, 0x89ABCDEF, "getAndSetRelease int value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(array, i, 0x01234567);
+
+ int o = (int) vh.getAndAdd(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAdd int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAdd int value");
+ }
+
+ {
+ vh.set(array, i, 0x01234567);
+
+ int o = (int) vh.getAndAddAcquire(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAddAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddAcquire int value");
+ }
+
+ {
+ vh.set(array, i, 0x01234567);
+
+ int o = (int) vh.getAndAddRelease(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAddReleaseint");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddRelease int value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set(array, i, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseOr(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOr int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOr int value");
+ }
+
+ {
+ vh.set(array, i, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseOrAcquire(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOrAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrAcquire int value");
+ }
+
+ {
+ vh.set(array, i, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseOrRelease(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOrRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrRelease int value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(array, i, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseAnd(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAnd int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAnd int value");
+ }
+
+ {
+ vh.set(array, i, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseAndAcquire(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAndAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndAcquire int value");
+ }
+
+ {
+ vh.set(array, i, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseAndRelease(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAndRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndRelease int value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(array, i, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseXor(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXor int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXor int value");
+ }
+
+ {
+ vh.set(array, i, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseXorAcquire(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXorAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorAcquire int value");
+ }
+
+ {
+ vh.set(array, i, 0x01234567);
+
+ int o = (int) vh.getAndBitwiseXorRelease(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXorRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorRelease int value");
+ }
+ }
+ }
+
+ static void testArrayUnsupported(VarHandle vh) {
+ int[] array = new int[10];
+
+ int i = 0;
+
+
+ }
+
+ static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
+ int[] array = new int[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ int x = (int) vh.get(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.set(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int x = (int) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int x = (int) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int x = (int) vh.getOpaque(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, 0x01234567, 0x89ABCDEF);
+ });
+
+ checkIOOBE(() -> {
+ int r = (int) vh.compareAndExchange(array, ci, 0x89ABCDEF, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int r = (int) vh.compareAndExchangeAcquire(array, ci, 0x89ABCDEF, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int r = (int) vh.compareAndExchangeRelease(array, ci, 0x89ABCDEF, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, 0x01234567, 0x89ABCDEF);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, 0x01234567, 0x89ABCDEF);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, 0x01234567, 0x89ABCDEF);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, 0x01234567, 0x89ABCDEF);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndSet(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndSetAcquire(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndSetRelease(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndAdd(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndAddAcquire(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndAddRelease(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseOr(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseOrAcquire(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseOrRelease(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseAnd(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseAndAcquire(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseAndRelease(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseXor(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseXorAcquire(array, ci, 0x01234567);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseXorRelease(array, ci, 0x01234567);
+ });
+ }
+ }
+
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessLong.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessLong.java
new file mode 100644
index 0000000..6d94859
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessLong.java
@@ -0,0 +1,1297 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessLong
+ * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessLong
+ * @run testng/othervm -Diters=20000 VarHandleTestAccessLong
+ * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestAccessLong
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestAccessLong extends VarHandleBaseTest {
+ static final long static_final_v = 0x0123456789ABCDEFL;
+
+ static long static_v;
+
+ final long final_v = 0x0123456789ABCDEFL;
+
+ long v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessLong.class, "final_v", long.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessLong.class, "v", long.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessLong.class, "static_final_v", long.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessLong.class, "static_v", long.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(long[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] varHandlesProvider() throws Exception {
+ List<VarHandle> vhs = new ArrayList<>();
+ vhs.add(vhField);
+ vhs.add(vhStaticField);
+ vhs.add(vhArray);
+
+ return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "varHandlesProvider")
+ public void testIsAccessModeSupported(VarHandle vh) {
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+ }
+
+
+ @DataProvider
+ public Object[][] typesProvider() throws Exception {
+ List<Object[]> types = new ArrayList<>();
+ types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessLong.class)});
+ types.add(new Object[] {vhStaticField, Arrays.asList()});
+ types.add(new Object[] {vhArray, Arrays.asList(long[].class, int.class)});
+
+ return types.stream().toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "typesProvider")
+ public void testTypes(VarHandle vh, List<Class<?>> pts) {
+ assertEquals(vh.varType(), long.class);
+
+ assertEquals(vh.coordinateTypes(), pts);
+
+ testTypes(vh);
+ }
+
+
+ @Test
+ public void testLookupInstanceToStatic() {
+ checkIAE("Lookup of static final field to instance final field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessLong.class, "final_v", long.class);
+ });
+
+ checkIAE("Lookup of static field to instance field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessLong.class, "v", long.class);
+ });
+ }
+
+ @Test
+ public void testLookupStaticToInstance() {
+ checkIAE("Lookup of instance final field to static final field", () -> {
+ MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessLong.class, "static_final_v", long.class);
+ });
+
+ checkIAE("Lookup of instance field to static field", () -> {
+ vhStaticField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessLong.class, "static_v", long.class);
+ });
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance final field",
+ vhFinalField, vh -> testInstanceFinalField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
+ vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static final field",
+ vhStaticFinalField, VarHandleTestAccessLong::testStaticFinalField));
+ cases.add(new VarHandleAccessTestCase("Static final field unsupported",
+ vhStaticFinalField, VarHandleTestAccessLong::testStaticFinalFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance field unsupported",
+ vhField, vh -> testInstanceFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestAccessLong::testStaticField));
+ cases.add(new VarHandleAccessTestCase("Static field unsupported",
+ vhStaticField, VarHandleTestAccessLong::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestAccessLong::testArray));
+ cases.add(new VarHandleAccessTestCase("Array unsupported",
+ vhArray, VarHandleTestAccessLong::testArrayUnsupported,
+ false));
+ cases.add(new VarHandleAccessTestCase("Array index out of bounds",
+ vhArray, VarHandleTestAccessLong::testArrayIndexOutOfBounds,
+ false));
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+
+
+ static void testInstanceFinalField(VarHandleTestAccessLong recv, VarHandle vh) {
+ // Plain
+ {
+ long x = (long) vh.get(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "get long value");
+ }
+
+
+ // Volatile
+ {
+ long x = (long) vh.getVolatile(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "getVolatile long value");
+ }
+
+ // Lazy
+ {
+ long x = (long) vh.getAcquire(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "getRelease long value");
+ }
+
+ // Opaque
+ {
+ long x = (long) vh.getOpaque(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "getOpaque long value");
+ }
+ }
+
+ static void testInstanceFinalFieldUnsupported(VarHandleTestAccessLong recv, VarHandle vh) {
+ checkUOE(() -> {
+ vh.set(recv, 0xCAFEBABECAFEBABEL);
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile(recv, 0xCAFEBABECAFEBABEL);
+ });
+
+ checkUOE(() -> {
+ vh.setRelease(recv, 0xCAFEBABECAFEBABEL);
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque(recv, 0xCAFEBABECAFEBABEL);
+ });
+
+
+
+ }
+
+
+ static void testStaticFinalField(VarHandle vh) {
+ // Plain
+ {
+ long x = (long) vh.get();
+ assertEquals(x, 0x0123456789ABCDEFL, "get long value");
+ }
+
+
+ // Volatile
+ {
+ long x = (long) vh.getVolatile();
+ assertEquals(x, 0x0123456789ABCDEFL, "getVolatile long value");
+ }
+
+ // Lazy
+ {
+ long x = (long) vh.getAcquire();
+ assertEquals(x, 0x0123456789ABCDEFL, "getRelease long value");
+ }
+
+ // Opaque
+ {
+ long x = (long) vh.getOpaque();
+ assertEquals(x, 0x0123456789ABCDEFL, "getOpaque long value");
+ }
+ }
+
+ static void testStaticFinalFieldUnsupported(VarHandle vh) {
+ checkUOE(() -> {
+ vh.set(0xCAFEBABECAFEBABEL);
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile(0xCAFEBABECAFEBABEL);
+ });
+
+ checkUOE(() -> {
+ vh.setRelease(0xCAFEBABECAFEBABEL);
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque(0xCAFEBABECAFEBABEL);
+ });
+
+
+
+ }
+
+
+ static void testInstanceField(VarHandleTestAccessLong recv, VarHandle vh) {
+ // Plain
+ {
+ vh.set(recv, 0x0123456789ABCDEFL);
+ long x = (long) vh.get(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "set long value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(recv, 0xCAFEBABECAFEBABEL);
+ long x = (long) vh.getVolatile(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(recv, 0x0123456789ABCDEFL);
+ long x = (long) vh.getAcquire(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(recv, 0xCAFEBABECAFEBABEL);
+ long x = (long) vh.getOpaque(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
+ }
+
+ vh.set(recv, 0x0123456789ABCDEFL);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ assertEquals(r, true, "success compareAndSet long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, false, "failing compareAndSet long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchange(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchange(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeAcquire(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeAcquire(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeRelease(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeRelease(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetPlain long value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ }
+ assertEquals(success, true, "weakCompareAndSet long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSet long value");
+ }
+
+ // Compare set and get
+ {
+ vh.set(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndSet(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
+ }
+
+ {
+ vh.set(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndSetAcquire(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndSetAcquire long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetAcquire long value");
+ }
+
+ {
+ vh.set(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndSetRelease(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndSetRelease long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetRelease long value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndAdd(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value");
+ }
+
+ {
+ vh.set(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndAddAcquire(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value");
+ }
+
+ {
+ vh.set(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndAddRelease(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAddReleaselong");
+ long x = (long) vh.get(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseOr(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value");
+ }
+
+ {
+ vh.set(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseOrAcquire(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value");
+ }
+
+ {
+ vh.set(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseOrRelease(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseAnd(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value");
+ }
+
+ {
+ vh.set(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseAndAcquire(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value");
+ }
+
+ {
+ vh.set(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseAndRelease(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseXor(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value");
+ }
+
+ {
+ vh.set(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseXorAcquire(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value");
+ }
+
+ {
+ vh.set(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseXorRelease(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long");
+ long x = (long) vh.get(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value");
+ }
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestAccessLong recv, VarHandle vh) {
+
+
+ }
+
+
+ static void testStaticField(VarHandle vh) {
+ // Plain
+ {
+ vh.set(0x0123456789ABCDEFL);
+ long x = (long) vh.get();
+ assertEquals(x, 0x0123456789ABCDEFL, "set long value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(0xCAFEBABECAFEBABEL);
+ long x = (long) vh.getVolatile();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(0x0123456789ABCDEFL);
+ long x = (long) vh.getAcquire();
+ assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(0xCAFEBABECAFEBABEL);
+ long x = (long) vh.getOpaque();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
+ }
+
+ vh.set(0x0123456789ABCDEFL);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ assertEquals(r, true, "success compareAndSet long");
+ long x = (long) vh.get();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, false, "failing compareAndSet long");
+ long x = (long) vh.get();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchange(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
+ long x = (long) vh.get();
+ assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchange(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
+ long x = (long) vh.get();
+ assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeAcquire(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
+ long x = (long) vh.get();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeAcquire(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
+ long x = (long) vh.get();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeRelease(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
+ long x = (long) vh.get();
+ assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeRelease(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
+ long x = (long) vh.get();
+ assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain long");
+ long x = (long) vh.get();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetPlain long value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire long");
+ long x = (long) vh.get();
+ assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease long");
+ long x = (long) vh.get();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ }
+ assertEquals(success, true, "weakCompareAndSet long");
+ long x = (long) vh.get();
+ assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSet long");
+ }
+
+ // Compare set and get
+ {
+ vh.set(0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndSet(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
+ long x = (long) vh.get();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
+ }
+
+ {
+ vh.set(0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndSetAcquire(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndSetAcquire long");
+ long x = (long) vh.get();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetAcquire long value");
+ }
+
+ {
+ vh.set(0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndSetRelease(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndSetRelease long");
+ long x = (long) vh.get();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetRelease long value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndAdd(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
+ long x = (long) vh.get();
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value");
+ }
+
+ {
+ vh.set(0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndAddAcquire(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long");
+ long x = (long) vh.get();
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value");
+ }
+
+ {
+ vh.set(0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndAddRelease(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAddReleaselong");
+ long x = (long) vh.get();
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set(0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseOr(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long");
+ long x = (long) vh.get();
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value");
+ }
+
+ {
+ vh.set(0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseOrAcquire(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long");
+ long x = (long) vh.get();
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value");
+ }
+
+ {
+ vh.set(0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseOrRelease(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long");
+ long x = (long) vh.get();
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseAnd(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long");
+ long x = (long) vh.get();
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value");
+ }
+
+ {
+ vh.set(0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseAndAcquire(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long");
+ long x = (long) vh.get();
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value");
+ }
+
+ {
+ vh.set(0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseAndRelease(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long");
+ long x = (long) vh.get();
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseXor(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long");
+ long x = (long) vh.get();
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value");
+ }
+
+ {
+ vh.set(0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseXorAcquire(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long");
+ long x = (long) vh.get();
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value");
+ }
+
+ {
+ vh.set(0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseXorRelease(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long");
+ long x = (long) vh.get();
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value");
+ }
+ }
+
+ static void testStaticFieldUnsupported(VarHandle vh) {
+
+
+ }
+
+
+ static void testArray(VarHandle vh) {
+ long[] array = new long[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ vh.set(array, i, 0x0123456789ABCDEFL);
+ long x = (long) vh.get(array, i);
+ assertEquals(x, 0x0123456789ABCDEFL, "get long value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(array, i, 0xCAFEBABECAFEBABEL);
+ long x = (long) vh.getVolatile(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, 0x0123456789ABCDEFL);
+ long x = (long) vh.getAcquire(array, i);
+ assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, 0xCAFEBABECAFEBABEL);
+ long x = (long) vh.getOpaque(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
+ }
+
+ vh.set(array, i, 0x0123456789ABCDEFL);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ assertEquals(r, true, "success compareAndSet long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, false, "failing compareAndSet long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchange(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchange(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeAcquire(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeAcquire(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeRelease(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeRelease(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetPlain long value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ }
+ assertEquals(success, true, "weakCompareAndSet long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSet long");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndSet(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
+ }
+
+ {
+ vh.set(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndSetAcquire(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndSetAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetAcquire long value");
+ }
+
+ {
+ vh.set(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndSetRelease(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndSetRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetRelease long value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndAdd(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value");
+ }
+
+ {
+ vh.set(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndAddAcquire(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value");
+ }
+
+ {
+ vh.set(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndAddRelease(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAddReleaselong");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseOr(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value");
+ }
+
+ {
+ vh.set(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseOrAcquire(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value");
+ }
+
+ {
+ vh.set(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseOrRelease(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseAnd(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value");
+ }
+
+ {
+ vh.set(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseAndAcquire(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value");
+ }
+
+ {
+ vh.set(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseAndRelease(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseXor(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value");
+ }
+
+ {
+ vh.set(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseXorAcquire(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value");
+ }
+
+ {
+ vh.set(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) vh.getAndBitwiseXorRelease(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value");
+ }
+ }
+ }
+
+ static void testArrayUnsupported(VarHandle vh) {
+ long[] array = new long[10];
+
+ int i = 0;
+
+
+ }
+
+ static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
+ long[] array = new long[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ long x = (long) vh.get(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.set(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long x = (long) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long x = (long) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long x = (long) vh.getOpaque(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ });
+
+ checkIOOBE(() -> {
+ long r = (long) vh.compareAndExchange(array, ci, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long r = (long) vh.compareAndExchangeAcquire(array, ci, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long r = (long) vh.compareAndExchangeRelease(array, ci, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndSet(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndSetAcquire(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndSetRelease(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndAdd(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndAddAcquire(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndAddRelease(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseOr(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseOrAcquire(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseOrRelease(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseAnd(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseAndAcquire(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseAndRelease(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseXor(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseXorAcquire(array, ci, 0x0123456789ABCDEFL);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseXorRelease(array, ci, 0x0123456789ABCDEFL);
+ });
+ }
+ }
+
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessModeMethodNames.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessModeMethodNames.java
index fda5277..d28ada5 100644
--- a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessModeMethodNames.java
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessModeMethodNames.java
@@ -21,12 +21,10 @@
* questions.
*/
-// Android-added: package name
-package test.java.lang.invoke.VarHandles;
-
/*
* @test
* @run testng VarHandleTestAccessModeMethodNames
+ * @modules java.base/java.lang.invoke:open
*/
import org.testng.annotations.DataProvider;
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessShort.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessShort.java
new file mode 100644
index 0000000..088de60
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessShort.java
@@ -0,0 +1,1297 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessShort
+ * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessShort
+ * @run testng/othervm -Diters=20000 VarHandleTestAccessShort
+ * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestAccessShort
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestAccessShort extends VarHandleBaseTest {
+ static final short static_final_v = (short)0x0123;
+
+ static short static_v;
+
+ final short final_v = (short)0x0123;
+
+ short v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessShort.class, "final_v", short.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessShort.class, "v", short.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessShort.class, "static_final_v", short.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessShort.class, "static_v", short.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(short[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] varHandlesProvider() throws Exception {
+ List<VarHandle> vhs = new ArrayList<>();
+ vhs.add(vhField);
+ vhs.add(vhStaticField);
+ vhs.add(vhArray);
+
+ return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "varHandlesProvider")
+ public void testIsAccessModeSupported(VarHandle vh) {
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+ }
+
+
+ @DataProvider
+ public Object[][] typesProvider() throws Exception {
+ List<Object[]> types = new ArrayList<>();
+ types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessShort.class)});
+ types.add(new Object[] {vhStaticField, Arrays.asList()});
+ types.add(new Object[] {vhArray, Arrays.asList(short[].class, int.class)});
+
+ return types.stream().toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "typesProvider")
+ public void testTypes(VarHandle vh, List<Class<?>> pts) {
+ assertEquals(vh.varType(), short.class);
+
+ assertEquals(vh.coordinateTypes(), pts);
+
+ testTypes(vh);
+ }
+
+
+ @Test
+ public void testLookupInstanceToStatic() {
+ checkIAE("Lookup of static final field to instance final field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessShort.class, "final_v", short.class);
+ });
+
+ checkIAE("Lookup of static field to instance field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessShort.class, "v", short.class);
+ });
+ }
+
+ @Test
+ public void testLookupStaticToInstance() {
+ checkIAE("Lookup of instance final field to static final field", () -> {
+ MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessShort.class, "static_final_v", short.class);
+ });
+
+ checkIAE("Lookup of instance field to static field", () -> {
+ vhStaticField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessShort.class, "static_v", short.class);
+ });
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance final field",
+ vhFinalField, vh -> testInstanceFinalField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
+ vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static final field",
+ vhStaticFinalField, VarHandleTestAccessShort::testStaticFinalField));
+ cases.add(new VarHandleAccessTestCase("Static final field unsupported",
+ vhStaticFinalField, VarHandleTestAccessShort::testStaticFinalFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance field unsupported",
+ vhField, vh -> testInstanceFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestAccessShort::testStaticField));
+ cases.add(new VarHandleAccessTestCase("Static field unsupported",
+ vhStaticField, VarHandleTestAccessShort::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestAccessShort::testArray));
+ cases.add(new VarHandleAccessTestCase("Array unsupported",
+ vhArray, VarHandleTestAccessShort::testArrayUnsupported,
+ false));
+ cases.add(new VarHandleAccessTestCase("Array index out of bounds",
+ vhArray, VarHandleTestAccessShort::testArrayIndexOutOfBounds,
+ false));
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+
+
+ static void testInstanceFinalField(VarHandleTestAccessShort recv, VarHandle vh) {
+ // Plain
+ {
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)0x0123, "get short value");
+ }
+
+
+ // Volatile
+ {
+ short x = (short) vh.getVolatile(recv);
+ assertEquals(x, (short)0x0123, "getVolatile short value");
+ }
+
+ // Lazy
+ {
+ short x = (short) vh.getAcquire(recv);
+ assertEquals(x, (short)0x0123, "getRelease short value");
+ }
+
+ // Opaque
+ {
+ short x = (short) vh.getOpaque(recv);
+ assertEquals(x, (short)0x0123, "getOpaque short value");
+ }
+ }
+
+ static void testInstanceFinalFieldUnsupported(VarHandleTestAccessShort recv, VarHandle vh) {
+ checkUOE(() -> {
+ vh.set(recv, (short)0x4567);
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile(recv, (short)0x4567);
+ });
+
+ checkUOE(() -> {
+ vh.setRelease(recv, (short)0x4567);
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque(recv, (short)0x4567);
+ });
+
+
+
+ }
+
+
+ static void testStaticFinalField(VarHandle vh) {
+ // Plain
+ {
+ short x = (short) vh.get();
+ assertEquals(x, (short)0x0123, "get short value");
+ }
+
+
+ // Volatile
+ {
+ short x = (short) vh.getVolatile();
+ assertEquals(x, (short)0x0123, "getVolatile short value");
+ }
+
+ // Lazy
+ {
+ short x = (short) vh.getAcquire();
+ assertEquals(x, (short)0x0123, "getRelease short value");
+ }
+
+ // Opaque
+ {
+ short x = (short) vh.getOpaque();
+ assertEquals(x, (short)0x0123, "getOpaque short value");
+ }
+ }
+
+ static void testStaticFinalFieldUnsupported(VarHandle vh) {
+ checkUOE(() -> {
+ vh.set((short)0x4567);
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile((short)0x4567);
+ });
+
+ checkUOE(() -> {
+ vh.setRelease((short)0x4567);
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque((short)0x4567);
+ });
+
+
+
+ }
+
+
+ static void testInstanceField(VarHandleTestAccessShort recv, VarHandle vh) {
+ // Plain
+ {
+ vh.set(recv, (short)0x0123);
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)0x0123, "set short value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(recv, (short)0x4567);
+ short x = (short) vh.getVolatile(recv);
+ assertEquals(x, (short)0x4567, "setVolatile short value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(recv, (short)0x0123);
+ short x = (short) vh.getAcquire(recv);
+ assertEquals(x, (short)0x0123, "setRelease short value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(recv, (short)0x4567);
+ short x = (short) vh.getOpaque(recv);
+ assertEquals(x, (short)0x4567, "setOpaque short value");
+ }
+
+ vh.set(recv, (short)0x0123);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(recv, (short)0x0123, (short)0x4567);
+ assertEquals(r, true, "success compareAndSet short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)0x4567, "success compareAndSet short value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(recv, (short)0x0123, (short)0x89AB);
+ assertEquals(r, false, "failing compareAndSet short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)0x4567, "failing compareAndSet short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchange(recv, (short)0x4567, (short)0x0123);
+ assertEquals(r, (short)0x4567, "success compareAndExchange short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)0x0123, "success compareAndExchange short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchange(recv, (short)0x4567, (short)0x89AB);
+ assertEquals(r, (short)0x0123, "failing compareAndExchange short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)0x0123, "failing compareAndExchange short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchangeAcquire(recv, (short)0x0123, (short)0x4567);
+ assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchangeAcquire(recv, (short)0x0123, (short)0x89AB);
+ assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchangeRelease(recv, (short)0x4567, (short)0x0123);
+ assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchangeRelease(recv, (short)0x4567, (short)0x89AB);
+ assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(recv, (short)0x0123, (short)0x4567);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)0x4567, "weakCompareAndSetPlain short value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(recv, (short)0x4567, (short)0x0123);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)0x0123, "weakCompareAndSetAcquire short");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(recv, (short)0x0123, (short)0x4567);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)0x4567, "weakCompareAndSetRelease short");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(recv, (short)0x4567, (short)0x0123);
+ }
+ assertEquals(success, true, "weakCompareAndSet short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)0x0123, "weakCompareAndSet short value");
+ }
+
+ // Compare set and get
+ {
+ vh.set(recv, (short)0x0123);
+
+ short o = (short) vh.getAndSet(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndSet short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)0x4567, "getAndSet short value");
+ }
+
+ {
+ vh.set(recv, (short)0x0123);
+
+ short o = (short) vh.getAndSetAcquire(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndSetAcquire short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)0x4567, "getAndSetAcquire short value");
+ }
+
+ {
+ vh.set(recv, (short)0x0123);
+
+ short o = (short) vh.getAndSetRelease(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndSetRelease short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)0x4567, "getAndSetRelease short value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(recv, (short)0x0123);
+
+ short o = (short) vh.getAndAdd(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAdd short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value");
+ }
+
+ {
+ vh.set(recv, (short)0x0123);
+
+ short o = (short) vh.getAndAddAcquire(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAddAcquire short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value");
+ }
+
+ {
+ vh.set(recv, (short)0x0123);
+
+ short o = (short) vh.getAndAddRelease(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAddReleaseshort");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set(recv, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseOr(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOr short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value");
+ }
+
+ {
+ vh.set(recv, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseOrAcquire(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value");
+ }
+
+ {
+ vh.set(recv, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseOrRelease(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(recv, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseAnd(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAnd short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value");
+ }
+
+ {
+ vh.set(recv, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseAndAcquire(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value");
+ }
+
+ {
+ vh.set(recv, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseAndRelease(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(recv, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseXor(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXor short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value");
+ }
+
+ {
+ vh.set(recv, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseXorAcquire(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value");
+ }
+
+ {
+ vh.set(recv, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseXorRelease(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short");
+ short x = (short) vh.get(recv);
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short value");
+ }
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestAccessShort recv, VarHandle vh) {
+
+
+ }
+
+
+ static void testStaticField(VarHandle vh) {
+ // Plain
+ {
+ vh.set((short)0x0123);
+ short x = (short) vh.get();
+ assertEquals(x, (short)0x0123, "set short value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile((short)0x4567);
+ short x = (short) vh.getVolatile();
+ assertEquals(x, (short)0x4567, "setVolatile short value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease((short)0x0123);
+ short x = (short) vh.getAcquire();
+ assertEquals(x, (short)0x0123, "setRelease short value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque((short)0x4567);
+ short x = (short) vh.getOpaque();
+ assertEquals(x, (short)0x4567, "setOpaque short value");
+ }
+
+ vh.set((short)0x0123);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet((short)0x0123, (short)0x4567);
+ assertEquals(r, true, "success compareAndSet short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)0x4567, "success compareAndSet short value");
+ }
+
+ {
+ boolean r = vh.compareAndSet((short)0x0123, (short)0x89AB);
+ assertEquals(r, false, "failing compareAndSet short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)0x4567, "failing compareAndSet short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchange((short)0x4567, (short)0x0123);
+ assertEquals(r, (short)0x4567, "success compareAndExchange short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)0x0123, "success compareAndExchange short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchange((short)0x4567, (short)0x89AB);
+ assertEquals(r, (short)0x0123, "failing compareAndExchange short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)0x0123, "failing compareAndExchange short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchangeAcquire((short)0x0123, (short)0x4567);
+ assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchangeAcquire((short)0x0123, (short)0x89AB);
+ assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchangeRelease((short)0x4567, (short)0x0123);
+ assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchangeRelease((short)0x4567, (short)0x89AB);
+ assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain((short)0x0123, (short)0x4567);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)0x4567, "weakCompareAndSetPlain short value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire((short)0x4567, (short)0x0123);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)0x0123, "weakCompareAndSetAcquire short");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease((short)0x0123, (short)0x4567);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)0x4567, "weakCompareAndSetRelease short");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet((short)0x4567, (short)0x0123);
+ }
+ assertEquals(success, true, "weakCompareAndSet short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)0x0123, "weakCompareAndSet short");
+ }
+
+ // Compare set and get
+ {
+ vh.set((short)0x0123);
+
+ short o = (short) vh.getAndSet((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndSet short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)0x4567, "getAndSet short value");
+ }
+
+ {
+ vh.set((short)0x0123);
+
+ short o = (short) vh.getAndSetAcquire((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndSetAcquire short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)0x4567, "getAndSetAcquire short value");
+ }
+
+ {
+ vh.set((short)0x0123);
+
+ short o = (short) vh.getAndSetRelease((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndSetRelease short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)0x4567, "getAndSetRelease short value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set((short)0x0123);
+
+ short o = (short) vh.getAndAdd((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAdd short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value");
+ }
+
+ {
+ vh.set((short)0x0123);
+
+ short o = (short) vh.getAndAddAcquire((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAddAcquire short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value");
+ }
+
+ {
+ vh.set((short)0x0123);
+
+ short o = (short) vh.getAndAddRelease((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAddReleaseshort");
+ short x = (short) vh.get();
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set((short)0x0123);
+
+ short o = (short) vh.getAndBitwiseOr((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOr short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value");
+ }
+
+ {
+ vh.set((short)0x0123);
+
+ short o = (short) vh.getAndBitwiseOrAcquire((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value");
+ }
+
+ {
+ vh.set((short)0x0123);
+
+ short o = (short) vh.getAndBitwiseOrRelease((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set((short)0x0123);
+
+ short o = (short) vh.getAndBitwiseAnd((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAnd short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value");
+ }
+
+ {
+ vh.set((short)0x0123);
+
+ short o = (short) vh.getAndBitwiseAndAcquire((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value");
+ }
+
+ {
+ vh.set((short)0x0123);
+
+ short o = (short) vh.getAndBitwiseAndRelease((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set((short)0x0123);
+
+ short o = (short) vh.getAndBitwiseXor((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXor short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value");
+ }
+
+ {
+ vh.set((short)0x0123);
+
+ short o = (short) vh.getAndBitwiseXorAcquire((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value");
+ }
+
+ {
+ vh.set((short)0x0123);
+
+ short o = (short) vh.getAndBitwiseXorRelease((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short");
+ short x = (short) vh.get();
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short value");
+ }
+ }
+
+ static void testStaticFieldUnsupported(VarHandle vh) {
+
+
+ }
+
+
+ static void testArray(VarHandle vh) {
+ short[] array = new short[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ vh.set(array, i, (short)0x0123);
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)0x0123, "get short value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(array, i, (short)0x4567);
+ short x = (short) vh.getVolatile(array, i);
+ assertEquals(x, (short)0x4567, "setVolatile short value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, (short)0x0123);
+ short x = (short) vh.getAcquire(array, i);
+ assertEquals(x, (short)0x0123, "setRelease short value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, (short)0x4567);
+ short x = (short) vh.getOpaque(array, i);
+ assertEquals(x, (short)0x4567, "setOpaque short value");
+ }
+
+ vh.set(array, i, (short)0x0123);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, (short)0x0123, (short)0x4567);
+ assertEquals(r, true, "success compareAndSet short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)0x4567, "success compareAndSet short value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, (short)0x0123, (short)0x89AB);
+ assertEquals(r, false, "failing compareAndSet short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)0x4567, "failing compareAndSet short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchange(array, i, (short)0x4567, (short)0x0123);
+ assertEquals(r, (short)0x4567, "success compareAndExchange short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)0x0123, "success compareAndExchange short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchange(array, i, (short)0x4567, (short)0x89AB);
+ assertEquals(r, (short)0x0123, "failing compareAndExchange short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)0x0123, "failing compareAndExchange short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchangeAcquire(array, i, (short)0x0123, (short)0x4567);
+ assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchangeAcquire(array, i, (short)0x0123, (short)0x89AB);
+ assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchangeRelease(array, i, (short)0x4567, (short)0x0123);
+ assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value");
+ }
+
+ {
+ short r = (short) vh.compareAndExchangeRelease(array, i, (short)0x4567, (short)0x89AB);
+ assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, (short)0x0123, (short)0x4567);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)0x4567, "weakCompareAndSetPlain short value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, (short)0x4567, (short)0x0123);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)0x0123, "weakCompareAndSetAcquire short");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, (short)0x0123, (short)0x4567);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)0x4567, "weakCompareAndSetRelease short");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, (short)0x4567, (short)0x0123);
+ }
+ assertEquals(success, true, "weakCompareAndSet short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)0x0123, "weakCompareAndSet short");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, (short)0x0123);
+
+ short o = (short) vh.getAndSet(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndSet short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)0x4567, "getAndSet short value");
+ }
+
+ {
+ vh.set(array, i, (short)0x0123);
+
+ short o = (short) vh.getAndSetAcquire(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndSetAcquire short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)0x4567, "getAndSetAcquire short value");
+ }
+
+ {
+ vh.set(array, i, (short)0x0123);
+
+ short o = (short) vh.getAndSetRelease(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndSetRelease short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)0x4567, "getAndSetRelease short value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(array, i, (short)0x0123);
+
+ short o = (short) vh.getAndAdd(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAdd short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value");
+ }
+
+ {
+ vh.set(array, i, (short)0x0123);
+
+ short o = (short) vh.getAndAddAcquire(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAddAcquire short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value");
+ }
+
+ {
+ vh.set(array, i, (short)0x0123);
+
+ short o = (short) vh.getAndAddRelease(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAddReleaseshort");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set(array, i, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseOr(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOr short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value");
+ }
+
+ {
+ vh.set(array, i, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseOrAcquire(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value");
+ }
+
+ {
+ vh.set(array, i, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseOrRelease(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(array, i, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseAnd(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAnd short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value");
+ }
+
+ {
+ vh.set(array, i, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseAndAcquire(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value");
+ }
+
+ {
+ vh.set(array, i, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseAndRelease(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(array, i, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseXor(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXor short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value");
+ }
+
+ {
+ vh.set(array, i, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseXorAcquire(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value");
+ }
+
+ {
+ vh.set(array, i, (short)0x0123);
+
+ short o = (short) vh.getAndBitwiseXorRelease(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short");
+ short x = (short) vh.get(array, i);
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short value");
+ }
+ }
+ }
+
+ static void testArrayUnsupported(VarHandle vh) {
+ short[] array = new short[10];
+
+ int i = 0;
+
+
+ }
+
+ static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
+ short[] array = new short[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ short x = (short) vh.get(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.set(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short x = (short) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short x = (short) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short x = (short) vh.getOpaque(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, (short)0x0123, (short)0x4567);
+ });
+
+ checkIOOBE(() -> {
+ short r = (short) vh.compareAndExchange(array, ci, (short)0x4567, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short r = (short) vh.compareAndExchangeAcquire(array, ci, (short)0x4567, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short r = (short) vh.compareAndExchangeRelease(array, ci, (short)0x4567, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, (short)0x0123, (short)0x4567);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, (short)0x0123, (short)0x4567);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, (short)0x0123, (short)0x4567);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, (short)0x0123, (short)0x4567);
+ });
+
+ checkIOOBE(() -> {
+ short o = (short) vh.getAndSet(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short o = (short) vh.getAndSetAcquire(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short o = (short) vh.getAndSetRelease(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short o = (short) vh.getAndAdd(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short o = (short) vh.getAndAddAcquire(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short o = (short) vh.getAndAddRelease(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short o = (short) vh.getAndBitwiseOr(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short o = (short) vh.getAndBitwiseOrAcquire(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short o = (short) vh.getAndBitwiseOrRelease(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short o = (short) vh.getAndBitwiseAnd(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short o = (short) vh.getAndBitwiseAndAcquire(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short o = (short) vh.getAndBitwiseAndRelease(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short o = (short) vh.getAndBitwiseXor(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short o = (short) vh.getAndBitwiseXorAcquire(array, ci, (short)0x0123);
+ });
+
+ checkIOOBE(() -> {
+ short o = (short) vh.getAndBitwiseXorRelease(array, ci, (short)0x0123);
+ });
+ }
+ }
+
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessString.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessString.java
new file mode 100644
index 0000000..04ed5de
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestAccessString.java
@@ -0,0 +1,1238 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessString
+ * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessString
+ * @run testng/othervm -Diters=20000 VarHandleTestAccessString
+ * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestAccessString
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestAccessString extends VarHandleBaseTest {
+ static final String static_final_v = "foo";
+
+ static String static_v;
+
+ final String final_v = "foo";
+
+ String v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ VarHandle vhArrayObject;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessString.class, "final_v", String.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessString.class, "v", String.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessString.class, "static_final_v", String.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessString.class, "static_v", String.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(String[].class);
+ vhArrayObject = MethodHandles.arrayElementVarHandle(Object[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] varHandlesProvider() throws Exception {
+ List<VarHandle> vhs = new ArrayList<>();
+ vhs.add(vhField);
+ vhs.add(vhStaticField);
+ vhs.add(vhArray);
+
+ return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "varHandlesProvider")
+ public void testIsAccessModeSupported(VarHandle vh) {
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+ }
+
+
+ @DataProvider
+ public Object[][] typesProvider() throws Exception {
+ List<Object[]> types = new ArrayList<>();
+ types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessString.class)});
+ types.add(new Object[] {vhStaticField, Arrays.asList()});
+ types.add(new Object[] {vhArray, Arrays.asList(String[].class, int.class)});
+
+ return types.stream().toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "typesProvider")
+ public void testTypes(VarHandle vh, List<Class<?>> pts) {
+ assertEquals(vh.varType(), String.class);
+
+ assertEquals(vh.coordinateTypes(), pts);
+
+ testTypes(vh);
+ }
+
+
+ @Test
+ public void testLookupInstanceToStatic() {
+ checkIAE("Lookup of static final field to instance final field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessString.class, "final_v", String.class);
+ });
+
+ checkIAE("Lookup of static field to instance field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccessString.class, "v", String.class);
+ });
+ }
+
+ @Test
+ public void testLookupStaticToInstance() {
+ checkIAE("Lookup of instance final field to static final field", () -> {
+ MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessString.class, "static_final_v", String.class);
+ });
+
+ checkIAE("Lookup of instance field to static field", () -> {
+ vhStaticField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccessString.class, "static_v", String.class);
+ });
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance final field",
+ vhFinalField, vh -> testInstanceFinalField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
+ vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static final field",
+ vhStaticFinalField, VarHandleTestAccessString::testStaticFinalField));
+ cases.add(new VarHandleAccessTestCase("Static final field unsupported",
+ vhStaticFinalField, VarHandleTestAccessString::testStaticFinalFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance field unsupported",
+ vhField, vh -> testInstanceFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestAccessString::testStaticField));
+ cases.add(new VarHandleAccessTestCase("Static field unsupported",
+ vhStaticField, VarHandleTestAccessString::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestAccessString::testArray));
+ cases.add(new VarHandleAccessTestCase("Array Object[]",
+ vhArrayObject, VarHandleTestAccessString::testArray));
+ cases.add(new VarHandleAccessTestCase("Array unsupported",
+ vhArray, VarHandleTestAccessString::testArrayUnsupported,
+ false));
+ cases.add(new VarHandleAccessTestCase("Array index out of bounds",
+ vhArray, VarHandleTestAccessString::testArrayIndexOutOfBounds,
+ false));
+ cases.add(new VarHandleAccessTestCase("Array store exception",
+ vhArrayObject, VarHandleTestAccessString::testArrayStoreException,
+ false));
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+
+
+ static void testInstanceFinalField(VarHandleTestAccessString recv, VarHandle vh) {
+ // Plain
+ {
+ String x = (String) vh.get(recv);
+ assertEquals(x, "foo", "get String value");
+ }
+
+
+ // Volatile
+ {
+ String x = (String) vh.getVolatile(recv);
+ assertEquals(x, "foo", "getVolatile String value");
+ }
+
+ // Lazy
+ {
+ String x = (String) vh.getAcquire(recv);
+ assertEquals(x, "foo", "getRelease String value");
+ }
+
+ // Opaque
+ {
+ String x = (String) vh.getOpaque(recv);
+ assertEquals(x, "foo", "getOpaque String value");
+ }
+ }
+
+ static void testInstanceFinalFieldUnsupported(VarHandleTestAccessString recv, VarHandle vh) {
+ checkUOE(() -> {
+ vh.set(recv, "bar");
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile(recv, "bar");
+ });
+
+ checkUOE(() -> {
+ vh.setRelease(recv, "bar");
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque(recv, "bar");
+ });
+
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndAdd(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndAddAcquire(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndAddRelease(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseOr(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseOrAcquire(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseOrRelease(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseAnd(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseAndAcquire(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseAndRelease(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseXor(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseXorAcquire(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseXorRelease(recv, "foo");
+ });
+ }
+
+
+ static void testStaticFinalField(VarHandle vh) {
+ // Plain
+ {
+ String x = (String) vh.get();
+ assertEquals(x, "foo", "get String value");
+ }
+
+
+ // Volatile
+ {
+ String x = (String) vh.getVolatile();
+ assertEquals(x, "foo", "getVolatile String value");
+ }
+
+ // Lazy
+ {
+ String x = (String) vh.getAcquire();
+ assertEquals(x, "foo", "getRelease String value");
+ }
+
+ // Opaque
+ {
+ String x = (String) vh.getOpaque();
+ assertEquals(x, "foo", "getOpaque String value");
+ }
+ }
+
+ static void testStaticFinalFieldUnsupported(VarHandle vh) {
+ checkUOE(() -> {
+ vh.set("bar");
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile("bar");
+ });
+
+ checkUOE(() -> {
+ vh.setRelease("bar");
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque("bar");
+ });
+
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndAdd("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndAddAcquire("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndAddRelease("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseOr("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseOrAcquire("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseOrRelease("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseAnd("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseAndAcquire("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseAndRelease("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseXor("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseXorAcquire("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseXorRelease("foo");
+ });
+ }
+
+
+ static void testInstanceField(VarHandleTestAccessString recv, VarHandle vh) {
+ // Plain
+ {
+ vh.set(recv, "foo");
+ String x = (String) vh.get(recv);
+ assertEquals(x, "foo", "set String value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(recv, "bar");
+ String x = (String) vh.getVolatile(recv);
+ assertEquals(x, "bar", "setVolatile String value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(recv, "foo");
+ String x = (String) vh.getAcquire(recv);
+ assertEquals(x, "foo", "setRelease String value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(recv, "bar");
+ String x = (String) vh.getOpaque(recv);
+ assertEquals(x, "bar", "setOpaque String value");
+ }
+
+ vh.set(recv, "foo");
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(recv, "foo", "bar");
+ assertEquals(r, true, "success compareAndSet String");
+ String x = (String) vh.get(recv);
+ assertEquals(x, "bar", "success compareAndSet String value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(recv, "foo", "baz");
+ assertEquals(r, false, "failing compareAndSet String");
+ String x = (String) vh.get(recv);
+ assertEquals(x, "bar", "failing compareAndSet String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchange(recv, "bar", "foo");
+ assertEquals(r, "bar", "success compareAndExchange String");
+ String x = (String) vh.get(recv);
+ assertEquals(x, "foo", "success compareAndExchange String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchange(recv, "bar", "baz");
+ assertEquals(r, "foo", "failing compareAndExchange String");
+ String x = (String) vh.get(recv);
+ assertEquals(x, "foo", "failing compareAndExchange String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchangeAcquire(recv, "foo", "bar");
+ assertEquals(r, "foo", "success compareAndExchangeAcquire String");
+ String x = (String) vh.get(recv);
+ assertEquals(x, "bar", "success compareAndExchangeAcquire String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchangeAcquire(recv, "foo", "baz");
+ assertEquals(r, "bar", "failing compareAndExchangeAcquire String");
+ String x = (String) vh.get(recv);
+ assertEquals(x, "bar", "failing compareAndExchangeAcquire String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchangeRelease(recv, "bar", "foo");
+ assertEquals(r, "bar", "success compareAndExchangeRelease String");
+ String x = (String) vh.get(recv);
+ assertEquals(x, "foo", "success compareAndExchangeRelease String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchangeRelease(recv, "bar", "baz");
+ assertEquals(r, "foo", "failing compareAndExchangeRelease String");
+ String x = (String) vh.get(recv);
+ assertEquals(x, "foo", "failing compareAndExchangeRelease String value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(recv, "foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain String");
+ String x = (String) vh.get(recv);
+ assertEquals(x, "bar", "weakCompareAndSetPlain String value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(recv, "bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire String");
+ String x = (String) vh.get(recv);
+ assertEquals(x, "foo", "weakCompareAndSetAcquire String");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(recv, "foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease String");
+ String x = (String) vh.get(recv);
+ assertEquals(x, "bar", "weakCompareAndSetRelease String");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(recv, "bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSet String");
+ String x = (String) vh.get(recv);
+ assertEquals(x, "foo", "weakCompareAndSet String value");
+ }
+
+ // Compare set and get
+ {
+ vh.set(recv, "foo");
+
+ String o = (String) vh.getAndSet(recv, "bar");
+ assertEquals(o, "foo", "getAndSet String");
+ String x = (String) vh.get(recv);
+ assertEquals(x, "bar", "getAndSet String value");
+ }
+
+ {
+ vh.set(recv, "foo");
+
+ String o = (String) vh.getAndSetAcquire(recv, "bar");
+ assertEquals(o, "foo", "getAndSetAcquire String");
+ String x = (String) vh.get(recv);
+ assertEquals(x, "bar", "getAndSetAcquire String value");
+ }
+
+ {
+ vh.set(recv, "foo");
+
+ String o = (String) vh.getAndSetRelease(recv, "bar");
+ assertEquals(o, "foo", "getAndSetRelease String");
+ String x = (String) vh.get(recv);
+ assertEquals(x, "bar", "getAndSetRelease String value");
+ }
+
+
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestAccessString recv, VarHandle vh) {
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndAdd(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndAddAcquire(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndAddRelease(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseOr(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseOrAcquire(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseOrRelease(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseAnd(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseAndAcquire(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseAndRelease(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseXor(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseXorAcquire(recv, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseXorRelease(recv, "foo");
+ });
+ }
+
+
+ static void testStaticField(VarHandle vh) {
+ // Plain
+ {
+ vh.set("foo");
+ String x = (String) vh.get();
+ assertEquals(x, "foo", "set String value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile("bar");
+ String x = (String) vh.getVolatile();
+ assertEquals(x, "bar", "setVolatile String value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease("foo");
+ String x = (String) vh.getAcquire();
+ assertEquals(x, "foo", "setRelease String value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque("bar");
+ String x = (String) vh.getOpaque();
+ assertEquals(x, "bar", "setOpaque String value");
+ }
+
+ vh.set("foo");
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet("foo", "bar");
+ assertEquals(r, true, "success compareAndSet String");
+ String x = (String) vh.get();
+ assertEquals(x, "bar", "success compareAndSet String value");
+ }
+
+ {
+ boolean r = vh.compareAndSet("foo", "baz");
+ assertEquals(r, false, "failing compareAndSet String");
+ String x = (String) vh.get();
+ assertEquals(x, "bar", "failing compareAndSet String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchange("bar", "foo");
+ assertEquals(r, "bar", "success compareAndExchange String");
+ String x = (String) vh.get();
+ assertEquals(x, "foo", "success compareAndExchange String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchange("bar", "baz");
+ assertEquals(r, "foo", "failing compareAndExchange String");
+ String x = (String) vh.get();
+ assertEquals(x, "foo", "failing compareAndExchange String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchangeAcquire("foo", "bar");
+ assertEquals(r, "foo", "success compareAndExchangeAcquire String");
+ String x = (String) vh.get();
+ assertEquals(x, "bar", "success compareAndExchangeAcquire String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchangeAcquire("foo", "baz");
+ assertEquals(r, "bar", "failing compareAndExchangeAcquire String");
+ String x = (String) vh.get();
+ assertEquals(x, "bar", "failing compareAndExchangeAcquire String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchangeRelease("bar", "foo");
+ assertEquals(r, "bar", "success compareAndExchangeRelease String");
+ String x = (String) vh.get();
+ assertEquals(x, "foo", "success compareAndExchangeRelease String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchangeRelease("bar", "baz");
+ assertEquals(r, "foo", "failing compareAndExchangeRelease String");
+ String x = (String) vh.get();
+ assertEquals(x, "foo", "failing compareAndExchangeRelease String value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain("foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain String");
+ String x = (String) vh.get();
+ assertEquals(x, "bar", "weakCompareAndSetPlain String value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire("bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire String");
+ String x = (String) vh.get();
+ assertEquals(x, "foo", "weakCompareAndSetAcquire String");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease("foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease String");
+ String x = (String) vh.get();
+ assertEquals(x, "bar", "weakCompareAndSetRelease String");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet("bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSet String");
+ String x = (String) vh.get();
+ assertEquals(x, "foo", "weakCompareAndSet String");
+ }
+
+ // Compare set and get
+ {
+ vh.set("foo");
+
+ String o = (String) vh.getAndSet("bar");
+ assertEquals(o, "foo", "getAndSet String");
+ String x = (String) vh.get();
+ assertEquals(x, "bar", "getAndSet String value");
+ }
+
+ {
+ vh.set("foo");
+
+ String o = (String) vh.getAndSetAcquire("bar");
+ assertEquals(o, "foo", "getAndSetAcquire String");
+ String x = (String) vh.get();
+ assertEquals(x, "bar", "getAndSetAcquire String value");
+ }
+
+ {
+ vh.set("foo");
+
+ String o = (String) vh.getAndSetRelease("bar");
+ assertEquals(o, "foo", "getAndSetRelease String");
+ String x = (String) vh.get();
+ assertEquals(x, "bar", "getAndSetRelease String value");
+ }
+
+
+ }
+
+ static void testStaticFieldUnsupported(VarHandle vh) {
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndAdd("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndAddAcquire("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndAddRelease("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseOr("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseOrAcquire("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseOrRelease("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseAnd("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseAndAcquire("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseAndRelease("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseXor("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseXorAcquire("foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseXorRelease("foo");
+ });
+ }
+
+
+ static void testArray(VarHandle vh) {
+ String[] array = new String[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ vh.set(array, i, "foo");
+ String x = (String) vh.get(array, i);
+ assertEquals(x, "foo", "get String value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(array, i, "bar");
+ String x = (String) vh.getVolatile(array, i);
+ assertEquals(x, "bar", "setVolatile String value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, "foo");
+ String x = (String) vh.getAcquire(array, i);
+ assertEquals(x, "foo", "setRelease String value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, "bar");
+ String x = (String) vh.getOpaque(array, i);
+ assertEquals(x, "bar", "setOpaque String value");
+ }
+
+ vh.set(array, i, "foo");
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, "foo", "bar");
+ assertEquals(r, true, "success compareAndSet String");
+ String x = (String) vh.get(array, i);
+ assertEquals(x, "bar", "success compareAndSet String value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, "foo", "baz");
+ assertEquals(r, false, "failing compareAndSet String");
+ String x = (String) vh.get(array, i);
+ assertEquals(x, "bar", "failing compareAndSet String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchange(array, i, "bar", "foo");
+ assertEquals(r, "bar", "success compareAndExchange String");
+ String x = (String) vh.get(array, i);
+ assertEquals(x, "foo", "success compareAndExchange String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchange(array, i, "bar", "baz");
+ assertEquals(r, "foo", "failing compareAndExchange String");
+ String x = (String) vh.get(array, i);
+ assertEquals(x, "foo", "failing compareAndExchange String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchangeAcquire(array, i, "foo", "bar");
+ assertEquals(r, "foo", "success compareAndExchangeAcquire String");
+ String x = (String) vh.get(array, i);
+ assertEquals(x, "bar", "success compareAndExchangeAcquire String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchangeAcquire(array, i, "foo", "baz");
+ assertEquals(r, "bar", "failing compareAndExchangeAcquire String");
+ String x = (String) vh.get(array, i);
+ assertEquals(x, "bar", "failing compareAndExchangeAcquire String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchangeRelease(array, i, "bar", "foo");
+ assertEquals(r, "bar", "success compareAndExchangeRelease String");
+ String x = (String) vh.get(array, i);
+ assertEquals(x, "foo", "success compareAndExchangeRelease String value");
+ }
+
+ {
+ String r = (String) vh.compareAndExchangeRelease(array, i, "bar", "baz");
+ assertEquals(r, "foo", "failing compareAndExchangeRelease String");
+ String x = (String) vh.get(array, i);
+ assertEquals(x, "foo", "failing compareAndExchangeRelease String value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, "foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain String");
+ String x = (String) vh.get(array, i);
+ assertEquals(x, "bar", "weakCompareAndSetPlain String value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, "bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire String");
+ String x = (String) vh.get(array, i);
+ assertEquals(x, "foo", "weakCompareAndSetAcquire String");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, "foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease String");
+ String x = (String) vh.get(array, i);
+ assertEquals(x, "bar", "weakCompareAndSetRelease String");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, "bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSet String");
+ String x = (String) vh.get(array, i);
+ assertEquals(x, "foo", "weakCompareAndSet String");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, "foo");
+
+ String o = (String) vh.getAndSet(array, i, "bar");
+ assertEquals(o, "foo", "getAndSet String");
+ String x = (String) vh.get(array, i);
+ assertEquals(x, "bar", "getAndSet String value");
+ }
+
+ {
+ vh.set(array, i, "foo");
+
+ String o = (String) vh.getAndSetAcquire(array, i, "bar");
+ assertEquals(o, "foo", "getAndSetAcquire String");
+ String x = (String) vh.get(array, i);
+ assertEquals(x, "bar", "getAndSetAcquire String value");
+ }
+
+ {
+ vh.set(array, i, "foo");
+
+ String o = (String) vh.getAndSetRelease(array, i, "bar");
+ assertEquals(o, "foo", "getAndSetRelease String");
+ String x = (String) vh.get(array, i);
+ assertEquals(x, "bar", "getAndSetRelease String value");
+ }
+
+
+ }
+ }
+
+ static void testArrayUnsupported(VarHandle vh) {
+ String[] array = new String[10];
+
+ int i = 0;
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndAdd(array, i, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndAddAcquire(array, i, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndAddRelease(array, i, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseOr(array, i, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseOrAcquire(array, i, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseOrRelease(array, i, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseAnd(array, i, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseAndAcquire(array, i, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseAndRelease(array, i, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseXor(array, i, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseXorAcquire(array, i, "foo");
+ });
+
+ checkUOE(() -> {
+ String o = (String) vh.getAndBitwiseXorRelease(array, i, "foo");
+ });
+ }
+
+ static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
+ String[] array = new String[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ String x = (String) vh.get(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.set(array, ci, "foo");
+ });
+
+ checkIOOBE(() -> {
+ String x = (String) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, "foo");
+ });
+
+ checkIOOBE(() -> {
+ String x = (String) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, "foo");
+ });
+
+ checkIOOBE(() -> {
+ String x = (String) vh.getOpaque(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, "foo");
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, "foo", "bar");
+ });
+
+ checkIOOBE(() -> {
+ String r = (String) vh.compareAndExchange(array, ci, "bar", "foo");
+ });
+
+ checkIOOBE(() -> {
+ String r = (String) vh.compareAndExchangeAcquire(array, ci, "bar", "foo");
+ });
+
+ checkIOOBE(() -> {
+ String r = (String) vh.compareAndExchangeRelease(array, ci, "bar", "foo");
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, "foo", "bar");
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, "foo", "bar");
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, "foo", "bar");
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, "foo", "bar");
+ });
+
+ checkIOOBE(() -> {
+ String o = (String) vh.getAndSet(array, ci, "foo");
+ });
+
+ checkIOOBE(() -> {
+ String o = (String) vh.getAndSetAcquire(array, ci, "foo");
+ });
+
+ checkIOOBE(() -> {
+ String o = (String) vh.getAndSetRelease(array, ci, "foo");
+ });
+
+
+ }
+ }
+
+ static void testArrayStoreException(VarHandle vh) throws Throwable {
+ Object[] array = new String[10];
+ Arrays.fill(array, "foo");
+ Object value = new Object();
+
+ // Set
+ checkASE(() -> {
+ vh.set(array, 0, value);
+ });
+
+ // SetVolatile
+ checkASE(() -> {
+ vh.setVolatile(array, 0, value);
+ });
+
+ // SetOpaque
+ checkASE(() -> {
+ vh.setOpaque(array, 0, value);
+ });
+
+ // SetRelease
+ checkASE(() -> {
+ vh.setRelease(array, 0, value);
+ });
+
+ // CompareAndSet
+ checkASE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(array, 0, "foo", value);
+ });
+
+ // WeakCompareAndSet
+ checkASE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, "foo", value);
+ });
+
+ // WeakCompareAndSetVolatile
+ checkASE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(array, 0, "foo", value);
+ });
+
+ // WeakCompareAndSetAcquire
+ checkASE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, "foo", value);
+ });
+
+ // WeakCompareAndSetRelease
+ checkASE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, "foo", value);
+ });
+
+ // CompareAndExchange
+ checkASE(() -> { // receiver reference class
+ String x = (String) vh.compareAndExchange(array, 0, "foo", value);
+ });
+
+ // CompareAndExchangeAcquire
+ checkASE(() -> { // receiver reference class
+ String x = (String) vh.compareAndExchangeAcquire(array, 0, "foo", value);
+ });
+
+ // CompareAndExchangeRelease
+ checkASE(() -> { // receiver reference class
+ String x = (String) vh.compareAndExchangeRelease(array, 0, "foo", value);
+ });
+
+ // GetAndSet
+ checkASE(() -> { // receiver reference class
+ String x = (String) vh.getAndSet(array, 0, value);
+ });
+
+ // GetAndSetAcquire
+ checkASE(() -> { // receiver reference class
+ String x = (String) vh.getAndSetAcquire(array, 0, value);
+ });
+
+ // GetAndSetRelease
+ checkASE(() -> { // receiver reference class
+ String x = (String) vh.getAndSetRelease(array, 0, value);
+ });
+ }
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsChar.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsChar.java
new file mode 100644
index 0000000..7d0cce2
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsChar.java
@@ -0,0 +1,911 @@
+/*
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8154556
+ * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsChar
+ * @run testng/othervm -Diters=20000 VarHandleTestByteArrayAsChar
+ * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestByteArrayAsChar
+ */
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest {
+ static final int SIZE = Character.BYTES;
+
+ static final char VALUE_1 = (char)0x0102;
+
+ static final char VALUE_2 = (char)0x1112;
+
+ static final char VALUE_3 = (char)0xFFFE;
+
+
+ @Override
+ public void setupVarHandleSources() {
+ // Combinations of VarHandle byte[] or ByteBuffer
+ vhss = new ArrayList<>();
+ for (MemoryMode endianess : Arrays.asList(MemoryMode.BIG_ENDIAN, MemoryMode.LITTLE_ENDIAN)) {
+
+ ByteOrder bo = endianess == MemoryMode.BIG_ENDIAN
+ ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
+ VarHandleSource aeh = new VarHandleSource(
+ MethodHandles.byteArrayViewVarHandle(char[].class, bo),
+ endianess, MemoryMode.READ_WRITE);
+ vhss.add(aeh);
+
+ VarHandleSource bbh = new VarHandleSource(
+ MethodHandles.byteBufferViewVarHandle(char[].class, bo),
+ endianess, MemoryMode.READ_WRITE);
+ vhss.add(bbh);
+ }
+ }
+
+
+ @Test(dataProvider = "varHandlesProvider")
+ public void testIsAccessModeSupported(VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
+
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+ }
+
+ @Test(dataProvider = "typesProvider")
+ public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
+ assertEquals(vh.varType(), char.class);
+
+ assertEquals(vh.coordinateTypes(), pts);
+
+ testTypes(vh);
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ for (ByteArrayViewSource<?> bav : bavss) {
+ for (VarHandleSource vh : vhss) {
+ if (vh.matches(bav)) {
+ if (bav instanceof ByteArraySource) {
+ ByteArraySource bas = (ByteArraySource) bav;
+
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read write", bav, vh, h -> testArrayReadWrite(bas, h),
+ true));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "null array", bav, vh, h -> testArrayNPE(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "unsupported", bav, vh, h -> testArrayUnsupported(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "misaligned access", bav, vh, h -> testArrayMisalignedAccess(bas, h),
+ false));
+ }
+ else {
+ ByteBufferSource bbs = (ByteBufferSource) bav;
+
+ if (MemoryMode.READ_WRITE.isSet(bav.memoryModes)) {
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read write", bav, vh, h -> testArrayReadWrite(bbs, h),
+ true));
+ }
+ else {
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read only", bav, vh, h -> testArrayReadOnly(bbs, h),
+ true));
+ }
+
+ cases.add(new VarHandleSourceAccessTestCase(
+ "null buffer", bav, vh, h -> testArrayNPE(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "unsupported", bav, vh, h -> testArrayUnsupported(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "misaligned access", bav, vh, h -> testArrayMisalignedAccess(bbs, h),
+ false));
+ }
+ }
+ }
+ }
+
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = null;
+ int ci = 1;
+
+ checkNPE(() -> {
+ char x = (char) vh.get(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ char x = (char) vh.getVolatile(array, ci);
+ });
+
+ checkNPE(() -> {
+ char x = (char) vh.getAcquire(array, ci);
+ });
+
+ checkNPE(() -> {
+ char x = (char) vh.getOpaque(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+
+
+ }
+
+ static void testArrayNPE(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = null;
+ int ci = 1;
+
+ checkNPE(() -> {
+ char x = (char) vh.get(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ char x = (char) vh.getVolatile(array, ci);
+ });
+
+ checkNPE(() -> {
+ char x = (char) vh.getAcquire(array, ci);
+ });
+
+ checkNPE(() -> {
+ char x = (char) vh.getOpaque(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+
+
+ }
+
+ static void testArrayUnsupported(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+ int ci = 1;
+
+ checkUOE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ char r = (char) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char r = (char) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char r = (char) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+
+ static void testArrayUnsupported(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+ int ci = 0;
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+
+ if (readOnly) {
+ checkROBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+ }
+
+ if (readOnly) {
+ checkROBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+ checkUOE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ char r = (char) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char r = (char) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char r = (char) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+ else {
+ checkUOE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ char r = (char) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char r = (char) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char r = (char) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+ checkUOE(() -> {
+ char o = (char) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ char o = (char) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+ }
+
+
+ static void testArrayIndexOutOfBounds(ByteArraySource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int length = array.length - SIZE + 1;
+ for (int i : new int[]{-1, Integer.MIN_VALUE, length, length + 1, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ char x = (char) vh.get(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ char x = (char) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ char x = (char) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ char x = (char) vh.getOpaque(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+
+
+ }
+ }
+
+ static void testArrayIndexOutOfBounds(ByteBufferSource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+
+ int length = array.limit() - SIZE + 1;
+ for (int i : new int[]{-1, Integer.MIN_VALUE, length, length + 1, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ char x = (char) vh.get(array, ci);
+ });
+
+ if (!readOnly) {
+ checkIOOBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+ }
+
+ checkIOOBE(() -> {
+ char x = (char) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ char x = (char) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ char x = (char) vh.getOpaque(array, ci);
+ });
+
+ if (!readOnly) {
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+
+
+ }
+ }
+ }
+
+ static void testArrayMisalignedAccess(ByteArraySource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int misalignmentAtZero = ByteBuffer.wrap(array).alignmentOffset(0, SIZE);
+
+ int length = array.length - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+ final int ci = i;
+
+ if (!iAligned) {
+ checkISE(() -> {
+ char x = (char) vh.getVolatile(array, ci);
+ });
+
+ checkISE(() -> {
+ char x = (char) vh.getAcquire(array, ci);
+ });
+
+ checkISE(() -> {
+ char x = (char) vh.getOpaque(array, ci);
+ });
+
+ checkISE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+
+ }
+ }
+ }
+
+ static void testArrayMisalignedAccess(ByteBufferSource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+ final int ci = i;
+
+ if (!iAligned) {
+ checkISE(() -> {
+ char x = (char) vh.getVolatile(array, ci);
+ });
+
+ checkISE(() -> {
+ char x = (char) vh.getAcquire(array, ci);
+ });
+
+ checkISE(() -> {
+ char x = (char) vh.getOpaque(array, ci);
+ });
+
+ if (!readOnly) {
+ checkISE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+
+
+ }
+ }
+ }
+ }
+
+ static void testArrayReadWrite(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int misalignmentAtZero = ByteBuffer.wrap(array).alignmentOffset(0, SIZE);
+
+ bs.fill((byte) 0xff);
+ int length = array.length - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ // Plain
+ {
+ vh.set(array, i, VALUE_1);
+ char x = (char) vh.get(array, i);
+ assertEquals(x, VALUE_1, "get char value");
+ }
+
+
+ if (iAligned) {
+ // Volatile
+ {
+ vh.setVolatile(array, i, VALUE_2);
+ char x = (char) vh.getVolatile(array, i);
+ assertEquals(x, VALUE_2, "setVolatile char value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, VALUE_1);
+ char x = (char) vh.getAcquire(array, i);
+ assertEquals(x, VALUE_1, "setRelease char value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, VALUE_2);
+ char x = (char) vh.getOpaque(array, i);
+ assertEquals(x, VALUE_2, "setOpaque char value");
+ }
+
+
+ }
+ }
+ }
+
+
+ static void testArrayReadWrite(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ bs.fill((byte) 0xff);
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ // Plain
+ {
+ vh.set(array, i, VALUE_1);
+ char x = (char) vh.get(array, i);
+ assertEquals(x, VALUE_1, "get char value");
+ }
+
+ if (iAligned) {
+ // Volatile
+ {
+ vh.setVolatile(array, i, VALUE_2);
+ char x = (char) vh.getVolatile(array, i);
+ assertEquals(x, VALUE_2, "setVolatile char value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, VALUE_1);
+ char x = (char) vh.getAcquire(array, i);
+ assertEquals(x, VALUE_1, "setRelease char value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, VALUE_2);
+ char x = (char) vh.getOpaque(array, i);
+ assertEquals(x, VALUE_2, "setOpaque char value");
+ }
+
+
+ }
+ }
+ }
+
+ static void testArrayReadOnly(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ ByteBuffer bb = ByteBuffer.allocate(SIZE);
+ bb.order(MemoryMode.BIG_ENDIAN.isSet(vhs.memoryModes) ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
+ bs.fill(bb.putChar(0, VALUE_2).array());
+
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ char v = MemoryMode.BIG_ENDIAN.isSet(vhs.memoryModes)
+ ? rotateLeft(VALUE_2, (i % SIZE) << 3)
+ : rotateRight(VALUE_2, (i % SIZE) << 3);
+ // Plain
+ {
+ char x = (char) vh.get(array, i);
+ assertEquals(x, v, "get char value");
+ }
+
+ if (iAligned) {
+ // Volatile
+ {
+ char x = (char) vh.getVolatile(array, i);
+ assertEquals(x, v, "getVolatile char value");
+ }
+
+ // Lazy
+ {
+ char x = (char) vh.getAcquire(array, i);
+ assertEquals(x, v, "getRelease char value");
+ }
+
+ // Opaque
+ {
+ char x = (char) vh.getOpaque(array, i);
+ assertEquals(x, v, "getOpaque char value");
+ }
+ }
+ }
+ }
+
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsDouble.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsDouble.java
new file mode 100644
index 0000000..8d2c935
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsDouble.java
@@ -0,0 +1,1341 @@
+/*
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8154556
+ * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsDouble
+ * @run testng/othervm -Diters=20000 VarHandleTestByteArrayAsDouble
+ * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestByteArrayAsDouble
+ */
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
+ static final int SIZE = Double.BYTES;
+
+ static final double VALUE_1 = 0x0102030405060708L;
+
+ static final double VALUE_2 = 0x1112131415161718L;
+
+ static final double VALUE_3 = 0xFFFEFDFCFBFAF9F8L;
+
+
+ @Override
+ public void setupVarHandleSources() {
+ // Combinations of VarHandle byte[] or ByteBuffer
+ vhss = new ArrayList<>();
+ for (MemoryMode endianess : Arrays.asList(MemoryMode.BIG_ENDIAN, MemoryMode.LITTLE_ENDIAN)) {
+
+ ByteOrder bo = endianess == MemoryMode.BIG_ENDIAN
+ ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
+ VarHandleSource aeh = new VarHandleSource(
+ MethodHandles.byteArrayViewVarHandle(double[].class, bo),
+ endianess, MemoryMode.READ_WRITE);
+ vhss.add(aeh);
+
+ VarHandleSource bbh = new VarHandleSource(
+ MethodHandles.byteBufferViewVarHandle(double[].class, bo),
+ endianess, MemoryMode.READ_WRITE);
+ vhss.add(bbh);
+ }
+ }
+
+
+ @Test(dataProvider = "varHandlesProvider")
+ public void testIsAccessModeSupported(VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+ }
+
+ @Test(dataProvider = "typesProvider")
+ public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
+ assertEquals(vh.varType(), double.class);
+
+ assertEquals(vh.coordinateTypes(), pts);
+
+ testTypes(vh);
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ for (ByteArrayViewSource<?> bav : bavss) {
+ for (VarHandleSource vh : vhss) {
+ if (vh.matches(bav)) {
+ if (bav instanceof ByteArraySource) {
+ ByteArraySource bas = (ByteArraySource) bav;
+
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read write", bav, vh, h -> testArrayReadWrite(bas, h),
+ true));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "null array", bav, vh, h -> testArrayNPE(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "unsupported", bav, vh, h -> testArrayUnsupported(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "misaligned access", bav, vh, h -> testArrayMisalignedAccess(bas, h),
+ false));
+ }
+ else {
+ ByteBufferSource bbs = (ByteBufferSource) bav;
+
+ if (MemoryMode.READ_WRITE.isSet(bav.memoryModes)) {
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read write", bav, vh, h -> testArrayReadWrite(bbs, h),
+ true));
+ }
+ else {
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read only", bav, vh, h -> testArrayReadOnly(bbs, h),
+ true));
+ }
+
+ cases.add(new VarHandleSourceAccessTestCase(
+ "null buffer", bav, vh, h -> testArrayNPE(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "unsupported", bav, vh, h -> testArrayUnsupported(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "misaligned access", bav, vh, h -> testArrayMisalignedAccess(bbs, h),
+ false));
+ }
+ }
+ }
+ }
+
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = null;
+ int ci = 1;
+
+ checkNPE(() -> {
+ double x = (double) vh.get(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ double x = (double) vh.getVolatile(array, ci);
+ });
+
+ checkNPE(() -> {
+ double x = (double) vh.getAcquire(array, ci);
+ });
+
+ checkNPE(() -> {
+ double x = (double) vh.getOpaque(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ double r = (double) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ double r = (double) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ double r = (double) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ double o = (double) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ double o = (double) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ double o = (double) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+
+ }
+
+ static void testArrayNPE(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = null;
+ int ci = 1;
+
+ checkNPE(() -> {
+ double x = (double) vh.get(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ double x = (double) vh.getVolatile(array, ci);
+ });
+
+ checkNPE(() -> {
+ double x = (double) vh.getAcquire(array, ci);
+ });
+
+ checkNPE(() -> {
+ double x = (double) vh.getOpaque(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ double r = (double) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ double r = (double) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ double r = (double) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ double o = (double) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ double o = (double) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ double o = (double) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+
+ }
+
+ static void testArrayUnsupported(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+ int ci = 1;
+
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+
+ static void testArrayUnsupported(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+ int ci = 0;
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+
+ if (readOnly) {
+ checkROBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+ }
+
+ if (readOnly) {
+ checkROBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ double r = (double) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ double r = (double) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ double r = (double) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ double o = (double) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ double o = (double) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ double o = (double) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+ else {
+ checkUOE(() -> {
+ double o = (double) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ double o = (double) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+ }
+
+
+ static void testArrayIndexOutOfBounds(ByteArraySource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int length = array.length - SIZE + 1;
+ for (int i : new int[]{-1, Integer.MIN_VALUE, length, length + 1, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ double x = (double) vh.get(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ double x = (double) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ double x = (double) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ double x = (double) vh.getOpaque(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ double r = (double) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ double r = (double) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ double r = (double) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ double o = (double) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ double o = (double) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ double o = (double) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+
+
+ }
+ }
+
+ static void testArrayIndexOutOfBounds(ByteBufferSource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+
+ int length = array.limit() - SIZE + 1;
+ for (int i : new int[]{-1, Integer.MIN_VALUE, length, length + 1, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ double x = (double) vh.get(array, ci);
+ });
+
+ if (!readOnly) {
+ checkIOOBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+ }
+
+ checkIOOBE(() -> {
+ double x = (double) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ double x = (double) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ double x = (double) vh.getOpaque(array, ci);
+ });
+
+ if (!readOnly) {
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ double r = (double) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ double r = (double) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ double r = (double) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ double o = (double) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ double o = (double) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ double o = (double) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+
+ }
+ }
+ }
+
+ static void testArrayMisalignedAccess(ByteArraySource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int misalignmentAtZero = ByteBuffer.wrap(array).alignmentOffset(0, SIZE);
+
+ int length = array.length - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+ final int ci = i;
+
+ if (!iAligned) {
+ checkISE(() -> {
+ double x = (double) vh.getVolatile(array, ci);
+ });
+
+ checkISE(() -> {
+ double x = (double) vh.getAcquire(array, ci);
+ });
+
+ checkISE(() -> {
+ double x = (double) vh.getOpaque(array, ci);
+ });
+
+ checkISE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ double r = (double) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ double r = (double) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ double r = (double) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ double o = (double) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ double o = (double) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ double o = (double) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+
+ }
+ }
+ }
+
+ static void testArrayMisalignedAccess(ByteBufferSource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+ final int ci = i;
+
+ if (!iAligned) {
+ checkISE(() -> {
+ double x = (double) vh.getVolatile(array, ci);
+ });
+
+ checkISE(() -> {
+ double x = (double) vh.getAcquire(array, ci);
+ });
+
+ checkISE(() -> {
+ double x = (double) vh.getOpaque(array, ci);
+ });
+
+ if (!readOnly) {
+ checkISE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ double r = (double) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ double r = (double) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ double r = (double) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ double o = (double) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ double o = (double) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ double o = (double) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+
+ }
+ }
+ }
+ }
+
+ static void testArrayReadWrite(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int misalignmentAtZero = ByteBuffer.wrap(array).alignmentOffset(0, SIZE);
+
+ bs.fill((byte) 0xff);
+ int length = array.length - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ // Plain
+ {
+ vh.set(array, i, VALUE_1);
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_1, "get double value");
+ }
+
+
+ if (iAligned) {
+ // Volatile
+ {
+ vh.setVolatile(array, i, VALUE_2);
+ double x = (double) vh.getVolatile(array, i);
+ assertEquals(x, VALUE_2, "setVolatile double value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, VALUE_1);
+ double x = (double) vh.getAcquire(array, i);
+ assertEquals(x, VALUE_1, "setRelease double value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, VALUE_2);
+ double x = (double) vh.getOpaque(array, i);
+ assertEquals(x, VALUE_2, "setOpaque double value");
+ }
+
+ vh.set(array, i, VALUE_1);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, true, "success compareAndSet double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndSet double value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, false, "failing compareAndSet double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndSet double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchange double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchange double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchange double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchange double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, VALUE_1, "success compareAndExchangeAcquire double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndExchangeAcquire double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchangeRelease double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchangeRelease double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchangeRelease double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchangeRelease double value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetPlain double value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSetAcquire double");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetRelease double");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSet double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSet double");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, VALUE_1);
+
+ double o = (double) vh.getAndSet(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSet double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSet double value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ double o = (double) vh.getAndSetAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetAcquire double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetAcquire double value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ double o = (double) vh.getAndSetRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetRelease double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetRelease double value");
+ }
+
+
+ }
+ }
+ }
+
+
+ static void testArrayReadWrite(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ bs.fill((byte) 0xff);
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ // Plain
+ {
+ vh.set(array, i, VALUE_1);
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_1, "get double value");
+ }
+
+ if (iAligned) {
+ // Volatile
+ {
+ vh.setVolatile(array, i, VALUE_2);
+ double x = (double) vh.getVolatile(array, i);
+ assertEquals(x, VALUE_2, "setVolatile double value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, VALUE_1);
+ double x = (double) vh.getAcquire(array, i);
+ assertEquals(x, VALUE_1, "setRelease double value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, VALUE_2);
+ double x = (double) vh.getOpaque(array, i);
+ assertEquals(x, VALUE_2, "setOpaque double value");
+ }
+
+ vh.set(array, i, VALUE_1);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, true, "success compareAndSet double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndSet double value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, false, "failing compareAndSet double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndSet double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchange double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchange double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchange double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchange double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, VALUE_1, "success compareAndExchangeAcquire double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndExchangeAcquire double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchangeRelease double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchangeRelease double value");
+ }
+
+ {
+ double r = (double) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchangeRelease double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchangeRelease double value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetPlain double value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSetAcquire double");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetRelease double");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSet double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSet double");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, VALUE_1);
+
+ double o = (double) vh.getAndSet(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSet double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSet double value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ double o = (double) vh.getAndSetAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetAcquire double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetAcquire double value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ double o = (double) vh.getAndSetRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetRelease double");
+ double x = (double) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetRelease double value");
+ }
+
+
+ }
+ }
+ }
+
+ static void testArrayReadOnly(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ ByteBuffer bb = ByteBuffer.allocate(SIZE);
+ bb.order(MemoryMode.BIG_ENDIAN.isSet(vhs.memoryModes) ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
+ bs.fill(bb.putDouble(0, VALUE_2).array());
+
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ double v = MemoryMode.BIG_ENDIAN.isSet(vhs.memoryModes)
+ ? rotateLeft(VALUE_2, (i % SIZE) << 3)
+ : rotateRight(VALUE_2, (i % SIZE) << 3);
+ // Plain
+ {
+ double x = (double) vh.get(array, i);
+ assertEquals(x, v, "get double value");
+ }
+
+ if (iAligned) {
+ // Volatile
+ {
+ double x = (double) vh.getVolatile(array, i);
+ assertEquals(x, v, "getVolatile double value");
+ }
+
+ // Lazy
+ {
+ double x = (double) vh.getAcquire(array, i);
+ assertEquals(x, v, "getRelease double value");
+ }
+
+ // Opaque
+ {
+ double x = (double) vh.getOpaque(array, i);
+ assertEquals(x, v, "getOpaque double value");
+ }
+ }
+ }
+ }
+
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsFloat.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsFloat.java
new file mode 100644
index 0000000..b9be42b
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsFloat.java
@@ -0,0 +1,1341 @@
+/*
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8154556
+ * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsFloat
+ * @run testng/othervm -Diters=20000 VarHandleTestByteArrayAsFloat
+ * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestByteArrayAsFloat
+ */
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
+ static final int SIZE = Float.BYTES;
+
+ static final float VALUE_1 = 0x01020304;
+
+ static final float VALUE_2 = 0x11121314;
+
+ static final float VALUE_3 = 0xFFFEFDFC;
+
+
+ @Override
+ public void setupVarHandleSources() {
+ // Combinations of VarHandle byte[] or ByteBuffer
+ vhss = new ArrayList<>();
+ for (MemoryMode endianess : Arrays.asList(MemoryMode.BIG_ENDIAN, MemoryMode.LITTLE_ENDIAN)) {
+
+ ByteOrder bo = endianess == MemoryMode.BIG_ENDIAN
+ ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
+ VarHandleSource aeh = new VarHandleSource(
+ MethodHandles.byteArrayViewVarHandle(float[].class, bo),
+ endianess, MemoryMode.READ_WRITE);
+ vhss.add(aeh);
+
+ VarHandleSource bbh = new VarHandleSource(
+ MethodHandles.byteBufferViewVarHandle(float[].class, bo),
+ endianess, MemoryMode.READ_WRITE);
+ vhss.add(bbh);
+ }
+ }
+
+
+ @Test(dataProvider = "varHandlesProvider")
+ public void testIsAccessModeSupported(VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+ }
+
+ @Test(dataProvider = "typesProvider")
+ public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
+ assertEquals(vh.varType(), float.class);
+
+ assertEquals(vh.coordinateTypes(), pts);
+
+ testTypes(vh);
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ for (ByteArrayViewSource<?> bav : bavss) {
+ for (VarHandleSource vh : vhss) {
+ if (vh.matches(bav)) {
+ if (bav instanceof ByteArraySource) {
+ ByteArraySource bas = (ByteArraySource) bav;
+
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read write", bav, vh, h -> testArrayReadWrite(bas, h),
+ true));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "null array", bav, vh, h -> testArrayNPE(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "unsupported", bav, vh, h -> testArrayUnsupported(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "misaligned access", bav, vh, h -> testArrayMisalignedAccess(bas, h),
+ false));
+ }
+ else {
+ ByteBufferSource bbs = (ByteBufferSource) bav;
+
+ if (MemoryMode.READ_WRITE.isSet(bav.memoryModes)) {
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read write", bav, vh, h -> testArrayReadWrite(bbs, h),
+ true));
+ }
+ else {
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read only", bav, vh, h -> testArrayReadOnly(bbs, h),
+ true));
+ }
+
+ cases.add(new VarHandleSourceAccessTestCase(
+ "null buffer", bav, vh, h -> testArrayNPE(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "unsupported", bav, vh, h -> testArrayUnsupported(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "misaligned access", bav, vh, h -> testArrayMisalignedAccess(bbs, h),
+ false));
+ }
+ }
+ }
+ }
+
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = null;
+ int ci = 1;
+
+ checkNPE(() -> {
+ float x = (float) vh.get(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ float x = (float) vh.getVolatile(array, ci);
+ });
+
+ checkNPE(() -> {
+ float x = (float) vh.getAcquire(array, ci);
+ });
+
+ checkNPE(() -> {
+ float x = (float) vh.getOpaque(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ float r = (float) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ float r = (float) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ float r = (float) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ float o = (float) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ float o = (float) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ float o = (float) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+
+ }
+
+ static void testArrayNPE(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = null;
+ int ci = 1;
+
+ checkNPE(() -> {
+ float x = (float) vh.get(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ float x = (float) vh.getVolatile(array, ci);
+ });
+
+ checkNPE(() -> {
+ float x = (float) vh.getAcquire(array, ci);
+ });
+
+ checkNPE(() -> {
+ float x = (float) vh.getOpaque(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ float r = (float) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ float r = (float) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ float r = (float) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ float o = (float) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ float o = (float) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ float o = (float) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+
+ }
+
+ static void testArrayUnsupported(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+ int ci = 1;
+
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+
+ static void testArrayUnsupported(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+ int ci = 0;
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+
+ if (readOnly) {
+ checkROBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+ }
+
+ if (readOnly) {
+ checkROBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ float r = (float) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ float r = (float) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ float r = (float) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ float o = (float) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ float o = (float) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ float o = (float) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+ else {
+ checkUOE(() -> {
+ float o = (float) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ float o = (float) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+ }
+
+
+ static void testArrayIndexOutOfBounds(ByteArraySource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int length = array.length - SIZE + 1;
+ for (int i : new int[]{-1, Integer.MIN_VALUE, length, length + 1, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ float x = (float) vh.get(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ float x = (float) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ float x = (float) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ float x = (float) vh.getOpaque(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ float r = (float) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ float r = (float) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ float r = (float) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ float o = (float) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ float o = (float) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ float o = (float) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+
+
+ }
+ }
+
+ static void testArrayIndexOutOfBounds(ByteBufferSource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+
+ int length = array.limit() - SIZE + 1;
+ for (int i : new int[]{-1, Integer.MIN_VALUE, length, length + 1, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ float x = (float) vh.get(array, ci);
+ });
+
+ if (!readOnly) {
+ checkIOOBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+ }
+
+ checkIOOBE(() -> {
+ float x = (float) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ float x = (float) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ float x = (float) vh.getOpaque(array, ci);
+ });
+
+ if (!readOnly) {
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ float r = (float) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ float r = (float) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ float r = (float) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ float o = (float) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ float o = (float) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ float o = (float) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+
+ }
+ }
+ }
+
+ static void testArrayMisalignedAccess(ByteArraySource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int misalignmentAtZero = ByteBuffer.wrap(array).alignmentOffset(0, SIZE);
+
+ int length = array.length - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+ final int ci = i;
+
+ if (!iAligned) {
+ checkISE(() -> {
+ float x = (float) vh.getVolatile(array, ci);
+ });
+
+ checkISE(() -> {
+ float x = (float) vh.getAcquire(array, ci);
+ });
+
+ checkISE(() -> {
+ float x = (float) vh.getOpaque(array, ci);
+ });
+
+ checkISE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ float r = (float) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ float r = (float) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ float r = (float) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ float o = (float) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ float o = (float) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ float o = (float) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+
+ }
+ }
+ }
+
+ static void testArrayMisalignedAccess(ByteBufferSource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+ final int ci = i;
+
+ if (!iAligned) {
+ checkISE(() -> {
+ float x = (float) vh.getVolatile(array, ci);
+ });
+
+ checkISE(() -> {
+ float x = (float) vh.getAcquire(array, ci);
+ });
+
+ checkISE(() -> {
+ float x = (float) vh.getOpaque(array, ci);
+ });
+
+ if (!readOnly) {
+ checkISE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ float r = (float) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ float r = (float) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ float r = (float) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ float o = (float) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ float o = (float) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ float o = (float) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+
+ }
+ }
+ }
+ }
+
+ static void testArrayReadWrite(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int misalignmentAtZero = ByteBuffer.wrap(array).alignmentOffset(0, SIZE);
+
+ bs.fill((byte) 0xff);
+ int length = array.length - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ // Plain
+ {
+ vh.set(array, i, VALUE_1);
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_1, "get float value");
+ }
+
+
+ if (iAligned) {
+ // Volatile
+ {
+ vh.setVolatile(array, i, VALUE_2);
+ float x = (float) vh.getVolatile(array, i);
+ assertEquals(x, VALUE_2, "setVolatile float value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, VALUE_1);
+ float x = (float) vh.getAcquire(array, i);
+ assertEquals(x, VALUE_1, "setRelease float value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, VALUE_2);
+ float x = (float) vh.getOpaque(array, i);
+ assertEquals(x, VALUE_2, "setOpaque float value");
+ }
+
+ vh.set(array, i, VALUE_1);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, true, "success compareAndSet float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndSet float value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, false, "failing compareAndSet float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndSet float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchange float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchange float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchange float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchange float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, VALUE_1, "success compareAndExchangeAcquire float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndExchangeAcquire float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchangeRelease float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchangeRelease float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchangeRelease float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchangeRelease float value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetPlain float value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSetAcquire float");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetRelease float");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSet float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSet float");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, VALUE_1);
+
+ float o = (float) vh.getAndSet(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSet float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSet float value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ float o = (float) vh.getAndSetAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetAcquire float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetAcquire float value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ float o = (float) vh.getAndSetRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetRelease float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetRelease float value");
+ }
+
+
+ }
+ }
+ }
+
+
+ static void testArrayReadWrite(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ bs.fill((byte) 0xff);
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ // Plain
+ {
+ vh.set(array, i, VALUE_1);
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_1, "get float value");
+ }
+
+ if (iAligned) {
+ // Volatile
+ {
+ vh.setVolatile(array, i, VALUE_2);
+ float x = (float) vh.getVolatile(array, i);
+ assertEquals(x, VALUE_2, "setVolatile float value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, VALUE_1);
+ float x = (float) vh.getAcquire(array, i);
+ assertEquals(x, VALUE_1, "setRelease float value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, VALUE_2);
+ float x = (float) vh.getOpaque(array, i);
+ assertEquals(x, VALUE_2, "setOpaque float value");
+ }
+
+ vh.set(array, i, VALUE_1);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, true, "success compareAndSet float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndSet float value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, false, "failing compareAndSet float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndSet float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchange float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchange float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchange float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchange float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, VALUE_1, "success compareAndExchangeAcquire float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndExchangeAcquire float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchangeRelease float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchangeRelease float value");
+ }
+
+ {
+ float r = (float) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchangeRelease float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchangeRelease float value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetPlain float value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSetAcquire float");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetRelease float");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSet float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSet float");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, VALUE_1);
+
+ float o = (float) vh.getAndSet(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSet float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSet float value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ float o = (float) vh.getAndSetAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetAcquire float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetAcquire float value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ float o = (float) vh.getAndSetRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetRelease float");
+ float x = (float) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetRelease float value");
+ }
+
+
+ }
+ }
+ }
+
+ static void testArrayReadOnly(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ ByteBuffer bb = ByteBuffer.allocate(SIZE);
+ bb.order(MemoryMode.BIG_ENDIAN.isSet(vhs.memoryModes) ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
+ bs.fill(bb.putFloat(0, VALUE_2).array());
+
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ float v = MemoryMode.BIG_ENDIAN.isSet(vhs.memoryModes)
+ ? rotateLeft(VALUE_2, (i % SIZE) << 3)
+ : rotateRight(VALUE_2, (i % SIZE) << 3);
+ // Plain
+ {
+ float x = (float) vh.get(array, i);
+ assertEquals(x, v, "get float value");
+ }
+
+ if (iAligned) {
+ // Volatile
+ {
+ float x = (float) vh.getVolatile(array, i);
+ assertEquals(x, v, "getVolatile float value");
+ }
+
+ // Lazy
+ {
+ float x = (float) vh.getAcquire(array, i);
+ assertEquals(x, v, "getRelease float value");
+ }
+
+ // Opaque
+ {
+ float x = (float) vh.getOpaque(array, i);
+ assertEquals(x, v, "getOpaque float value");
+ }
+ }
+ }
+ }
+
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsInt.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsInt.java
new file mode 100644
index 0000000..d8c48dd
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsInt.java
@@ -0,0 +1,1745 @@
+/*
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8154556
+ * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsInt
+ * @run testng/othervm -Diters=20000 VarHandleTestByteArrayAsInt
+ * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestByteArrayAsInt
+ */
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
+ static final int SIZE = Integer.BYTES;
+
+ static final int VALUE_1 = 0x01020304;
+
+ static final int VALUE_2 = 0x11121314;
+
+ static final int VALUE_3 = 0xFFFEFDFC;
+
+
+ @Override
+ public void setupVarHandleSources() {
+ // Combinations of VarHandle byte[] or ByteBuffer
+ vhss = new ArrayList<>();
+ for (MemoryMode endianess : Arrays.asList(MemoryMode.BIG_ENDIAN, MemoryMode.LITTLE_ENDIAN)) {
+
+ ByteOrder bo = endianess == MemoryMode.BIG_ENDIAN
+ ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
+ VarHandleSource aeh = new VarHandleSource(
+ MethodHandles.byteArrayViewVarHandle(int[].class, bo),
+ endianess, MemoryMode.READ_WRITE);
+ vhss.add(aeh);
+
+ VarHandleSource bbh = new VarHandleSource(
+ MethodHandles.byteBufferViewVarHandle(int[].class, bo),
+ endianess, MemoryMode.READ_WRITE);
+ vhss.add(bbh);
+ }
+ }
+
+
+ @Test(dataProvider = "varHandlesProvider")
+ public void testIsAccessModeSupported(VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+ }
+
+ @Test(dataProvider = "typesProvider")
+ public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
+ assertEquals(vh.varType(), int.class);
+
+ assertEquals(vh.coordinateTypes(), pts);
+
+ testTypes(vh);
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ for (ByteArrayViewSource<?> bav : bavss) {
+ for (VarHandleSource vh : vhss) {
+ if (vh.matches(bav)) {
+ if (bav instanceof ByteArraySource) {
+ ByteArraySource bas = (ByteArraySource) bav;
+
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read write", bav, vh, h -> testArrayReadWrite(bas, h),
+ true));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "null array", bav, vh, h -> testArrayNPE(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "unsupported", bav, vh, h -> testArrayUnsupported(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "misaligned access", bav, vh, h -> testArrayMisalignedAccess(bas, h),
+ false));
+ }
+ else {
+ ByteBufferSource bbs = (ByteBufferSource) bav;
+
+ if (MemoryMode.READ_WRITE.isSet(bav.memoryModes)) {
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read write", bav, vh, h -> testArrayReadWrite(bbs, h),
+ true));
+ }
+ else {
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read only", bav, vh, h -> testArrayReadOnly(bbs, h),
+ true));
+ }
+
+ cases.add(new VarHandleSourceAccessTestCase(
+ "null buffer", bav, vh, h -> testArrayNPE(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "unsupported", bav, vh, h -> testArrayUnsupported(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "misaligned access", bav, vh, h -> testArrayMisalignedAccess(bbs, h),
+ false));
+ }
+ }
+ }
+ }
+
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = null;
+ int ci = 1;
+
+ checkNPE(() -> {
+ int x = (int) vh.get(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int x = (int) vh.getVolatile(array, ci);
+ });
+
+ checkNPE(() -> {
+ int x = (int) vh.getAcquire(array, ci);
+ });
+
+ checkNPE(() -> {
+ int x = (int) vh.getOpaque(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ int r = (int) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int r = (int) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int r = (int) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+
+ static void testArrayNPE(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = null;
+ int ci = 1;
+
+ checkNPE(() -> {
+ int x = (int) vh.get(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int x = (int) vh.getVolatile(array, ci);
+ });
+
+ checkNPE(() -> {
+ int x = (int) vh.getAcquire(array, ci);
+ });
+
+ checkNPE(() -> {
+ int x = (int) vh.getOpaque(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ int r = (int) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int r = (int) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int r = (int) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ int o = (int) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+
+ static void testArrayUnsupported(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+ int ci = 1;
+
+
+
+ }
+
+ static void testArrayUnsupported(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+ int ci = 0;
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+
+ if (readOnly) {
+ checkROBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+ }
+
+ if (readOnly) {
+ checkROBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ int r = (int) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ int r = (int) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ int r = (int) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ int o = (int) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ int o = (int) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ int o = (int) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+
+ checkROBE(() -> {
+ int o = (int) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ int o = (int) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ int o = (int) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ int o = (int) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ int o = (int) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ int o = (int) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ int o = (int) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ int o = (int) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ int o = (int) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ int o = (int) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ int o = (int) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ int o = (int) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+ else {
+ }
+ }
+
+
+ static void testArrayIndexOutOfBounds(ByteArraySource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int length = array.length - SIZE + 1;
+ for (int i : new int[]{-1, Integer.MIN_VALUE, length, length + 1, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ int x = (int) vh.get(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int x = (int) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ int x = (int) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ int x = (int) vh.getOpaque(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ int r = (int) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int r = (int) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int r = (int) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+
+ }
+ }
+
+ static void testArrayIndexOutOfBounds(ByteBufferSource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+
+ int length = array.limit() - SIZE + 1;
+ for (int i : new int[]{-1, Integer.MIN_VALUE, length, length + 1, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ int x = (int) vh.get(array, ci);
+ });
+
+ if (!readOnly) {
+ checkIOOBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+ }
+
+ checkIOOBE(() -> {
+ int x = (int) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ int x = (int) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ int x = (int) vh.getOpaque(array, ci);
+ });
+
+ if (!readOnly) {
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ int r = (int) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int r = (int) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int r = (int) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ int o = (int) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+ }
+ }
+
+ static void testArrayMisalignedAccess(ByteArraySource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int misalignmentAtZero = ByteBuffer.wrap(array).alignmentOffset(0, SIZE);
+
+ int length = array.length - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+ final int ci = i;
+
+ if (!iAligned) {
+ checkISE(() -> {
+ int x = (int) vh.getVolatile(array, ci);
+ });
+
+ checkISE(() -> {
+ int x = (int) vh.getAcquire(array, ci);
+ });
+
+ checkISE(() -> {
+ int x = (int) vh.getOpaque(array, ci);
+ });
+
+ checkISE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ int r = (int) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int r = (int) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int r = (int) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+ }
+ }
+
+ static void testArrayMisalignedAccess(ByteBufferSource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+ final int ci = i;
+
+ if (!iAligned) {
+ checkISE(() -> {
+ int x = (int) vh.getVolatile(array, ci);
+ });
+
+ checkISE(() -> {
+ int x = (int) vh.getAcquire(array, ci);
+ });
+
+ checkISE(() -> {
+ int x = (int) vh.getOpaque(array, ci);
+ });
+
+ if (!readOnly) {
+ checkISE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ int r = (int) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int r = (int) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int r = (int) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ int o = (int) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+ }
+ }
+ }
+
+ static void testArrayReadWrite(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int misalignmentAtZero = ByteBuffer.wrap(array).alignmentOffset(0, SIZE);
+
+ bs.fill((byte) 0xff);
+ int length = array.length - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ // Plain
+ {
+ vh.set(array, i, VALUE_1);
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1, "get int value");
+ }
+
+
+ if (iAligned) {
+ // Volatile
+ {
+ vh.setVolatile(array, i, VALUE_2);
+ int x = (int) vh.getVolatile(array, i);
+ assertEquals(x, VALUE_2, "setVolatile int value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, VALUE_1);
+ int x = (int) vh.getAcquire(array, i);
+ assertEquals(x, VALUE_1, "setRelease int value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, VALUE_2);
+ int x = (int) vh.getOpaque(array, i);
+ assertEquals(x, VALUE_2, "setOpaque int value");
+ }
+
+ vh.set(array, i, VALUE_1);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, true, "success compareAndSet int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndSet int value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, false, "failing compareAndSet int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndSet int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchange int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchange int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchange int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchange int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, VALUE_1, "success compareAndExchangeAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndExchangeAcquire int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchangeRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchangeRelease int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchangeRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchangeRelease int value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetPlain int value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSetAcquire int");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetRelease int");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSet int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSet int");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndSet(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSet int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSet int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndSetAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetAcquire int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndSetRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetRelease int value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndAdd(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAdd int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAdd int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndAddAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAddAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAddAcquire int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndAddRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAddRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAddRelease int value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseOr(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOr int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOr int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseOrAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOrAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrAcquire int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseOrRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOrRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrRelease int value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseAnd(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAnd int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAnd int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseAndAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAndAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndAcquire int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseAndRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAndRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndRelease int value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseXor(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXor int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXor int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseXorAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXorAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorAcquire int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseXorRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXorRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorRelease int value");
+ }
+ }
+ }
+ }
+
+
+ static void testArrayReadWrite(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ bs.fill((byte) 0xff);
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ // Plain
+ {
+ vh.set(array, i, VALUE_1);
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1, "get int value");
+ }
+
+ if (iAligned) {
+ // Volatile
+ {
+ vh.setVolatile(array, i, VALUE_2);
+ int x = (int) vh.getVolatile(array, i);
+ assertEquals(x, VALUE_2, "setVolatile int value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, VALUE_1);
+ int x = (int) vh.getAcquire(array, i);
+ assertEquals(x, VALUE_1, "setRelease int value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, VALUE_2);
+ int x = (int) vh.getOpaque(array, i);
+ assertEquals(x, VALUE_2, "setOpaque int value");
+ }
+
+ vh.set(array, i, VALUE_1);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, true, "success compareAndSet int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndSet int value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, false, "failing compareAndSet int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndSet int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchange int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchange int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchange int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchange int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, VALUE_1, "success compareAndExchangeAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndExchangeAcquire int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchangeRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchangeRelease int value");
+ }
+
+ {
+ int r = (int) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchangeRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchangeRelease int value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetPlain int value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSetAcquire int");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetRelease int");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSet int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSet int");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndSet(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSet int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSet int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndSetAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetAcquire int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndSetRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetRelease int value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndAdd(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAdd int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAdd int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndAddAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAddAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAddAcquire int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndAddRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAddRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAddRelease int value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseOr(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOr int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOr int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseOrAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOrAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrAcquire int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseOrRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOrRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrRelease int value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseAnd(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAnd int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAnd int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseAndAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAndAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndAcquire int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseAndRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAndRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndRelease int value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseXor(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXor int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXor int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseXorAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXorAcquire int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorAcquire int value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ int o = (int) vh.getAndBitwiseXorRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXorRelease int");
+ int x = (int) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorRelease int value");
+ }
+ }
+ }
+ }
+
+ static void testArrayReadOnly(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ ByteBuffer bb = ByteBuffer.allocate(SIZE);
+ bb.order(MemoryMode.BIG_ENDIAN.isSet(vhs.memoryModes) ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
+ bs.fill(bb.putInt(0, VALUE_2).array());
+
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ int v = MemoryMode.BIG_ENDIAN.isSet(vhs.memoryModes)
+ ? rotateLeft(VALUE_2, (i % SIZE) << 3)
+ : rotateRight(VALUE_2, (i % SIZE) << 3);
+ // Plain
+ {
+ int x = (int) vh.get(array, i);
+ assertEquals(x, v, "get int value");
+ }
+
+ if (iAligned) {
+ // Volatile
+ {
+ int x = (int) vh.getVolatile(array, i);
+ assertEquals(x, v, "getVolatile int value");
+ }
+
+ // Lazy
+ {
+ int x = (int) vh.getAcquire(array, i);
+ assertEquals(x, v, "getRelease int value");
+ }
+
+ // Opaque
+ {
+ int x = (int) vh.getOpaque(array, i);
+ assertEquals(x, v, "getOpaque int value");
+ }
+ }
+ }
+ }
+
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsLong.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsLong.java
new file mode 100644
index 0000000..8f622f1
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsLong.java
@@ -0,0 +1,1745 @@
+/*
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8154556
+ * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsLong
+ * @run testng/othervm -Diters=20000 VarHandleTestByteArrayAsLong
+ * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestByteArrayAsLong
+ */
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
+ static final int SIZE = Long.BYTES;
+
+ static final long VALUE_1 = 0x0102030405060708L;
+
+ static final long VALUE_2 = 0x1112131415161718L;
+
+ static final long VALUE_3 = 0xFFFEFDFCFBFAF9F8L;
+
+
+ @Override
+ public void setupVarHandleSources() {
+ // Combinations of VarHandle byte[] or ByteBuffer
+ vhss = new ArrayList<>();
+ for (MemoryMode endianess : Arrays.asList(MemoryMode.BIG_ENDIAN, MemoryMode.LITTLE_ENDIAN)) {
+
+ ByteOrder bo = endianess == MemoryMode.BIG_ENDIAN
+ ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
+ VarHandleSource aeh = new VarHandleSource(
+ MethodHandles.byteArrayViewVarHandle(long[].class, bo),
+ endianess, MemoryMode.READ_WRITE);
+ vhss.add(aeh);
+
+ VarHandleSource bbh = new VarHandleSource(
+ MethodHandles.byteBufferViewVarHandle(long[].class, bo),
+ endianess, MemoryMode.READ_WRITE);
+ vhss.add(bbh);
+ }
+ }
+
+
+ @Test(dataProvider = "varHandlesProvider")
+ public void testIsAccessModeSupported(VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+ }
+
+ @Test(dataProvider = "typesProvider")
+ public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
+ assertEquals(vh.varType(), long.class);
+
+ assertEquals(vh.coordinateTypes(), pts);
+
+ testTypes(vh);
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ for (ByteArrayViewSource<?> bav : bavss) {
+ for (VarHandleSource vh : vhss) {
+ if (vh.matches(bav)) {
+ if (bav instanceof ByteArraySource) {
+ ByteArraySource bas = (ByteArraySource) bav;
+
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read write", bav, vh, h -> testArrayReadWrite(bas, h),
+ true));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "null array", bav, vh, h -> testArrayNPE(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "unsupported", bav, vh, h -> testArrayUnsupported(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "misaligned access", bav, vh, h -> testArrayMisalignedAccess(bas, h),
+ false));
+ }
+ else {
+ ByteBufferSource bbs = (ByteBufferSource) bav;
+
+ if (MemoryMode.READ_WRITE.isSet(bav.memoryModes)) {
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read write", bav, vh, h -> testArrayReadWrite(bbs, h),
+ true));
+ }
+ else {
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read only", bav, vh, h -> testArrayReadOnly(bbs, h),
+ true));
+ }
+
+ cases.add(new VarHandleSourceAccessTestCase(
+ "null buffer", bav, vh, h -> testArrayNPE(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "unsupported", bav, vh, h -> testArrayUnsupported(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "misaligned access", bav, vh, h -> testArrayMisalignedAccess(bbs, h),
+ false));
+ }
+ }
+ }
+ }
+
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = null;
+ int ci = 1;
+
+ checkNPE(() -> {
+ long x = (long) vh.get(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long x = (long) vh.getVolatile(array, ci);
+ });
+
+ checkNPE(() -> {
+ long x = (long) vh.getAcquire(array, ci);
+ });
+
+ checkNPE(() -> {
+ long x = (long) vh.getOpaque(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ long r = (long) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long r = (long) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long r = (long) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+
+ static void testArrayNPE(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = null;
+ int ci = 1;
+
+ checkNPE(() -> {
+ long x = (long) vh.get(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long x = (long) vh.getVolatile(array, ci);
+ });
+
+ checkNPE(() -> {
+ long x = (long) vh.getAcquire(array, ci);
+ });
+
+ checkNPE(() -> {
+ long x = (long) vh.getOpaque(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ long r = (long) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long r = (long) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long r = (long) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ long o = (long) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+
+ static void testArrayUnsupported(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+ int ci = 1;
+
+
+
+ }
+
+ static void testArrayUnsupported(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+ int ci = 0;
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+
+ if (readOnly) {
+ checkROBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+ }
+
+ if (readOnly) {
+ checkROBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ long r = (long) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ long r = (long) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ long r = (long) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ long o = (long) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ long o = (long) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ long o = (long) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+
+ checkROBE(() -> {
+ long o = (long) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ long o = (long) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ long o = (long) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ long o = (long) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ long o = (long) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ long o = (long) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ long o = (long) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ long o = (long) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ long o = (long) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ long o = (long) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ long o = (long) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ long o = (long) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+ else {
+ }
+ }
+
+
+ static void testArrayIndexOutOfBounds(ByteArraySource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int length = array.length - SIZE + 1;
+ for (int i : new int[]{-1, Integer.MIN_VALUE, length, length + 1, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ long x = (long) vh.get(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long x = (long) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ long x = (long) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ long x = (long) vh.getOpaque(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ long r = (long) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long r = (long) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long r = (long) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+
+ }
+ }
+
+ static void testArrayIndexOutOfBounds(ByteBufferSource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+
+ int length = array.limit() - SIZE + 1;
+ for (int i : new int[]{-1, Integer.MIN_VALUE, length, length + 1, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ long x = (long) vh.get(array, ci);
+ });
+
+ if (!readOnly) {
+ checkIOOBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+ }
+
+ checkIOOBE(() -> {
+ long x = (long) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ long x = (long) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ long x = (long) vh.getOpaque(array, ci);
+ });
+
+ if (!readOnly) {
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ long r = (long) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long r = (long) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long r = (long) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ long o = (long) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+ }
+ }
+
+ static void testArrayMisalignedAccess(ByteArraySource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int misalignmentAtZero = ByteBuffer.wrap(array).alignmentOffset(0, SIZE);
+
+ int length = array.length - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+ final int ci = i;
+
+ if (!iAligned) {
+ checkISE(() -> {
+ long x = (long) vh.getVolatile(array, ci);
+ });
+
+ checkISE(() -> {
+ long x = (long) vh.getAcquire(array, ci);
+ });
+
+ checkISE(() -> {
+ long x = (long) vh.getOpaque(array, ci);
+ });
+
+ checkISE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ long r = (long) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long r = (long) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long r = (long) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+ }
+ }
+
+ static void testArrayMisalignedAccess(ByteBufferSource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+ final int ci = i;
+
+ if (!iAligned) {
+ checkISE(() -> {
+ long x = (long) vh.getVolatile(array, ci);
+ });
+
+ checkISE(() -> {
+ long x = (long) vh.getAcquire(array, ci);
+ });
+
+ checkISE(() -> {
+ long x = (long) vh.getOpaque(array, ci);
+ });
+
+ if (!readOnly) {
+ checkISE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ long r = (long) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long r = (long) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long r = (long) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ long o = (long) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+ }
+ }
+ }
+
+ static void testArrayReadWrite(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int misalignmentAtZero = ByteBuffer.wrap(array).alignmentOffset(0, SIZE);
+
+ bs.fill((byte) 0xff);
+ int length = array.length - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ // Plain
+ {
+ vh.set(array, i, VALUE_1);
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1, "get long value");
+ }
+
+
+ if (iAligned) {
+ // Volatile
+ {
+ vh.setVolatile(array, i, VALUE_2);
+ long x = (long) vh.getVolatile(array, i);
+ assertEquals(x, VALUE_2, "setVolatile long value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, VALUE_1);
+ long x = (long) vh.getAcquire(array, i);
+ assertEquals(x, VALUE_1, "setRelease long value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, VALUE_2);
+ long x = (long) vh.getOpaque(array, i);
+ assertEquals(x, VALUE_2, "setOpaque long value");
+ }
+
+ vh.set(array, i, VALUE_1);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, true, "success compareAndSet long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndSet long value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, false, "failing compareAndSet long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndSet long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchange long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchange long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchange long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchange long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, VALUE_1, "success compareAndExchangeAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndExchangeAcquire long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchangeRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchangeRelease long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchangeRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchangeRelease long value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetPlain long value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSetAcquire long");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetRelease long");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSet long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSet long");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndSet(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSet long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSet long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndSetAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetAcquire long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndSetRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetRelease long value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndAdd(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAdd long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAdd long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndAddAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAddAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAddAcquire long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndAddRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAddRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAddRelease long value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseOr(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOr long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOr long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseOrAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOrAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrAcquire long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseOrRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOrRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrRelease long value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseAnd(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAnd long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAnd long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseAndAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAndAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndAcquire long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseAndRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAndRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndRelease long value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseXor(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXor long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXor long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseXorAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXorAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorAcquire long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseXorRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXorRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorRelease long value");
+ }
+ }
+ }
+ }
+
+
+ static void testArrayReadWrite(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ bs.fill((byte) 0xff);
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ // Plain
+ {
+ vh.set(array, i, VALUE_1);
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1, "get long value");
+ }
+
+ if (iAligned) {
+ // Volatile
+ {
+ vh.setVolatile(array, i, VALUE_2);
+ long x = (long) vh.getVolatile(array, i);
+ assertEquals(x, VALUE_2, "setVolatile long value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, VALUE_1);
+ long x = (long) vh.getAcquire(array, i);
+ assertEquals(x, VALUE_1, "setRelease long value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, VALUE_2);
+ long x = (long) vh.getOpaque(array, i);
+ assertEquals(x, VALUE_2, "setOpaque long value");
+ }
+
+ vh.set(array, i, VALUE_1);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, true, "success compareAndSet long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndSet long value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, false, "failing compareAndSet long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndSet long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchange long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchange long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchange long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchange long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, VALUE_1, "success compareAndExchangeAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndExchangeAcquire long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchangeRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchangeRelease long value");
+ }
+
+ {
+ long r = (long) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchangeRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchangeRelease long value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetPlain long value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSetAcquire long");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetRelease long");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSet long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSet long");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndSet(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSet long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSet long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndSetAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetAcquire long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndSetRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetRelease long value");
+ }
+
+ // get and add, add and get
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndAdd(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAdd long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAdd long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndAddAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAddAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAddAcquire long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndAddRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAddRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAddRelease long value");
+ }
+
+ // get and bitwise or
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseOr(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOr long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOr long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseOrAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOrAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrAcquire long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseOrRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOrRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrRelease long value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseAnd(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAnd long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAnd long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseAndAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAndAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndAcquire long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseAndRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAndRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndRelease long value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseXor(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXor long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXor long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseXorAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXorAcquire long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorAcquire long value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ long o = (long) vh.getAndBitwiseXorRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXorRelease long");
+ long x = (long) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorRelease long value");
+ }
+ }
+ }
+ }
+
+ static void testArrayReadOnly(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ ByteBuffer bb = ByteBuffer.allocate(SIZE);
+ bb.order(MemoryMode.BIG_ENDIAN.isSet(vhs.memoryModes) ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
+ bs.fill(bb.putLong(0, VALUE_2).array());
+
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ long v = MemoryMode.BIG_ENDIAN.isSet(vhs.memoryModes)
+ ? rotateLeft(VALUE_2, (i % SIZE) << 3)
+ : rotateRight(VALUE_2, (i % SIZE) << 3);
+ // Plain
+ {
+ long x = (long) vh.get(array, i);
+ assertEquals(x, v, "get long value");
+ }
+
+ if (iAligned) {
+ // Volatile
+ {
+ long x = (long) vh.getVolatile(array, i);
+ assertEquals(x, v, "getVolatile long value");
+ }
+
+ // Lazy
+ {
+ long x = (long) vh.getAcquire(array, i);
+ assertEquals(x, v, "getRelease long value");
+ }
+
+ // Opaque
+ {
+ long x = (long) vh.getOpaque(array, i);
+ assertEquals(x, v, "getOpaque long value");
+ }
+ }
+ }
+ }
+
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsShort.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsShort.java
new file mode 100644
index 0000000..7e8f99f
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsShort.java
@@ -0,0 +1,911 @@
+/*
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8154556
+ * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsShort
+ * @run testng/othervm -Diters=20000 VarHandleTestByteArrayAsShort
+ * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestByteArrayAsShort
+ */
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest {
+ static final int SIZE = Short.BYTES;
+
+ static final short VALUE_1 = (short)0x0102;
+
+ static final short VALUE_2 = (short)0x1112;
+
+ static final short VALUE_3 = (short)0xFFFE;
+
+
+ @Override
+ public void setupVarHandleSources() {
+ // Combinations of VarHandle byte[] or ByteBuffer
+ vhss = new ArrayList<>();
+ for (MemoryMode endianess : Arrays.asList(MemoryMode.BIG_ENDIAN, MemoryMode.LITTLE_ENDIAN)) {
+
+ ByteOrder bo = endianess == MemoryMode.BIG_ENDIAN
+ ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
+ VarHandleSource aeh = new VarHandleSource(
+ MethodHandles.byteArrayViewVarHandle(short[].class, bo),
+ endianess, MemoryMode.READ_WRITE);
+ vhss.add(aeh);
+
+ VarHandleSource bbh = new VarHandleSource(
+ MethodHandles.byteBufferViewVarHandle(short[].class, bo),
+ endianess, MemoryMode.READ_WRITE);
+ vhss.add(bbh);
+ }
+ }
+
+
+ @Test(dataProvider = "varHandlesProvider")
+ public void testIsAccessModeSupported(VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
+
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+ }
+
+ @Test(dataProvider = "typesProvider")
+ public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
+ assertEquals(vh.varType(), short.class);
+
+ assertEquals(vh.coordinateTypes(), pts);
+
+ testTypes(vh);
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ for (ByteArrayViewSource<?> bav : bavss) {
+ for (VarHandleSource vh : vhss) {
+ if (vh.matches(bav)) {
+ if (bav instanceof ByteArraySource) {
+ ByteArraySource bas = (ByteArraySource) bav;
+
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read write", bav, vh, h -> testArrayReadWrite(bas, h),
+ true));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "null array", bav, vh, h -> testArrayNPE(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "unsupported", bav, vh, h -> testArrayUnsupported(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "misaligned access", bav, vh, h -> testArrayMisalignedAccess(bas, h),
+ false));
+ }
+ else {
+ ByteBufferSource bbs = (ByteBufferSource) bav;
+
+ if (MemoryMode.READ_WRITE.isSet(bav.memoryModes)) {
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read write", bav, vh, h -> testArrayReadWrite(bbs, h),
+ true));
+ }
+ else {
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read only", bav, vh, h -> testArrayReadOnly(bbs, h),
+ true));
+ }
+
+ cases.add(new VarHandleSourceAccessTestCase(
+ "null buffer", bav, vh, h -> testArrayNPE(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "unsupported", bav, vh, h -> testArrayUnsupported(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "misaligned access", bav, vh, h -> testArrayMisalignedAccess(bbs, h),
+ false));
+ }
+ }
+ }
+ }
+
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = null;
+ int ci = 1;
+
+ checkNPE(() -> {
+ short x = (short) vh.get(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ short x = (short) vh.getVolatile(array, ci);
+ });
+
+ checkNPE(() -> {
+ short x = (short) vh.getAcquire(array, ci);
+ });
+
+ checkNPE(() -> {
+ short x = (short) vh.getOpaque(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+
+
+ }
+
+ static void testArrayNPE(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = null;
+ int ci = 1;
+
+ checkNPE(() -> {
+ short x = (short) vh.get(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ short x = (short) vh.getVolatile(array, ci);
+ });
+
+ checkNPE(() -> {
+ short x = (short) vh.getAcquire(array, ci);
+ });
+
+ checkNPE(() -> {
+ short x = (short) vh.getOpaque(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+
+
+ }
+
+ static void testArrayUnsupported(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+ int ci = 1;
+
+ checkUOE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ short r = (short) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short r = (short) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short r = (short) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+
+ static void testArrayUnsupported(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+ int ci = 0;
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+
+ if (readOnly) {
+ checkROBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+ }
+
+ if (readOnly) {
+ checkROBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+ checkUOE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ short r = (short) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short r = (short) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short r = (short) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+ else {
+ checkUOE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ short r = (short) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short r = (short) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short r = (short) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+ checkUOE(() -> {
+ short o = (short) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ short o = (short) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+ }
+ }
+
+
+ static void testArrayIndexOutOfBounds(ByteArraySource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int length = array.length - SIZE + 1;
+ for (int i : new int[]{-1, Integer.MIN_VALUE, length, length + 1, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ short x = (short) vh.get(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ short x = (short) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ short x = (short) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ short x = (short) vh.getOpaque(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+
+
+ }
+ }
+
+ static void testArrayIndexOutOfBounds(ByteBufferSource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+
+ int length = array.limit() - SIZE + 1;
+ for (int i : new int[]{-1, Integer.MIN_VALUE, length, length + 1, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ short x = (short) vh.get(array, ci);
+ });
+
+ if (!readOnly) {
+ checkIOOBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+ }
+
+ checkIOOBE(() -> {
+ short x = (short) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ short x = (short) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ short x = (short) vh.getOpaque(array, ci);
+ });
+
+ if (!readOnly) {
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+
+
+ }
+ }
+ }
+
+ static void testArrayMisalignedAccess(ByteArraySource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int misalignmentAtZero = ByteBuffer.wrap(array).alignmentOffset(0, SIZE);
+
+ int length = array.length - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+ final int ci = i;
+
+ if (!iAligned) {
+ checkISE(() -> {
+ short x = (short) vh.getVolatile(array, ci);
+ });
+
+ checkISE(() -> {
+ short x = (short) vh.getAcquire(array, ci);
+ });
+
+ checkISE(() -> {
+ short x = (short) vh.getOpaque(array, ci);
+ });
+
+ checkISE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+
+ }
+ }
+ }
+
+ static void testArrayMisalignedAccess(ByteBufferSource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+ final int ci = i;
+
+ if (!iAligned) {
+ checkISE(() -> {
+ short x = (short) vh.getVolatile(array, ci);
+ });
+
+ checkISE(() -> {
+ short x = (short) vh.getAcquire(array, ci);
+ });
+
+ checkISE(() -> {
+ short x = (short) vh.getOpaque(array, ci);
+ });
+
+ if (!readOnly) {
+ checkISE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+
+
+ }
+ }
+ }
+ }
+
+ static void testArrayReadWrite(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int misalignmentAtZero = ByteBuffer.wrap(array).alignmentOffset(0, SIZE);
+
+ bs.fill((byte) 0xff);
+ int length = array.length - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ // Plain
+ {
+ vh.set(array, i, VALUE_1);
+ short x = (short) vh.get(array, i);
+ assertEquals(x, VALUE_1, "get short value");
+ }
+
+
+ if (iAligned) {
+ // Volatile
+ {
+ vh.setVolatile(array, i, VALUE_2);
+ short x = (short) vh.getVolatile(array, i);
+ assertEquals(x, VALUE_2, "setVolatile short value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, VALUE_1);
+ short x = (short) vh.getAcquire(array, i);
+ assertEquals(x, VALUE_1, "setRelease short value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, VALUE_2);
+ short x = (short) vh.getOpaque(array, i);
+ assertEquals(x, VALUE_2, "setOpaque short value");
+ }
+
+
+ }
+ }
+ }
+
+
+ static void testArrayReadWrite(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ bs.fill((byte) 0xff);
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ // Plain
+ {
+ vh.set(array, i, VALUE_1);
+ short x = (short) vh.get(array, i);
+ assertEquals(x, VALUE_1, "get short value");
+ }
+
+ if (iAligned) {
+ // Volatile
+ {
+ vh.setVolatile(array, i, VALUE_2);
+ short x = (short) vh.getVolatile(array, i);
+ assertEquals(x, VALUE_2, "setVolatile short value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, VALUE_1);
+ short x = (short) vh.getAcquire(array, i);
+ assertEquals(x, VALUE_1, "setRelease short value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, VALUE_2);
+ short x = (short) vh.getOpaque(array, i);
+ assertEquals(x, VALUE_2, "setOpaque short value");
+ }
+
+
+ }
+ }
+ }
+
+ static void testArrayReadOnly(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ ByteBuffer bb = ByteBuffer.allocate(SIZE);
+ bb.order(MemoryMode.BIG_ENDIAN.isSet(vhs.memoryModes) ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
+ bs.fill(bb.putShort(0, VALUE_2).array());
+
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ short v = MemoryMode.BIG_ENDIAN.isSet(vhs.memoryModes)
+ ? rotateLeft(VALUE_2, (i % SIZE) << 3)
+ : rotateRight(VALUE_2, (i % SIZE) << 3);
+ // Plain
+ {
+ short x = (short) vh.get(array, i);
+ assertEquals(x, v, "get short value");
+ }
+
+ if (iAligned) {
+ // Volatile
+ {
+ short x = (short) vh.getVolatile(array, i);
+ assertEquals(x, v, "getVolatile short value");
+ }
+
+ // Lazy
+ {
+ short x = (short) vh.getAcquire(array, i);
+ assertEquals(x, v, "getRelease short value");
+ }
+
+ // Opaque
+ {
+ short x = (short) vh.getOpaque(array, i);
+ assertEquals(x, v, "getOpaque short value");
+ }
+ }
+ }
+ }
+
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessBoolean.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessBoolean.java
new file mode 100644
index 0000000..99904d3
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessBoolean.java
@@ -0,0 +1,916 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessBoolean
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
+ static final boolean static_final_v = true;
+
+ static boolean static_v;
+
+ final boolean final_v = true;
+
+ boolean v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessBoolean.class, "final_v", boolean.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessBoolean.class, "v", boolean.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessBoolean.class, "static_final_v", boolean.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessBoolean.class, "static_v", boolean.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(boolean[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceField(this, hs)));
+ cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
+ vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodHandleAccessBoolean::testStaticField));
+ cases.add(new MethodHandleAccessTestCase("Static field unsupported",
+ vhStaticField, f, VarHandleTestMethodHandleAccessBoolean::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodHandleAccessBoolean::testArray));
+ cases.add(new MethodHandleAccessTestCase("Array unsupported",
+ vhArray, f, VarHandleTestMethodHandleAccessBoolean::testArrayUnsupported,
+ false));
+ cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
+ vhArray, f, VarHandleTestMethodHandleAccessBoolean::testArrayIndexOutOfBounds,
+ false));
+ }
+
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceField(VarHandleTestMethodHandleAccessBoolean recv, Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, true);
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, true, "set boolean value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, false);
+ boolean x = (boolean) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
+ assertEquals(x, false, "setVolatile boolean value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, true);
+ boolean x = (boolean) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
+ assertEquals(x, true, "setRelease boolean value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, false);
+ boolean x = (boolean) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
+ assertEquals(x, false, "setOpaque boolean value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(recv, true);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, true, false);
+ assertEquals(r, true, "success compareAndSet boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, false, "success compareAndSet boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, true, false);
+ assertEquals(r, false, "failing compareAndSet boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, false, "failing compareAndSet boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, false, true);
+ assertEquals(r, false, "success compareAndExchange boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, true, "success compareAndExchange boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, false, false);
+ assertEquals(r, true, "failing compareAndExchange boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, true, "failing compareAndExchange boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, true, false);
+ assertEquals(r, true, "success compareAndExchangeAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, true, false);
+ assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, false, true);
+ assertEquals(r, false, "success compareAndExchangeRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, true, "success compareAndExchangeRelease boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, false, false);
+ assertEquals(r, true, "failing compareAndExchangeRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, true, false);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, false, "weakCompareAndSetPlain boolean value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, false, true);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, true, "weakCompareAndSetAcquire boolean");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, true, false);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, false, "weakCompareAndSetRelease boolean");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, false, true);
+ }
+ assertEquals(success, true, "weakCompareAndSet boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, true, "weakCompareAndSet boolean");
+ }
+
+ // Compare set and get
+ {
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, false);
+ assertEquals(o, true, "getAndSet boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, false, "getAndSet boolean value");
+ }
+
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, false);
+ assertEquals(o, true, "getAndBitwiseOr boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOr boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, false);
+ assertEquals(o, true, "getAndBitwiseOrAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOrAcquire boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, false);
+ assertEquals(o, true, "getAndBitwiseOrRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOrRelease boolean value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, false);
+ assertEquals(o, true, "getAndBitwiseAnd boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAnd boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, false);
+ assertEquals(o, true, "getAndBitwiseAndAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAndAcquire boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, false);
+ assertEquals(o, true, "getAndBitwiseAndRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAndRelease boolean value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, false);
+ assertEquals(o, true, "getAndBitwiseXor boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXor boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, false);
+ assertEquals(o, true, "getAndBitwiseXorAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorAcquire boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, false);
+ assertEquals(o, true, "getAndBitwiseXorRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorRelease boolean value");
+ }
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessBoolean recv, Handles hs) throws Throwable {
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkUOE(am, () -> {
+ boolean r = (boolean) hs.get(am).invokeExact(recv, true);
+ });
+ }
+
+ }
+
+
+ static void testStaticField(Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(true);
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, true, "set boolean value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(false);
+ boolean x = (boolean) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
+ assertEquals(x, false, "setVolatile boolean value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(true);
+ boolean x = (boolean) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
+ assertEquals(x, true, "setRelease boolean value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(false);
+ boolean x = (boolean) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
+ assertEquals(x, false, "setOpaque boolean value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(true);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(true, false);
+ assertEquals(r, true, "success compareAndSet boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, false, "success compareAndSet boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(true, false);
+ assertEquals(r, false, "failing compareAndSet boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, false, "failing compareAndSet boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(false, true);
+ assertEquals(r, false, "success compareAndExchange boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, true, "success compareAndExchange boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(false, false);
+ assertEquals(r, true, "failing compareAndExchange boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, true, "failing compareAndExchange boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(true, false);
+ assertEquals(r, true, "success compareAndExchangeAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(true, false);
+ assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(false, true);
+ assertEquals(r, false, "success compareAndExchangeRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, true, "success compareAndExchangeRelease boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(false, false);
+ assertEquals(r, true, "failing compareAndExchangeRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(true, false);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, false, "weakCompareAndSetPlain boolean value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(false, true);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, true, "weakCompareAndSetAcquire boolean");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(true, false);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, false, "weakCompareAndSetRelease boolean");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(false, true);
+ }
+ assertEquals(success, true, "weakCompareAndSet boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, true, "weakCompareAndSet boolean");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact(false);
+ assertEquals(o, true, "getAndSet boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, false, "getAndSet boolean value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(false);
+ assertEquals(o, true, "getAndSetAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, false, "getAndSetAcquire boolean value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(false);
+ assertEquals(o, true, "getAndSetRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, false, "getAndSetRelease boolean value");
+ }
+
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact(true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(false);
+ assertEquals(o, true, "getAndBitwiseOr boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOr boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(false);
+ assertEquals(o, true, "getAndBitwiseOrAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOrAcquire boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(false);
+ assertEquals(o, true, "getAndBitwiseOrRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOrRelease boolean value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact(true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(false);
+ assertEquals(o, true, "getAndBitwiseAnd boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAnd boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(false);
+ assertEquals(o, true, "getAndBitwiseAndAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAndAcquire boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(false);
+ assertEquals(o, true, "getAndBitwiseAndRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAndRelease boolean value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact(true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(false);
+ assertEquals(o, true, "getAndBitwiseXor boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXor boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(false);
+ assertEquals(o, true, "getAndBitwiseXorAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorAcquire boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(false);
+ assertEquals(o, true, "getAndBitwiseXorRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorRelease boolean value");
+ }
+ }
+
+ static void testStaticFieldUnsupported(Handles hs) throws Throwable {
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkUOE(am, () -> {
+ boolean r = (boolean) hs.get(am).invokeExact(true);
+ });
+ }
+
+ }
+
+
+ static void testArray(Handles hs) throws Throwable {
+ boolean[] array = new boolean[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, true);
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, true, "get boolean value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, false);
+ boolean x = (boolean) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
+ assertEquals(x, false, "setVolatile boolean value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, true);
+ boolean x = (boolean) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
+ assertEquals(x, true, "setRelease boolean value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, false);
+ boolean x = (boolean) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
+ assertEquals(x, false, "setOpaque boolean value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(array, i, true);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, true, false);
+ assertEquals(r, true, "success compareAndSet boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, false, "success compareAndSet boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, true, false);
+ assertEquals(r, false, "failing compareAndSet boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, false, "failing compareAndSet boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, false, true);
+ assertEquals(r, false, "success compareAndExchange boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, true, "success compareAndExchange boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, false, false);
+ assertEquals(r, true, "failing compareAndExchange boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, true, "failing compareAndExchange boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, true, false);
+ assertEquals(r, true, "success compareAndExchangeAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, true, false);
+ assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, false, true);
+ assertEquals(r, false, "success compareAndExchangeRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, true, "success compareAndExchangeRelease boolean value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, false, false);
+ assertEquals(r, true, "failing compareAndExchangeRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, true, false);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, false, "weakCompareAndSetPlain boolean value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, false, true);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, true, "weakCompareAndSetAcquire boolean");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, true, false);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, false, "weakCompareAndSetRelease boolean");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, false, true);
+ }
+ assertEquals(success, true, "weakCompareAndSet boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, true, "weakCompareAndSet boolean");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, false);
+ assertEquals(o, true, "getAndSet boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, false, "getAndSet boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, false);
+ assertEquals(o, true, "getAndSetAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, false, "getAndSetAcquire boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, false);
+ assertEquals(o, true, "getAndSetRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, false, "getAndSetRelease boolean value");
+ }
+
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, false);
+ assertEquals(o, true, "getAndBitwiseOr boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOr boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, false);
+ assertEquals(o, true, "getAndBitwiseOrAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOrAcquire boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, false);
+ assertEquals(o, true, "getAndBitwiseOrRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (boolean)(true | false), "getAndBitwiseOrRelease boolean value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, false);
+ assertEquals(o, true, "getAndBitwiseAnd boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAnd boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, false);
+ assertEquals(o, true, "getAndBitwiseAndAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAndAcquire boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, false);
+ assertEquals(o, true, "getAndBitwiseAndRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (boolean)(true & false), "getAndBitwiseAndRelease boolean value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, false);
+ assertEquals(o, true, "getAndBitwiseXor boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXor boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, false);
+ assertEquals(o, true, "getAndBitwiseXorAcquire boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorAcquire boolean value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, true);
+
+ boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, false);
+ assertEquals(o, true, "getAndBitwiseXorRelease boolean");
+ boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorRelease boolean value");
+ }
+ }
+ }
+
+ static void testArrayUnsupported(Handles hs) throws Throwable {
+ boolean[] array = new boolean[10];
+
+ final int i = 0;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkUOE(am, () -> {
+ boolean o = (boolean) hs.get(am).invokeExact(array, i, true);
+ });
+ }
+
+ }
+
+ static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
+ boolean[] array = new boolean[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ checkIOOBE(am, () -> {
+ boolean x = (boolean) hs.get(am).invokeExact(array, ci);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkIOOBE(am, () -> {
+ hs.get(am).invokeExact(array, ci, true);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ checkIOOBE(am, () -> {
+ boolean r = (boolean) hs.get(am).invokeExact(array, ci, true, false);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkIOOBE(am, () -> {
+ boolean r = (boolean) hs.get(am).invokeExact(array, ci, false, true);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkIOOBE(am, () -> {
+ boolean o = (boolean) hs.get(am).invokeExact(array, ci, true);
+ });
+ }
+
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkIOOBE(am, () -> {
+ boolean o = (boolean) hs.get(am).invokeExact(array, ci, false);
+ });
+ }
+ }
+ }
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessByte.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessByte.java
new file mode 100644
index 0000000..7ab3b99
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessByte.java
@@ -0,0 +1,987 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessByte
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest {
+ static final byte static_final_v = (byte)0x01;
+
+ static byte static_v;
+
+ final byte final_v = (byte)0x01;
+
+ byte v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessByte.class, "final_v", byte.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessByte.class, "v", byte.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessByte.class, "static_final_v", byte.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessByte.class, "static_v", byte.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(byte[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceField(this, hs)));
+ cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
+ vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodHandleAccessByte::testStaticField));
+ cases.add(new MethodHandleAccessTestCase("Static field unsupported",
+ vhStaticField, f, VarHandleTestMethodHandleAccessByte::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodHandleAccessByte::testArray));
+ cases.add(new MethodHandleAccessTestCase("Array unsupported",
+ vhArray, f, VarHandleTestMethodHandleAccessByte::testArrayUnsupported,
+ false));
+ cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
+ vhArray, f, VarHandleTestMethodHandleAccessByte::testArrayIndexOutOfBounds,
+ false));
+ }
+
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceField(VarHandleTestMethodHandleAccessByte recv, Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)0x01, "set byte value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, (byte)0x23);
+ byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
+ assertEquals(x, (byte)0x23, "setVolatile byte value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, (byte)0x01);
+ byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
+ assertEquals(x, (byte)0x01, "setRelease byte value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, (byte)0x23);
+ byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
+ assertEquals(x, (byte)0x23, "setOpaque byte value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (byte)0x01, (byte)0x23);
+ assertEquals(r, true, "success compareAndSet byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)0x23, "success compareAndSet byte value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (byte)0x01, (byte)0x45);
+ assertEquals(r, false, "failing compareAndSet byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (byte)0x23, (byte)0x01);
+ assertEquals(r, (byte)0x23, "success compareAndExchange byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)0x01, "success compareAndExchange byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (byte)0x23, (byte)0x45);
+ assertEquals(r, (byte)0x01, "failing compareAndExchange byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)0x01, "failing compareAndExchange byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (byte)0x01, (byte)0x23);
+ assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (byte)0x01, (byte)0x45);
+ assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (byte)0x23, (byte)0x01);
+ assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (byte)0x23, (byte)0x45);
+ assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, (byte)0x01, (byte)0x23);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)0x23, "weakCompareAndSetPlain byte value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, (byte)0x23, (byte)0x01);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, (byte)0x01, (byte)0x23);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, (byte)0x23, (byte)0x01);
+ }
+ assertEquals(success, true, "weakCompareAndSet byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)0x01, "weakCompareAndSet byte");
+ }
+
+ // Compare set and get
+ {
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndSet byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)0x23, "getAndSet byte value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAdd byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAddAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAddRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value");
+ }
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOr byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXor byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value");
+ }
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessByte recv, Handles hs) throws Throwable {
+
+
+ }
+
+
+ static void testStaticField(Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)0x01, "set byte value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact((byte)0x23);
+ byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
+ assertEquals(x, (byte)0x23, "setVolatile byte value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact((byte)0x01);
+ byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
+ assertEquals(x, (byte)0x01, "setRelease byte value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact((byte)0x23);
+ byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
+ assertEquals(x, (byte)0x23, "setOpaque byte value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((byte)0x01, (byte)0x23);
+ assertEquals(r, true, "success compareAndSet byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)0x23, "success compareAndSet byte value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((byte)0x01, (byte)0x45);
+ assertEquals(r, false, "failing compareAndSet byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((byte)0x23, (byte)0x01);
+ assertEquals(r, (byte)0x23, "success compareAndExchange byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)0x01, "success compareAndExchange byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((byte)0x23, (byte)0x45);
+ assertEquals(r, (byte)0x01, "failing compareAndExchange byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)0x01, "failing compareAndExchange byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((byte)0x01, (byte)0x23);
+ assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((byte)0x01, (byte)0x45);
+ assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((byte)0x23, (byte)0x01);
+ assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((byte)0x23, (byte)0x45);
+ assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact((byte)0x01, (byte)0x23);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)0x23, "weakCompareAndSetPlain byte value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact((byte)0x23, (byte)0x01);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact((byte)0x01, (byte)0x23);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact((byte)0x23, (byte)0x01);
+ }
+ assertEquals(success, true, "weakCompareAndSet byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)0x01, "weakCompareAndSet byte");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndSet byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)0x23, "getAndSet byte value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndSetAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)0x23, "getAndSetAcquire byte value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndSetRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)0x23, "getAndSetRelease byte value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAdd byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAddAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAddRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value");
+ }
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOr byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXor byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact((byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value");
+ }
+ }
+
+ static void testStaticFieldUnsupported(Handles hs) throws Throwable {
+
+
+ }
+
+
+ static void testArray(Handles hs) throws Throwable {
+ byte[] array = new byte[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)0x01, "get byte value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, (byte)0x23);
+ byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
+ assertEquals(x, (byte)0x23, "setVolatile byte value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, (byte)0x01);
+ byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
+ assertEquals(x, (byte)0x01, "setRelease byte value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, (byte)0x23);
+ byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
+ assertEquals(x, (byte)0x23, "setOpaque byte value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (byte)0x01, (byte)0x23);
+ assertEquals(r, true, "success compareAndSet byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)0x23, "success compareAndSet byte value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (byte)0x01, (byte)0x45);
+ assertEquals(r, false, "failing compareAndSet byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (byte)0x23, (byte)0x01);
+ assertEquals(r, (byte)0x23, "success compareAndExchange byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)0x01, "success compareAndExchange byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (byte)0x23, (byte)0x45);
+ assertEquals(r, (byte)0x01, "failing compareAndExchange byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)0x01, "failing compareAndExchange byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (byte)0x01, (byte)0x23);
+ assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (byte)0x01, (byte)0x45);
+ assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (byte)0x23, (byte)0x01);
+ assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
+ }
+
+ {
+ byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (byte)0x23, (byte)0x45);
+ assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, (byte)0x01, (byte)0x23);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)0x23, "weakCompareAndSetPlain byte value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, (byte)0x23, (byte)0x01);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, (byte)0x01, (byte)0x23);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, (byte)0x23, (byte)0x01);
+ }
+ assertEquals(success, true, "weakCompareAndSet byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)0x01, "weakCompareAndSet byte");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndSet byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)0x23, "getAndSet byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndSetAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)0x23, "getAndSetAcquire byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndSetRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)0x23, "getAndSetRelease byte value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAdd byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAddAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndAddRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value");
+ }
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOr byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXor byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
+
+ byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, (byte)0x23);
+ assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte");
+ byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value");
+ }
+ }
+ }
+
+ static void testArrayUnsupported(Handles hs) throws Throwable {
+ byte[] array = new byte[10];
+
+ final int i = 0;
+
+
+ }
+
+ static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
+ byte[] array = new byte[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ checkIOOBE(am, () -> {
+ byte x = (byte) hs.get(am).invokeExact(array, ci);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkIOOBE(am, () -> {
+ hs.get(am).invokeExact(array, ci, (byte)0x01);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ checkIOOBE(am, () -> {
+ boolean r = (boolean) hs.get(am).invokeExact(array, ci, (byte)0x01, (byte)0x23);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkIOOBE(am, () -> {
+ byte r = (byte) hs.get(am).invokeExact(array, ci, (byte)0x23, (byte)0x01);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkIOOBE(am, () -> {
+ byte o = (byte) hs.get(am).invokeExact(array, ci, (byte)0x01);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkIOOBE(am, () -> {
+ byte o = (byte) hs.get(am).invokeExact(array, ci, (byte)0x45);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkIOOBE(am, () -> {
+ byte o = (byte) hs.get(am).invokeExact(array, ci, (byte)0x45);
+ });
+ }
+ }
+ }
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessChar.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessChar.java
new file mode 100644
index 0000000..762134b
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessChar.java
@@ -0,0 +1,987 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessChar
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest {
+ static final char static_final_v = '\u0123';
+
+ static char static_v;
+
+ final char final_v = '\u0123';
+
+ char v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessChar.class, "final_v", char.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessChar.class, "v", char.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessChar.class, "static_final_v", char.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessChar.class, "static_v", char.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(char[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceField(this, hs)));
+ cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
+ vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodHandleAccessChar::testStaticField));
+ cases.add(new MethodHandleAccessTestCase("Static field unsupported",
+ vhStaticField, f, VarHandleTestMethodHandleAccessChar::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodHandleAccessChar::testArray));
+ cases.add(new MethodHandleAccessTestCase("Array unsupported",
+ vhArray, f, VarHandleTestMethodHandleAccessChar::testArrayUnsupported,
+ false));
+ cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
+ vhArray, f, VarHandleTestMethodHandleAccessChar::testArrayIndexOutOfBounds,
+ false));
+ }
+
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceField(VarHandleTestMethodHandleAccessChar recv, Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123');
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, '\u0123', "set char value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, '\u4567');
+ char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
+ assertEquals(x, '\u4567', "setVolatile char value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, '\u0123');
+ char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
+ assertEquals(x, '\u0123', "setRelease char value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, '\u4567');
+ char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
+ assertEquals(x, '\u4567', "setOpaque char value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123');
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, '\u0123', '\u4567');
+ assertEquals(r, true, "success compareAndSet char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, '\u4567', "success compareAndSet char value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, '\u0123', '\u89AB');
+ assertEquals(r, false, "failing compareAndSet char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, '\u4567', "failing compareAndSet char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, '\u4567', '\u0123');
+ assertEquals(r, '\u4567', "success compareAndExchange char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, '\u0123', "success compareAndExchange char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, '\u4567', '\u89AB');
+ assertEquals(r, '\u0123', "failing compareAndExchange char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, '\u0123', "failing compareAndExchange char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, '\u0123', '\u4567');
+ assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, '\u0123', '\u89AB');
+ assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, '\u4567', '\u0123');
+ assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, '\u4567', '\u89AB');
+ assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, '\u0123', '\u4567');
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, '\u4567', "weakCompareAndSetPlain char value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, '\u4567', '\u0123');
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, '\u0123', '\u4567');
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, '\u4567', '\u0123');
+ }
+ assertEquals(success, true, "weakCompareAndSet char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, '\u0123', "weakCompareAndSet char");
+ }
+
+ // Compare set and get
+ {
+ char o = (char) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndSet char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, '\u4567', "getAndSet char value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndAdd char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndAddAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndAddRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value");
+ }
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOr char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOrRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAnd char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAndRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXor char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXorRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value");
+ }
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessChar recv, Handles hs) throws Throwable {
+
+
+ }
+
+
+ static void testStaticField(Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact('\u0123');
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, '\u0123', "set char value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact('\u4567');
+ char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
+ assertEquals(x, '\u4567', "setVolatile char value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact('\u0123');
+ char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
+ assertEquals(x, '\u0123', "setRelease char value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact('\u4567');
+ char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
+ assertEquals(x, '\u4567', "setOpaque char value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact('\u0123');
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact('\u0123', '\u4567');
+ assertEquals(r, true, "success compareAndSet char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, '\u4567', "success compareAndSet char value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact('\u0123', '\u89AB');
+ assertEquals(r, false, "failing compareAndSet char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, '\u4567', "failing compareAndSet char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact('\u4567', '\u0123');
+ assertEquals(r, '\u4567', "success compareAndExchange char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, '\u0123', "success compareAndExchange char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact('\u4567', '\u89AB');
+ assertEquals(r, '\u0123', "failing compareAndExchange char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, '\u0123', "failing compareAndExchange char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact('\u0123', '\u4567');
+ assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact('\u0123', '\u89AB');
+ assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact('\u4567', '\u0123');
+ assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact('\u4567', '\u89AB');
+ assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact('\u0123', '\u4567');
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, '\u4567', "weakCompareAndSetPlain char value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact('\u4567', '\u0123');
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact('\u0123', '\u4567');
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact('\u4567', '\u0123');
+ }
+ assertEquals(success, true, "weakCompareAndSet char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, '\u0123', "weakCompareAndSet char");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact('\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_SET).invokeExact('\u4567');
+ assertEquals(o, '\u0123', "getAndSet char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, '\u4567', "getAndSet char value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact('\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact('\u4567');
+ assertEquals(o, '\u0123', "getAndSetAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, '\u4567', "getAndSetAcquire char value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact('\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact('\u4567');
+ assertEquals(o, '\u0123', "getAndSetRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, '\u4567', "getAndSetRelease char value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact('\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_ADD).invokeExact('\u4567');
+ assertEquals(o, '\u0123', "getAndAdd char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact('\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact('\u4567');
+ assertEquals(o, '\u0123', "getAndAddAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact('\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact('\u4567');
+ assertEquals(o, '\u0123', "getAndAddRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value");
+ }
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact('\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOr char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact('\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact('\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOrRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact('\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAnd char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact('\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact('\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAndRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact('\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXor char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact('\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact('\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact('\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXorRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value");
+ }
+ }
+
+ static void testStaticFieldUnsupported(Handles hs) throws Throwable {
+
+
+ }
+
+
+ static void testArray(Handles hs) throws Throwable {
+ char[] array = new char[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, '\u0123', "get char value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, '\u4567');
+ char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
+ assertEquals(x, '\u4567', "setVolatile char value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, '\u0123');
+ char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
+ assertEquals(x, '\u0123', "setRelease char value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, '\u4567');
+ char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
+ assertEquals(x, '\u4567', "setOpaque char value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, '\u0123', '\u4567');
+ assertEquals(r, true, "success compareAndSet char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, '\u4567', "success compareAndSet char value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, '\u0123', '\u89AB');
+ assertEquals(r, false, "failing compareAndSet char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, '\u4567', "failing compareAndSet char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, '\u4567', '\u0123');
+ assertEquals(r, '\u4567', "success compareAndExchange char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, '\u0123', "success compareAndExchange char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, '\u4567', '\u89AB');
+ assertEquals(r, '\u0123', "failing compareAndExchange char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, '\u0123', "failing compareAndExchange char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, '\u0123', '\u4567');
+ assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, '\u0123', '\u89AB');
+ assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, '\u4567', '\u0123');
+ assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
+ }
+
+ {
+ char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, '\u4567', '\u89AB');
+ assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, '\u0123', '\u4567');
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, '\u4567', "weakCompareAndSetPlain char value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, '\u4567', '\u0123');
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, '\u0123', '\u4567');
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, '\u4567', '\u0123');
+ }
+ assertEquals(success, true, "weakCompareAndSet char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, '\u0123', "weakCompareAndSet char");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndSet char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, '\u4567', "getAndSet char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndSetAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, '\u4567', "getAndSetAcquire char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndSetRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, '\u4567', "getAndSetRelease char value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndAdd char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndAddAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndAddRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value");
+ }
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOr char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseOrRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAnd char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseAndRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXor char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123');
+
+ char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, '\u4567');
+ assertEquals(o, '\u0123', "getAndBitwiseXorRelease char");
+ char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value");
+ }
+ }
+ }
+
+ static void testArrayUnsupported(Handles hs) throws Throwable {
+ char[] array = new char[10];
+
+ final int i = 0;
+
+
+ }
+
+ static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
+ char[] array = new char[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ checkIOOBE(am, () -> {
+ char x = (char) hs.get(am).invokeExact(array, ci);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkIOOBE(am, () -> {
+ hs.get(am).invokeExact(array, ci, '\u0123');
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ checkIOOBE(am, () -> {
+ boolean r = (boolean) hs.get(am).invokeExact(array, ci, '\u0123', '\u4567');
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkIOOBE(am, () -> {
+ char r = (char) hs.get(am).invokeExact(array, ci, '\u4567', '\u0123');
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkIOOBE(am, () -> {
+ char o = (char) hs.get(am).invokeExact(array, ci, '\u0123');
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkIOOBE(am, () -> {
+ char o = (char) hs.get(am).invokeExact(array, ci, '\u89AB');
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkIOOBE(am, () -> {
+ char o = (char) hs.get(am).invokeExact(array, ci, '\u89AB');
+ });
+ }
+ }
+ }
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessDouble.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessDouble.java
new file mode 100644
index 0000000..409d700
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessDouble.java
@@ -0,0 +1,748 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessDouble
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
+ static final double static_final_v = 1.0d;
+
+ static double static_v;
+
+ final double final_v = 1.0d;
+
+ double v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessDouble.class, "final_v", double.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessDouble.class, "v", double.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessDouble.class, "static_final_v", double.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessDouble.class, "static_v", double.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(double[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceField(this, hs)));
+ cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
+ vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodHandleAccessDouble::testStaticField));
+ cases.add(new MethodHandleAccessTestCase("Static field unsupported",
+ vhStaticField, f, VarHandleTestMethodHandleAccessDouble::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodHandleAccessDouble::testArray));
+ cases.add(new MethodHandleAccessTestCase("Array unsupported",
+ vhArray, f, VarHandleTestMethodHandleAccessDouble::testArrayUnsupported,
+ false));
+ cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
+ vhArray, f, VarHandleTestMethodHandleAccessDouble::testArrayIndexOutOfBounds,
+ false));
+ }
+
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceField(VarHandleTestMethodHandleAccessDouble recv, Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 1.0d);
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 1.0d, "set double value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 2.0d);
+ double x = (double) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
+ assertEquals(x, 2.0d, "setVolatile double value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 1.0d);
+ double x = (double) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
+ assertEquals(x, 1.0d, "setRelease double value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 2.0d);
+ double x = (double) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
+ assertEquals(x, 2.0d, "setOpaque double value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(recv, 1.0d);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0d, 2.0d);
+ assertEquals(r, true, "success compareAndSet double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 2.0d, "success compareAndSet double value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0d, 3.0d);
+ assertEquals(r, false, "failing compareAndSet double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 2.0d, "failing compareAndSet double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0d, 1.0d);
+ assertEquals(r, 2.0d, "success compareAndExchange double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 1.0d, "success compareAndExchange double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0d, 3.0d);
+ assertEquals(r, 1.0d, "failing compareAndExchange double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 1.0d, "failing compareAndExchange double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0d, 2.0d);
+ assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0d, 3.0d);
+ assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0d, 1.0d);
+ assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0d, 3.0d);
+ assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, 1.0d, 2.0d);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 2.0d, "weakCompareAndSetPlain 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).invokeExact(recv, 2.0d, 1.0d);
+ }
+ assertEquals(success, true, "weakCompareAndSet double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 1.0d, "weakCompareAndSet 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");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 1.0d);
+
+ double o = (double) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 2.0d);
+ assertEquals(o, 1.0d, "getAndAdd double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 1.0d);
+
+ double o = (double) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, 2.0d);
+ assertEquals(o, 1.0d, "getAndAddAcquire double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 1.0d);
+
+ double o = (double) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, 2.0d);
+ assertEquals(o, 1.0d, "getAndAddRelease double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value");
+ }
+
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessDouble recv, Handles hs) throws Throwable {
+
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkUOE(am, () -> {
+ double r = (double) hs.get(am).invokeExact(recv, 1.0d);
+ });
+ }
+ }
+
+
+ static void testStaticField(Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(1.0d);
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 1.0d, "set double value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(2.0d);
+ double x = (double) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
+ assertEquals(x, 2.0d, "setVolatile double value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(1.0d);
+ double x = (double) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
+ assertEquals(x, 1.0d, "setRelease double value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(2.0d);
+ double x = (double) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
+ assertEquals(x, 2.0d, "setOpaque double value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(1.0d);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0d, 2.0d);
+ assertEquals(r, true, "success compareAndSet double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 2.0d, "success compareAndSet double value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0d, 3.0d);
+ assertEquals(r, false, "failing compareAndSet double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 2.0d, "failing compareAndSet double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0d, 1.0d);
+ assertEquals(r, 2.0d, "success compareAndExchange double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 1.0d, "success compareAndExchange double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0d, 3.0d);
+ assertEquals(r, 1.0d, "failing compareAndExchange double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 1.0d, "failing compareAndExchange double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0d, 2.0d);
+ assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0d, 3.0d);
+ assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0d, 1.0d);
+ assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0d, 3.0d);
+ assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(1.0d, 2.0d);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 2.0d, "weakCompareAndSetPlain 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).invokeExact(2.0d, 1.0d);
+ }
+ assertEquals(success, true, "weakCompareAndSet double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 1.0d, "weakCompareAndSet double");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(1.0d);
+
+ 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");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(1.0d);
+
+ double o = (double) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(2.0d);
+ assertEquals(o, 1.0d, "getAndSetAcquire double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 2.0d, "getAndSetAcquire double value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(1.0d);
+
+ double o = (double) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(2.0d);
+ assertEquals(o, 1.0d, "getAndSetRelease double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 2.0d, "getAndSetRelease double value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(1.0d);
+
+ double o = (double) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(2.0d);
+ assertEquals(o, 1.0d, "getAndAdd double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(1.0d);
+
+ double o = (double) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(2.0d);
+ assertEquals(o, 1.0d, "getAndAddAcquire double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(1.0d);
+
+ double o = (double) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(2.0d);
+ assertEquals(o, 1.0d, "getAndAddRelease double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value");
+ }
+
+ }
+
+ static void testStaticFieldUnsupported(Handles hs) throws Throwable {
+
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkUOE(am, () -> {
+ double r = (double) hs.get(am).invokeExact(1.0d);
+ });
+ }
+ }
+
+
+ static void testArray(Handles hs) throws Throwable {
+ double[] array = new double[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d);
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 1.0d, "get double value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 2.0d);
+ double x = (double) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
+ assertEquals(x, 2.0d, "setVolatile double value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 1.0d);
+ double x = (double) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
+ assertEquals(x, 1.0d, "setRelease double value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 2.0d);
+ double x = (double) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
+ assertEquals(x, 2.0d, "setOpaque double value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0d, 2.0d);
+ assertEquals(r, true, "success compareAndSet double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 2.0d, "success compareAndSet double value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0d, 3.0d);
+ assertEquals(r, false, "failing compareAndSet double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 2.0d, "failing compareAndSet double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0d, 1.0d);
+ assertEquals(r, 2.0d, "success compareAndExchange double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 1.0d, "success compareAndExchange double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0d, 3.0d);
+ assertEquals(r, 1.0d, "failing compareAndExchange double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 1.0d, "failing compareAndExchange double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0d, 2.0d);
+ assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0d, 3.0d);
+ assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0d, 1.0d);
+ assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
+ }
+
+ {
+ double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0d, 3.0d);
+ assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, 1.0d, 2.0d);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 2.0d, "weakCompareAndSetPlain 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).invokeExact(array, i, 2.0d, 1.0d);
+ }
+ assertEquals(success, true, "weakCompareAndSet double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 1.0d, "weakCompareAndSet double");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d);
+
+ 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);
+
+ double o = (double) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, 2.0d);
+ assertEquals(o, 1.0d, "getAndSetAcquire double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 2.0d, "getAndSetAcquire double value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d);
+
+ double o = (double) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, 2.0d);
+ assertEquals(o, 1.0d, "getAndSetRelease double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 2.0d, "getAndSetRelease double value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d);
+
+ double o = (double) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 2.0d);
+ assertEquals(o, 1.0d, "getAndAdd double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d);
+
+ double o = (double) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, 2.0d);
+ assertEquals(o, 1.0d, "getAndAddAcquire double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d);
+
+ double o = (double) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, 2.0d);
+ assertEquals(o, 1.0d, "getAndAddRelease double");
+ double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value");
+ }
+
+ }
+ }
+
+ static void testArrayUnsupported(Handles hs) throws Throwable {
+ double[] array = new double[10];
+
+ final int i = 0;
+
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkUOE(am, () -> {
+ double o = (double) hs.get(am).invokeExact(array, i, 1.0d);
+ });
+ }
+ }
+
+ static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
+ double[] array = new double[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ checkIOOBE(am, () -> {
+ double x = (double) hs.get(am).invokeExact(array, ci);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkIOOBE(am, () -> {
+ hs.get(am).invokeExact(array, ci, 1.0d);
+ });
+ }
+
+ 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);
+ });
+ }
+
+ }
+ }
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessFloat.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessFloat.java
new file mode 100644
index 0000000..b826e18
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessFloat.java
@@ -0,0 +1,748 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessFloat
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
+ static final float static_final_v = 1.0f;
+
+ static float static_v;
+
+ final float final_v = 1.0f;
+
+ float v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessFloat.class, "final_v", float.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessFloat.class, "v", float.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessFloat.class, "static_final_v", float.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessFloat.class, "static_v", float.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(float[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceField(this, hs)));
+ cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
+ vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodHandleAccessFloat::testStaticField));
+ cases.add(new MethodHandleAccessTestCase("Static field unsupported",
+ vhStaticField, f, VarHandleTestMethodHandleAccessFloat::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodHandleAccessFloat::testArray));
+ cases.add(new MethodHandleAccessTestCase("Array unsupported",
+ vhArray, f, VarHandleTestMethodHandleAccessFloat::testArrayUnsupported,
+ false));
+ cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
+ vhArray, f, VarHandleTestMethodHandleAccessFloat::testArrayIndexOutOfBounds,
+ false));
+ }
+
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceField(VarHandleTestMethodHandleAccessFloat recv, Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f);
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 1.0f, "set float value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 2.0f);
+ float x = (float) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
+ assertEquals(x, 2.0f, "setVolatile float value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 1.0f);
+ float x = (float) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
+ assertEquals(x, 1.0f, "setRelease float value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 2.0f);
+ float x = (float) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
+ assertEquals(x, 2.0f, "setOpaque float value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0f, 2.0f);
+ assertEquals(r, true, "success compareAndSet float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 2.0f, "success compareAndSet float value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0f, 3.0f);
+ assertEquals(r, false, "failing compareAndSet float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 2.0f, "failing compareAndSet float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0f, 1.0f);
+ assertEquals(r, 2.0f, "success compareAndExchange float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 1.0f, "success compareAndExchange float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0f, 3.0f);
+ assertEquals(r, 1.0f, "failing compareAndExchange float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 1.0f, "failing compareAndExchange float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0f, 2.0f);
+ assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0f, 3.0f);
+ assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0f, 1.0f);
+ assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0f, 3.0f);
+ assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, 1.0f, 2.0f);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 2.0f, "weakCompareAndSetPlain 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).invokeExact(recv, 2.0f, 1.0f);
+ }
+ assertEquals(success, true, "weakCompareAndSet float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 1.0f, "weakCompareAndSet 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");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f);
+
+ float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 2.0f);
+ assertEquals(o, 1.0f, "getAndAdd float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f);
+
+ float o = (float) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, 2.0f);
+ assertEquals(o, 1.0f, "getAndAddAcquire float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f);
+
+ float o = (float) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, 2.0f);
+ assertEquals(o, 1.0f, "getAndAddRelease float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
+ }
+
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessFloat recv, Handles hs) throws Throwable {
+
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkUOE(am, () -> {
+ float r = (float) hs.get(am).invokeExact(recv, 1.0f);
+ });
+ }
+ }
+
+
+ static void testStaticField(Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(1.0f);
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 1.0f, "set float value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(2.0f);
+ float x = (float) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
+ assertEquals(x, 2.0f, "setVolatile float value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(1.0f);
+ float x = (float) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
+ assertEquals(x, 1.0f, "setRelease float value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(2.0f);
+ float x = (float) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
+ assertEquals(x, 2.0f, "setOpaque float value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(1.0f);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0f, 2.0f);
+ assertEquals(r, true, "success compareAndSet float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 2.0f, "success compareAndSet float value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0f, 3.0f);
+ assertEquals(r, false, "failing compareAndSet float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 2.0f, "failing compareAndSet float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0f, 1.0f);
+ assertEquals(r, 2.0f, "success compareAndExchange float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 1.0f, "success compareAndExchange float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0f, 3.0f);
+ assertEquals(r, 1.0f, "failing compareAndExchange float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 1.0f, "failing compareAndExchange float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0f, 2.0f);
+ assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0f, 3.0f);
+ assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0f, 1.0f);
+ assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0f, 3.0f);
+ assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(1.0f, 2.0f);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 2.0f, "weakCompareAndSetPlain 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).invokeExact(2.0f, 1.0f);
+ }
+ assertEquals(success, true, "weakCompareAndSet float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 1.0f, "weakCompareAndSet float");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(1.0f);
+
+ 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");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(1.0f);
+
+ float o = (float) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(2.0f);
+ assertEquals(o, 1.0f, "getAndSetAcquire float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 2.0f, "getAndSetAcquire float value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(1.0f);
+
+ float o = (float) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(2.0f);
+ assertEquals(o, 1.0f, "getAndSetRelease float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 2.0f, "getAndSetRelease float value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(1.0f);
+
+ float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(2.0f);
+ assertEquals(o, 1.0f, "getAndAdd float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(1.0f);
+
+ float o = (float) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(2.0f);
+ assertEquals(o, 1.0f, "getAndAddAcquire float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(1.0f);
+
+ float o = (float) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(2.0f);
+ assertEquals(o, 1.0f, "getAndAddRelease float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
+ }
+
+ }
+
+ static void testStaticFieldUnsupported(Handles hs) throws Throwable {
+
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkUOE(am, () -> {
+ float r = (float) hs.get(am).invokeExact(1.0f);
+ });
+ }
+ }
+
+
+ static void testArray(Handles hs) throws Throwable {
+ float[] array = new float[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 1.0f, "get float value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 2.0f);
+ float x = (float) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
+ assertEquals(x, 2.0f, "setVolatile float value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 1.0f);
+ float x = (float) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
+ assertEquals(x, 1.0f, "setRelease float value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 2.0f);
+ float x = (float) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
+ assertEquals(x, 2.0f, "setOpaque float value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0f, 2.0f);
+ assertEquals(r, true, "success compareAndSet float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 2.0f, "success compareAndSet float value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0f, 3.0f);
+ assertEquals(r, false, "failing compareAndSet float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 2.0f, "failing compareAndSet float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0f, 1.0f);
+ assertEquals(r, 2.0f, "success compareAndExchange float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 1.0f, "success compareAndExchange float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0f, 3.0f);
+ assertEquals(r, 1.0f, "failing compareAndExchange float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 1.0f, "failing compareAndExchange float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0f, 2.0f);
+ assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0f, 3.0f);
+ assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0f, 1.0f);
+ assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
+ }
+
+ {
+ float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0f, 3.0f);
+ assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, 1.0f, 2.0f);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 2.0f, "weakCompareAndSetPlain 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).invokeExact(array, i, 2.0f, 1.0f);
+ }
+ assertEquals(success, true, "weakCompareAndSet float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 1.0f, "weakCompareAndSet float");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
+
+ 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);
+
+ float o = (float) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, 2.0f);
+ assertEquals(o, 1.0f, "getAndSetAcquire float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 2.0f, "getAndSetAcquire float value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
+
+ float o = (float) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, 2.0f);
+ assertEquals(o, 1.0f, "getAndSetRelease float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 2.0f, "getAndSetRelease float value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
+
+ float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 2.0f);
+ assertEquals(o, 1.0f, "getAndAdd float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
+
+ float o = (float) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, 2.0f);
+ assertEquals(o, 1.0f, "getAndAddAcquire float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
+
+ float o = (float) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, 2.0f);
+ assertEquals(o, 1.0f, "getAndAddRelease float");
+ float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
+ }
+
+ }
+ }
+
+ static void testArrayUnsupported(Handles hs) throws Throwable {
+ float[] array = new float[10];
+
+ final int i = 0;
+
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkUOE(am, () -> {
+ float o = (float) hs.get(am).invokeExact(array, i, 1.0f);
+ });
+ }
+ }
+
+ static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
+ float[] array = new float[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ checkIOOBE(am, () -> {
+ float x = (float) hs.get(am).invokeExact(array, ci);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkIOOBE(am, () -> {
+ hs.get(am).invokeExact(array, ci, 1.0f);
+ });
+ }
+
+ 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);
+ });
+ }
+
+ }
+ }
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessInt.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessInt.java
new file mode 100644
index 0000000..da0c63f
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessInt.java
@@ -0,0 +1,987 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessInt
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest {
+ static final int static_final_v = 0x01234567;
+
+ static int static_v;
+
+ final int final_v = 0x01234567;
+
+ int v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessInt.class, "final_v", int.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessInt.class, "v", int.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessInt.class, "static_final_v", int.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessInt.class, "static_v", int.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(int[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceField(this, hs)));
+ cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
+ vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodHandleAccessInt::testStaticField));
+ cases.add(new MethodHandleAccessTestCase("Static field unsupported",
+ vhStaticField, f, VarHandleTestMethodHandleAccessInt::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodHandleAccessInt::testArray));
+ cases.add(new MethodHandleAccessTestCase("Array unsupported",
+ vhArray, f, VarHandleTestMethodHandleAccessInt::testArrayUnsupported,
+ false));
+ cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
+ vhArray, f, VarHandleTestMethodHandleAccessInt::testArrayIndexOutOfBounds,
+ false));
+ }
+
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceField(VarHandleTestMethodHandleAccessInt recv, Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567);
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x01234567, "set int value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 0x89ABCDEF);
+ int x = (int) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
+ assertEquals(x, 0x89ABCDEF, "setVolatile int value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 0x01234567);
+ int x = (int) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
+ assertEquals(x, 0x01234567, "setRelease int value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 0x89ABCDEF);
+ int x = (int) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
+ assertEquals(x, 0x89ABCDEF, "setOpaque int value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 0x01234567, 0x89ABCDEF);
+ assertEquals(r, true, "success compareAndSet int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x89ABCDEF, "success compareAndSet int value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 0x01234567, 0xCAFEBABE);
+ assertEquals(r, false, "failing compareAndSet int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 0x89ABCDEF, 0x01234567);
+ assertEquals(r, 0x89ABCDEF, "success compareAndExchange int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x01234567, "success compareAndExchange int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 0x89ABCDEF, 0xCAFEBABE);
+ assertEquals(r, 0x01234567, "failing compareAndExchange int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x01234567, "failing compareAndExchange int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 0x01234567, 0x89ABCDEF);
+ assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 0x01234567, 0xCAFEBABE);
+ assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 0x89ABCDEF, 0x01234567);
+ assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 0x89ABCDEF, 0xCAFEBABE);
+ assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, 0x01234567, 0x89ABCDEF);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x89ABCDEF, "weakCompareAndSetPlain int 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, 0x89ABCDEF, 0x01234567);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 0x01234567, 0x89ABCDEF);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 0x89ABCDEF, 0x01234567);
+ }
+ assertEquals(success, true, "weakCompareAndSet int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x01234567, "weakCompareAndSet int");
+ }
+
+ // Compare set and get
+ {
+ int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndSet int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x89ABCDEF, "getAndSet int value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAdd int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAdd int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAddAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddAcquire int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAddRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddRelease int value");
+ }
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOr int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOr int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOrAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrAcquire int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOrRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrRelease int value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAnd int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAnd int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAndAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndAcquire int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAndRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndRelease int value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXor int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXor int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXorAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorAcquire int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXorRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorRelease int value");
+ }
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessInt recv, Handles hs) throws Throwable {
+
+
+ }
+
+
+ static void testStaticField(Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x01234567);
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x01234567, "set int value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(0x89ABCDEF);
+ int x = (int) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
+ assertEquals(x, 0x89ABCDEF, "setVolatile int value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(0x01234567);
+ int x = (int) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
+ assertEquals(x, 0x01234567, "setRelease int value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(0x89ABCDEF);
+ int x = (int) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
+ assertEquals(x, 0x89ABCDEF, "setOpaque int value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(0x01234567);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(0x01234567, 0x89ABCDEF);
+ assertEquals(r, true, "success compareAndSet int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x89ABCDEF, "success compareAndSet int value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(0x01234567, 0xCAFEBABE);
+ assertEquals(r, false, "failing compareAndSet int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(0x89ABCDEF, 0x01234567);
+ assertEquals(r, 0x89ABCDEF, "success compareAndExchange int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x01234567, "success compareAndExchange int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(0x89ABCDEF, 0xCAFEBABE);
+ assertEquals(r, 0x01234567, "failing compareAndExchange int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x01234567, "failing compareAndExchange int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(0x01234567, 0x89ABCDEF);
+ assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(0x01234567, 0xCAFEBABE);
+ assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(0x89ABCDEF, 0x01234567);
+ assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(0x89ABCDEF, 0xCAFEBABE);
+ assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(0x01234567, 0x89ABCDEF);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x89ABCDEF, "weakCompareAndSetPlain int value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(0x89ABCDEF, 0x01234567);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(0x01234567, 0x89ABCDEF);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(0x89ABCDEF, 0x01234567);
+ }
+ assertEquals(success, true, "weakCompareAndSet int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x01234567, "weakCompareAndSet int");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndSet int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x89ABCDEF, "getAndSet int value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndSetAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x89ABCDEF, "getAndSetAcquire int value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndSetRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x89ABCDEF, "getAndSetRelease int value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAdd int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAdd int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAddAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddAcquire int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAddRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddRelease int value");
+ }
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOr int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOr int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOrAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrAcquire int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOrRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrRelease int value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAnd int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAnd int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAndAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndAcquire int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAndRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndRelease int value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXor int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXor int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXorAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorAcquire int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXorRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorRelease int value");
+ }
+ }
+
+ static void testStaticFieldUnsupported(Handles hs) throws Throwable {
+
+
+ }
+
+
+ static void testArray(Handles hs) throws Throwable {
+ int[] array = new int[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x01234567, "get int value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 0x89ABCDEF);
+ int x = (int) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
+ assertEquals(x, 0x89ABCDEF, "setVolatile int value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 0x01234567);
+ int x = (int) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
+ assertEquals(x, 0x01234567, "setRelease int value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 0x89ABCDEF);
+ int x = (int) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
+ assertEquals(x, 0x89ABCDEF, "setOpaque int value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 0x01234567, 0x89ABCDEF);
+ assertEquals(r, true, "success compareAndSet int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x89ABCDEF, "success compareAndSet int value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 0x01234567, 0xCAFEBABE);
+ assertEquals(r, false, "failing compareAndSet int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 0x89ABCDEF, 0x01234567);
+ assertEquals(r, 0x89ABCDEF, "success compareAndExchange int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x01234567, "success compareAndExchange int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 0x89ABCDEF, 0xCAFEBABE);
+ assertEquals(r, 0x01234567, "failing compareAndExchange int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x01234567, "failing compareAndExchange int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 0x01234567, 0x89ABCDEF);
+ assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 0x01234567, 0xCAFEBABE);
+ assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 0x89ABCDEF, 0x01234567);
+ assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value");
+ }
+
+ {
+ int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 0x89ABCDEF, 0xCAFEBABE);
+ assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, 0x01234567, 0x89ABCDEF);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x89ABCDEF, "weakCompareAndSetPlain int 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, 0x89ABCDEF, 0x01234567);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int");
+ }
+
+ {
+ 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, 0x01234567, 0x89ABCDEF);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 0x89ABCDEF, 0x01234567);
+ }
+ assertEquals(success, true, "weakCompareAndSet int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x01234567, "weakCompareAndSet int");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndSet int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x89ABCDEF, "getAndSet int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndSetAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x89ABCDEF, "getAndSetAcquire int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndSetRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x89ABCDEF, "getAndSetRelease int value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAdd int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAdd int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAddAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddAcquire int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndAddRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddRelease int value");
+ }
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOr int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOr int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOrAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrAcquire int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseOrRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrRelease int value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAnd int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAnd int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAndAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndAcquire int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseAndRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndRelease int value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXor int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXor int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXorAcquire int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorAcquire int value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567);
+
+ int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, 0x89ABCDEF);
+ assertEquals(o, 0x01234567, "getAndBitwiseXorRelease int");
+ int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorRelease int value");
+ }
+ }
+ }
+
+ static void testArrayUnsupported(Handles hs) throws Throwable {
+ int[] array = new int[10];
+
+ final int i = 0;
+
+
+ }
+
+ static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
+ int[] array = new int[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ checkIOOBE(am, () -> {
+ int x = (int) hs.get(am).invokeExact(array, ci);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkIOOBE(am, () -> {
+ hs.get(am).invokeExact(array, ci, 0x01234567);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ checkIOOBE(am, () -> {
+ boolean r = (boolean) hs.get(am).invokeExact(array, ci, 0x01234567, 0x89ABCDEF);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkIOOBE(am, () -> {
+ int r = (int) hs.get(am).invokeExact(array, ci, 0x89ABCDEF, 0x01234567);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkIOOBE(am, () -> {
+ int o = (int) hs.get(am).invokeExact(array, ci, 0x01234567);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkIOOBE(am, () -> {
+ int o = (int) hs.get(am).invokeExact(array, ci, 0xCAFEBABE);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkIOOBE(am, () -> {
+ int o = (int) hs.get(am).invokeExact(array, ci, 0xCAFEBABE);
+ });
+ }
+ }
+ }
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessLong.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessLong.java
new file mode 100644
index 0000000..6e16e7c
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessLong.java
@@ -0,0 +1,987 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessLong
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest {
+ static final long static_final_v = 0x0123456789ABCDEFL;
+
+ static long static_v;
+
+ final long final_v = 0x0123456789ABCDEFL;
+
+ long v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessLong.class, "final_v", long.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessLong.class, "v", long.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessLong.class, "static_final_v", long.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessLong.class, "static_v", long.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(long[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceField(this, hs)));
+ cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
+ vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodHandleAccessLong::testStaticField));
+ cases.add(new MethodHandleAccessTestCase("Static field unsupported",
+ vhStaticField, f, VarHandleTestMethodHandleAccessLong::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodHandleAccessLong::testArray));
+ cases.add(new MethodHandleAccessTestCase("Array unsupported",
+ vhArray, f, VarHandleTestMethodHandleAccessLong::testArrayUnsupported,
+ false));
+ cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
+ vhArray, f, VarHandleTestMethodHandleAccessLong::testArrayIndexOutOfBounds,
+ false));
+ }
+
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceField(VarHandleTestMethodHandleAccessLong recv, Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "set long value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
+ long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 0x0123456789ABCDEFL);
+ long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
+ long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ assertEquals(r, true, "success compareAndSet long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, false, "failing compareAndSet long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetPlain long 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, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ }
+ assertEquals(success, true, "weakCompareAndSet long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSet long");
+ }
+
+ // Compare set and get
+ {
+ long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAddRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value");
+ }
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value");
+ }
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessLong recv, Handles hs) throws Throwable {
+
+
+ }
+
+
+ static void testStaticField(Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x0123456789ABCDEFL, "set long value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(0xCAFEBABECAFEBABEL);
+ long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(0x0123456789ABCDEFL);
+ long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
+ assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(0xCAFEBABECAFEBABEL);
+ long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ assertEquals(r, true, "success compareAndSet long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, false, "failing compareAndSet long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetPlain long value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ }
+ assertEquals(success, true, "weakCompareAndSet long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSet long");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndSetAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetAcquire long value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndSetRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetRelease long value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAddRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value");
+ }
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value");
+ }
+ }
+
+ static void testStaticFieldUnsupported(Handles hs) throws Throwable {
+
+
+ }
+
+
+ static void testArray(Handles hs) throws Throwable {
+ long[] array = new long[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x0123456789ABCDEFL, "get long value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
+ long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 0x0123456789ABCDEFL);
+ long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
+ assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
+ long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ assertEquals(r, true, "success compareAndSet long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, false, "failing compareAndSet long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
+ }
+
+ {
+ long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
+ assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetPlain long 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, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
+ }
+
+ {
+ 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, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ }
+ assertEquals(success, true, "weakCompareAndSet long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSet long");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndSetAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetAcquire long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndSetRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetRelease long value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndAddRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value");
+ }
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
+
+ long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
+ assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long");
+ long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value");
+ }
+ }
+ }
+
+ static void testArrayUnsupported(Handles hs) throws Throwable {
+ long[] array = new long[10];
+
+ final int i = 0;
+
+
+ }
+
+ static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
+ long[] array = new long[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ checkIOOBE(am, () -> {
+ long x = (long) hs.get(am).invokeExact(array, ci);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkIOOBE(am, () -> {
+ hs.get(am).invokeExact(array, ci, 0x0123456789ABCDEFL);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ checkIOOBE(am, () -> {
+ boolean r = (boolean) hs.get(am).invokeExact(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkIOOBE(am, () -> {
+ long r = (long) hs.get(am).invokeExact(array, ci, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkIOOBE(am, () -> {
+ long o = (long) hs.get(am).invokeExact(array, ci, 0x0123456789ABCDEFL);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkIOOBE(am, () -> {
+ long o = (long) hs.get(am).invokeExact(array, ci, 0xDEADBEEFDEADBEEFL);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkIOOBE(am, () -> {
+ long o = (long) hs.get(am).invokeExact(array, ci, 0xDEADBEEFDEADBEEFL);
+ });
+ }
+ }
+ }
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessShort.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessShort.java
new file mode 100644
index 0000000..5b6b8ad
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessShort.java
@@ -0,0 +1,987 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessShort
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest {
+ static final short static_final_v = (short)0x0123;
+
+ static short static_v;
+
+ final short final_v = (short)0x0123;
+
+ short v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessShort.class, "final_v", short.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessShort.class, "v", short.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessShort.class, "static_final_v", short.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessShort.class, "static_v", short.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(short[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceField(this, hs)));
+ cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
+ vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodHandleAccessShort::testStaticField));
+ cases.add(new MethodHandleAccessTestCase("Static field unsupported",
+ vhStaticField, f, VarHandleTestMethodHandleAccessShort::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodHandleAccessShort::testArray));
+ cases.add(new MethodHandleAccessTestCase("Array unsupported",
+ vhArray, f, VarHandleTestMethodHandleAccessShort::testArrayUnsupported,
+ false));
+ cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
+ vhArray, f, VarHandleTestMethodHandleAccessShort::testArrayIndexOutOfBounds,
+ false));
+ }
+
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceField(VarHandleTestMethodHandleAccessShort recv, Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)0x0123, "set short value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, (short)0x4567);
+ short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
+ assertEquals(x, (short)0x4567, "setVolatile short value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, (short)0x0123);
+ short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
+ assertEquals(x, (short)0x0123, "setRelease short value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, (short)0x4567);
+ short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
+ assertEquals(x, (short)0x4567, "setOpaque short value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (short)0x0123, (short)0x4567);
+ assertEquals(r, true, "success compareAndSet short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)0x4567, "success compareAndSet short value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (short)0x0123, (short)0x89AB);
+ assertEquals(r, false, "failing compareAndSet short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)0x4567, "failing compareAndSet short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (short)0x4567, (short)0x0123);
+ assertEquals(r, (short)0x4567, "success compareAndExchange short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)0x0123, "success compareAndExchange short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (short)0x4567, (short)0x89AB);
+ assertEquals(r, (short)0x0123, "failing compareAndExchange short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)0x0123, "failing compareAndExchange short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (short)0x0123, (short)0x4567);
+ assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (short)0x0123, (short)0x89AB);
+ assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (short)0x4567, (short)0x0123);
+ assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (short)0x4567, (short)0x89AB);
+ assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, (short)0x0123, (short)0x4567);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)0x4567, "weakCompareAndSetPlain short value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, (short)0x4567, (short)0x0123);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)0x0123, "weakCompareAndSetAcquire short");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, (short)0x0123, (short)0x4567);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)0x4567, "weakCompareAndSetRelease short");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, (short)0x4567, (short)0x0123);
+ }
+ assertEquals(success, true, "weakCompareAndSet short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)0x0123, "weakCompareAndSet short");
+ }
+
+ // Compare set and get
+ {
+ short o = (short) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndSet short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)0x4567, "getAndSet short value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAdd short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAddAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAddRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value");
+ }
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOr short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAnd short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXor short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short value");
+ }
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessShort recv, Handles hs) throws Throwable {
+
+
+ }
+
+
+ static void testStaticField(Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)0x0123, "set short value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact((short)0x4567);
+ short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
+ assertEquals(x, (short)0x4567, "setVolatile short value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact((short)0x0123);
+ short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
+ assertEquals(x, (short)0x0123, "setRelease short value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact((short)0x4567);
+ short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
+ assertEquals(x, (short)0x4567, "setOpaque short value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((short)0x0123, (short)0x4567);
+ assertEquals(r, true, "success compareAndSet short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)0x4567, "success compareAndSet short value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((short)0x0123, (short)0x89AB);
+ assertEquals(r, false, "failing compareAndSet short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)0x4567, "failing compareAndSet short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((short)0x4567, (short)0x0123);
+ assertEquals(r, (short)0x4567, "success compareAndExchange short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)0x0123, "success compareAndExchange short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((short)0x4567, (short)0x89AB);
+ assertEquals(r, (short)0x0123, "failing compareAndExchange short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)0x0123, "failing compareAndExchange short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((short)0x0123, (short)0x4567);
+ assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((short)0x0123, (short)0x89AB);
+ assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((short)0x4567, (short)0x0123);
+ assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((short)0x4567, (short)0x89AB);
+ assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact((short)0x0123, (short)0x4567);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)0x4567, "weakCompareAndSetPlain short value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact((short)0x4567, (short)0x0123);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)0x0123, "weakCompareAndSetAcquire short");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact((short)0x0123, (short)0x4567);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)0x4567, "weakCompareAndSetRelease short");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact((short)0x4567, (short)0x0123);
+ }
+ assertEquals(success, true, "weakCompareAndSet short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)0x0123, "weakCompareAndSet short");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_SET).invokeExact((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndSet short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)0x4567, "getAndSet short value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndSetAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)0x4567, "getAndSetAcquire short value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndSetRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)0x4567, "getAndSetRelease short value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_ADD).invokeExact((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAdd short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAddAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAddRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value");
+ }
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOr short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAnd short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXor short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact((short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short value");
+ }
+ }
+
+ static void testStaticFieldUnsupported(Handles hs) throws Throwable {
+
+
+ }
+
+
+ static void testArray(Handles hs) throws Throwable {
+ short[] array = new short[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)0x0123, "get short value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, (short)0x4567);
+ short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
+ assertEquals(x, (short)0x4567, "setVolatile short value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, (short)0x0123);
+ short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
+ assertEquals(x, (short)0x0123, "setRelease short value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, (short)0x4567);
+ short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
+ assertEquals(x, (short)0x4567, "setOpaque short value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (short)0x0123, (short)0x4567);
+ assertEquals(r, true, "success compareAndSet short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)0x4567, "success compareAndSet short value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (short)0x0123, (short)0x89AB);
+ assertEquals(r, false, "failing compareAndSet short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)0x4567, "failing compareAndSet short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (short)0x4567, (short)0x0123);
+ assertEquals(r, (short)0x4567, "success compareAndExchange short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)0x0123, "success compareAndExchange short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (short)0x4567, (short)0x89AB);
+ assertEquals(r, (short)0x0123, "failing compareAndExchange short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)0x0123, "failing compareAndExchange short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (short)0x0123, (short)0x4567);
+ assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (short)0x0123, (short)0x89AB);
+ assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (short)0x4567, (short)0x0123);
+ assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value");
+ }
+
+ {
+ short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (short)0x4567, (short)0x89AB);
+ assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, (short)0x0123, (short)0x4567);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)0x4567, "weakCompareAndSetPlain short value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, (short)0x4567, (short)0x0123);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)0x0123, "weakCompareAndSetAcquire short");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, (short)0x0123, (short)0x4567);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)0x4567, "weakCompareAndSetRelease short");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, (short)0x4567, (short)0x0123);
+ }
+ assertEquals(success, true, "weakCompareAndSet short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)0x0123, "weakCompareAndSet short");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndSet short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)0x4567, "getAndSet short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndSetAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)0x4567, "getAndSetAcquire short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndSetRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)0x4567, "getAndSetRelease short value");
+ }
+
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAdd short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAddAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndAddRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value");
+ }
+
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOr short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAnd short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXor short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
+
+ short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, (short)0x4567);
+ assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short");
+ short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short value");
+ }
+ }
+ }
+
+ static void testArrayUnsupported(Handles hs) throws Throwable {
+ short[] array = new short[10];
+
+ final int i = 0;
+
+
+ }
+
+ static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
+ short[] array = new short[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ checkIOOBE(am, () -> {
+ short x = (short) hs.get(am).invokeExact(array, ci);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkIOOBE(am, () -> {
+ hs.get(am).invokeExact(array, ci, (short)0x0123);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ checkIOOBE(am, () -> {
+ boolean r = (boolean) hs.get(am).invokeExact(array, ci, (short)0x0123, (short)0x4567);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkIOOBE(am, () -> {
+ short r = (short) hs.get(am).invokeExact(array, ci, (short)0x4567, (short)0x0123);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkIOOBE(am, () -> {
+ short o = (short) hs.get(am).invokeExact(array, ci, (short)0x0123);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkIOOBE(am, () -> {
+ short o = (short) hs.get(am).invokeExact(array, ci, (short)0x89AB);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkIOOBE(am, () -> {
+ short o = (short) hs.get(am).invokeExact(array, ci, (short)0x89AB);
+ });
+ }
+ }
+ }
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessString.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessString.java
new file mode 100644
index 0000000..0eb9785
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessString.java
@@ -0,0 +1,677 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessString
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
+ static final String static_final_v = "foo";
+
+ static String static_v;
+
+ final String final_v = "foo";
+
+ String v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessString.class, "final_v", String.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccessString.class, "v", String.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessString.class, "static_final_v", String.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccessString.class, "static_v", String.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(String[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceField(this, hs)));
+ cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
+ vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodHandleAccessString::testStaticField));
+ cases.add(new MethodHandleAccessTestCase("Static field unsupported",
+ vhStaticField, f, VarHandleTestMethodHandleAccessString::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodHandleAccessString::testArray));
+ cases.add(new MethodHandleAccessTestCase("Array unsupported",
+ vhArray, f, VarHandleTestMethodHandleAccessString::testArrayUnsupported,
+ false));
+ cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
+ vhArray, f, VarHandleTestMethodHandleAccessString::testArrayIndexOutOfBounds,
+ false));
+ }
+
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceField(VarHandleTestMethodHandleAccessString recv, Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, "foo");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, "foo", "set String value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, "bar");
+ String x = (String) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
+ assertEquals(x, "bar", "setVolatile String value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, "foo");
+ String x = (String) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
+ assertEquals(x, "foo", "setRelease String value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, "bar");
+ String x = (String) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
+ assertEquals(x, "bar", "setOpaque String value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(recv, "foo");
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, "foo", "bar");
+ assertEquals(r, true, "success compareAndSet String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, "bar", "success compareAndSet String value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, "foo", "baz");
+ assertEquals(r, false, "failing compareAndSet String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, "bar", "failing compareAndSet String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, "bar", "foo");
+ assertEquals(r, "bar", "success compareAndExchange String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, "foo", "success compareAndExchange String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, "bar", "baz");
+ assertEquals(r, "foo", "failing compareAndExchange String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, "foo", "failing compareAndExchange String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, "foo", "bar");
+ assertEquals(r, "foo", "success compareAndExchangeAcquire String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, "bar", "success compareAndExchangeAcquire String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, "foo", "baz");
+ assertEquals(r, "bar", "failing compareAndExchangeAcquire String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, "bar", "failing compareAndExchangeAcquire String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, "bar", "foo");
+ assertEquals(r, "bar", "success compareAndExchangeRelease String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, "foo", "success compareAndExchangeRelease String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, "bar", "baz");
+ assertEquals(r, "foo", "failing compareAndExchangeRelease String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, "foo", "failing compareAndExchangeRelease String value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, "foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, "bar", "weakCompareAndSetPlain String 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, "bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, "foo", "weakCompareAndSetAcquire String");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, "foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, "bar", "weakCompareAndSetRelease String");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, "bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSet String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, "foo", "weakCompareAndSet String");
+ }
+
+ // Compare set and get
+ {
+ String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, "bar");
+ assertEquals(o, "foo", "getAndSet String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, "bar", "getAndSet String value");
+ }
+
+
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessString recv, Handles hs) throws Throwable {
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkUOE(am, () -> {
+ String r = (String) hs.get(am).invokeExact(recv, "foo");
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkUOE(am, () -> {
+ String r = (String) hs.get(am).invokeExact(recv, "foo");
+ });
+ }
+ }
+
+
+ static void testStaticField(Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact("foo");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, "foo", "set String value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact("bar");
+ String x = (String) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
+ assertEquals(x, "bar", "setVolatile String value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact("foo");
+ String x = (String) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
+ assertEquals(x, "foo", "setRelease String value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact("bar");
+ String x = (String) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
+ assertEquals(x, "bar", "setOpaque String value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact("foo");
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact("foo", "bar");
+ assertEquals(r, true, "success compareAndSet String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, "bar", "success compareAndSet String value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact("foo", "baz");
+ assertEquals(r, false, "failing compareAndSet String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, "bar", "failing compareAndSet String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact("bar", "foo");
+ assertEquals(r, "bar", "success compareAndExchange String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, "foo", "success compareAndExchange String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact("bar", "baz");
+ assertEquals(r, "foo", "failing compareAndExchange String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, "foo", "failing compareAndExchange String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact("foo", "bar");
+ assertEquals(r, "foo", "success compareAndExchangeAcquire String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, "bar", "success compareAndExchangeAcquire String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact("foo", "baz");
+ assertEquals(r, "bar", "failing compareAndExchangeAcquire String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, "bar", "failing compareAndExchangeAcquire String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact("bar", "foo");
+ assertEquals(r, "bar", "success compareAndExchangeRelease String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, "foo", "success compareAndExchangeRelease String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact("bar", "baz");
+ assertEquals(r, "foo", "failing compareAndExchangeRelease String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, "foo", "failing compareAndExchangeRelease String value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact("foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, "bar", "weakCompareAndSetPlain String value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact("bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, "foo", "weakCompareAndSetAcquire String");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact("foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, "bar", "weakCompareAndSetRelease String");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact("bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSet String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, "foo", "weakCompareAndSet String");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact("foo");
+
+ String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact("bar");
+ assertEquals(o, "foo", "getAndSet String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, "bar", "getAndSet String value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact("foo");
+
+ String o = (String) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact("bar");
+ assertEquals(o, "foo", "getAndSetAcquire String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, "bar", "getAndSetAcquire String value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact("foo");
+
+ String o = (String) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact("bar");
+ assertEquals(o, "foo", "getAndSetRelease String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, "bar", "getAndSetRelease String value");
+ }
+
+
+ }
+
+ static void testStaticFieldUnsupported(Handles hs) throws Throwable {
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkUOE(am, () -> {
+ String r = (String) hs.get(am).invokeExact("foo");
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkUOE(am, () -> {
+ String r = (String) hs.get(am).invokeExact("foo");
+ });
+ }
+ }
+
+
+ static void testArray(Handles hs) throws Throwable {
+ String[] array = new String[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, "foo");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, "foo", "get String value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, "bar");
+ String x = (String) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
+ assertEquals(x, "bar", "setVolatile String value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, "foo");
+ String x = (String) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
+ assertEquals(x, "foo", "setRelease String value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, "bar");
+ String x = (String) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
+ assertEquals(x, "bar", "setOpaque String value");
+ }
+
+ hs.get(TestAccessMode.SET).invokeExact(array, i, "foo");
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, "foo", "bar");
+ assertEquals(r, true, "success compareAndSet String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, "bar", "success compareAndSet String value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, "foo", "baz");
+ assertEquals(r, false, "failing compareAndSet String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, "bar", "failing compareAndSet String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, "bar", "foo");
+ assertEquals(r, "bar", "success compareAndExchange String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, "foo", "success compareAndExchange String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, "bar", "baz");
+ assertEquals(r, "foo", "failing compareAndExchange String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, "foo", "failing compareAndExchange String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, "foo", "bar");
+ assertEquals(r, "foo", "success compareAndExchangeAcquire String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, "bar", "success compareAndExchangeAcquire String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, "foo", "baz");
+ assertEquals(r, "bar", "failing compareAndExchangeAcquire String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, "bar", "failing compareAndExchangeAcquire String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, "bar", "foo");
+ assertEquals(r, "bar", "success compareAndExchangeRelease String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, "foo", "success compareAndExchangeRelease String value");
+ }
+
+ {
+ String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, "bar", "baz");
+ assertEquals(r, "foo", "failing compareAndExchangeRelease String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, "foo", "failing compareAndExchangeRelease String value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, "foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, "bar", "weakCompareAndSetPlain String 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, "bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, "foo", "weakCompareAndSetAcquire String");
+ }
+
+ {
+ 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, "foo", "bar");
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, "bar", "weakCompareAndSetRelease String");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, "bar", "foo");
+ }
+ assertEquals(success, true, "weakCompareAndSet String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, "foo", "weakCompareAndSet String");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, "foo");
+
+ String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, "bar");
+ assertEquals(o, "foo", "getAndSet String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, "bar", "getAndSet String value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, "foo");
+
+ String o = (String) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, "bar");
+ assertEquals(o, "foo", "getAndSetAcquire String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, "bar", "getAndSetAcquire String value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, "foo");
+
+ String o = (String) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, "bar");
+ assertEquals(o, "foo", "getAndSetRelease String");
+ String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, "bar", "getAndSetRelease String value");
+ }
+
+
+ }
+ }
+
+ static void testArrayUnsupported(Handles hs) throws Throwable {
+ String[] array = new String[10];
+
+ final int i = 0;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkUOE(am, () -> {
+ String o = (String) hs.get(am).invokeExact(array, i, "foo");
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkUOE(am, () -> {
+ String o = (String) hs.get(am).invokeExact(array, i, "foo");
+ });
+ }
+ }
+
+ static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
+ String[] array = new String[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ checkIOOBE(am, () -> {
+ String x = (String) hs.get(am).invokeExact(array, ci);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkIOOBE(am, () -> {
+ hs.get(am).invokeExact(array, ci, "foo");
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ checkIOOBE(am, () -> {
+ boolean r = (boolean) hs.get(am).invokeExact(array, ci, "foo", "bar");
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkIOOBE(am, () -> {
+ String r = (String) hs.get(am).invokeExact(array, ci, "bar", "foo");
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkIOOBE(am, () -> {
+ String o = (String) hs.get(am).invokeExact(array, ci, "foo");
+ });
+ }
+
+
+ }
+ }
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeBoolean.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeBoolean.java
new file mode 100644
index 0000000..46b752d
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeBoolean.java
@@ -0,0 +1,2908 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8156486
+ * @run testng/othervm VarHandleTestMethodTypeBoolean
+ * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestMethodTypeBoolean
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+import static java.lang.invoke.MethodType.*;
+
+public class VarHandleTestMethodTypeBoolean extends VarHandleBaseTest {
+ static final boolean static_final_v = true;
+
+ static boolean static_v = true;
+
+ final boolean final_v = true;
+
+ boolean v = true;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeBoolean.class, "final_v", boolean.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeBoolean.class, "v", boolean.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeBoolean.class, "static_final_v", boolean.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeBoolean.class, "static_v", boolean.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(boolean[].class);
+ }
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestMethodTypeBoolean::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestMethodTypeBoolean::testArrayWrongMethodType,
+ false));
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceFieldWrongMethodType(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodTypeBoolean::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodTypeBoolean::testArrayWrongMethodType,
+ false));
+ }
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeBoolean recv, VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.get(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.get(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean x = (boolean) vh.get(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.get(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.get();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.get(recv, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.set(null, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.set(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.set(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(recv, true, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.getVolatile(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.getVolatile(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean x = (boolean) vh.getVolatile(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getVolatile(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getVolatile(recv, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setVolatile(null, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setVolatile(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(recv, true, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.getOpaque(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.getOpaque(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean x = (boolean) vh.getOpaque(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getOpaque(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getOpaque(recv, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setOpaque(null, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setOpaque(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(recv, true, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.getAcquire(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.getAcquire(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean x = (boolean) vh.getAcquire(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAcquire(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAcquire(recv, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setRelease(null, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setRelease(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(recv, true, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, true, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(recv, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(recv, true, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(recv, true, true, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, true, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, true, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(recv, true, true, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, true, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(recv, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(recv, true, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(recv, true, true, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, true, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, true, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(recv, true, true, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, true, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, true, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(recv, true, true, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.compareAndExchange(null, true, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.compareAndExchange(Void.class, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean x = (boolean) vh.compareAndExchange(recv, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean x = (boolean) vh.compareAndExchange(recv, true, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) vh.compareAndExchange(0, true, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(recv, true, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.compareAndExchange(recv, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.compareAndExchange(recv, true, true, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.compareAndExchangeAcquire(null, true, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(Void.class, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(recv, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(recv, true, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(0, true, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(recv, true, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.compareAndExchangeAcquire(recv, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.compareAndExchangeAcquire(recv, true, true, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.compareAndExchangeRelease(null, true, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.compareAndExchangeRelease(Void.class, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean x = (boolean) vh.compareAndExchangeRelease(recv, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean x = (boolean) vh.compareAndExchangeRelease(recv, true, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(0, true, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(recv, true, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.compareAndExchangeRelease(recv, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.compareAndExchangeRelease(recv, true, true, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.getAndSet(null, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.getAndSet(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndSet(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) vh.getAndSet(0, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(recv, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndSet(recv, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndSet(recv, true, Void.class);
+ });
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.getAndSetAcquire(null, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.getAndSetAcquire(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndSetAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(0, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(recv, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndSetAcquire(recv, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndSetAcquire(recv, true, Void.class);
+ });
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.getAndSetRelease(null, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.getAndSetRelease(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndSetRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) vh.getAndSetRelease(0, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(recv, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndSetRelease(recv, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndSetRelease(recv, true, Void.class);
+ });
+
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.getAndBitwiseOr(null, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.getAndBitwiseOr(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseOr(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(0, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(recv, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseOr(recv, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseOr(recv, true, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(null, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(0, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire(recv, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseOrAcquire(recv, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(recv, true, Void.class);
+ });
+
+
+ // GetAndBitwiseOrRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.getAndBitwiseOrRelease(null, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.getAndBitwiseOr(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseOr(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(0, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(recv, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseOr(recv, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseOr(recv, true, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.getAndBitwiseAnd(null, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.getAndBitwiseAnd(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseAnd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(0, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(recv, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseAnd(recv, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseAnd(recv, true, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(null, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(0, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire(recv, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseAndAcquire(recv, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(recv, true, Void.class);
+ });
+
+
+ // GetAndBitwiseAndRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.getAndBitwiseAndRelease(null, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.getAndBitwiseAnd(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseAnd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(0, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(recv, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseAnd(recv, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseAnd(recv, true, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.getAndBitwiseXor(null, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.getAndBitwiseXor(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseXor(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(0, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(recv, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseXor(recv, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseXor(recv, true, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(null, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(0, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire(recv, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseXorAcquire(recv, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(recv, true, Void.class);
+ });
+
+
+ // GetAndBitwiseXorRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.getAndBitwiseXorRelease(null, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean x = (boolean) vh.getAndBitwiseXor(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseXor(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(0, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(recv, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseXor(recv, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseXor(recv, true, Void.class);
+ });
+ }
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeBoolean recv, Handles hs) throws Throwable {
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class)).
+ invokeExact((VarHandleTestMethodTypeBoolean) null);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class)).
+ invokeExact(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeBoolean.class)).
+ invokeExact(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeBoolean.class)).
+ invokeExact(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
+ invokeExact((VarHandleTestMethodTypeBoolean) null, true);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ hs.get(am, methodType(void.class, Class.class, boolean.class)).
+ invokeExact(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeBoolean.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, boolean.class)).
+ invokeExact(0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeBoolean.class, boolean.class, Class.class)).
+ invokeExact(recv, true, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, boolean.class)).
+ invokeExact((VarHandleTestMethodTypeBoolean) null, true, true);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, boolean.class, boolean.class)).
+ invokeExact(Void.class, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, Class.class, boolean.class)).
+ invokeExact(recv, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, Class.class)).
+ invokeExact(recv, true, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , boolean.class, boolean.class)).
+ invokeExact(0, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, boolean.class, Class.class)).
+ invokeExact(recv, true, true, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, boolean.class)).
+ invokeExact((VarHandleTestMethodTypeBoolean) null, true, true);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, boolean.class, boolean.class)).
+ invokeExact(Void.class, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, Class.class, boolean.class)).
+ invokeExact(recv, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, Class.class)).
+ invokeExact(recv, true, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class , boolean.class, boolean.class)).
+ invokeExact(0, true, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeBoolean.class , boolean.class, boolean.class)).
+ invokeExact(recv, true, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeBoolean.class , boolean.class, boolean.class)).
+ invokeExact(recv, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, boolean.class, Class.class)).
+ invokeExact(recv, true, true, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
+ invokeExact((VarHandleTestMethodTypeBoolean) null, true);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, boolean.class)).
+ invokeExact(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class, boolean.class)).
+ invokeExact(0, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
+ invokeExact(recv, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
+ invokeExact(recv, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
+ invokeExact(recv, true, Void.class);
+ });
+ }
+
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
+ invokeExact((VarHandleTestMethodTypeBoolean) null, true);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, boolean.class)).
+ invokeExact(Void.class, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class, boolean.class)).
+ invokeExact(0, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
+ invokeExact(recv, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
+ invokeExact(recv, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
+ invokeExact(recv, true, Void.class);
+ });
+ }
+ }
+
+
+ static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get();
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.get();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.get(Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.set(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(true, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile();
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getVolatile(Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(true, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque();
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getOpaque(Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(true, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire();
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAcquire(Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(true, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(true, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(true, true, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(true, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(true, true, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(true, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(true, true, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(true, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(true, true, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(true, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(true, true, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean x = (boolean) vh.compareAndExchange(Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean x = (boolean) vh.compareAndExchange(true, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(true, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.compareAndExchange(true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.compareAndExchange(true, true, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(true, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(true, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.compareAndExchangeAcquire(true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.compareAndExchangeAcquire(true, true, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean x = (boolean) vh.compareAndExchangeRelease(Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean x = (boolean) vh.compareAndExchangeRelease(true, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(true, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.compareAndExchangeRelease(true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.compareAndExchangeRelease(true, true, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndSet(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndSet(true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndSet(true, Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndSetAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndSetAcquire(true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndSetAcquire(true, Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndSetRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndSetRelease(true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndSetRelease(true, Void.class);
+ });
+
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseOr(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseOr(true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseOr(true, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire(true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseOrAcquire(true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(true, Void.class);
+ });
+
+
+ // GetAndBitwiseOrReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseOrRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrRelease(true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseOrRelease(true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseOrRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseOrRelease(true, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseAnd(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseAnd(true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseAnd(true, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire(true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseAndAcquire(true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(true, Void.class);
+ });
+
+
+ // GetAndBitwiseAndReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseAndRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndRelease(true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseAndRelease(true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseAndRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseAndRelease(true, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseXor(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseXor(true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseXor(true, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire(true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseXorAcquire(true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(true, Void.class);
+ });
+
+
+ // GetAndBitwiseXorReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseXorRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorRelease(true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseXorRelease(true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseXorRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseXorRelease(true, Void.class);
+ });
+ }
+
+ static void testStaticFieldWrongMethodType(Handles hs) throws Throwable {
+ int i = 0;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) hs.get(am, methodType(int.class)).
+ invokeExact();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ boolean x = (boolean) hs.get(am, methodType(Class.class)).
+ invokeExact(Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, boolean.class, Class.class)).
+ invokeExact(true, Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, boolean.class)).
+ invokeExact(Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean.class, Class.class)).
+ invokeExact(true, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean.class, boolean.class, Class.class)).
+ invokeExact(true, true, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, boolean.class)).
+ invokeExact(Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean.class, Class.class)).
+ invokeExact(true, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, boolean.class, boolean.class)).
+ invokeExact(true, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) hs.get(am, methodType(int.class, boolean.class, boolean.class)).
+ invokeExact(true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean.class, boolean.class, Class.class)).
+ invokeExact(true, true, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, boolean.class)).
+ invokeExact(true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) hs.get(am, methodType(int.class, boolean.class)).
+ invokeExact(true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean.class, Class.class)).
+ invokeExact(true, Void.class);
+ });
+ }
+
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, boolean.class)).
+ invokeExact(true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) hs.get(am, methodType(int.class, boolean.class)).
+ invokeExact(true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean.class, Class.class)).
+ invokeExact(true, Void.class);
+ });
+ }
+ }
+
+
+ static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
+ boolean[] array = new boolean[10];
+ Arrays.fill(array, true);
+
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) vh.get(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.get(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) vh.get(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.get(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.get(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.get();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.get(array, 0, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.set(null, 0, true);
+ });
+ checkCCE(() -> { // array reference class
+ vh.set(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.set(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.set(array, Void.class, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(array, 0, true, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) vh.getVolatile(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.getVolatile(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) vh.getVolatile(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.getVolatile(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getVolatile(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getVolatile(array, 0, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setVolatile(null, 0, true);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setVolatile(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setVolatile(array, Void.class, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(array, 0, true, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) vh.getOpaque(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.getOpaque(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) vh.getOpaque(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.getOpaque(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getOpaque(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getOpaque(array, 0, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setOpaque(null, 0, true);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setOpaque(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setOpaque(array, Void.class, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(array, 0, true, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) vh.getAcquire(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.getAcquire(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) vh.getAcquire(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.getAcquire(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAcquire(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAcquire(array, 0, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setRelease(null, 0, true);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setRelease(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setRelease(array, Void.class, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(array, 0, true, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, 0, true, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, 0, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(array, 0, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(array, 0, true, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, 0, true, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.compareAndSet(array, Void.class, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(array, 0, true, true, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, 0, true, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 0, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, true, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, 0, true, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetPlain(array, Void.class, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(array, 0, true, true, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, 0, true, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 0, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(array, 0, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(array, 0, true, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, 0, true, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSet(array, Void.class, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(array, 0, true, true, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, 0, true, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 0, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, true, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, 0, true, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, Void.class, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, true, true, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, 0, true, true);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 0, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, true, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, 0, true, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetRelease(array, Void.class, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(array, 0, true, true, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.compareAndExchange(null, 0, true, true);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.compareAndExchange(Void.class, 0, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean x = (boolean) vh.compareAndExchange(array, 0, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean x = (boolean) vh.compareAndExchange(array, 0, true, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) vh.compareAndExchange(0, 0, true, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.compareAndExchange(array, Void.class, true, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(array, 0, true, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.compareAndExchange(array, 0, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.compareAndExchange(array, 0, true, true, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.compareAndExchangeAcquire(null, 0, true, true);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(Void.class, 0, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(array, 0, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(array, 0, true, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(0, 0, true, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(array, Void.class, true, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(array, 0, true, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.compareAndExchangeAcquire(array, 0, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.compareAndExchangeAcquire(array, 0, true, true, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) vh.compareAndExchangeRelease(null, 0, true, true);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.compareAndExchangeRelease(Void.class, 0, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean x = (boolean) vh.compareAndExchangeRelease(array, 0, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean x = (boolean) vh.compareAndExchangeRelease(array, 0, true, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(0, 0, true, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.compareAndExchangeRelease(array, Void.class, true, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(array, 0, true, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.compareAndExchangeRelease(array, 0, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.compareAndExchangeRelease(array, 0, true, true, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) vh.getAndSet(null, 0, true);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.getAndSet(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndSet(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ boolean x = (boolean) vh.getAndSet(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.getAndSet(array, Void.class, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(array, 0, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndSet(array, 0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndSet(array, 0, true, Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) vh.getAndSetAcquire(null, 0, true);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.getAndSetAcquire(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndSetAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.getAndSetAcquire(array, Void.class, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(array, 0, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndSetAcquire(array, 0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndSetAcquire(array, 0, true, Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) vh.getAndSetRelease(null, 0, true);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.getAndSetRelease(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndSetRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ boolean x = (boolean) vh.getAndSetRelease(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.getAndSetRelease(array, Void.class, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(array, 0, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndSetRelease(array, 0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndSetRelease(array, 0, true, Void.class);
+ });
+
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) vh.getAndBitwiseOr(null, 0, true);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.getAndBitwiseOr(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseOr(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.getAndBitwiseOr(array, Void.class, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(array, 0, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseOr(array, 0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseOr(array, 0, true, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(null, 0, true);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(array, Void.class, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire(array, 0, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseOrAcquire(array, 0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(array, 0, true, Void.class);
+ });
+
+
+ // GetAndBitwiseOrRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) vh.getAndBitwiseOrRelease(null, 0, true);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.getAndBitwiseOrRelease(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseOrRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrRelease(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.getAndBitwiseOrRelease(array, Void.class, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrRelease(array, 0, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseOrRelease(array, 0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseOrRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseOrRelease(array, 0, true, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) vh.getAndBitwiseAnd(null, 0, true);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.getAndBitwiseAnd(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseAnd(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.getAndBitwiseAnd(array, Void.class, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(array, 0, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseAnd(array, 0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseAnd(array, 0, true, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(null, 0, true);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(array, Void.class, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire(array, 0, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseAndAcquire(array, 0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(array, 0, true, Void.class);
+ });
+
+
+ // GetAndBitwiseAndRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) vh.getAndBitwiseAndRelease(null, 0, true);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.getAndBitwiseAndRelease(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseAndRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndRelease(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.getAndBitwiseAndRelease(array, Void.class, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndRelease(array, 0, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseAndRelease(array, 0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseAndRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseAndRelease(array, 0, true, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) vh.getAndBitwiseXor(null, 0, true);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.getAndBitwiseXor(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseXor(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.getAndBitwiseXor(array, Void.class, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(array, 0, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseXor(array, 0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseXor(array, 0, true, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(null, 0, true);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(array, Void.class, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire(array, 0, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseXorAcquire(array, 0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(array, 0, true, Void.class);
+ });
+
+
+ // GetAndBitwiseXorRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) vh.getAndBitwiseXorRelease(null, 0, true);
+ });
+ checkCCE(() -> { // array reference class
+ boolean x = (boolean) vh.getAndBitwiseXorRelease(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) vh.getAndBitwiseXorRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorRelease(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) vh.getAndBitwiseXorRelease(array, Void.class, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorRelease(array, 0, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) vh.getAndBitwiseXorRelease(array, 0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) vh.getAndBitwiseXorRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) vh.getAndBitwiseXorRelease(array, 0, true, Void.class);
+ });
+ }
+
+ static void testArrayWrongMethodType(Handles hs) throws Throwable {
+ boolean[] array = new boolean[10];
+ Arrays.fill(array, true);
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class)).
+ invokeExact((boolean[]) null, 0);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class)).
+ invokeExact(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class)).
+ invokeExact(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, Class.class)).
+ invokeExact(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, boolean[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) hs.get(am, methodType(int.class, boolean[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ hs.get(am, methodType(void.class, boolean[].class, int.class, boolean.class)).
+ invokeExact((boolean[]) null, 0, true);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ hs.get(am, methodType(void.class, Class.class, int.class, boolean.class)).
+ invokeExact(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, boolean[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, int.class, boolean.class)).
+ invokeExact(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ hs.get(am, methodType(void.class, boolean[].class, Class.class, boolean.class)).
+ invokeExact(array, Void.class, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, boolean[].class, int.class, Class.class)).
+ invokeExact(array, 0, true, Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, boolean.class)).
+ invokeExact((boolean[]) null, 0, true, true);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, boolean.class, boolean.class)).
+ invokeExact(Void.class, 0, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, Class.class, boolean.class)).
+ invokeExact(array, 0, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, Class.class)).
+ invokeExact(array, 0, true, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, boolean.class, boolean.class)).
+ invokeExact(0, 0, true, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, Class.class, boolean.class, boolean.class)).
+ invokeExact(array, Void.class, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, boolean.class, Class.class)).
+ invokeExact(array, 0, true, true, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, boolean.class)).
+ invokeExact((boolean[]) null, 0, true, true);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, boolean.class, boolean.class)).
+ invokeExact(Void.class, 0, true, true);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, Class.class, boolean.class)).
+ invokeExact(array, 0, Void.class, true);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, Class.class)).
+ invokeExact(array, 0, true, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, boolean.class, boolean.class)).
+ invokeExact(0, 0, true, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, Class.class, boolean.class, boolean.class)).
+ invokeExact(array, Void.class, true, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, boolean[].class, int.class, boolean.class, boolean.class)).
+ invokeExact(array, 0, true, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) hs.get(am, methodType(int.class, boolean[].class, int.class, boolean.class, boolean.class)).
+ invokeExact(array, 0, true, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, boolean.class, Class.class)).
+ invokeExact(array, 0, true, true, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class)).
+ invokeExact((boolean[]) null, 0, true);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, boolean.class)).
+ invokeExact(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, boolean.class)).
+ invokeExact(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, Class.class, boolean.class)).
+ invokeExact(array, Void.class, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, boolean[].class, int.class, boolean.class)).
+ invokeExact(array, 0, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) hs.get(am, methodType(int.class, boolean[].class, int.class, boolean.class)).
+ invokeExact(array, 0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, Class.class)).
+ invokeExact(array, 0, true, Void.class);
+ });
+ }
+
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class)).
+ invokeExact((boolean[]) null, 0, true);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, boolean.class)).
+ invokeExact(Void.class, 0, true);
+ });
+ checkWMTE(() -> { // value reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, boolean.class)).
+ invokeExact(0, 0, true);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, Class.class, boolean.class)).
+ invokeExact(array, Void.class, true);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, boolean[].class, int.class, boolean.class)).
+ invokeExact(array, 0, true);
+ });
+ checkWMTE(() -> { // primitive class
+ int x = (int) hs.get(am, methodType(int.class, boolean[].class, int.class, boolean.class)).
+ invokeExact(array, 0, true);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, Class.class)).
+ invokeExact(array, 0, true, Void.class);
+ });
+ }
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeByte.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeByte.java
new file mode 100644
index 0000000..ce45525
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeByte.java
@@ -0,0 +1,3254 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8156486
+ * @run testng/othervm VarHandleTestMethodTypeByte
+ * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestMethodTypeByte
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+import static java.lang.invoke.MethodType.*;
+
+public class VarHandleTestMethodTypeByte extends VarHandleBaseTest {
+ static final byte static_final_v = (byte)0x01;
+
+ static byte static_v = (byte)0x01;
+
+ final byte final_v = (byte)0x01;
+
+ byte v = (byte)0x01;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeByte.class, "final_v", byte.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeByte.class, "v", byte.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeByte.class, "static_final_v", byte.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeByte.class, "static_v", byte.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(byte[].class);
+ }
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestMethodTypeByte::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestMethodTypeByte::testArrayWrongMethodType,
+ false));
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceFieldWrongMethodType(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodTypeByte::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodTypeByte::testArrayWrongMethodType,
+ false));
+ }
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeByte recv, VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.get(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.get(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ byte x = (byte) vh.get(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.get();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.get(recv, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.set(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.set(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.set(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(recv, (byte)0x01, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getVolatile(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getVolatile(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ byte x = (byte) vh.getVolatile(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getVolatile(recv, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setVolatile(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setVolatile(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(recv, (byte)0x01, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getOpaque(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getOpaque(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ byte x = (byte) vh.getOpaque(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getOpaque(recv, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setOpaque(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setOpaque(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(recv, (byte)0x01, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getAcquire(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getAcquire(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ byte x = (byte) vh.getAcquire(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAcquire(recv, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setRelease(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setRelease(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(recv, (byte)0x01, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, (byte)0x01, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(recv, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(recv, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(recv, (byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, (byte)0x01, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(recv, (byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, (byte)0x01, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(recv, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(recv, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(recv, (byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, (byte)0x01, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(recv, (byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, (byte)0x01, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(recv, (byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.compareAndExchange(null, (byte)0x01, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.compareAndExchange(Void.class, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ byte x = (byte) vh.compareAndExchange(recv, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ byte x = (byte) vh.compareAndExchange(recv, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.compareAndExchange(0, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(recv, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(recv, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.compareAndExchange(recv, (byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.compareAndExchangeAcquire(null, (byte)0x01, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.compareAndExchangeAcquire(Void.class, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ byte x = (byte) vh.compareAndExchangeAcquire(recv, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ byte x = (byte) vh.compareAndExchangeAcquire(recv, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.compareAndExchangeAcquire(0, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(recv, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(recv, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.compareAndExchangeAcquire(recv, (byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.compareAndExchangeRelease(null, (byte)0x01, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.compareAndExchangeRelease(Void.class, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ byte x = (byte) vh.compareAndExchangeRelease(recv, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ byte x = (byte) vh.compareAndExchangeRelease(recv, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.compareAndExchangeRelease(0, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(recv, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(recv, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.compareAndExchangeRelease(recv, (byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getAndSet(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getAndSet(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndSet(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.getAndSet(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndSet(recv, (byte)0x01, Void.class);
+ });
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getAndSetAcquire(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getAndSetAcquire(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndSetAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.getAndSetAcquire(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndSetAcquire(recv, (byte)0x01, Void.class);
+ });
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getAndSetRelease(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getAndSetRelease(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndSetRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.getAndSetRelease(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndSetRelease(recv, (byte)0x01, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getAndAdd(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getAndAdd(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndAdd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.getAndAdd(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndAdd(recv, (byte)0x01, Void.class);
+ });
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getAndAddAcquire(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getAndAddAcquire(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndAddAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.getAndAddAcquire(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndAddAcquire(recv, (byte)0x01, Void.class);
+ });
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getAndAddRelease(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getAndAddRelease(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndAddRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.getAndAddRelease(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndAddRelease(recv, (byte)0x01, Void.class);
+ });
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getAndBitwiseOr(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getAndBitwiseOr(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseOr(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.getAndBitwiseOr(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseOr(recv, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getAndBitwiseOrAcquire(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getAndBitwiseOrAcquire(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseOrAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.getAndBitwiseOrAcquire(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseOrAcquire(recv, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseOrRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getAndBitwiseOrRelease(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getAndBitwiseOr(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseOr(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.getAndBitwiseOr(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseOr(recv, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getAndBitwiseAnd(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getAndBitwiseAnd(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseAnd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.getAndBitwiseAnd(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseAnd(recv, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getAndBitwiseAndAcquire(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getAndBitwiseAndAcquire(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseAndAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.getAndBitwiseAndAcquire(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseAndAcquire(recv, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseAndRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getAndBitwiseAndRelease(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getAndBitwiseAnd(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseAnd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.getAndBitwiseAnd(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseAnd(recv, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getAndBitwiseXor(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getAndBitwiseXor(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseXor(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.getAndBitwiseXor(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseXor(recv, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getAndBitwiseXorAcquire(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getAndBitwiseXorAcquire(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseXorAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.getAndBitwiseXorAcquire(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseXorAcquire(recv, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseXorRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.getAndBitwiseXorRelease(null, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ byte x = (byte) vh.getAndBitwiseXor(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseXor(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) vh.getAndBitwiseXor(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseXor(recv, (byte)0x01, Void.class);
+ });
+ }
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeByte recv, Handles hs) throws Throwable {
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class)).
+ invokeExact((VarHandleTestMethodTypeByte) null);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ byte x = (byte) hs.get(am, methodType(byte.class, int.class)).
+ invokeExact(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeByte.class)).
+ invokeExact(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class)).
+ invokeExact(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) hs.get(am, methodType(byte.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeByte.class, byte.class)).
+ invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ hs.get(am, methodType(void.class, Class.class, byte.class)).
+ invokeExact(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeByte.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, byte.class)).
+ invokeExact(0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeByte.class, byte.class, Class.class)).
+ invokeExact(recv, (byte)0x01, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, byte.class, byte.class)).
+ invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01, (byte)0x01);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, byte.class, byte.class)).
+ invokeExact(Void.class, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, Class.class, byte.class)).
+ invokeExact(recv, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, byte.class, Class.class)).
+ invokeExact(recv, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , byte.class, byte.class)).
+ invokeExact(0, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, byte.class, byte.class, Class.class)).
+ invokeExact(recv, (byte)0x01, (byte)0x01, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkNPE(() -> { // null receiver
+ byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class, byte.class)).
+ invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01, (byte)0x01);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, Class.class, byte.class, byte.class)).
+ invokeExact(Void.class, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, Class.class, byte.class)).
+ invokeExact(recv, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class, Class.class)).
+ invokeExact(recv, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) hs.get(am, methodType(byte.class, int.class , byte.class, byte.class)).
+ invokeExact(0, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeByte.class , byte.class, byte.class)).
+ invokeExact(recv, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class , byte.class, byte.class)).
+ invokeExact(recv, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) hs.get(am, methodType(byte.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class, byte.class, Class.class)).
+ invokeExact(recv, (byte)0x01, (byte)0x01, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkNPE(() -> { // null receiver
+ byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class)).
+ invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, Class.class, byte.class)).
+ invokeExact(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) hs.get(am, methodType(byte.class, int.class, byte.class)).
+ invokeExact(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeByte.class, byte.class)).
+ invokeExact(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, byte.class)).
+ invokeExact(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) hs.get(am, methodType(byte.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class)).
+ invokeExact(recv, (byte)0x01, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkNPE(() -> { // null receiver
+ byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class)).
+ invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, Class.class, byte.class)).
+ invokeExact(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) hs.get(am, methodType(byte.class, int.class, byte.class)).
+ invokeExact(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeByte.class, byte.class)).
+ invokeExact(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, byte.class)).
+ invokeExact(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) hs.get(am, methodType(byte.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class)).
+ invokeExact(recv, (byte)0x01, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkNPE(() -> { // null receiver
+ byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class)).
+ invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, Class.class, byte.class)).
+ invokeExact(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ byte x = (byte) hs.get(am, methodType(byte.class, int.class, byte.class)).
+ invokeExact(0, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeByte.class, byte.class)).
+ invokeExact(recv, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, byte.class)).
+ invokeExact(recv, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) hs.get(am, methodType(byte.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class)).
+ invokeExact(recv, (byte)0x01, Void.class);
+ });
+ }
+ }
+
+
+ static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.get(Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.set(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set((byte)0x01, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getVolatile(Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile((byte)0x01, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getOpaque(Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque((byte)0x01, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAcquire(Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease((byte)0x01, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet((byte)0x01, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet((byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain((byte)0x01, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain((byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet((byte)0x01, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet((byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire((byte)0x01, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire((byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease((byte)0x01, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease((byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ byte x = (byte) vh.compareAndExchange(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ byte x = (byte) vh.compareAndExchange((byte)0x01, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange((byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange((byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.compareAndExchange((byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ byte x = (byte) vh.compareAndExchangeAcquire(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ byte x = (byte) vh.compareAndExchangeAcquire((byte)0x01, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire((byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire((byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.compareAndExchangeAcquire((byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ byte x = (byte) vh.compareAndExchangeRelease(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ byte x = (byte) vh.compareAndExchangeRelease((byte)0x01, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease((byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease((byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.compareAndExchangeRelease((byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndSet(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndSet((byte)0x01, Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndSetAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndSetAcquire((byte)0x01, Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndSetRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndSetRelease((byte)0x01, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndAdd(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndAdd((byte)0x01, Void.class);
+ });
+
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndAddAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndAddAcquire((byte)0x01, Void.class);
+ });
+
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndAddRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndAddRelease((byte)0x01, Void.class);
+ });
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseOr(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseOr((byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseOrAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseOrAcquire((byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseOrReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseOrRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrRelease((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrRelease((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseOrRelease();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseOrRelease((byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseAnd(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseAnd((byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseAndAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseAndAcquire((byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseAndReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseAndRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndRelease((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndRelease((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseAndRelease();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseAndRelease((byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseXor(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseXor((byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseXorAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseXorAcquire((byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseXorReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseXorRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorRelease((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorRelease((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseXorRelease();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseXorRelease((byte)0x01, Void.class);
+ });
+ }
+
+ static void testStaticFieldWrongMethodType(Handles hs) throws Throwable {
+ int i = 0;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ byte x = (byte) hs.get(am, methodType(Class.class)).
+ invokeExact(Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, byte.class, Class.class)).
+ invokeExact((byte)0x01, Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, byte.class)).
+ invokeExact(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, byte.class, Class.class)).
+ invokeExact((byte)0x01, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, byte.class, byte.class, Class.class)).
+ invokeExact((byte)0x01, (byte)0x01, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, Class.class, byte.class)).
+ invokeExact(Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, byte.class, Class.class)).
+ invokeExact((byte)0x01, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, byte.class, byte.class)).
+ invokeExact((byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, byte.class, byte.class)).
+ invokeExact((byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) hs.get(am, methodType(byte.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) hs.get(am, methodType(byte.class, byte.class, byte.class, Class.class)).
+ invokeExact((byte)0x01, (byte)0x01, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, byte.class)).
+ invokeExact((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, byte.class)).
+ invokeExact((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) hs.get(am, methodType(byte.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) hs.get(am, methodType(byte.class, byte.class, Class.class)).
+ invokeExact((byte)0x01, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, byte.class)).
+ invokeExact((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, byte.class)).
+ invokeExact((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) hs.get(am, methodType(byte.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) hs.get(am, methodType(byte.class, byte.class, Class.class)).
+ invokeExact((byte)0x01, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, byte.class)).
+ invokeExact((byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, byte.class)).
+ invokeExact((byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) hs.get(am, methodType(byte.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) hs.get(am, methodType(byte.class, byte.class, Class.class)).
+ invokeExact((byte)0x01, Void.class);
+ });
+ }
+ }
+
+
+ static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
+ byte[] array = new byte[10];
+ Arrays.fill(array, (byte)0x01);
+
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.get(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.get(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.get(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.get(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.get();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.get(array, 0, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.set(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ vh.set(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.set(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.set(array, Void.class, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(array, 0, (byte)0x01, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getVolatile(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getVolatile(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.getVolatile(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getVolatile(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getVolatile(array, 0, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setVolatile(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setVolatile(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setVolatile(array, Void.class, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(array, 0, (byte)0x01, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getOpaque(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getOpaque(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.getOpaque(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getOpaque(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getOpaque(array, 0, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setOpaque(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setOpaque(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setOpaque(array, Void.class, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(array, 0, (byte)0x01, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getAcquire(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getAcquire(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.getAcquire(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getAcquire(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAcquire(array, 0, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setRelease(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setRelease(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setRelease(array, Void.class, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(array, 0, (byte)0x01, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, 0, (byte)0x01, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(array, 0, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(array, 0, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.compareAndSet(array, Void.class, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(array, 0, (byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, 0, (byte)0x01, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetPlain(array, Void.class, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(array, 0, (byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, 0, (byte)0x01, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(array, 0, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(array, 0, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSet(array, Void.class, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(array, 0, (byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, 0, (byte)0x01, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, Void.class, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, (byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, 0, (byte)0x01, (byte)0x01);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetRelease(array, Void.class, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(array, 0, (byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.compareAndExchange(null, 0, (byte)0x01, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.compareAndExchange(Void.class, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ byte x = (byte) vh.compareAndExchange(array, 0, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ byte x = (byte) vh.compareAndExchange(array, 0, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.compareAndExchange(0, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.compareAndExchange(array, Void.class, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(array, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(array, 0, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.compareAndExchange(array, 0, (byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.compareAndExchangeAcquire(null, 0, (byte)0x01, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.compareAndExchangeAcquire(Void.class, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ byte x = (byte) vh.compareAndExchangeAcquire(array, 0, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ byte x = (byte) vh.compareAndExchangeAcquire(array, 0, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.compareAndExchangeAcquire(0, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.compareAndExchangeAcquire(array, Void.class, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(array, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(array, 0, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.compareAndExchangeAcquire(array, 0, (byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) vh.compareAndExchangeRelease(null, 0, (byte)0x01, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.compareAndExchangeRelease(Void.class, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ byte x = (byte) vh.compareAndExchangeRelease(array, 0, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ byte x = (byte) vh.compareAndExchangeRelease(array, 0, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.compareAndExchangeRelease(0, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.compareAndExchangeRelease(array, Void.class, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(array, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(array, 0, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.compareAndExchangeRelease(array, 0, (byte)0x01, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getAndSet(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getAndSet(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndSet(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ byte x = (byte) vh.getAndSet(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getAndSet(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndSet(array, 0, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getAndSetAcquire(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getAndSetAcquire(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndSetAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ byte x = (byte) vh.getAndSetAcquire(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getAndSetAcquire(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndSetAcquire(array, 0, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getAndSetRelease(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getAndSetRelease(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndSetRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ byte x = (byte) vh.getAndSetRelease(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getAndSetRelease(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndSetRelease(array, 0, (byte)0x01, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getAndAdd(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getAndAdd(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndAdd(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.getAndAdd(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getAndAdd(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndAdd(array, 0, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getAndAddAcquire(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getAndAddAcquire(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndAddAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.getAndAddAcquire(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getAndAddAcquire(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndAddAcquire(array, 0, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getAndAddRelease(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getAndAddRelease(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndAddRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.getAndAddRelease(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getAndAddRelease(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndAddRelease(array, 0, (byte)0x01, Void.class);
+ });
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getAndBitwiseOr(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getAndBitwiseOr(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseOr(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.getAndBitwiseOr(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getAndBitwiseOr(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseOr(array, 0, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getAndBitwiseOrAcquire(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getAndBitwiseOrAcquire(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseOrAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.getAndBitwiseOrAcquire(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getAndBitwiseOrAcquire(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseOrAcquire(array, 0, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseOrRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getAndBitwiseOrRelease(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getAndBitwiseOrRelease(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseOrRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.getAndBitwiseOrRelease(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getAndBitwiseOrRelease(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrRelease(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrRelease(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseOrRelease();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseOrRelease(array, 0, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getAndBitwiseAnd(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getAndBitwiseAnd(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseAnd(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.getAndBitwiseAnd(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getAndBitwiseAnd(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseAnd(array, 0, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getAndBitwiseAndAcquire(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getAndBitwiseAndAcquire(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseAndAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.getAndBitwiseAndAcquire(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getAndBitwiseAndAcquire(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseAndAcquire(array, 0, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseAndRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getAndBitwiseAndRelease(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getAndBitwiseAndRelease(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseAndRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.getAndBitwiseAndRelease(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getAndBitwiseAndRelease(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndRelease(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndRelease(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseAndRelease();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseAndRelease(array, 0, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getAndBitwiseXor(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getAndBitwiseXor(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseXor(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.getAndBitwiseXor(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getAndBitwiseXor(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseXor(array, 0, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getAndBitwiseXorAcquire(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getAndBitwiseXorAcquire(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseXorAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.getAndBitwiseXorAcquire(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getAndBitwiseXorAcquire(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseXorAcquire(array, 0, (byte)0x01, Void.class);
+ });
+
+
+ // GetAndBitwiseXorRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) vh.getAndBitwiseXorRelease(null, 0, (byte)0x01);
+ });
+ checkCCE(() -> { // array reference class
+ byte x = (byte) vh.getAndBitwiseXorRelease(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) vh.getAndBitwiseXorRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) vh.getAndBitwiseXorRelease(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) vh.getAndBitwiseXorRelease(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorRelease(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorRelease(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) vh.getAndBitwiseXorRelease();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) vh.getAndBitwiseXorRelease(array, 0, (byte)0x01, Void.class);
+ });
+ }
+
+ static void testArrayWrongMethodType(Handles hs) throws Throwable {
+ byte[] array = new byte[10];
+ Arrays.fill(array, (byte)0x01);
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class)).
+ invokeExact((byte[]) null, 0);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, Class.class, int.class)).
+ invokeExact(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) hs.get(am, methodType(byte.class, int.class, int.class)).
+ invokeExact(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, Class.class)).
+ invokeExact(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, byte[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) hs.get(am, methodType(byte.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ hs.get(am, methodType(void.class, byte[].class, int.class, byte.class)).
+ invokeExact((byte[]) null, 0, (byte)0x01);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ hs.get(am, methodType(void.class, Class.class, int.class, byte.class)).
+ invokeExact(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, byte[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, int.class, byte.class)).
+ invokeExact(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ hs.get(am, methodType(void.class, byte[].class, Class.class, byte.class)).
+ invokeExact(array, Void.class, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, byte[].class, int.class, Class.class)).
+ invokeExact(array, 0, (byte)0x01, Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, byte.class, byte.class)).
+ invokeExact((byte[]) null, 0, (byte)0x01, (byte)0x01);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, byte.class, byte.class)).
+ invokeExact(Void.class, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, Class.class, byte.class)).
+ invokeExact(array, 0, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, byte.class, Class.class)).
+ invokeExact(array, 0, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, byte.class, byte.class)).
+ invokeExact(0, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, byte[].class, Class.class, byte.class, byte.class)).
+ invokeExact(array, Void.class, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, byte.class, byte.class, Class.class)).
+ invokeExact(array, 0, (byte)0x01, (byte)0x01, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class, byte.class)).
+ invokeExact((byte[]) null, 0, (byte)0x01, (byte)0x01);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, Class.class, int.class, byte.class, byte.class)).
+ invokeExact(Void.class, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // expected reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, Class.class, byte.class)).
+ invokeExact(array, 0, Void.class, (byte)0x01);
+ });
+ checkWMTE(() -> { // actual reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class, Class.class)).
+ invokeExact(array, 0, (byte)0x01, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) hs.get(am, methodType(byte.class, int.class, int.class, byte.class, byte.class)).
+ invokeExact(0, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, Class.class, byte.class, byte.class)).
+ invokeExact(array, Void.class, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, byte[].class, int.class, byte.class, byte.class)).
+ invokeExact(array, 0, (byte)0x01, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, byte.class, byte.class)).
+ invokeExact(array, 0, (byte)0x01, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) hs.get(am, methodType(byte.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class, byte.class, Class.class)).
+ invokeExact(array, 0, (byte)0x01, (byte)0x01, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class)).
+ invokeExact((byte[]) null, 0, (byte)0x01);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, Class.class, int.class, byte.class)).
+ invokeExact(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) hs.get(am, methodType(byte.class, int.class, int.class, byte.class)).
+ invokeExact(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, Class.class, byte.class)).
+ invokeExact(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, byte[].class, int.class, byte.class)).
+ invokeExact(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, byte.class)).
+ invokeExact(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) hs.get(am, methodType(byte.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class, Class.class)).
+ invokeExact(array, 0, (byte)0x01, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class)).
+ invokeExact((byte[]) null, 0, (byte)0x01);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, Class.class, int.class, byte.class)).
+ invokeExact(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) hs.get(am, methodType(byte.class, int.class, int.class, byte.class)).
+ invokeExact(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, Class.class, byte.class)).
+ invokeExact(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, byte[].class, int.class, byte.class)).
+ invokeExact(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, byte.class)).
+ invokeExact(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) hs.get(am, methodType(byte.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class, Class.class)).
+ invokeExact(array, 0, (byte)0x01, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class)).
+ invokeExact((byte[]) null, 0, (byte)0x01);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, Class.class, int.class, byte.class)).
+ invokeExact(Void.class, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // value reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ byte x = (byte) hs.get(am, methodType(byte.class, int.class, int.class, byte.class)).
+ invokeExact(0, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // index reference class
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, Class.class, byte.class)).
+ invokeExact(array, Void.class, (byte)0x01);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, byte[].class, int.class, byte.class)).
+ invokeExact(array, 0, (byte)0x01);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, byte.class)).
+ invokeExact(array, 0, (byte)0x01);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ byte x = (byte) hs.get(am, methodType(byte.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class, Class.class)).
+ invokeExact(array, 0, (byte)0x01, Void.class);
+ });
+ }
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeChar.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeChar.java
new file mode 100644
index 0000000..0498c62
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeChar.java
@@ -0,0 +1,3254 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8156486
+ * @run testng/othervm VarHandleTestMethodTypeChar
+ * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestMethodTypeChar
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+import static java.lang.invoke.MethodType.*;
+
+public class VarHandleTestMethodTypeChar extends VarHandleBaseTest {
+ static final char static_final_v = '\u0123';
+
+ static char static_v = '\u0123';
+
+ final char final_v = '\u0123';
+
+ char v = '\u0123';
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeChar.class, "final_v", char.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeChar.class, "v", char.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeChar.class, "static_final_v", char.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeChar.class, "static_v", char.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(char[].class);
+ }
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestMethodTypeChar::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestMethodTypeChar::testArrayWrongMethodType,
+ false));
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceFieldWrongMethodType(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodTypeChar::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodTypeChar::testArrayWrongMethodType,
+ false));
+ }
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeChar recv, VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.get(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.get(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ char x = (char) vh.get(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.get();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.get(recv, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.set(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.set(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ vh.set(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(recv, '\u0123', Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getVolatile(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getVolatile(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ char x = (char) vh.getVolatile(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getVolatile(recv, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setVolatile(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setVolatile(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(recv, '\u0123', Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getOpaque(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getOpaque(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ char x = (char) vh.getOpaque(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getOpaque(recv, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setOpaque(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setOpaque(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(recv, '\u0123', Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getAcquire(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getAcquire(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ char x = (char) vh.getAcquire(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAcquire(recv, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setRelease(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setRelease(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(recv, '\u0123', Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, '\u0123', '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(recv, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(recv, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(recv, '\u0123', '\u0123', Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, '\u0123', '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(recv, '\u0123', '\u0123', Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, '\u0123', '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(recv, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(recv, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(recv, '\u0123', '\u0123', Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, '\u0123', '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(recv, '\u0123', '\u0123', Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, '\u0123', '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(recv, '\u0123', '\u0123', Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.compareAndExchange(null, '\u0123', '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.compareAndExchange(Void.class, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ char x = (char) vh.compareAndExchange(recv, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ char x = (char) vh.compareAndExchange(recv, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.compareAndExchange(0, '\u0123', '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(recv, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(recv, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.compareAndExchange(recv, '\u0123', '\u0123', Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.compareAndExchangeAcquire(null, '\u0123', '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.compareAndExchangeAcquire(Void.class, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ char x = (char) vh.compareAndExchangeAcquire(recv, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ char x = (char) vh.compareAndExchangeAcquire(recv, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.compareAndExchangeAcquire(0, '\u0123', '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(recv, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(recv, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.compareAndExchangeAcquire(recv, '\u0123', '\u0123', Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.compareAndExchangeRelease(null, '\u0123', '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.compareAndExchangeRelease(Void.class, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ char x = (char) vh.compareAndExchangeRelease(recv, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ char x = (char) vh.compareAndExchangeRelease(recv, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.compareAndExchangeRelease(0, '\u0123', '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(recv, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(recv, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.compareAndExchangeRelease(recv, '\u0123', '\u0123', Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getAndSet(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getAndSet(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndSet(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.getAndSet(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndSet(recv, '\u0123', Void.class);
+ });
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getAndSetAcquire(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getAndSetAcquire(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndSetAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.getAndSetAcquire(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndSetAcquire(recv, '\u0123', Void.class);
+ });
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getAndSetRelease(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getAndSetRelease(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndSetRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.getAndSetRelease(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndSetRelease(recv, '\u0123', Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getAndAdd(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getAndAdd(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndAdd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.getAndAdd(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndAdd(recv, '\u0123', Void.class);
+ });
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getAndAddAcquire(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getAndAddAcquire(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndAddAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.getAndAddAcquire(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndAddAcquire(recv, '\u0123', Void.class);
+ });
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getAndAddRelease(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getAndAddRelease(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndAddRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.getAndAddRelease(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndAddRelease(recv, '\u0123', Void.class);
+ });
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getAndBitwiseOr(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getAndBitwiseOr(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseOr(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.getAndBitwiseOr(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseOr(recv, '\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getAndBitwiseOrAcquire(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getAndBitwiseOrAcquire(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseOrAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.getAndBitwiseOrAcquire(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseOrAcquire(recv, '\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseOrRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getAndBitwiseOrRelease(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getAndBitwiseOr(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseOr(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.getAndBitwiseOr(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseOr(recv, '\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getAndBitwiseAnd(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getAndBitwiseAnd(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseAnd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.getAndBitwiseAnd(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseAnd(recv, '\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getAndBitwiseAndAcquire(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getAndBitwiseAndAcquire(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseAndAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.getAndBitwiseAndAcquire(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseAndAcquire(recv, '\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseAndRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getAndBitwiseAndRelease(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getAndBitwiseAnd(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseAnd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.getAndBitwiseAnd(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseAnd(recv, '\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getAndBitwiseXor(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getAndBitwiseXor(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseXor(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.getAndBitwiseXor(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseXor(recv, '\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getAndBitwiseXorAcquire(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getAndBitwiseXorAcquire(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseXorAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.getAndBitwiseXorAcquire(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseXorAcquire(recv, '\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseXorRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.getAndBitwiseXorRelease(null, '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ char x = (char) vh.getAndBitwiseXor(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseXor(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) vh.getAndBitwiseXor(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseXor(recv, '\u0123', Void.class);
+ });
+ }
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeChar recv, Handles hs) throws Throwable {
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) hs.get(am, methodType(char.class, VarHandleTestMethodTypeChar.class)).
+ invokeExact((VarHandleTestMethodTypeChar) null);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ char x = (char) hs.get(am, methodType(char.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ char x = (char) hs.get(am, methodType(char.class, int.class)).
+ invokeExact(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeChar.class)).
+ invokeExact(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeChar.class)).
+ invokeExact(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) hs.get(am, methodType(char.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) hs.get(am, methodType(char.class, VarHandleTestMethodTypeChar.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeChar.class, char.class)).
+ invokeExact((VarHandleTestMethodTypeChar) null, '\u0123');
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ hs.get(am, methodType(void.class, Class.class, char.class)).
+ invokeExact(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeChar.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, char.class)).
+ invokeExact(0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeChar.class, char.class, Class.class)).
+ invokeExact(recv, '\u0123', Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeChar.class, char.class, char.class)).
+ invokeExact((VarHandleTestMethodTypeChar) null, '\u0123', '\u0123');
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, char.class, char.class)).
+ invokeExact(Void.class, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeChar.class, Class.class, char.class)).
+ invokeExact(recv, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeChar.class, char.class, Class.class)).
+ invokeExact(recv, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , char.class, char.class)).
+ invokeExact(0, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeChar.class, char.class, char.class, Class.class)).
+ invokeExact(recv, '\u0123', '\u0123', Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkNPE(() -> { // null receiver
+ char x = (char) hs.get(am, methodType(char.class, VarHandleTestMethodTypeChar.class, char.class, char.class)).
+ invokeExact((VarHandleTestMethodTypeChar) null, '\u0123', '\u0123');
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ char x = (char) hs.get(am, methodType(char.class, Class.class, char.class, char.class)).
+ invokeExact(Void.class, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ char x = (char) hs.get(am, methodType(char.class, VarHandleTestMethodTypeChar.class, Class.class, char.class)).
+ invokeExact(recv, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ char x = (char) hs.get(am, methodType(char.class, VarHandleTestMethodTypeChar.class, char.class, Class.class)).
+ invokeExact(recv, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) hs.get(am, methodType(char.class, int.class , char.class, char.class)).
+ invokeExact(0, '\u0123', '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeChar.class , char.class, char.class)).
+ invokeExact(recv, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeChar.class , char.class, char.class)).
+ invokeExact(recv, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) hs.get(am, methodType(char.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) hs.get(am, methodType(char.class, VarHandleTestMethodTypeChar.class, char.class, char.class, Class.class)).
+ invokeExact(recv, '\u0123', '\u0123', Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkNPE(() -> { // null receiver
+ char x = (char) hs.get(am, methodType(char.class, VarHandleTestMethodTypeChar.class, char.class)).
+ invokeExact((VarHandleTestMethodTypeChar) null, '\u0123');
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ char x = (char) hs.get(am, methodType(char.class, Class.class, char.class)).
+ invokeExact(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) hs.get(am, methodType(char.class, VarHandleTestMethodTypeChar.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) hs.get(am, methodType(char.class, int.class, char.class)).
+ invokeExact(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeChar.class, char.class)).
+ invokeExact(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeChar.class, char.class)).
+ invokeExact(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) hs.get(am, methodType(char.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) hs.get(am, methodType(char.class, VarHandleTestMethodTypeChar.class, char.class)).
+ invokeExact(recv, '\u0123', Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkNPE(() -> { // null receiver
+ char x = (char) hs.get(am, methodType(char.class, VarHandleTestMethodTypeChar.class, char.class)).
+ invokeExact((VarHandleTestMethodTypeChar) null, '\u0123');
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ char x = (char) hs.get(am, methodType(char.class, Class.class, char.class)).
+ invokeExact(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) hs.get(am, methodType(char.class, VarHandleTestMethodTypeChar.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) hs.get(am, methodType(char.class, int.class, char.class)).
+ invokeExact(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeChar.class, char.class)).
+ invokeExact(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeChar.class, char.class)).
+ invokeExact(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) hs.get(am, methodType(char.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) hs.get(am, methodType(char.class, VarHandleTestMethodTypeChar.class, char.class)).
+ invokeExact(recv, '\u0123', Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkNPE(() -> { // null receiver
+ char x = (char) hs.get(am, methodType(char.class, VarHandleTestMethodTypeChar.class, char.class)).
+ invokeExact((VarHandleTestMethodTypeChar) null, '\u0123');
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ char x = (char) hs.get(am, methodType(char.class, Class.class, char.class)).
+ invokeExact(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) hs.get(am, methodType(char.class, VarHandleTestMethodTypeChar.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ char x = (char) hs.get(am, methodType(char.class, int.class, char.class)).
+ invokeExact(0, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeChar.class, char.class)).
+ invokeExact(recv, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeChar.class, char.class)).
+ invokeExact(recv, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) hs.get(am, methodType(char.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) hs.get(am, methodType(char.class, VarHandleTestMethodTypeChar.class, char.class)).
+ invokeExact(recv, '\u0123', Void.class);
+ });
+ }
+ }
+
+
+ static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ char x = (char) vh.get(Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.set(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set('\u0123', Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getVolatile(Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile('\u0123', Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getOpaque(Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque('\u0123', Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAcquire(Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease('\u0123', Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet('\u0123', Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet('\u0123', '\u0123', Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain('\u0123', Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain('\u0123', '\u0123', Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet('\u0123', Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet('\u0123', '\u0123', Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire('\u0123', Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire('\u0123', '\u0123', Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease('\u0123', Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease('\u0123', '\u0123', Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ char x = (char) vh.compareAndExchange(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ char x = (char) vh.compareAndExchange('\u0123', Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange('\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange('\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.compareAndExchange('\u0123', '\u0123', Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ char x = (char) vh.compareAndExchangeAcquire(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ char x = (char) vh.compareAndExchangeAcquire('\u0123', Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire('\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire('\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.compareAndExchangeAcquire('\u0123', '\u0123', Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ char x = (char) vh.compareAndExchangeRelease(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ char x = (char) vh.compareAndExchangeRelease('\u0123', Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease('\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease('\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.compareAndExchangeRelease('\u0123', '\u0123', Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndSet(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndSet('\u0123', Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndSetAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndSetAcquire('\u0123', Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndSetRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndSetRelease('\u0123', Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndAdd(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndAdd('\u0123', Void.class);
+ });
+
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndAddAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndAddAcquire('\u0123', Void.class);
+ });
+
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndAddRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndAddRelease('\u0123', Void.class);
+ });
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseOr(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseOr('\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseOrAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseOrAcquire('\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseOrReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseOrRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrRelease('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrRelease('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseOrRelease();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseOrRelease('\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseAnd(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseAnd('\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseAndAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseAndAcquire('\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseAndReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseAndRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndRelease('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndRelease('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseAndRelease();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseAndRelease('\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseXor(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseXor('\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseXorAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseXorAcquire('\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseXorReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseXorRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorRelease('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorRelease('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseXorRelease();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseXorRelease('\u0123', Void.class);
+ });
+ }
+
+ static void testStaticFieldWrongMethodType(Handles hs) throws Throwable {
+ int i = 0;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ char x = (char) hs.get(am, methodType(Class.class)).
+ invokeExact(Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, char.class, Class.class)).
+ invokeExact('\u0123', Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, char.class)).
+ invokeExact(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, char.class, Class.class)).
+ invokeExact('\u0123', Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, char.class, char.class, Class.class)).
+ invokeExact('\u0123', '\u0123', Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ char x = (char) hs.get(am, methodType(char.class, Class.class, char.class)).
+ invokeExact(Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ char x = (char) hs.get(am, methodType(char.class, char.class, Class.class)).
+ invokeExact('\u0123', Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, char.class, char.class)).
+ invokeExact('\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, char.class, char.class)).
+ invokeExact('\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) hs.get(am, methodType(char.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) hs.get(am, methodType(char.class, char.class, char.class, Class.class)).
+ invokeExact('\u0123', '\u0123', Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) hs.get(am, methodType(char.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, char.class)).
+ invokeExact('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, char.class)).
+ invokeExact('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) hs.get(am, methodType(char.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) hs.get(am, methodType(char.class, char.class, Class.class)).
+ invokeExact('\u0123', Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) hs.get(am, methodType(char.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, char.class)).
+ invokeExact('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, char.class)).
+ invokeExact('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) hs.get(am, methodType(char.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) hs.get(am, methodType(char.class, char.class, Class.class)).
+ invokeExact('\u0123', Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ char x = (char) hs.get(am, methodType(char.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, char.class)).
+ invokeExact('\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, char.class)).
+ invokeExact('\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) hs.get(am, methodType(char.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) hs.get(am, methodType(char.class, char.class, Class.class)).
+ invokeExact('\u0123', Void.class);
+ });
+ }
+ }
+
+
+ static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
+ char[] array = new char[10];
+ Arrays.fill(array, '\u0123');
+
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.get(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.get(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.get(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.get(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.get();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.get(array, 0, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.set(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ vh.set(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ vh.set(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ vh.set(array, Void.class, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(array, 0, '\u0123', Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getVolatile(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getVolatile(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.getVolatile(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getVolatile(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getVolatile(array, 0, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setVolatile(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ vh.setVolatile(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setVolatile(array, Void.class, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(array, 0, '\u0123', Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getOpaque(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getOpaque(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.getOpaque(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getOpaque(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getOpaque(array, 0, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setOpaque(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ vh.setOpaque(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setOpaque(array, Void.class, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(array, 0, '\u0123', Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getAcquire(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getAcquire(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.getAcquire(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getAcquire(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAcquire(array, 0, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setRelease(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ vh.setRelease(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setRelease(array, Void.class, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(array, 0, '\u0123', Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, 0, '\u0123', '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(array, 0, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(array, 0, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.compareAndSet(array, Void.class, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(array, 0, '\u0123', '\u0123', Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, 0, '\u0123', '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetPlain(array, Void.class, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(array, 0, '\u0123', '\u0123', Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, 0, '\u0123', '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(array, 0, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(array, 0, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSet(array, Void.class, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(array, 0, '\u0123', '\u0123', Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, 0, '\u0123', '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, Void.class, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, '\u0123', '\u0123', Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, 0, '\u0123', '\u0123');
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetRelease(array, Void.class, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(array, 0, '\u0123', '\u0123', Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.compareAndExchange(null, 0, '\u0123', '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.compareAndExchange(Void.class, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ char x = (char) vh.compareAndExchange(array, 0, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ char x = (char) vh.compareAndExchange(array, 0, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.compareAndExchange(0, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.compareAndExchange(array, Void.class, '\u0123', '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(array, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(array, 0, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.compareAndExchange(array, 0, '\u0123', '\u0123', Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.compareAndExchangeAcquire(null, 0, '\u0123', '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.compareAndExchangeAcquire(Void.class, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ char x = (char) vh.compareAndExchangeAcquire(array, 0, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ char x = (char) vh.compareAndExchangeAcquire(array, 0, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.compareAndExchangeAcquire(0, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.compareAndExchangeAcquire(array, Void.class, '\u0123', '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(array, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(array, 0, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.compareAndExchangeAcquire(array, 0, '\u0123', '\u0123', Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) vh.compareAndExchangeRelease(null, 0, '\u0123', '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.compareAndExchangeRelease(Void.class, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ char x = (char) vh.compareAndExchangeRelease(array, 0, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ char x = (char) vh.compareAndExchangeRelease(array, 0, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.compareAndExchangeRelease(0, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.compareAndExchangeRelease(array, Void.class, '\u0123', '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(array, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(array, 0, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.compareAndExchangeRelease(array, 0, '\u0123', '\u0123', Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getAndSet(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getAndSet(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndSet(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ char x = (char) vh.getAndSet(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getAndSet(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndSet(array, 0, '\u0123', Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getAndSetAcquire(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getAndSetAcquire(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndSetAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ char x = (char) vh.getAndSetAcquire(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getAndSetAcquire(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndSetAcquire(array, 0, '\u0123', Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getAndSetRelease(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getAndSetRelease(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndSetRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ char x = (char) vh.getAndSetRelease(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getAndSetRelease(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndSetRelease(array, 0, '\u0123', Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getAndAdd(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getAndAdd(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndAdd(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.getAndAdd(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getAndAdd(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndAdd(array, 0, '\u0123', Void.class);
+ });
+
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getAndAddAcquire(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getAndAddAcquire(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndAddAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.getAndAddAcquire(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getAndAddAcquire(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndAddAcquire(array, 0, '\u0123', Void.class);
+ });
+
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getAndAddRelease(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getAndAddRelease(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndAddRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.getAndAddRelease(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getAndAddRelease(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndAddRelease(array, 0, '\u0123', Void.class);
+ });
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getAndBitwiseOr(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getAndBitwiseOr(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseOr(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.getAndBitwiseOr(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getAndBitwiseOr(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseOr(array, 0, '\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getAndBitwiseOrAcquire(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getAndBitwiseOrAcquire(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseOrAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.getAndBitwiseOrAcquire(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getAndBitwiseOrAcquire(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseOrAcquire(array, 0, '\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseOrRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getAndBitwiseOrRelease(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getAndBitwiseOrRelease(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseOrRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.getAndBitwiseOrRelease(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getAndBitwiseOrRelease(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrRelease(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrRelease(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseOrRelease();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseOrRelease(array, 0, '\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getAndBitwiseAnd(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getAndBitwiseAnd(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseAnd(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.getAndBitwiseAnd(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getAndBitwiseAnd(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseAnd(array, 0, '\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getAndBitwiseAndAcquire(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getAndBitwiseAndAcquire(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseAndAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.getAndBitwiseAndAcquire(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getAndBitwiseAndAcquire(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseAndAcquire(array, 0, '\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseAndRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getAndBitwiseAndRelease(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getAndBitwiseAndRelease(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseAndRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.getAndBitwiseAndRelease(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getAndBitwiseAndRelease(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndRelease(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndRelease(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseAndRelease();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseAndRelease(array, 0, '\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getAndBitwiseXor(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getAndBitwiseXor(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseXor(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.getAndBitwiseXor(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getAndBitwiseXor(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseXor(array, 0, '\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getAndBitwiseXorAcquire(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getAndBitwiseXorAcquire(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseXorAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.getAndBitwiseXorAcquire(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getAndBitwiseXorAcquire(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseXorAcquire(array, 0, '\u0123', Void.class);
+ });
+
+
+ // GetAndBitwiseXorRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) vh.getAndBitwiseXorRelease(null, 0, '\u0123');
+ });
+ checkCCE(() -> { // array reference class
+ char x = (char) vh.getAndBitwiseXorRelease(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) vh.getAndBitwiseXorRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) vh.getAndBitwiseXorRelease(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) vh.getAndBitwiseXorRelease(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorRelease(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorRelease(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) vh.getAndBitwiseXorRelease();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) vh.getAndBitwiseXorRelease(array, 0, '\u0123', Void.class);
+ });
+ }
+
+ static void testArrayWrongMethodType(Handles hs) throws Throwable {
+ char[] array = new char[10];
+ Arrays.fill(array, '\u0123');
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) hs.get(am, methodType(char.class, char[].class, int.class)).
+ invokeExact((char[]) null, 0);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ char x = (char) hs.get(am, methodType(char.class, Class.class, int.class)).
+ invokeExact(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) hs.get(am, methodType(char.class, int.class, int.class)).
+ invokeExact(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) hs.get(am, methodType(char.class, char[].class, Class.class)).
+ invokeExact(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, char[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, char[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) hs.get(am, methodType(char.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) hs.get(am, methodType(char.class, char[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ hs.get(am, methodType(void.class, char[].class, int.class, char.class)).
+ invokeExact((char[]) null, 0, '\u0123');
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ hs.get(am, methodType(void.class, Class.class, int.class, char.class)).
+ invokeExact(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, char[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, int.class, char.class)).
+ invokeExact(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ hs.get(am, methodType(void.class, char[].class, Class.class, char.class)).
+ invokeExact(array, Void.class, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, char[].class, int.class, Class.class)).
+ invokeExact(array, 0, '\u0123', Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, char[].class, int.class, char.class, char.class)).
+ invokeExact((char[]) null, 0, '\u0123', '\u0123');
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, char.class, char.class)).
+ invokeExact(Void.class, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, char[].class, int.class, Class.class, char.class)).
+ invokeExact(array, 0, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, char[].class, int.class, char.class, Class.class)).
+ invokeExact(array, 0, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, char.class, char.class)).
+ invokeExact(0, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, char[].class, Class.class, char.class, char.class)).
+ invokeExact(array, Void.class, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, char[].class, int.class, char.class, char.class, Class.class)).
+ invokeExact(array, 0, '\u0123', '\u0123', Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ char x = (char) hs.get(am, methodType(char.class, char[].class, int.class, char.class, char.class)).
+ invokeExact((char[]) null, 0, '\u0123', '\u0123');
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ char x = (char) hs.get(am, methodType(char.class, Class.class, int.class, char.class, char.class)).
+ invokeExact(Void.class, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // expected reference class
+ char x = (char) hs.get(am, methodType(char.class, char[].class, int.class, Class.class, char.class)).
+ invokeExact(array, 0, Void.class, '\u0123');
+ });
+ checkWMTE(() -> { // actual reference class
+ char x = (char) hs.get(am, methodType(char.class, char[].class, int.class, char.class, Class.class)).
+ invokeExact(array, 0, '\u0123', Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) hs.get(am, methodType(char.class, int.class, int.class, char.class, char.class)).
+ invokeExact(0, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) hs.get(am, methodType(char.class, char[].class, Class.class, char.class, char.class)).
+ invokeExact(array, Void.class, '\u0123', '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, char[].class, int.class, char.class, char.class)).
+ invokeExact(array, 0, '\u0123', '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, char[].class, int.class, char.class, char.class)).
+ invokeExact(array, 0, '\u0123', '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) hs.get(am, methodType(char.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) hs.get(am, methodType(char.class, char[].class, int.class, char.class, char.class, Class.class)).
+ invokeExact(array, 0, '\u0123', '\u0123', Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) hs.get(am, methodType(char.class, char[].class, int.class, char.class)).
+ invokeExact((char[]) null, 0, '\u0123');
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ char x = (char) hs.get(am, methodType(char.class, Class.class, int.class, char.class)).
+ invokeExact(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) hs.get(am, methodType(char.class, char[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) hs.get(am, methodType(char.class, int.class, int.class, char.class)).
+ invokeExact(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) hs.get(am, methodType(char.class, char[].class, Class.class, char.class)).
+ invokeExact(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, char[].class, int.class, char.class)).
+ invokeExact(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, char[].class, int.class, char.class)).
+ invokeExact(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) hs.get(am, methodType(char.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) hs.get(am, methodType(char.class, char[].class, int.class, char.class, Class.class)).
+ invokeExact(array, 0, '\u0123', Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) hs.get(am, methodType(char.class, char[].class, int.class, char.class)).
+ invokeExact((char[]) null, 0, '\u0123');
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ char x = (char) hs.get(am, methodType(char.class, Class.class, int.class, char.class)).
+ invokeExact(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) hs.get(am, methodType(char.class, char[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) hs.get(am, methodType(char.class, int.class, int.class, char.class)).
+ invokeExact(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) hs.get(am, methodType(char.class, char[].class, Class.class, char.class)).
+ invokeExact(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, char[].class, int.class, char.class)).
+ invokeExact(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, char[].class, int.class, char.class)).
+ invokeExact(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) hs.get(am, methodType(char.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) hs.get(am, methodType(char.class, char[].class, int.class, char.class, Class.class)).
+ invokeExact(array, 0, '\u0123', Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ char x = (char) hs.get(am, methodType(char.class, char[].class, int.class, char.class)).
+ invokeExact((char[]) null, 0, '\u0123');
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ char x = (char) hs.get(am, methodType(char.class, Class.class, int.class, char.class)).
+ invokeExact(Void.class, 0, '\u0123');
+ });
+ checkWMTE(() -> { // value reference class
+ char x = (char) hs.get(am, methodType(char.class, char[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ char x = (char) hs.get(am, methodType(char.class, int.class, int.class, char.class)).
+ invokeExact(0, 0, '\u0123');
+ });
+ checkWMTE(() -> { // index reference class
+ char x = (char) hs.get(am, methodType(char.class, char[].class, Class.class, char.class)).
+ invokeExact(array, Void.class, '\u0123');
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, char[].class, int.class, char.class)).
+ invokeExact(array, 0, '\u0123');
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, char[].class, int.class, char.class)).
+ invokeExact(array, 0, '\u0123');
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ char x = (char) hs.get(am, methodType(char.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ char x = (char) hs.get(am, methodType(char.class, char[].class, int.class, char.class, Class.class)).
+ invokeExact(array, 0, '\u0123', Void.class);
+ });
+ }
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeDouble.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeDouble.java
new file mode 100644
index 0000000..a9f7eb7
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeDouble.java
@@ -0,0 +1,2402 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8156486
+ * @run testng/othervm VarHandleTestMethodTypeDouble
+ * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestMethodTypeDouble
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+import static java.lang.invoke.MethodType.*;
+
+public class VarHandleTestMethodTypeDouble extends VarHandleBaseTest {
+ static final double static_final_v = 1.0d;
+
+ static double static_v = 1.0d;
+
+ final double final_v = 1.0d;
+
+ double v = 1.0d;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeDouble.class, "final_v", double.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeDouble.class, "v", double.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeDouble.class, "static_final_v", double.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeDouble.class, "static_v", double.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(double[].class);
+ }
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestMethodTypeDouble::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestMethodTypeDouble::testArrayWrongMethodType,
+ false));
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceFieldWrongMethodType(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodTypeDouble::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodTypeDouble::testArrayWrongMethodType,
+ false));
+ }
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeDouble recv, VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) vh.get(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ double x = (double) vh.get(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ double x = (double) vh.get(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.get();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.get(recv, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.set(null, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.set(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.set(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(recv, 1.0d, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) vh.getVolatile(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ double x = (double) vh.getVolatile(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ double x = (double) vh.getVolatile(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getVolatile(recv, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setVolatile(null, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setVolatile(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(recv, 1.0d, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) vh.getOpaque(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ double x = (double) vh.getOpaque(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ double x = (double) vh.getOpaque(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getOpaque(recv, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setOpaque(null, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setOpaque(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(recv, 1.0d, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) vh.getAcquire(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ double x = (double) vh.getAcquire(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ double x = (double) vh.getAcquire(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAcquire(recv, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setRelease(null, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setRelease(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(recv, 1.0d, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, 1.0d, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(recv, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(recv, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(recv, 1.0d, 1.0d, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, 1.0d, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(recv, 1.0d, 1.0d, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, 1.0d, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(recv, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(recv, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(recv, 1.0d, 1.0d, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, 1.0d, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(recv, 1.0d, 1.0d, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, 1.0d, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(recv, 1.0d, 1.0d, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) vh.compareAndExchange(null, 1.0d, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ double x = (double) vh.compareAndExchange(Void.class, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ double x = (double) vh.compareAndExchange(recv, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ double x = (double) vh.compareAndExchange(recv, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ double x = (double) vh.compareAndExchange(0, 1.0d, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(recv, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(recv, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.compareAndExchange(recv, 1.0d, 1.0d, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) vh.compareAndExchangeAcquire(null, 1.0d, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ double x = (double) vh.compareAndExchangeAcquire(Void.class, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ double x = (double) vh.compareAndExchangeAcquire(recv, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ double x = (double) vh.compareAndExchangeAcquire(recv, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ double x = (double) vh.compareAndExchangeAcquire(0, 1.0d, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(recv, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(recv, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.compareAndExchangeAcquire(recv, 1.0d, 1.0d, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) vh.compareAndExchangeRelease(null, 1.0d, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ double x = (double) vh.compareAndExchangeRelease(Void.class, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ double x = (double) vh.compareAndExchangeRelease(recv, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ double x = (double) vh.compareAndExchangeRelease(recv, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ double x = (double) vh.compareAndExchangeRelease(0, 1.0d, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(recv, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(recv, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.compareAndExchangeRelease(recv, 1.0d, 1.0d, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) vh.getAndSet(null, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ double x = (double) vh.getAndSet(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndSet(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ double x = (double) vh.getAndSet(0, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(recv, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(recv, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndSet(recv, 1.0d, Void.class);
+ });
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) vh.getAndSetAcquire(null, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ double x = (double) vh.getAndSetAcquire(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndSetAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ double x = (double) vh.getAndSetAcquire(0, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(recv, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(recv, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndSetAcquire(recv, 1.0d, Void.class);
+ });
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) vh.getAndSetRelease(null, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ double x = (double) vh.getAndSetRelease(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndSetRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ double x = (double) vh.getAndSetRelease(0, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(recv, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(recv, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndSetRelease(recv, 1.0d, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) vh.getAndAdd(null, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ double x = (double) vh.getAndAdd(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndAdd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ double x = (double) vh.getAndAdd(0, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(recv, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(recv, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndAdd(recv, 1.0d, Void.class);
+ });
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) vh.getAndAddAcquire(null, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ double x = (double) vh.getAndAddAcquire(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndAddAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ double x = (double) vh.getAndAddAcquire(0, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(recv, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(recv, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndAddAcquire(recv, 1.0d, Void.class);
+ });
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) vh.getAndAddRelease(null, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ double x = (double) vh.getAndAddRelease(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndAddRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ double x = (double) vh.getAndAddRelease(0, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(recv, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(recv, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndAddRelease(recv, 1.0d, Void.class);
+ });
+
+ }
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeDouble recv, Handles hs) throws Throwable {
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class)).
+ invokeExact((VarHandleTestMethodTypeDouble) null);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ double x = (double) hs.get(am, methodType(double.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ double x = (double) hs.get(am, methodType(double.class, int.class)).
+ invokeExact(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeDouble.class)).
+ invokeExact(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class)).
+ invokeExact(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) hs.get(am, methodType(double.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeDouble.class, double.class)).
+ invokeExact((VarHandleTestMethodTypeDouble) null, 1.0d);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ hs.get(am, methodType(void.class, Class.class, double.class)).
+ invokeExact(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeDouble.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, double.class)).
+ invokeExact(0, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeDouble.class, double.class, Class.class)).
+ invokeExact(recv, 1.0d, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, double.class, double.class)).
+ invokeExact((VarHandleTestMethodTypeDouble) null, 1.0d, 1.0d);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, double.class, double.class)).
+ invokeExact(Void.class, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, Class.class, double.class)).
+ invokeExact(recv, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, double.class, Class.class)).
+ invokeExact(recv, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , double.class, double.class)).
+ invokeExact(0, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, double.class, double.class, Class.class)).
+ invokeExact(recv, 1.0d, 1.0d, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkNPE(() -> { // null receiver
+ double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, double.class, double.class)).
+ invokeExact((VarHandleTestMethodTypeDouble) null, 1.0d, 1.0d);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ double x = (double) hs.get(am, methodType(double.class, Class.class, double.class, double.class)).
+ invokeExact(Void.class, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, Class.class, double.class)).
+ invokeExact(recv, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, double.class, Class.class)).
+ invokeExact(recv, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ double x = (double) hs.get(am, methodType(double.class, int.class , double.class, double.class)).
+ invokeExact(0, 1.0d, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeDouble.class , double.class, double.class)).
+ invokeExact(recv, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class , double.class, double.class)).
+ invokeExact(recv, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) hs.get(am, methodType(double.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, double.class, double.class, Class.class)).
+ invokeExact(recv, 1.0d, 1.0d, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkNPE(() -> { // null receiver
+ double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, double.class)).
+ invokeExact((VarHandleTestMethodTypeDouble) null, 1.0d);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ double x = (double) hs.get(am, methodType(double.class, Class.class, double.class)).
+ invokeExact(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ double x = (double) hs.get(am, methodType(double.class, int.class, double.class)).
+ invokeExact(0, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeDouble.class, double.class)).
+ invokeExact(recv, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, double.class)).
+ invokeExact(recv, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) hs.get(am, methodType(double.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, double.class)).
+ invokeExact(recv, 1.0d, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkNPE(() -> { // null receiver
+ double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, double.class)).
+ invokeExact((VarHandleTestMethodTypeDouble) null, 1.0d);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ double x = (double) hs.get(am, methodType(double.class, Class.class, double.class)).
+ invokeExact(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ double x = (double) hs.get(am, methodType(double.class, int.class, double.class)).
+ invokeExact(0, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeDouble.class, double.class)).
+ invokeExact(recv, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, double.class)).
+ invokeExact(recv, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) hs.get(am, methodType(double.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, double.class)).
+ invokeExact(recv, 1.0d, Void.class);
+ });
+ }
+
+ }
+
+
+ static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ double x = (double) vh.get(Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.set(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(1.0d, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getVolatile(Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(1.0d, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getOpaque(Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(1.0d, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAcquire(Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(1.0d, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(1.0d, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(1.0d, 1.0d, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(1.0d, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(1.0d, 1.0d, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(1.0d, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(1.0d, 1.0d, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(1.0d, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(1.0d, 1.0d, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(1.0d, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(1.0d, 1.0d, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ double x = (double) vh.compareAndExchange(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ double x = (double) vh.compareAndExchange(1.0d, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.compareAndExchange(1.0d, 1.0d, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ double x = (double) vh.compareAndExchangeAcquire(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ double x = (double) vh.compareAndExchangeAcquire(1.0d, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.compareAndExchangeAcquire(1.0d, 1.0d, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ double x = (double) vh.compareAndExchangeRelease(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ double x = (double) vh.compareAndExchangeRelease(1.0d, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.compareAndExchangeRelease(1.0d, 1.0d, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndSet(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndSet(1.0d, Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndSetAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndSetAcquire(1.0d, Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndSetRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndSetRelease(1.0d, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndAdd(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndAdd(1.0d, Void.class);
+ });
+
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndAddAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndAddAcquire(1.0d, Void.class);
+ });
+
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndAddRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndAddRelease(1.0d, Void.class);
+ });
+
+ }
+
+ static void testStaticFieldWrongMethodType(Handles hs) throws Throwable {
+ int i = 0;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ double x = (double) hs.get(am, methodType(Class.class)).
+ invokeExact(Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, double.class, Class.class)).
+ invokeExact(1.0d, Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, double.class)).
+ invokeExact(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, double.class, Class.class)).
+ invokeExact(1.0d, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, double.class, double.class, Class.class)).
+ invokeExact(1.0d, 1.0d, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ double x = (double) hs.get(am, methodType(double.class, Class.class, double.class)).
+ invokeExact(Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ double x = (double) hs.get(am, methodType(double.class, double.class, Class.class)).
+ invokeExact(1.0d, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, double.class, double.class)).
+ invokeExact(1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, double.class, double.class)).
+ invokeExact(1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) hs.get(am, methodType(double.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) hs.get(am, methodType(double.class, double.class, double.class, Class.class)).
+ invokeExact(1.0d, 1.0d, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ double x = (double) hs.get(am, methodType(double.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, double.class)).
+ invokeExact(1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, double.class)).
+ invokeExact(1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) hs.get(am, methodType(double.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) hs.get(am, methodType(double.class, double.class, Class.class)).
+ invokeExact(1.0d, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ double x = (double) hs.get(am, methodType(double.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, double.class)).
+ invokeExact(1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, double.class)).
+ invokeExact(1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) hs.get(am, methodType(double.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) hs.get(am, methodType(double.class, double.class, Class.class)).
+ invokeExact(1.0d, Void.class);
+ });
+ }
+
+ }
+
+
+ static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
+ double[] array = new double[10];
+ Arrays.fill(array, 1.0d);
+
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ double x = (double) vh.get(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ double x = (double) vh.get(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ double x = (double) vh.get(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ double x = (double) vh.get(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.get();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.get(array, 0, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.set(null, 0, 1.0d);
+ });
+ checkCCE(() -> { // array reference class
+ vh.set(Void.class, 0, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.set(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, 0, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.set(array, Void.class, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(array, 0, 1.0d, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ double x = (double) vh.getVolatile(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ double x = (double) vh.getVolatile(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ double x = (double) vh.getVolatile(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ double x = (double) vh.getVolatile(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getVolatile(array, 0, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setVolatile(null, 0, 1.0d);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setVolatile(Void.class, 0, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, 0, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setVolatile(array, Void.class, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(array, 0, 1.0d, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ double x = (double) vh.getOpaque(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ double x = (double) vh.getOpaque(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ double x = (double) vh.getOpaque(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ double x = (double) vh.getOpaque(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getOpaque(array, 0, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setOpaque(null, 0, 1.0d);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setOpaque(Void.class, 0, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, 0, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setOpaque(array, Void.class, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(array, 0, 1.0d, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ double x = (double) vh.getAcquire(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ double x = (double) vh.getAcquire(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ double x = (double) vh.getAcquire(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ double x = (double) vh.getAcquire(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAcquire(array, 0, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setRelease(null, 0, 1.0d);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setRelease(Void.class, 0, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, 0, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setRelease(array, Void.class, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(array, 0, 1.0d, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, 0, 1.0d, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(array, 0, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(array, 0, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.compareAndSet(array, Void.class, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(array, 0, 1.0d, 1.0d, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, 0, 1.0d, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetPlain(array, Void.class, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(array, 0, 1.0d, 1.0d, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, 0, 1.0d, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(array, 0, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(array, 0, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSet(array, Void.class, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(array, 0, 1.0d, 1.0d, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, 0, 1.0d, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, Void.class, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, 1.0d, 1.0d, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, 0, 1.0d, 1.0d);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetRelease(array, Void.class, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(array, 0, 1.0d, 1.0d, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) vh.compareAndExchange(null, 0, 1.0d, 1.0d);
+ });
+ checkCCE(() -> { // array reference class
+ double x = (double) vh.compareAndExchange(Void.class, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ double x = (double) vh.compareAndExchange(array, 0, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ double x = (double) vh.compareAndExchange(array, 0, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ double x = (double) vh.compareAndExchange(0, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ double x = (double) vh.compareAndExchange(array, Void.class, 1.0d, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(array, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(array, 0, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.compareAndExchange(array, 0, 1.0d, 1.0d, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) vh.compareAndExchangeAcquire(null, 0, 1.0d, 1.0d);
+ });
+ checkCCE(() -> { // array reference class
+ double x = (double) vh.compareAndExchangeAcquire(Void.class, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ double x = (double) vh.compareAndExchangeAcquire(array, 0, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ double x = (double) vh.compareAndExchangeAcquire(array, 0, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ double x = (double) vh.compareAndExchangeAcquire(0, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ double x = (double) vh.compareAndExchangeAcquire(array, Void.class, 1.0d, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(array, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(array, 0, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.compareAndExchangeAcquire(array, 0, 1.0d, 1.0d, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) vh.compareAndExchangeRelease(null, 0, 1.0d, 1.0d);
+ });
+ checkCCE(() -> { // array reference class
+ double x = (double) vh.compareAndExchangeRelease(Void.class, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ double x = (double) vh.compareAndExchangeRelease(array, 0, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ double x = (double) vh.compareAndExchangeRelease(array, 0, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ double x = (double) vh.compareAndExchangeRelease(0, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ double x = (double) vh.compareAndExchangeRelease(array, Void.class, 1.0d, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(array, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(array, 0, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.compareAndExchangeRelease(array, 0, 1.0d, 1.0d, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ double x = (double) vh.getAndSet(null, 0, 1.0d);
+ });
+ checkCCE(() -> { // array reference class
+ double x = (double) vh.getAndSet(Void.class, 0, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndSet(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ double x = (double) vh.getAndSet(0, 0, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ double x = (double) vh.getAndSet(array, Void.class, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(array, 0, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(array, 0, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndSet(array, 0, 1.0d, Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ double x = (double) vh.getAndSetAcquire(null, 0, 1.0d);
+ });
+ checkCCE(() -> { // array reference class
+ double x = (double) vh.getAndSetAcquire(Void.class, 0, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndSetAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ double x = (double) vh.getAndSetAcquire(0, 0, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ double x = (double) vh.getAndSetAcquire(array, Void.class, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(array, 0, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(array, 0, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndSetAcquire(array, 0, 1.0d, Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ double x = (double) vh.getAndSetRelease(null, 0, 1.0d);
+ });
+ checkCCE(() -> { // array reference class
+ double x = (double) vh.getAndSetRelease(Void.class, 0, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndSetRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ double x = (double) vh.getAndSetRelease(0, 0, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ double x = (double) vh.getAndSetRelease(array, Void.class, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(array, 0, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(array, 0, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndSetRelease(array, 0, 1.0d, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ double x = (double) vh.getAndAdd(null, 0, 1.0d);
+ });
+ checkCCE(() -> { // array reference class
+ double x = (double) vh.getAndAdd(Void.class, 0, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndAdd(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ double x = (double) vh.getAndAdd(0, 0, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ double x = (double) vh.getAndAdd(array, Void.class, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(array, 0, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(array, 0, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndAdd(array, 0, 1.0d, Void.class);
+ });
+
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ double x = (double) vh.getAndAddAcquire(null, 0, 1.0d);
+ });
+ checkCCE(() -> { // array reference class
+ double x = (double) vh.getAndAddAcquire(Void.class, 0, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndAddAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ double x = (double) vh.getAndAddAcquire(0, 0, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ double x = (double) vh.getAndAddAcquire(array, Void.class, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(array, 0, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(array, 0, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndAddAcquire(array, 0, 1.0d, Void.class);
+ });
+
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ double x = (double) vh.getAndAddRelease(null, 0, 1.0d);
+ });
+ checkCCE(() -> { // array reference class
+ double x = (double) vh.getAndAddRelease(Void.class, 0, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ double x = (double) vh.getAndAddRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ double x = (double) vh.getAndAddRelease(0, 0, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ double x = (double) vh.getAndAddRelease(array, Void.class, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(array, 0, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(array, 0, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) vh.getAndAddRelease(array, 0, 1.0d, Void.class);
+ });
+
+ }
+
+ static void testArrayWrongMethodType(Handles hs) throws Throwable {
+ double[] array = new double[10];
+ Arrays.fill(array, 1.0d);
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ double x = (double) hs.get(am, methodType(double.class, double[].class, int.class)).
+ invokeExact((double[]) null, 0);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ double x = (double) hs.get(am, methodType(double.class, Class.class, int.class)).
+ invokeExact(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ double x = (double) hs.get(am, methodType(double.class, int.class, int.class)).
+ invokeExact(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ double x = (double) hs.get(am, methodType(double.class, double[].class, Class.class)).
+ invokeExact(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, double[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) hs.get(am, methodType(double.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ hs.get(am, methodType(void.class, double[].class, int.class, double.class)).
+ invokeExact((double[]) null, 0, 1.0d);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ hs.get(am, methodType(void.class, Class.class, int.class, double.class)).
+ invokeExact(Void.class, 0, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, double[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, int.class, double.class)).
+ invokeExact(0, 0, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ hs.get(am, methodType(void.class, double[].class, Class.class, double.class)).
+ invokeExact(array, Void.class, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, double[].class, int.class, Class.class)).
+ invokeExact(array, 0, 1.0d, Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, double.class, double.class)).
+ invokeExact((double[]) null, 0, 1.0d, 1.0d);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, double.class, double.class)).
+ invokeExact(Void.class, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, Class.class, double.class)).
+ invokeExact(array, 0, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, double.class, Class.class)).
+ invokeExact(array, 0, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, double.class, double.class)).
+ invokeExact(0, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, double[].class, Class.class, double.class, double.class)).
+ invokeExact(array, Void.class, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, double.class, double.class, Class.class)).
+ invokeExact(array, 0, 1.0d, 1.0d, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, double.class, double.class)).
+ invokeExact((double[]) null, 0, 1.0d, 1.0d);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ double x = (double) hs.get(am, methodType(double.class, Class.class, int.class, double.class, double.class)).
+ invokeExact(Void.class, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // expected reference class
+ double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, Class.class, double.class)).
+ invokeExact(array, 0, Void.class, 1.0d);
+ });
+ checkWMTE(() -> { // actual reference class
+ double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, double.class, Class.class)).
+ invokeExact(array, 0, 1.0d, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ double x = (double) hs.get(am, methodType(double.class, int.class, int.class, double.class, double.class)).
+ invokeExact(0, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ double x = (double) hs.get(am, methodType(double.class, double[].class, Class.class, double.class, double.class)).
+ invokeExact(array, Void.class, 1.0d, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, double[].class, int.class, double.class, double.class)).
+ invokeExact(array, 0, 1.0d, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, double.class, double.class)).
+ invokeExact(array, 0, 1.0d, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) hs.get(am, methodType(double.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, double.class, double.class, Class.class)).
+ invokeExact(array, 0, 1.0d, 1.0d, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, double.class)).
+ invokeExact((double[]) null, 0, 1.0d);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ double x = (double) hs.get(am, methodType(double.class, Class.class, int.class, double.class)).
+ invokeExact(Void.class, 0, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ double x = (double) hs.get(am, methodType(double.class, int.class, int.class, double.class)).
+ invokeExact(0, 0, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ double x = (double) hs.get(am, methodType(double.class, double[].class, Class.class, double.class)).
+ invokeExact(array, Void.class, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, double[].class, int.class, double.class)).
+ invokeExact(array, 0, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, double.class)).
+ invokeExact(array, 0, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) hs.get(am, methodType(double.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, double.class, Class.class)).
+ invokeExact(array, 0, 1.0d, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, double.class)).
+ invokeExact((double[]) null, 0, 1.0d);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ double x = (double) hs.get(am, methodType(double.class, Class.class, int.class, double.class)).
+ invokeExact(Void.class, 0, 1.0d);
+ });
+ checkWMTE(() -> { // value reference class
+ double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ double x = (double) hs.get(am, methodType(double.class, int.class, int.class, double.class)).
+ invokeExact(0, 0, 1.0d);
+ });
+ checkWMTE(() -> { // index reference class
+ double x = (double) hs.get(am, methodType(double.class, double[].class, Class.class, double.class)).
+ invokeExact(array, Void.class, 1.0d);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, double[].class, int.class, double.class)).
+ invokeExact(array, 0, 1.0d);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, double.class)).
+ invokeExact(array, 0, 1.0d);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ double x = (double) hs.get(am, methodType(double.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, double.class, Class.class)).
+ invokeExact(array, 0, 1.0d, Void.class);
+ });
+ }
+
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeFloat.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeFloat.java
new file mode 100644
index 0000000..8064bdc
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeFloat.java
@@ -0,0 +1,2402 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8156486
+ * @run testng/othervm VarHandleTestMethodTypeFloat
+ * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestMethodTypeFloat
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+import static java.lang.invoke.MethodType.*;
+
+public class VarHandleTestMethodTypeFloat extends VarHandleBaseTest {
+ static final float static_final_v = 1.0f;
+
+ static float static_v = 1.0f;
+
+ final float final_v = 1.0f;
+
+ float v = 1.0f;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeFloat.class, "final_v", float.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeFloat.class, "v", float.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeFloat.class, "static_final_v", float.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeFloat.class, "static_v", float.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(float[].class);
+ }
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestMethodTypeFloat::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestMethodTypeFloat::testArrayWrongMethodType,
+ false));
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceFieldWrongMethodType(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodTypeFloat::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodTypeFloat::testArrayWrongMethodType,
+ false));
+ }
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeFloat recv, VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) vh.get(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ float x = (float) vh.get(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ float x = (float) vh.get(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.get();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.get(recv, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.set(null, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.set(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.set(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(recv, 1.0f, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) vh.getVolatile(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ float x = (float) vh.getVolatile(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ float x = (float) vh.getVolatile(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getVolatile(recv, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setVolatile(null, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setVolatile(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(recv, 1.0f, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) vh.getOpaque(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ float x = (float) vh.getOpaque(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ float x = (float) vh.getOpaque(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getOpaque(recv, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setOpaque(null, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setOpaque(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(recv, 1.0f, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) vh.getAcquire(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ float x = (float) vh.getAcquire(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ float x = (float) vh.getAcquire(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAcquire(recv, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setRelease(null, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setRelease(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(recv, 1.0f, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, 1.0f, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(recv, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(recv, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(recv, 1.0f, 1.0f, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, 1.0f, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(recv, 1.0f, 1.0f, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, 1.0f, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(recv, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(recv, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(recv, 1.0f, 1.0f, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, 1.0f, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(recv, 1.0f, 1.0f, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, 1.0f, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(recv, 1.0f, 1.0f, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) vh.compareAndExchange(null, 1.0f, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ float x = (float) vh.compareAndExchange(Void.class, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ float x = (float) vh.compareAndExchange(recv, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ float x = (float) vh.compareAndExchange(recv, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ float x = (float) vh.compareAndExchange(0, 1.0f, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(recv, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(recv, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.compareAndExchange(recv, 1.0f, 1.0f, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) vh.compareAndExchangeAcquire(null, 1.0f, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ float x = (float) vh.compareAndExchangeAcquire(Void.class, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ float x = (float) vh.compareAndExchangeAcquire(recv, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ float x = (float) vh.compareAndExchangeAcquire(recv, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ float x = (float) vh.compareAndExchangeAcquire(0, 1.0f, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(recv, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(recv, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 1.0f, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) vh.compareAndExchangeRelease(null, 1.0f, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ float x = (float) vh.compareAndExchangeRelease(Void.class, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ float x = (float) vh.compareAndExchangeRelease(recv, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ float x = (float) vh.compareAndExchangeRelease(recv, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ float x = (float) vh.compareAndExchangeRelease(0, 1.0f, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(recv, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(recv, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.compareAndExchangeRelease(recv, 1.0f, 1.0f, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) vh.getAndSet(null, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ float x = (float) vh.getAndSet(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndSet(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ float x = (float) vh.getAndSet(0, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(recv, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(recv, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndSet(recv, 1.0f, Void.class);
+ });
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) vh.getAndSetAcquire(null, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ float x = (float) vh.getAndSetAcquire(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndSetAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ float x = (float) vh.getAndSetAcquire(0, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(recv, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(recv, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndSetAcquire(recv, 1.0f, Void.class);
+ });
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) vh.getAndSetRelease(null, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ float x = (float) vh.getAndSetRelease(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndSetRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ float x = (float) vh.getAndSetRelease(0, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(recv, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(recv, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndSetRelease(recv, 1.0f, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) vh.getAndAdd(null, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ float x = (float) vh.getAndAdd(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndAdd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ float x = (float) vh.getAndAdd(0, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(recv, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(recv, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndAdd(recv, 1.0f, Void.class);
+ });
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) vh.getAndAddAcquire(null, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ float x = (float) vh.getAndAddAcquire(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndAddAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ float x = (float) vh.getAndAddAcquire(0, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(recv, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(recv, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndAddAcquire(recv, 1.0f, Void.class);
+ });
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) vh.getAndAddRelease(null, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ float x = (float) vh.getAndAddRelease(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndAddRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ float x = (float) vh.getAndAddRelease(0, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(recv, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(recv, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndAddRelease(recv, 1.0f, Void.class);
+ });
+
+ }
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeFloat recv, Handles hs) throws Throwable {
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) hs.get(am, methodType(float.class, VarHandleTestMethodTypeFloat.class)).
+ invokeExact((VarHandleTestMethodTypeFloat) null);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ float x = (float) hs.get(am, methodType(float.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ float x = (float) hs.get(am, methodType(float.class, int.class)).
+ invokeExact(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeFloat.class)).
+ invokeExact(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeFloat.class)).
+ invokeExact(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) hs.get(am, methodType(float.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) hs.get(am, methodType(float.class, VarHandleTestMethodTypeFloat.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeFloat.class, float.class)).
+ invokeExact((VarHandleTestMethodTypeFloat) null, 1.0f);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ hs.get(am, methodType(void.class, Class.class, float.class)).
+ invokeExact(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeFloat.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, float.class)).
+ invokeExact(0, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeFloat.class, float.class, Class.class)).
+ invokeExact(recv, 1.0f, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeFloat.class, float.class, float.class)).
+ invokeExact((VarHandleTestMethodTypeFloat) null, 1.0f, 1.0f);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, float.class, float.class)).
+ invokeExact(Void.class, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeFloat.class, Class.class, float.class)).
+ invokeExact(recv, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeFloat.class, float.class, Class.class)).
+ invokeExact(recv, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , float.class, float.class)).
+ invokeExact(0, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeFloat.class, float.class, float.class, Class.class)).
+ invokeExact(recv, 1.0f, 1.0f, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkNPE(() -> { // null receiver
+ float x = (float) hs.get(am, methodType(float.class, VarHandleTestMethodTypeFloat.class, float.class, float.class)).
+ invokeExact((VarHandleTestMethodTypeFloat) null, 1.0f, 1.0f);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ float x = (float) hs.get(am, methodType(float.class, Class.class, float.class, float.class)).
+ invokeExact(Void.class, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ float x = (float) hs.get(am, methodType(float.class, VarHandleTestMethodTypeFloat.class, Class.class, float.class)).
+ invokeExact(recv, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ float x = (float) hs.get(am, methodType(float.class, VarHandleTestMethodTypeFloat.class, float.class, Class.class)).
+ invokeExact(recv, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ float x = (float) hs.get(am, methodType(float.class, int.class , float.class, float.class)).
+ invokeExact(0, 1.0f, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeFloat.class , float.class, float.class)).
+ invokeExact(recv, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeFloat.class , float.class, float.class)).
+ invokeExact(recv, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) hs.get(am, methodType(float.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) hs.get(am, methodType(float.class, VarHandleTestMethodTypeFloat.class, float.class, float.class, Class.class)).
+ invokeExact(recv, 1.0f, 1.0f, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkNPE(() -> { // null receiver
+ float x = (float) hs.get(am, methodType(float.class, VarHandleTestMethodTypeFloat.class, float.class)).
+ invokeExact((VarHandleTestMethodTypeFloat) null, 1.0f);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ float x = (float) hs.get(am, methodType(float.class, Class.class, float.class)).
+ invokeExact(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ float x = (float) hs.get(am, methodType(float.class, VarHandleTestMethodTypeFloat.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ float x = (float) hs.get(am, methodType(float.class, int.class, float.class)).
+ invokeExact(0, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeFloat.class, float.class)).
+ invokeExact(recv, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeFloat.class, float.class)).
+ invokeExact(recv, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) hs.get(am, methodType(float.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) hs.get(am, methodType(float.class, VarHandleTestMethodTypeFloat.class, float.class)).
+ invokeExact(recv, 1.0f, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkNPE(() -> { // null receiver
+ float x = (float) hs.get(am, methodType(float.class, VarHandleTestMethodTypeFloat.class, float.class)).
+ invokeExact((VarHandleTestMethodTypeFloat) null, 1.0f);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ float x = (float) hs.get(am, methodType(float.class, Class.class, float.class)).
+ invokeExact(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ float x = (float) hs.get(am, methodType(float.class, VarHandleTestMethodTypeFloat.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ float x = (float) hs.get(am, methodType(float.class, int.class, float.class)).
+ invokeExact(0, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeFloat.class, float.class)).
+ invokeExact(recv, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeFloat.class, float.class)).
+ invokeExact(recv, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) hs.get(am, methodType(float.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) hs.get(am, methodType(float.class, VarHandleTestMethodTypeFloat.class, float.class)).
+ invokeExact(recv, 1.0f, Void.class);
+ });
+ }
+
+ }
+
+
+ static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ float x = (float) vh.get(Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.set(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(1.0f, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getVolatile(Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(1.0f, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getOpaque(Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(1.0f, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAcquire(Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(1.0f, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(1.0f, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(1.0f, 1.0f, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(1.0f, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(1.0f, 1.0f, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(1.0f, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(1.0f, 1.0f, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(1.0f, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(1.0f, 1.0f, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(1.0f, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(1.0f, 1.0f, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ float x = (float) vh.compareAndExchange(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ float x = (float) vh.compareAndExchange(1.0f, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.compareAndExchange(1.0f, 1.0f, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ float x = (float) vh.compareAndExchangeAcquire(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ float x = (float) vh.compareAndExchangeAcquire(1.0f, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.compareAndExchangeAcquire(1.0f, 1.0f, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ float x = (float) vh.compareAndExchangeRelease(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ float x = (float) vh.compareAndExchangeRelease(1.0f, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.compareAndExchangeRelease(1.0f, 1.0f, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndSet(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndSet(1.0f, Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndSetAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndSetAcquire(1.0f, Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndSetRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndSetRelease(1.0f, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndAdd(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndAdd(1.0f, Void.class);
+ });
+
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndAddAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndAddAcquire(1.0f, Void.class);
+ });
+
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndAddRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndAddRelease(1.0f, Void.class);
+ });
+
+ }
+
+ static void testStaticFieldWrongMethodType(Handles hs) throws Throwable {
+ int i = 0;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ float x = (float) hs.get(am, methodType(Class.class)).
+ invokeExact(Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, float.class, Class.class)).
+ invokeExact(1.0f, Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, float.class)).
+ invokeExact(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, float.class, Class.class)).
+ invokeExact(1.0f, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, float.class, float.class, Class.class)).
+ invokeExact(1.0f, 1.0f, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ float x = (float) hs.get(am, methodType(float.class, Class.class, float.class)).
+ invokeExact(Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ float x = (float) hs.get(am, methodType(float.class, float.class, Class.class)).
+ invokeExact(1.0f, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, float.class, float.class)).
+ invokeExact(1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, float.class, float.class)).
+ invokeExact(1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) hs.get(am, methodType(float.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) hs.get(am, methodType(float.class, float.class, float.class, Class.class)).
+ invokeExact(1.0f, 1.0f, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ float x = (float) hs.get(am, methodType(float.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, float.class)).
+ invokeExact(1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, float.class)).
+ invokeExact(1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) hs.get(am, methodType(float.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) hs.get(am, methodType(float.class, float.class, Class.class)).
+ invokeExact(1.0f, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ float x = (float) hs.get(am, methodType(float.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, float.class)).
+ invokeExact(1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, float.class)).
+ invokeExact(1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) hs.get(am, methodType(float.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) hs.get(am, methodType(float.class, float.class, Class.class)).
+ invokeExact(1.0f, Void.class);
+ });
+ }
+
+ }
+
+
+ static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
+ float[] array = new float[10];
+ Arrays.fill(array, 1.0f);
+
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ float x = (float) vh.get(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ float x = (float) vh.get(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ float x = (float) vh.get(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ float x = (float) vh.get(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.get();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.get(array, 0, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.set(null, 0, 1.0f);
+ });
+ checkCCE(() -> { // array reference class
+ vh.set(Void.class, 0, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.set(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, 0, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.set(array, Void.class, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(array, 0, 1.0f, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ float x = (float) vh.getVolatile(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ float x = (float) vh.getVolatile(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ float x = (float) vh.getVolatile(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ float x = (float) vh.getVolatile(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getVolatile(array, 0, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setVolatile(null, 0, 1.0f);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setVolatile(Void.class, 0, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, 0, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setVolatile(array, Void.class, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(array, 0, 1.0f, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ float x = (float) vh.getOpaque(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ float x = (float) vh.getOpaque(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ float x = (float) vh.getOpaque(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ float x = (float) vh.getOpaque(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getOpaque(array, 0, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setOpaque(null, 0, 1.0f);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setOpaque(Void.class, 0, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, 0, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setOpaque(array, Void.class, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(array, 0, 1.0f, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ float x = (float) vh.getAcquire(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ float x = (float) vh.getAcquire(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ float x = (float) vh.getAcquire(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ float x = (float) vh.getAcquire(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAcquire(array, 0, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setRelease(null, 0, 1.0f);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setRelease(Void.class, 0, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, 0, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setRelease(array, Void.class, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(array, 0, 1.0f, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, 0, 1.0f, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(array, 0, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(array, 0, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.compareAndSet(array, Void.class, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(array, 0, 1.0f, 1.0f, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, 0, 1.0f, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetPlain(array, Void.class, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(array, 0, 1.0f, 1.0f, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, 0, 1.0f, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(array, 0, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(array, 0, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSet(array, Void.class, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(array, 0, 1.0f, 1.0f, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, 0, 1.0f, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, Void.class, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, 1.0f, 1.0f, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, 0, 1.0f, 1.0f);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetRelease(array, Void.class, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(array, 0, 1.0f, 1.0f, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) vh.compareAndExchange(null, 0, 1.0f, 1.0f);
+ });
+ checkCCE(() -> { // array reference class
+ float x = (float) vh.compareAndExchange(Void.class, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ float x = (float) vh.compareAndExchange(array, 0, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ float x = (float) vh.compareAndExchange(array, 0, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ float x = (float) vh.compareAndExchange(0, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ float x = (float) vh.compareAndExchange(array, Void.class, 1.0f, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(array, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(array, 0, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.compareAndExchange(array, 0, 1.0f, 1.0f, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) vh.compareAndExchangeAcquire(null, 0, 1.0f, 1.0f);
+ });
+ checkCCE(() -> { // array reference class
+ float x = (float) vh.compareAndExchangeAcquire(Void.class, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ float x = (float) vh.compareAndExchangeAcquire(array, 0, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ float x = (float) vh.compareAndExchangeAcquire(array, 0, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ float x = (float) vh.compareAndExchangeAcquire(0, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ float x = (float) vh.compareAndExchangeAcquire(array, Void.class, 1.0f, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(array, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(array, 0, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.compareAndExchangeAcquire(array, 0, 1.0f, 1.0f, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) vh.compareAndExchangeRelease(null, 0, 1.0f, 1.0f);
+ });
+ checkCCE(() -> { // array reference class
+ float x = (float) vh.compareAndExchangeRelease(Void.class, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ float x = (float) vh.compareAndExchangeRelease(array, 0, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ float x = (float) vh.compareAndExchangeRelease(array, 0, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ float x = (float) vh.compareAndExchangeRelease(0, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ float x = (float) vh.compareAndExchangeRelease(array, Void.class, 1.0f, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(array, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(array, 0, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.compareAndExchangeRelease(array, 0, 1.0f, 1.0f, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ float x = (float) vh.getAndSet(null, 0, 1.0f);
+ });
+ checkCCE(() -> { // array reference class
+ float x = (float) vh.getAndSet(Void.class, 0, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndSet(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ float x = (float) vh.getAndSet(0, 0, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ float x = (float) vh.getAndSet(array, Void.class, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(array, 0, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(array, 0, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndSet(array, 0, 1.0f, Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ float x = (float) vh.getAndSetAcquire(null, 0, 1.0f);
+ });
+ checkCCE(() -> { // array reference class
+ float x = (float) vh.getAndSetAcquire(Void.class, 0, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndSetAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ float x = (float) vh.getAndSetAcquire(0, 0, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ float x = (float) vh.getAndSetAcquire(array, Void.class, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(array, 0, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(array, 0, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndSetAcquire(array, 0, 1.0f, Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ float x = (float) vh.getAndSetRelease(null, 0, 1.0f);
+ });
+ checkCCE(() -> { // array reference class
+ float x = (float) vh.getAndSetRelease(Void.class, 0, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndSetRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ float x = (float) vh.getAndSetRelease(0, 0, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ float x = (float) vh.getAndSetRelease(array, Void.class, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(array, 0, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(array, 0, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndSetRelease(array, 0, 1.0f, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ float x = (float) vh.getAndAdd(null, 0, 1.0f);
+ });
+ checkCCE(() -> { // array reference class
+ float x = (float) vh.getAndAdd(Void.class, 0, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndAdd(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ float x = (float) vh.getAndAdd(0, 0, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ float x = (float) vh.getAndAdd(array, Void.class, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(array, 0, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(array, 0, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndAdd(array, 0, 1.0f, Void.class);
+ });
+
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ float x = (float) vh.getAndAddAcquire(null, 0, 1.0f);
+ });
+ checkCCE(() -> { // array reference class
+ float x = (float) vh.getAndAddAcquire(Void.class, 0, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndAddAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ float x = (float) vh.getAndAddAcquire(0, 0, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ float x = (float) vh.getAndAddAcquire(array, Void.class, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(array, 0, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(array, 0, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndAddAcquire(array, 0, 1.0f, Void.class);
+ });
+
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ float x = (float) vh.getAndAddRelease(null, 0, 1.0f);
+ });
+ checkCCE(() -> { // array reference class
+ float x = (float) vh.getAndAddRelease(Void.class, 0, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ float x = (float) vh.getAndAddRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ float x = (float) vh.getAndAddRelease(0, 0, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ float x = (float) vh.getAndAddRelease(array, Void.class, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(array, 0, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(array, 0, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) vh.getAndAddRelease(array, 0, 1.0f, Void.class);
+ });
+
+ }
+
+ static void testArrayWrongMethodType(Handles hs) throws Throwable {
+ float[] array = new float[10];
+ Arrays.fill(array, 1.0f);
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ float x = (float) hs.get(am, methodType(float.class, float[].class, int.class)).
+ invokeExact((float[]) null, 0);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ float x = (float) hs.get(am, methodType(float.class, Class.class, int.class)).
+ invokeExact(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ float x = (float) hs.get(am, methodType(float.class, int.class, int.class)).
+ invokeExact(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ float x = (float) hs.get(am, methodType(float.class, float[].class, Class.class)).
+ invokeExact(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, float[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, float[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) hs.get(am, methodType(float.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) hs.get(am, methodType(float.class, float[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ hs.get(am, methodType(void.class, float[].class, int.class, float.class)).
+ invokeExact((float[]) null, 0, 1.0f);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ hs.get(am, methodType(void.class, Class.class, int.class, float.class)).
+ invokeExact(Void.class, 0, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, float[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, int.class, float.class)).
+ invokeExact(0, 0, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ hs.get(am, methodType(void.class, float[].class, Class.class, float.class)).
+ invokeExact(array, Void.class, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, float[].class, int.class, Class.class)).
+ invokeExact(array, 0, 1.0f, Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, float[].class, int.class, float.class, float.class)).
+ invokeExact((float[]) null, 0, 1.0f, 1.0f);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, float.class, float.class)).
+ invokeExact(Void.class, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, float[].class, int.class, Class.class, float.class)).
+ invokeExact(array, 0, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, float[].class, int.class, float.class, Class.class)).
+ invokeExact(array, 0, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, float.class, float.class)).
+ invokeExact(0, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, float[].class, Class.class, float.class, float.class)).
+ invokeExact(array, Void.class, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, float[].class, int.class, float.class, float.class, Class.class)).
+ invokeExact(array, 0, 1.0f, 1.0f, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ float x = (float) hs.get(am, methodType(float.class, float[].class, int.class, float.class, float.class)).
+ invokeExact((float[]) null, 0, 1.0f, 1.0f);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ float x = (float) hs.get(am, methodType(float.class, Class.class, int.class, float.class, float.class)).
+ invokeExact(Void.class, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // expected reference class
+ float x = (float) hs.get(am, methodType(float.class, float[].class, int.class, Class.class, float.class)).
+ invokeExact(array, 0, Void.class, 1.0f);
+ });
+ checkWMTE(() -> { // actual reference class
+ float x = (float) hs.get(am, methodType(float.class, float[].class, int.class, float.class, Class.class)).
+ invokeExact(array, 0, 1.0f, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ float x = (float) hs.get(am, methodType(float.class, int.class, int.class, float.class, float.class)).
+ invokeExact(0, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ float x = (float) hs.get(am, methodType(float.class, float[].class, Class.class, float.class, float.class)).
+ invokeExact(array, Void.class, 1.0f, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, float[].class, int.class, float.class, float.class)).
+ invokeExact(array, 0, 1.0f, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, float[].class, int.class, float.class, float.class)).
+ invokeExact(array, 0, 1.0f, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) hs.get(am, methodType(float.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) hs.get(am, methodType(float.class, float[].class, int.class, float.class, float.class, Class.class)).
+ invokeExact(array, 0, 1.0f, 1.0f, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ float x = (float) hs.get(am, methodType(float.class, float[].class, int.class, float.class)).
+ invokeExact((float[]) null, 0, 1.0f);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ float x = (float) hs.get(am, methodType(float.class, Class.class, int.class, float.class)).
+ invokeExact(Void.class, 0, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ float x = (float) hs.get(am, methodType(float.class, float[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ float x = (float) hs.get(am, methodType(float.class, int.class, int.class, float.class)).
+ invokeExact(0, 0, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ float x = (float) hs.get(am, methodType(float.class, float[].class, Class.class, float.class)).
+ invokeExact(array, Void.class, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, float[].class, int.class, float.class)).
+ invokeExact(array, 0, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, float[].class, int.class, float.class)).
+ invokeExact(array, 0, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) hs.get(am, methodType(float.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) hs.get(am, methodType(float.class, float[].class, int.class, float.class, Class.class)).
+ invokeExact(array, 0, 1.0f, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ float x = (float) hs.get(am, methodType(float.class, float[].class, int.class, float.class)).
+ invokeExact((float[]) null, 0, 1.0f);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ float x = (float) hs.get(am, methodType(float.class, Class.class, int.class, float.class)).
+ invokeExact(Void.class, 0, 1.0f);
+ });
+ checkWMTE(() -> { // value reference class
+ float x = (float) hs.get(am, methodType(float.class, float[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ float x = (float) hs.get(am, methodType(float.class, int.class, int.class, float.class)).
+ invokeExact(0, 0, 1.0f);
+ });
+ checkWMTE(() -> { // index reference class
+ float x = (float) hs.get(am, methodType(float.class, float[].class, Class.class, float.class)).
+ invokeExact(array, Void.class, 1.0f);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, float[].class, int.class, float.class)).
+ invokeExact(array, 0, 1.0f);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, float[].class, int.class, float.class)).
+ invokeExact(array, 0, 1.0f);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ float x = (float) hs.get(am, methodType(float.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ float x = (float) hs.get(am, methodType(float.class, float[].class, int.class, float.class, Class.class)).
+ invokeExact(array, 0, 1.0f, Void.class);
+ });
+ }
+
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeInt.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeInt.java
new file mode 100644
index 0000000..7ab15c2
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeInt.java
@@ -0,0 +1,3254 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8156486
+ * @run testng/othervm VarHandleTestMethodTypeInt
+ * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestMethodTypeInt
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+import static java.lang.invoke.MethodType.*;
+
+public class VarHandleTestMethodTypeInt extends VarHandleBaseTest {
+ static final int static_final_v = 0x01234567;
+
+ static int static_v = 0x01234567;
+
+ final int final_v = 0x01234567;
+
+ int v = 0x01234567;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeInt.class, "final_v", int.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeInt.class, "v", int.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeInt.class, "static_final_v", int.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeInt.class, "static_v", int.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(int[].class);
+ }
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestMethodTypeInt::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestMethodTypeInt::testArrayWrongMethodType,
+ false));
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceFieldWrongMethodType(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodTypeInt::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodTypeInt::testArrayWrongMethodType,
+ false));
+ }
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeInt recv, VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.get(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.get(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ int x = (int) vh.get(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.get();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.get(recv, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.set(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.set(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.set(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(recv, 0x01234567, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getVolatile(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getVolatile(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ int x = (int) vh.getVolatile(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getVolatile(recv, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setVolatile(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setVolatile(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(recv, 0x01234567, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getOpaque(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getOpaque(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ int x = (int) vh.getOpaque(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getOpaque(recv, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setOpaque(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setOpaque(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(recv, 0x01234567, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getAcquire(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getAcquire(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ int x = (int) vh.getAcquire(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAcquire(recv, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setRelease(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setRelease(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(recv, 0x01234567, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, 0x01234567, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(recv, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(recv, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(recv, 0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, 0x01234567, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(recv, 0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, 0x01234567, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(recv, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(recv, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(recv, 0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, 0x01234567, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(recv, 0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, 0x01234567, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(recv, 0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.compareAndExchange(null, 0x01234567, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.compareAndExchange(Void.class, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ int x = (int) vh.compareAndExchange(recv, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ int x = (int) vh.compareAndExchange(recv, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.compareAndExchange(0, 0x01234567, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(recv, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(recv, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.compareAndExchange(recv, 0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.compareAndExchangeAcquire(null, 0x01234567, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.compareAndExchangeAcquire(Void.class, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ int x = (int) vh.compareAndExchangeAcquire(recv, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ int x = (int) vh.compareAndExchangeAcquire(recv, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.compareAndExchangeAcquire(0, 0x01234567, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(recv, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(recv, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.compareAndExchangeAcquire(recv, 0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.compareAndExchangeRelease(null, 0x01234567, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.compareAndExchangeRelease(Void.class, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ int x = (int) vh.compareAndExchangeRelease(recv, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ int x = (int) vh.compareAndExchangeRelease(recv, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.compareAndExchangeRelease(0, 0x01234567, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(recv, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(recv, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.compareAndExchangeRelease(recv, 0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getAndSet(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getAndSet(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndSet(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.getAndSet(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndSet(recv, 0x01234567, Void.class);
+ });
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getAndSetAcquire(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getAndSetAcquire(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndSetAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.getAndSetAcquire(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndSetAcquire(recv, 0x01234567, Void.class);
+ });
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getAndSetRelease(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getAndSetRelease(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndSetRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.getAndSetRelease(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndSetRelease(recv, 0x01234567, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getAndAdd(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getAndAdd(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndAdd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.getAndAdd(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndAdd(recv, 0x01234567, Void.class);
+ });
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getAndAddAcquire(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getAndAddAcquire(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndAddAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.getAndAddAcquire(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndAddAcquire(recv, 0x01234567, Void.class);
+ });
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getAndAddRelease(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getAndAddRelease(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndAddRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.getAndAddRelease(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndAddRelease(recv, 0x01234567, Void.class);
+ });
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getAndBitwiseOr(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getAndBitwiseOr(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseOr(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.getAndBitwiseOr(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseOr(recv, 0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getAndBitwiseOrAcquire(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getAndBitwiseOrAcquire(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseOrAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.getAndBitwiseOrAcquire(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseOrAcquire(recv, 0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseOrRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getAndBitwiseOrRelease(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getAndBitwiseOr(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseOr(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.getAndBitwiseOr(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseOr(recv, 0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getAndBitwiseAnd(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getAndBitwiseAnd(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseAnd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.getAndBitwiseAnd(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseAnd(recv, 0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getAndBitwiseAndAcquire(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getAndBitwiseAndAcquire(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseAndAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.getAndBitwiseAndAcquire(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseAndAcquire(recv, 0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseAndRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getAndBitwiseAndRelease(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getAndBitwiseAnd(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseAnd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.getAndBitwiseAnd(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseAnd(recv, 0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getAndBitwiseXor(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getAndBitwiseXor(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseXor(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.getAndBitwiseXor(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseXor(recv, 0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getAndBitwiseXorAcquire(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getAndBitwiseXorAcquire(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseXorAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.getAndBitwiseXorAcquire(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseXorAcquire(recv, 0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseXorRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.getAndBitwiseXorRelease(null, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ int x = (int) vh.getAndBitwiseXor(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseXor(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) vh.getAndBitwiseXor(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseXor(recv, 0x01234567, Void.class);
+ });
+ }
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeInt recv, Handles hs) throws Throwable {
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeInt.class)).
+ invokeExact((VarHandleTestMethodTypeInt) null);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ int x = (int) hs.get(am, methodType(int.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ int x = (int) hs.get(am, methodType(int.class, int.class)).
+ invokeExact(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeInt.class)).
+ invokeExact(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeInt.class)).
+ invokeExact(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) hs.get(am, methodType(int.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeInt.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeInt.class, int.class)).
+ invokeExact((VarHandleTestMethodTypeInt) null, 0x01234567);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ hs.get(am, methodType(void.class, Class.class, int.class)).
+ invokeExact(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeInt.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, int.class)).
+ invokeExact(0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeInt.class, int.class, Class.class)).
+ invokeExact(recv, 0x01234567, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeInt.class, int.class, int.class)).
+ invokeExact((VarHandleTestMethodTypeInt) null, 0x01234567, 0x01234567);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, int.class)).
+ invokeExact(Void.class, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeInt.class, Class.class, int.class)).
+ invokeExact(recv, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeInt.class, int.class, Class.class)).
+ invokeExact(recv, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , int.class, int.class)).
+ invokeExact(0, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeInt.class, int.class, int.class, Class.class)).
+ invokeExact(recv, 0x01234567, 0x01234567, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkNPE(() -> { // null receiver
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeInt.class, int.class, int.class)).
+ invokeExact((VarHandleTestMethodTypeInt) null, 0x01234567, 0x01234567);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ int x = (int) hs.get(am, methodType(int.class, Class.class, int.class, int.class)).
+ invokeExact(Void.class, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeInt.class, Class.class, int.class)).
+ invokeExact(recv, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeInt.class, int.class, Class.class)).
+ invokeExact(recv, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) hs.get(am, methodType(int.class, int.class , int.class, int.class)).
+ invokeExact(0, 0x01234567, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeInt.class , int.class, int.class)).
+ invokeExact(recv, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeInt.class , int.class, int.class)).
+ invokeExact(recv, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) hs.get(am, methodType(int.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeInt.class, int.class, int.class, Class.class)).
+ invokeExact(recv, 0x01234567, 0x01234567, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkNPE(() -> { // null receiver
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeInt.class, int.class)).
+ invokeExact((VarHandleTestMethodTypeInt) null, 0x01234567);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ int x = (int) hs.get(am, methodType(int.class, Class.class, int.class)).
+ invokeExact(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeInt.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) hs.get(am, methodType(int.class, int.class, int.class)).
+ invokeExact(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeInt.class, int.class)).
+ invokeExact(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeInt.class, int.class)).
+ invokeExact(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) hs.get(am, methodType(int.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeInt.class, int.class)).
+ invokeExact(recv, 0x01234567, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkNPE(() -> { // null receiver
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeInt.class, int.class)).
+ invokeExact((VarHandleTestMethodTypeInt) null, 0x01234567);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ int x = (int) hs.get(am, methodType(int.class, Class.class, int.class)).
+ invokeExact(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeInt.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) hs.get(am, methodType(int.class, int.class, int.class)).
+ invokeExact(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeInt.class, int.class)).
+ invokeExact(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeInt.class, int.class)).
+ invokeExact(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) hs.get(am, methodType(int.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeInt.class, int.class)).
+ invokeExact(recv, 0x01234567, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkNPE(() -> { // null receiver
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeInt.class, int.class)).
+ invokeExact((VarHandleTestMethodTypeInt) null, 0x01234567);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ int x = (int) hs.get(am, methodType(int.class, Class.class, int.class)).
+ invokeExact(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeInt.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ int x = (int) hs.get(am, methodType(int.class, int.class, int.class)).
+ invokeExact(0, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeInt.class, int.class)).
+ invokeExact(recv, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeInt.class, int.class)).
+ invokeExact(recv, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) hs.get(am, methodType(int.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeInt.class, int.class)).
+ invokeExact(recv, 0x01234567, Void.class);
+ });
+ }
+ }
+
+
+ static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ int x = (int) vh.get(Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.set(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(0x01234567, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getVolatile(Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(0x01234567, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getOpaque(Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(0x01234567, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAcquire(Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(0x01234567, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(0x01234567, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(0x01234567, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(0x01234567, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(0x01234567, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(0x01234567, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ int x = (int) vh.compareAndExchange(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ int x = (int) vh.compareAndExchange(0x01234567, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.compareAndExchange(0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ int x = (int) vh.compareAndExchangeAcquire(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ int x = (int) vh.compareAndExchangeAcquire(0x01234567, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.compareAndExchangeAcquire(0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ int x = (int) vh.compareAndExchangeRelease(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ int x = (int) vh.compareAndExchangeRelease(0x01234567, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.compareAndExchangeRelease(0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndSet(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndSet(0x01234567, Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndSetAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndSetAcquire(0x01234567, Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndSetRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndSetRelease(0x01234567, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndAdd(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndAdd(0x01234567, Void.class);
+ });
+
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndAddAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndAddAcquire(0x01234567, Void.class);
+ });
+
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndAddRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndAddRelease(0x01234567, Void.class);
+ });
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseOr(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseOr(0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseOrAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseOrAcquire(0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseOrReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseOrRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrRelease(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrRelease(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseOrRelease();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseOrRelease(0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseAnd(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseAnd(0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseAndAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseAndAcquire(0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseAndReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseAndRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndRelease(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndRelease(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseAndRelease();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseAndRelease(0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseXor(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseXor(0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseXorAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseXorAcquire(0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseXorReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseXorRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorRelease(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorRelease(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseXorRelease();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseXorRelease(0x01234567, Void.class);
+ });
+ }
+
+ static void testStaticFieldWrongMethodType(Handles hs) throws Throwable {
+ int i = 0;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ int x = (int) hs.get(am, methodType(Class.class)).
+ invokeExact(Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, int.class, Class.class)).
+ invokeExact(0x01234567, Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class)).
+ invokeExact(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, Class.class)).
+ invokeExact(0x01234567, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, Class.class)).
+ invokeExact(0x01234567, 0x01234567, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ int x = (int) hs.get(am, methodType(int.class, Class.class, int.class)).
+ invokeExact(Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ int x = (int) hs.get(am, methodType(int.class, int.class, Class.class)).
+ invokeExact(0x01234567, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, int.class, int.class)).
+ invokeExact(0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class)).
+ invokeExact(0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) hs.get(am, methodType(int.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) hs.get(am, methodType(int.class, int.class, int.class, Class.class)).
+ invokeExact(0x01234567, 0x01234567, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) hs.get(am, methodType(int.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, int.class)).
+ invokeExact(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class)).
+ invokeExact(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) hs.get(am, methodType(int.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) hs.get(am, methodType(int.class, int.class, Class.class)).
+ invokeExact(0x01234567, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) hs.get(am, methodType(int.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, int.class)).
+ invokeExact(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class)).
+ invokeExact(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) hs.get(am, methodType(int.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) hs.get(am, methodType(int.class, int.class, Class.class)).
+ invokeExact(0x01234567, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ int x = (int) hs.get(am, methodType(int.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, int.class)).
+ invokeExact(0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class)).
+ invokeExact(0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) hs.get(am, methodType(int.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) hs.get(am, methodType(int.class, int.class, Class.class)).
+ invokeExact(0x01234567, Void.class);
+ });
+ }
+ }
+
+
+ static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
+ int[] array = new int[10];
+ Arrays.fill(array, 0x01234567);
+
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.get(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.get(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.get(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.get(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.get();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.get(array, 0, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.set(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ vh.set(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.set(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.set(array, Void.class, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(array, 0, 0x01234567, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getVolatile(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getVolatile(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.getVolatile(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getVolatile(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getVolatile(array, 0, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setVolatile(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setVolatile(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setVolatile(array, Void.class, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(array, 0, 0x01234567, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getOpaque(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getOpaque(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.getOpaque(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getOpaque(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getOpaque(array, 0, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setOpaque(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setOpaque(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setOpaque(array, Void.class, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(array, 0, 0x01234567, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getAcquire(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getAcquire(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.getAcquire(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getAcquire(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAcquire(array, 0, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setRelease(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setRelease(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setRelease(array, Void.class, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(array, 0, 0x01234567, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, 0, 0x01234567, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(array, 0, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(array, 0, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.compareAndSet(array, Void.class, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(array, 0, 0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, 0, 0x01234567, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetPlain(array, Void.class, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(array, 0, 0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, 0, 0x01234567, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(array, 0, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(array, 0, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSet(array, Void.class, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(array, 0, 0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, 0, 0x01234567, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, Void.class, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, 0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, 0, 0x01234567, 0x01234567);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetRelease(array, Void.class, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(array, 0, 0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.compareAndExchange(null, 0, 0x01234567, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.compareAndExchange(Void.class, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ int x = (int) vh.compareAndExchange(array, 0, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ int x = (int) vh.compareAndExchange(array, 0, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.compareAndExchange(0, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.compareAndExchange(array, Void.class, 0x01234567, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(array, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(array, 0, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.compareAndExchange(array, 0, 0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.compareAndExchangeAcquire(null, 0, 0x01234567, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.compareAndExchangeAcquire(Void.class, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ int x = (int) vh.compareAndExchangeAcquire(array, 0, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ int x = (int) vh.compareAndExchangeAcquire(array, 0, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.compareAndExchangeAcquire(0, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.compareAndExchangeAcquire(array, Void.class, 0x01234567, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(array, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(array, 0, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.compareAndExchangeAcquire(array, 0, 0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) vh.compareAndExchangeRelease(null, 0, 0x01234567, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.compareAndExchangeRelease(Void.class, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ int x = (int) vh.compareAndExchangeRelease(array, 0, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ int x = (int) vh.compareAndExchangeRelease(array, 0, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.compareAndExchangeRelease(0, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.compareAndExchangeRelease(array, Void.class, 0x01234567, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(array, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(array, 0, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.compareAndExchangeRelease(array, 0, 0x01234567, 0x01234567, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getAndSet(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getAndSet(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndSet(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ int x = (int) vh.getAndSet(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getAndSet(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndSet(array, 0, 0x01234567, Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getAndSetAcquire(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getAndSetAcquire(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndSetAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ int x = (int) vh.getAndSetAcquire(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getAndSetAcquire(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndSetAcquire(array, 0, 0x01234567, Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getAndSetRelease(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getAndSetRelease(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndSetRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ int x = (int) vh.getAndSetRelease(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getAndSetRelease(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndSetRelease(array, 0, 0x01234567, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getAndAdd(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getAndAdd(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndAdd(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.getAndAdd(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getAndAdd(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndAdd(array, 0, 0x01234567, Void.class);
+ });
+
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getAndAddAcquire(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getAndAddAcquire(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndAddAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.getAndAddAcquire(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getAndAddAcquire(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndAddAcquire(array, 0, 0x01234567, Void.class);
+ });
+
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getAndAddRelease(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getAndAddRelease(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndAddRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.getAndAddRelease(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getAndAddRelease(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndAddRelease(array, 0, 0x01234567, Void.class);
+ });
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getAndBitwiseOr(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getAndBitwiseOr(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseOr(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.getAndBitwiseOr(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getAndBitwiseOr(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseOr(array, 0, 0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getAndBitwiseOrAcquire(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getAndBitwiseOrAcquire(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseOrAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.getAndBitwiseOrAcquire(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getAndBitwiseOrAcquire(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseOrAcquire(array, 0, 0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseOrRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getAndBitwiseOrRelease(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getAndBitwiseOrRelease(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseOrRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.getAndBitwiseOrRelease(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getAndBitwiseOrRelease(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrRelease(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrRelease(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseOrRelease();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseOrRelease(array, 0, 0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getAndBitwiseAnd(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getAndBitwiseAnd(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseAnd(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.getAndBitwiseAnd(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getAndBitwiseAnd(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseAnd(array, 0, 0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getAndBitwiseAndAcquire(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getAndBitwiseAndAcquire(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseAndAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.getAndBitwiseAndAcquire(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getAndBitwiseAndAcquire(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseAndAcquire(array, 0, 0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseAndRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getAndBitwiseAndRelease(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getAndBitwiseAndRelease(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseAndRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.getAndBitwiseAndRelease(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getAndBitwiseAndRelease(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndRelease(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndRelease(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseAndRelease();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseAndRelease(array, 0, 0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getAndBitwiseXor(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getAndBitwiseXor(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseXor(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.getAndBitwiseXor(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getAndBitwiseXor(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseXor(array, 0, 0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getAndBitwiseXorAcquire(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getAndBitwiseXorAcquire(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseXorAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.getAndBitwiseXorAcquire(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getAndBitwiseXorAcquire(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseXorAcquire(array, 0, 0x01234567, Void.class);
+ });
+
+
+ // GetAndBitwiseXorRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) vh.getAndBitwiseXorRelease(null, 0, 0x01234567);
+ });
+ checkCCE(() -> { // array reference class
+ int x = (int) vh.getAndBitwiseXorRelease(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) vh.getAndBitwiseXorRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) vh.getAndBitwiseXorRelease(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) vh.getAndBitwiseXorRelease(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorRelease(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorRelease(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) vh.getAndBitwiseXorRelease();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) vh.getAndBitwiseXorRelease(array, 0, 0x01234567, Void.class);
+ });
+ }
+
+ static void testArrayWrongMethodType(Handles hs) throws Throwable {
+ int[] array = new int[10];
+ Arrays.fill(array, 0x01234567);
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) hs.get(am, methodType(int.class, int[].class, int.class)).
+ invokeExact((int[]) null, 0);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ int x = (int) hs.get(am, methodType(int.class, Class.class, int.class)).
+ invokeExact(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) hs.get(am, methodType(int.class, int.class, int.class)).
+ invokeExact(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) hs.get(am, methodType(int.class, int[].class, Class.class)).
+ invokeExact(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, int[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, int[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) hs.get(am, methodType(int.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) hs.get(am, methodType(int.class, int[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ hs.get(am, methodType(void.class, int[].class, int.class, int.class)).
+ invokeExact((int[]) null, 0, 0x01234567);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ hs.get(am, methodType(void.class, Class.class, int.class, int.class)).
+ invokeExact(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, int[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, int.class, int.class)).
+ invokeExact(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ hs.get(am, methodType(void.class, int[].class, Class.class, int.class)).
+ invokeExact(array, Void.class, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, int[].class, int.class, Class.class)).
+ invokeExact(array, 0, 0x01234567, Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int[].class, int.class, int.class, int.class)).
+ invokeExact((int[]) null, 0, 0x01234567, 0x01234567);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, int.class, int.class)).
+ invokeExact(Void.class, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int[].class, int.class, Class.class, int.class)).
+ invokeExact(array, 0, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int[].class, int.class, int.class, Class.class)).
+ invokeExact(array, 0, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, int.class, int.class)).
+ invokeExact(0, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int[].class, Class.class, int.class, int.class)).
+ invokeExact(array, Void.class, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int[].class, int.class, int.class, int.class, Class.class)).
+ invokeExact(array, 0, 0x01234567, 0x01234567, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ int x = (int) hs.get(am, methodType(int.class, int[].class, int.class, int.class, int.class)).
+ invokeExact((int[]) null, 0, 0x01234567, 0x01234567);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ int x = (int) hs.get(am, methodType(int.class, Class.class, int.class, int.class, int.class)).
+ invokeExact(Void.class, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // expected reference class
+ int x = (int) hs.get(am, methodType(int.class, int[].class, int.class, Class.class, int.class)).
+ invokeExact(array, 0, Void.class, 0x01234567);
+ });
+ checkWMTE(() -> { // actual reference class
+ int x = (int) hs.get(am, methodType(int.class, int[].class, int.class, int.class, Class.class)).
+ invokeExact(array, 0, 0x01234567, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) hs.get(am, methodType(int.class, int.class, int.class, int.class, int.class)).
+ invokeExact(0, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) hs.get(am, methodType(int.class, int[].class, Class.class, int.class, int.class)).
+ invokeExact(array, Void.class, 0x01234567, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, int[].class, int.class, int.class, int.class)).
+ invokeExact(array, 0, 0x01234567, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, int[].class, int.class, int.class, int.class)).
+ invokeExact(array, 0, 0x01234567, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) hs.get(am, methodType(int.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) hs.get(am, methodType(int.class, int[].class, int.class, int.class, int.class, Class.class)).
+ invokeExact(array, 0, 0x01234567, 0x01234567, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) hs.get(am, methodType(int.class, int[].class, int.class, int.class)).
+ invokeExact((int[]) null, 0, 0x01234567);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ int x = (int) hs.get(am, methodType(int.class, Class.class, int.class, int.class)).
+ invokeExact(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) hs.get(am, methodType(int.class, int[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) hs.get(am, methodType(int.class, int.class, int.class, int.class)).
+ invokeExact(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) hs.get(am, methodType(int.class, int[].class, Class.class, int.class)).
+ invokeExact(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, int[].class, int.class, int.class)).
+ invokeExact(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, int[].class, int.class, int.class)).
+ invokeExact(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) hs.get(am, methodType(int.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) hs.get(am, methodType(int.class, int[].class, int.class, int.class, Class.class)).
+ invokeExact(array, 0, 0x01234567, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) hs.get(am, methodType(int.class, int[].class, int.class, int.class)).
+ invokeExact((int[]) null, 0, 0x01234567);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ int x = (int) hs.get(am, methodType(int.class, Class.class, int.class, int.class)).
+ invokeExact(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) hs.get(am, methodType(int.class, int[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) hs.get(am, methodType(int.class, int.class, int.class, int.class)).
+ invokeExact(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) hs.get(am, methodType(int.class, int[].class, Class.class, int.class)).
+ invokeExact(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, int[].class, int.class, int.class)).
+ invokeExact(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, int[].class, int.class, int.class)).
+ invokeExact(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) hs.get(am, methodType(int.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) hs.get(am, methodType(int.class, int[].class, int.class, int.class, Class.class)).
+ invokeExact(array, 0, 0x01234567, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ int x = (int) hs.get(am, methodType(int.class, int[].class, int.class, int.class)).
+ invokeExact((int[]) null, 0, 0x01234567);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ int x = (int) hs.get(am, methodType(int.class, Class.class, int.class, int.class)).
+ invokeExact(Void.class, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // value reference class
+ int x = (int) hs.get(am, methodType(int.class, int[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ int x = (int) hs.get(am, methodType(int.class, int.class, int.class, int.class)).
+ invokeExact(0, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // index reference class
+ int x = (int) hs.get(am, methodType(int.class, int[].class, Class.class, int.class)).
+ invokeExact(array, Void.class, 0x01234567);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, int[].class, int.class, int.class)).
+ invokeExact(array, 0, 0x01234567);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, int[].class, int.class, int.class)).
+ invokeExact(array, 0, 0x01234567);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ int x = (int) hs.get(am, methodType(int.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ int x = (int) hs.get(am, methodType(int.class, int[].class, int.class, int.class, Class.class)).
+ invokeExact(array, 0, 0x01234567, Void.class);
+ });
+ }
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeLong.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeLong.java
new file mode 100644
index 0000000..7d39ab5
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeLong.java
@@ -0,0 +1,3254 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8156486
+ * @run testng/othervm VarHandleTestMethodTypeLong
+ * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestMethodTypeLong
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+import static java.lang.invoke.MethodType.*;
+
+public class VarHandleTestMethodTypeLong extends VarHandleBaseTest {
+ static final long static_final_v = 0x0123456789ABCDEFL;
+
+ static long static_v = 0x0123456789ABCDEFL;
+
+ final long final_v = 0x0123456789ABCDEFL;
+
+ long v = 0x0123456789ABCDEFL;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeLong.class, "final_v", long.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeLong.class, "v", long.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeLong.class, "static_final_v", long.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeLong.class, "static_v", long.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(long[].class);
+ }
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestMethodTypeLong::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestMethodTypeLong::testArrayWrongMethodType,
+ false));
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceFieldWrongMethodType(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodTypeLong::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodTypeLong::testArrayWrongMethodType,
+ false));
+ }
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeLong recv, VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.get(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.get(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ long x = (long) vh.get(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.get();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.get(recv, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.set(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.set(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.set(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getVolatile(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getVolatile(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ long x = (long) vh.getVolatile(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getVolatile(recv, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setVolatile(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setVolatile(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getOpaque(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getOpaque(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ long x = (long) vh.getOpaque(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getOpaque(recv, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setOpaque(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setOpaque(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getAcquire(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getAcquire(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ long x = (long) vh.getAcquire(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAcquire(recv, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setRelease(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setRelease(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(recv, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(recv, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.compareAndExchange(null, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.compareAndExchange(Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ long x = (long) vh.compareAndExchange(recv, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ long x = (long) vh.compareAndExchange(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.compareAndExchange(0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.compareAndExchange(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.compareAndExchangeAcquire(null, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.compareAndExchangeAcquire(Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ long x = (long) vh.compareAndExchangeAcquire(recv, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ long x = (long) vh.compareAndExchangeAcquire(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.compareAndExchangeAcquire(0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.compareAndExchangeAcquire(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.compareAndExchangeRelease(null, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.compareAndExchangeRelease(Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ long x = (long) vh.compareAndExchangeRelease(recv, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ long x = (long) vh.compareAndExchangeRelease(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.compareAndExchangeRelease(0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.compareAndExchangeRelease(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getAndSet(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getAndSet(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndSet(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.getAndSet(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndSet(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getAndSetAcquire(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getAndSetAcquire(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndSetAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.getAndSetAcquire(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndSetAcquire(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getAndSetRelease(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getAndSetRelease(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndSetRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.getAndSetRelease(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndSetRelease(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getAndAdd(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getAndAdd(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndAdd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.getAndAdd(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndAdd(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getAndAddAcquire(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getAndAddAcquire(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndAddAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.getAndAddAcquire(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndAddAcquire(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getAndAddRelease(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getAndAddRelease(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndAddRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.getAndAddRelease(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndAddRelease(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getAndBitwiseOr(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getAndBitwiseOr(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseOr(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.getAndBitwiseOr(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseOr(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getAndBitwiseOrAcquire(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getAndBitwiseOrAcquire(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseOrAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.getAndBitwiseOrAcquire(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseOrAcquire(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseOrRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getAndBitwiseOrRelease(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getAndBitwiseOr(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseOr(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.getAndBitwiseOr(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseOr(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getAndBitwiseAnd(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getAndBitwiseAnd(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseAnd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.getAndBitwiseAnd(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseAnd(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getAndBitwiseAndAcquire(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getAndBitwiseAndAcquire(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseAndAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.getAndBitwiseAndAcquire(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseAndAcquire(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseAndRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getAndBitwiseAndRelease(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getAndBitwiseAnd(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseAnd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.getAndBitwiseAnd(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseAnd(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getAndBitwiseXor(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getAndBitwiseXor(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseXor(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.getAndBitwiseXor(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseXor(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getAndBitwiseXorAcquire(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getAndBitwiseXorAcquire(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseXorAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.getAndBitwiseXorAcquire(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseXorAcquire(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseXorRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.getAndBitwiseXorRelease(null, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ long x = (long) vh.getAndBitwiseXor(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseXor(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) vh.getAndBitwiseXor(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseXor(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+ }
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeLong recv, Handles hs) throws Throwable {
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class)).
+ invokeExact((VarHandleTestMethodTypeLong) null);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ long x = (long) hs.get(am, methodType(long.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ long x = (long) hs.get(am, methodType(long.class, int.class)).
+ invokeExact(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeLong.class)).
+ invokeExact(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class)).
+ invokeExact(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) hs.get(am, methodType(long.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeLong.class, long.class)).
+ invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ hs.get(am, methodType(void.class, Class.class, long.class)).
+ invokeExact(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeLong.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, long.class)).
+ invokeExact(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeLong.class, long.class, Class.class)).
+ invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, long.class, long.class)).
+ invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, long.class, long.class)).
+ invokeExact(Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, Class.class, long.class)).
+ invokeExact(recv, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, long.class, Class.class)).
+ invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , long.class, long.class)).
+ invokeExact(0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, long.class, long.class, Class.class)).
+ invokeExact(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkNPE(() -> { // null receiver
+ long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class, long.class)).
+ invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ long x = (long) hs.get(am, methodType(long.class, Class.class, long.class, long.class)).
+ invokeExact(Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, Class.class, long.class)).
+ invokeExact(recv, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class, Class.class)).
+ invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) hs.get(am, methodType(long.class, int.class , long.class, long.class)).
+ invokeExact(0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeLong.class , long.class, long.class)).
+ invokeExact(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class , long.class, long.class)).
+ invokeExact(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) hs.get(am, methodType(long.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class, long.class, Class.class)).
+ invokeExact(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkNPE(() -> { // null receiver
+ long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class)).
+ invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ long x = (long) hs.get(am, methodType(long.class, Class.class, long.class)).
+ invokeExact(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) hs.get(am, methodType(long.class, int.class, long.class)).
+ invokeExact(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeLong.class, long.class)).
+ invokeExact(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, long.class)).
+ invokeExact(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) hs.get(am, methodType(long.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class)).
+ invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkNPE(() -> { // null receiver
+ long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class)).
+ invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ long x = (long) hs.get(am, methodType(long.class, Class.class, long.class)).
+ invokeExact(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) hs.get(am, methodType(long.class, int.class, long.class)).
+ invokeExact(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeLong.class, long.class)).
+ invokeExact(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, long.class)).
+ invokeExact(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) hs.get(am, methodType(long.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class)).
+ invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkNPE(() -> { // null receiver
+ long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class)).
+ invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ long x = (long) hs.get(am, methodType(long.class, Class.class, long.class)).
+ invokeExact(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ long x = (long) hs.get(am, methodType(long.class, int.class, long.class)).
+ invokeExact(0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeLong.class, long.class)).
+ invokeExact(recv, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, long.class)).
+ invokeExact(recv, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) hs.get(am, methodType(long.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class)).
+ invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
+ });
+ }
+ }
+
+
+ static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ long x = (long) vh.get(Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.set(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getVolatile(Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getOpaque(Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAcquire(Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(0x0123456789ABCDEFL, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(0x0123456789ABCDEFL, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(0x0123456789ABCDEFL, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(0x0123456789ABCDEFL, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(0x0123456789ABCDEFL, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ long x = (long) vh.compareAndExchange(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ long x = (long) vh.compareAndExchange(0x0123456789ABCDEFL, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.compareAndExchange(0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ long x = (long) vh.compareAndExchangeAcquire(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ long x = (long) vh.compareAndExchangeAcquire(0x0123456789ABCDEFL, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.compareAndExchangeAcquire(0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ long x = (long) vh.compareAndExchangeRelease(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ long x = (long) vh.compareAndExchangeRelease(0x0123456789ABCDEFL, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.compareAndExchangeRelease(0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndSet(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndSet(0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndSetAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndSetAcquire(0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndSetRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndSetRelease(0x0123456789ABCDEFL, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndAdd(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndAdd(0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndAddAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndAddAcquire(0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndAddRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndAddRelease(0x0123456789ABCDEFL, Void.class);
+ });
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseOr(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseOr(0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseOrAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseOrAcquire(0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseOrReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseOrRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrRelease(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrRelease(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseOrRelease();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseOrRelease(0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseAnd(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseAnd(0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseAndAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseAndAcquire(0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseAndReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseAndRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndRelease(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndRelease(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseAndRelease();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseAndRelease(0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseXor(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseXor(0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseXorAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseXorAcquire(0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseXorReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseXorRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorRelease(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorRelease(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseXorRelease();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseXorRelease(0x0123456789ABCDEFL, Void.class);
+ });
+ }
+
+ static void testStaticFieldWrongMethodType(Handles hs) throws Throwable {
+ int i = 0;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ long x = (long) hs.get(am, methodType(Class.class)).
+ invokeExact(Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, long.class, Class.class)).
+ invokeExact(0x0123456789ABCDEFL, Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, long.class)).
+ invokeExact(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, long.class, Class.class)).
+ invokeExact(0x0123456789ABCDEFL, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, long.class, long.class, Class.class)).
+ invokeExact(0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ long x = (long) hs.get(am, methodType(long.class, Class.class, long.class)).
+ invokeExact(Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ long x = (long) hs.get(am, methodType(long.class, long.class, Class.class)).
+ invokeExact(0x0123456789ABCDEFL, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, long.class, long.class)).
+ invokeExact(0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, long.class, long.class)).
+ invokeExact(0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) hs.get(am, methodType(long.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) hs.get(am, methodType(long.class, long.class, long.class, Class.class)).
+ invokeExact(0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) hs.get(am, methodType(long.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, long.class)).
+ invokeExact(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, long.class)).
+ invokeExact(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) hs.get(am, methodType(long.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) hs.get(am, methodType(long.class, long.class, Class.class)).
+ invokeExact(0x0123456789ABCDEFL, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) hs.get(am, methodType(long.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, long.class)).
+ invokeExact(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, long.class)).
+ invokeExact(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) hs.get(am, methodType(long.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) hs.get(am, methodType(long.class, long.class, Class.class)).
+ invokeExact(0x0123456789ABCDEFL, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ long x = (long) hs.get(am, methodType(long.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, long.class)).
+ invokeExact(0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, long.class)).
+ invokeExact(0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) hs.get(am, methodType(long.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) hs.get(am, methodType(long.class, long.class, Class.class)).
+ invokeExact(0x0123456789ABCDEFL, Void.class);
+ });
+ }
+ }
+
+
+ static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
+ long[] array = new long[10];
+ Arrays.fill(array, 0x0123456789ABCDEFL);
+
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.get(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.get(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.get(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.get(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.get();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.get(array, 0, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.set(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ vh.set(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.set(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.set(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getVolatile(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getVolatile(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.getVolatile(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getVolatile(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getVolatile(array, 0, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setVolatile(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setVolatile(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setVolatile(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getOpaque(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getOpaque(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.getOpaque(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getOpaque(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getOpaque(array, 0, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setOpaque(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setOpaque(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setOpaque(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getAcquire(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getAcquire(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.getAcquire(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getAcquire(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAcquire(array, 0, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setRelease(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setRelease(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setRelease(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(array, 0, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.compareAndSet(array, Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetPlain(array, Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(array, 0, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSet(array, Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetRelease(array, Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.compareAndExchange(null, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.compareAndExchange(Void.class, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ long x = (long) vh.compareAndExchange(array, 0, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ long x = (long) vh.compareAndExchange(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.compareAndExchange(0, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.compareAndExchange(array, Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.compareAndExchange(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.compareAndExchangeAcquire(null, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.compareAndExchangeAcquire(Void.class, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ long x = (long) vh.compareAndExchangeAcquire(array, 0, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ long x = (long) vh.compareAndExchangeAcquire(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.compareAndExchangeAcquire(0, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.compareAndExchangeAcquire(array, Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.compareAndExchangeAcquire(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) vh.compareAndExchangeRelease(null, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.compareAndExchangeRelease(Void.class, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ long x = (long) vh.compareAndExchangeRelease(array, 0, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ long x = (long) vh.compareAndExchangeRelease(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.compareAndExchangeRelease(0, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.compareAndExchangeRelease(array, Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.compareAndExchangeRelease(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getAndSet(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getAndSet(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndSet(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ long x = (long) vh.getAndSet(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getAndSet(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndSet(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getAndSetAcquire(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getAndSetAcquire(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndSetAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ long x = (long) vh.getAndSetAcquire(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getAndSetAcquire(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndSetAcquire(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getAndSetRelease(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getAndSetRelease(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndSetRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ long x = (long) vh.getAndSetRelease(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getAndSetRelease(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndSetRelease(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getAndAdd(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getAndAdd(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndAdd(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.getAndAdd(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getAndAdd(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndAdd(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getAndAddAcquire(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getAndAddAcquire(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndAddAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.getAndAddAcquire(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getAndAddAcquire(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndAddAcquire(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getAndAddRelease(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getAndAddRelease(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndAddRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.getAndAddRelease(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getAndAddRelease(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndAddRelease(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getAndBitwiseOr(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getAndBitwiseOr(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseOr(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.getAndBitwiseOr(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getAndBitwiseOr(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseOr(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getAndBitwiseOrAcquire(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getAndBitwiseOrAcquire(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseOrAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.getAndBitwiseOrAcquire(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getAndBitwiseOrAcquire(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseOrAcquire(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseOrRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getAndBitwiseOrRelease(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getAndBitwiseOrRelease(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseOrRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.getAndBitwiseOrRelease(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getAndBitwiseOrRelease(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrRelease(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrRelease(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseOrRelease();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseOrRelease(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getAndBitwiseAnd(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getAndBitwiseAnd(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseAnd(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.getAndBitwiseAnd(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getAndBitwiseAnd(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseAnd(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getAndBitwiseAndAcquire(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getAndBitwiseAndAcquire(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseAndAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.getAndBitwiseAndAcquire(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getAndBitwiseAndAcquire(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseAndAcquire(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseAndRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getAndBitwiseAndRelease(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getAndBitwiseAndRelease(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseAndRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.getAndBitwiseAndRelease(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getAndBitwiseAndRelease(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndRelease(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndRelease(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseAndRelease();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseAndRelease(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getAndBitwiseXor(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getAndBitwiseXor(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseXor(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.getAndBitwiseXor(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getAndBitwiseXor(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseXor(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getAndBitwiseXorAcquire(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getAndBitwiseXorAcquire(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseXorAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.getAndBitwiseXorAcquire(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getAndBitwiseXorAcquire(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseXorAcquire(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+
+
+ // GetAndBitwiseXorRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) vh.getAndBitwiseXorRelease(null, 0, 0x0123456789ABCDEFL);
+ });
+ checkCCE(() -> { // array reference class
+ long x = (long) vh.getAndBitwiseXorRelease(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) vh.getAndBitwiseXorRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) vh.getAndBitwiseXorRelease(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) vh.getAndBitwiseXorRelease(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorRelease(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorRelease(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) vh.getAndBitwiseXorRelease();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) vh.getAndBitwiseXorRelease(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+ }
+
+ static void testArrayWrongMethodType(Handles hs) throws Throwable {
+ long[] array = new long[10];
+ Arrays.fill(array, 0x0123456789ABCDEFL);
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) hs.get(am, methodType(long.class, long[].class, int.class)).
+ invokeExact((long[]) null, 0);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ long x = (long) hs.get(am, methodType(long.class, Class.class, int.class)).
+ invokeExact(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) hs.get(am, methodType(long.class, int.class, int.class)).
+ invokeExact(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) hs.get(am, methodType(long.class, long[].class, Class.class)).
+ invokeExact(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, long[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) hs.get(am, methodType(long.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ hs.get(am, methodType(void.class, long[].class, int.class, long.class)).
+ invokeExact((long[]) null, 0, 0x0123456789ABCDEFL);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ hs.get(am, methodType(void.class, Class.class, int.class, long.class)).
+ invokeExact(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, long[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, int.class, long.class)).
+ invokeExact(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ hs.get(am, methodType(void.class, long[].class, Class.class, long.class)).
+ invokeExact(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, long[].class, int.class, Class.class)).
+ invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, long.class, long.class)).
+ invokeExact((long[]) null, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, long.class, long.class)).
+ invokeExact(Void.class, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, Class.class, long.class)).
+ invokeExact(array, 0, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, long.class, Class.class)).
+ invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, long.class, long.class)).
+ invokeExact(0, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, long[].class, Class.class, long.class, long.class)).
+ invokeExact(array, Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, long.class, long.class, Class.class)).
+ invokeExact(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class, long.class)).
+ invokeExact((long[]) null, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ long x = (long) hs.get(am, methodType(long.class, Class.class, int.class, long.class, long.class)).
+ invokeExact(Void.class, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // expected reference class
+ long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, Class.class, long.class)).
+ invokeExact(array, 0, Void.class, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // actual reference class
+ long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class, Class.class)).
+ invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) hs.get(am, methodType(long.class, int.class, int.class, long.class, long.class)).
+ invokeExact(0, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) hs.get(am, methodType(long.class, long[].class, Class.class, long.class, long.class)).
+ invokeExact(array, Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, long[].class, int.class, long.class, long.class)).
+ invokeExact(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, long.class, long.class)).
+ invokeExact(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) hs.get(am, methodType(long.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class, long.class, Class.class)).
+ invokeExact(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class)).
+ invokeExact((long[]) null, 0, 0x0123456789ABCDEFL);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ long x = (long) hs.get(am, methodType(long.class, Class.class, int.class, long.class)).
+ invokeExact(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) hs.get(am, methodType(long.class, int.class, int.class, long.class)).
+ invokeExact(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) hs.get(am, methodType(long.class, long[].class, Class.class, long.class)).
+ invokeExact(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, long[].class, int.class, long.class)).
+ invokeExact(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, long.class)).
+ invokeExact(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) hs.get(am, methodType(long.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class, Class.class)).
+ invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class)).
+ invokeExact((long[]) null, 0, 0x0123456789ABCDEFL);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ long x = (long) hs.get(am, methodType(long.class, Class.class, int.class, long.class)).
+ invokeExact(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) hs.get(am, methodType(long.class, int.class, int.class, long.class)).
+ invokeExact(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) hs.get(am, methodType(long.class, long[].class, Class.class, long.class)).
+ invokeExact(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, long[].class, int.class, long.class)).
+ invokeExact(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, long.class)).
+ invokeExact(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) hs.get(am, methodType(long.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class, Class.class)).
+ invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class)).
+ invokeExact((long[]) null, 0, 0x0123456789ABCDEFL);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ long x = (long) hs.get(am, methodType(long.class, Class.class, int.class, long.class)).
+ invokeExact(Void.class, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // value reference class
+ long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ long x = (long) hs.get(am, methodType(long.class, int.class, int.class, long.class)).
+ invokeExact(0, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // index reference class
+ long x = (long) hs.get(am, methodType(long.class, long[].class, Class.class, long.class)).
+ invokeExact(array, Void.class, 0x0123456789ABCDEFL);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, long[].class, int.class, long.class)).
+ invokeExact(array, 0, 0x0123456789ABCDEFL);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, long.class)).
+ invokeExact(array, 0, 0x0123456789ABCDEFL);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ long x = (long) hs.get(am, methodType(long.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class, Class.class)).
+ invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
+ });
+ }
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeShort.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeShort.java
new file mode 100644
index 0000000..d0d414f
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeShort.java
@@ -0,0 +1,3254 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8156486
+ * @run testng/othervm VarHandleTestMethodTypeShort
+ * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestMethodTypeShort
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+import static java.lang.invoke.MethodType.*;
+
+public class VarHandleTestMethodTypeShort extends VarHandleBaseTest {
+ static final short static_final_v = (short)0x0123;
+
+ static short static_v = (short)0x0123;
+
+ final short final_v = (short)0x0123;
+
+ short v = (short)0x0123;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeShort.class, "final_v", short.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeShort.class, "v", short.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeShort.class, "static_final_v", short.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeShort.class, "static_v", short.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(short[].class);
+ }
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestMethodTypeShort::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestMethodTypeShort::testArrayWrongMethodType,
+ false));
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceFieldWrongMethodType(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodTypeShort::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodTypeShort::testArrayWrongMethodType,
+ false));
+ }
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeShort recv, VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.get(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.get(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ short x = (short) vh.get(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.get();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.get(recv, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.set(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.set(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.set(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(recv, (short)0x0123, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getVolatile(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getVolatile(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ short x = (short) vh.getVolatile(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getVolatile(recv, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setVolatile(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setVolatile(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(recv, (short)0x0123, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getOpaque(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getOpaque(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ short x = (short) vh.getOpaque(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getOpaque(recv, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setOpaque(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setOpaque(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(recv, (short)0x0123, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getAcquire(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getAcquire(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ short x = (short) vh.getAcquire(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAcquire(recv, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setRelease(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setRelease(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(recv, (short)0x0123, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, (short)0x0123, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(recv, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(recv, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(recv, (short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, (short)0x0123, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(recv, (short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, (short)0x0123, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(recv, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(recv, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(recv, (short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, (short)0x0123, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(recv, (short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, (short)0x0123, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(recv, (short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.compareAndExchange(null, (short)0x0123, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.compareAndExchange(Void.class, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ short x = (short) vh.compareAndExchange(recv, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ short x = (short) vh.compareAndExchange(recv, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.compareAndExchange(0, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(recv, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(recv, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.compareAndExchange(recv, (short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.compareAndExchangeAcquire(null, (short)0x0123, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.compareAndExchangeAcquire(Void.class, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ short x = (short) vh.compareAndExchangeAcquire(recv, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ short x = (short) vh.compareAndExchangeAcquire(recv, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.compareAndExchangeAcquire(0, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(recv, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(recv, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.compareAndExchangeAcquire(recv, (short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.compareAndExchangeRelease(null, (short)0x0123, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.compareAndExchangeRelease(Void.class, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ short x = (short) vh.compareAndExchangeRelease(recv, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ short x = (short) vh.compareAndExchangeRelease(recv, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.compareAndExchangeRelease(0, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(recv, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(recv, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.compareAndExchangeRelease(recv, (short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getAndSet(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getAndSet(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndSet(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.getAndSet(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndSet(recv, (short)0x0123, Void.class);
+ });
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getAndSetAcquire(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getAndSetAcquire(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndSetAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.getAndSetAcquire(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndSetAcquire(recv, (short)0x0123, Void.class);
+ });
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getAndSetRelease(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getAndSetRelease(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndSetRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.getAndSetRelease(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndSetRelease(recv, (short)0x0123, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getAndAdd(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getAndAdd(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndAdd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.getAndAdd(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndAdd(recv, (short)0x0123, Void.class);
+ });
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getAndAddAcquire(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getAndAddAcquire(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndAddAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.getAndAddAcquire(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndAddAcquire(recv, (short)0x0123, Void.class);
+ });
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getAndAddRelease(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getAndAddRelease(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndAddRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.getAndAddRelease(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndAddRelease(recv, (short)0x0123, Void.class);
+ });
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getAndBitwiseOr(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getAndBitwiseOr(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseOr(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.getAndBitwiseOr(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseOr(recv, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getAndBitwiseOrAcquire(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getAndBitwiseOrAcquire(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseOrAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.getAndBitwiseOrAcquire(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseOrAcquire(recv, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseOrRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getAndBitwiseOrRelease(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getAndBitwiseOr(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseOr(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.getAndBitwiseOr(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseOr(recv, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getAndBitwiseAnd(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getAndBitwiseAnd(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseAnd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.getAndBitwiseAnd(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseAnd(recv, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getAndBitwiseAndAcquire(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getAndBitwiseAndAcquire(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseAndAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.getAndBitwiseAndAcquire(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseAndAcquire(recv, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseAndRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getAndBitwiseAndRelease(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getAndBitwiseAnd(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseAnd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.getAndBitwiseAnd(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseAnd(recv, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getAndBitwiseXor(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getAndBitwiseXor(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseXor(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.getAndBitwiseXor(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseXor(recv, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getAndBitwiseXorAcquire(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getAndBitwiseXorAcquire(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseXorAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.getAndBitwiseXorAcquire(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseXorAcquire(recv, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseXorRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.getAndBitwiseXorRelease(null, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ short x = (short) vh.getAndBitwiseXor(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseXor(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) vh.getAndBitwiseXor(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseXor(recv, (short)0x0123, Void.class);
+ });
+ }
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeShort recv, Handles hs) throws Throwable {
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) hs.get(am, methodType(short.class, VarHandleTestMethodTypeShort.class)).
+ invokeExact((VarHandleTestMethodTypeShort) null);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ short x = (short) hs.get(am, methodType(short.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ short x = (short) hs.get(am, methodType(short.class, int.class)).
+ invokeExact(0);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeShort.class)).
+ invokeExact(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeShort.class)).
+ invokeExact(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) hs.get(am, methodType(short.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) hs.get(am, methodType(short.class, VarHandleTestMethodTypeShort.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeShort.class, short.class)).
+ invokeExact((VarHandleTestMethodTypeShort) null, (short)0x0123);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ hs.get(am, methodType(void.class, Class.class, short.class)).
+ invokeExact(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeShort.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, short.class)).
+ invokeExact(0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeShort.class, short.class, Class.class)).
+ invokeExact(recv, (short)0x0123, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeShort.class, short.class, short.class)).
+ invokeExact((VarHandleTestMethodTypeShort) null, (short)0x0123, (short)0x0123);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, short.class, short.class)).
+ invokeExact(Void.class, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeShort.class, Class.class, short.class)).
+ invokeExact(recv, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeShort.class, short.class, Class.class)).
+ invokeExact(recv, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , short.class, short.class)).
+ invokeExact(0, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeShort.class, short.class, short.class, Class.class)).
+ invokeExact(recv, (short)0x0123, (short)0x0123, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkNPE(() -> { // null receiver
+ short x = (short) hs.get(am, methodType(short.class, VarHandleTestMethodTypeShort.class, short.class, short.class)).
+ invokeExact((VarHandleTestMethodTypeShort) null, (short)0x0123, (short)0x0123);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ short x = (short) hs.get(am, methodType(short.class, Class.class, short.class, short.class)).
+ invokeExact(Void.class, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ short x = (short) hs.get(am, methodType(short.class, VarHandleTestMethodTypeShort.class, Class.class, short.class)).
+ invokeExact(recv, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ short x = (short) hs.get(am, methodType(short.class, VarHandleTestMethodTypeShort.class, short.class, Class.class)).
+ invokeExact(recv, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) hs.get(am, methodType(short.class, int.class , short.class, short.class)).
+ invokeExact(0, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeShort.class , short.class, short.class)).
+ invokeExact(recv, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeShort.class , short.class, short.class)).
+ invokeExact(recv, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) hs.get(am, methodType(short.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) hs.get(am, methodType(short.class, VarHandleTestMethodTypeShort.class, short.class, short.class, Class.class)).
+ invokeExact(recv, (short)0x0123, (short)0x0123, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkNPE(() -> { // null receiver
+ short x = (short) hs.get(am, methodType(short.class, VarHandleTestMethodTypeShort.class, short.class)).
+ invokeExact((VarHandleTestMethodTypeShort) null, (short)0x0123);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ short x = (short) hs.get(am, methodType(short.class, Class.class, short.class)).
+ invokeExact(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) hs.get(am, methodType(short.class, VarHandleTestMethodTypeShort.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) hs.get(am, methodType(short.class, int.class, short.class)).
+ invokeExact(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeShort.class, short.class)).
+ invokeExact(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeShort.class, short.class)).
+ invokeExact(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) hs.get(am, methodType(short.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) hs.get(am, methodType(short.class, VarHandleTestMethodTypeShort.class, short.class)).
+ invokeExact(recv, (short)0x0123, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkNPE(() -> { // null receiver
+ short x = (short) hs.get(am, methodType(short.class, VarHandleTestMethodTypeShort.class, short.class)).
+ invokeExact((VarHandleTestMethodTypeShort) null, (short)0x0123);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ short x = (short) hs.get(am, methodType(short.class, Class.class, short.class)).
+ invokeExact(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) hs.get(am, methodType(short.class, VarHandleTestMethodTypeShort.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) hs.get(am, methodType(short.class, int.class, short.class)).
+ invokeExact(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeShort.class, short.class)).
+ invokeExact(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeShort.class, short.class)).
+ invokeExact(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) hs.get(am, methodType(short.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) hs.get(am, methodType(short.class, VarHandleTestMethodTypeShort.class, short.class)).
+ invokeExact(recv, (short)0x0123, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkNPE(() -> { // null receiver
+ short x = (short) hs.get(am, methodType(short.class, VarHandleTestMethodTypeShort.class, short.class)).
+ invokeExact((VarHandleTestMethodTypeShort) null, (short)0x0123);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ short x = (short) hs.get(am, methodType(short.class, Class.class, short.class)).
+ invokeExact(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) hs.get(am, methodType(short.class, VarHandleTestMethodTypeShort.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ short x = (short) hs.get(am, methodType(short.class, int.class, short.class)).
+ invokeExact(0, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeShort.class, short.class)).
+ invokeExact(recv, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeShort.class, short.class)).
+ invokeExact(recv, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) hs.get(am, methodType(short.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) hs.get(am, methodType(short.class, VarHandleTestMethodTypeShort.class, short.class)).
+ invokeExact(recv, (short)0x0123, Void.class);
+ });
+ }
+ }
+
+
+ static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ short x = (short) vh.get(Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.set(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set((short)0x0123, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getVolatile(Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile((short)0x0123, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getOpaque(Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque((short)0x0123, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAcquire(Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease((short)0x0123, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet((short)0x0123, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet((short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain((short)0x0123, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain((short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet((short)0x0123, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet((short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire((short)0x0123, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire((short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease((short)0x0123, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease((short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ short x = (short) vh.compareAndExchange(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ short x = (short) vh.compareAndExchange((short)0x0123, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange((short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange((short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.compareAndExchange((short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ short x = (short) vh.compareAndExchangeAcquire(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ short x = (short) vh.compareAndExchangeAcquire((short)0x0123, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire((short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire((short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.compareAndExchangeAcquire((short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ short x = (short) vh.compareAndExchangeRelease(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ short x = (short) vh.compareAndExchangeRelease((short)0x0123, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease((short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease((short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.compareAndExchangeRelease((short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndSet(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndSet((short)0x0123, Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndSetAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndSetAcquire((short)0x0123, Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndSetRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndSetRelease((short)0x0123, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndAdd(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndAdd((short)0x0123, Void.class);
+ });
+
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndAddAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndAddAcquire((short)0x0123, Void.class);
+ });
+
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndAddRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndAddRelease((short)0x0123, Void.class);
+ });
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseOr(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseOr((short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseOrAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseOrAcquire((short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseOrReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseOrRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrRelease((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrRelease((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseOrRelease();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseOrRelease((short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseAnd(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseAnd((short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseAndAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseAndAcquire((short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseAndReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseAndRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndRelease((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndRelease((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseAndRelease();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseAndRelease((short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseXor(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseXor((short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseXorAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseXorAcquire((short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseXorReleaseRelease
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseXorRelease(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorRelease((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorRelease((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseXorRelease();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseXorRelease((short)0x0123, Void.class);
+ });
+ }
+
+ static void testStaticFieldWrongMethodType(Handles hs) throws Throwable {
+ int i = 0;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ short x = (short) hs.get(am, methodType(Class.class)).
+ invokeExact(Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, short.class, Class.class)).
+ invokeExact((short)0x0123, Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, short.class)).
+ invokeExact(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, short.class, Class.class)).
+ invokeExact((short)0x0123, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, short.class, short.class, Class.class)).
+ invokeExact((short)0x0123, (short)0x0123, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // expected reference class
+ short x = (short) hs.get(am, methodType(short.class, Class.class, short.class)).
+ invokeExact(Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ short x = (short) hs.get(am, methodType(short.class, short.class, Class.class)).
+ invokeExact((short)0x0123, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, short.class, short.class)).
+ invokeExact((short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, short.class, short.class)).
+ invokeExact((short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) hs.get(am, methodType(short.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) hs.get(am, methodType(short.class, short.class, short.class, Class.class)).
+ invokeExact((short)0x0123, (short)0x0123, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) hs.get(am, methodType(short.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, short.class)).
+ invokeExact((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, short.class)).
+ invokeExact((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) hs.get(am, methodType(short.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) hs.get(am, methodType(short.class, short.class, Class.class)).
+ invokeExact((short)0x0123, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) hs.get(am, methodType(short.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, short.class)).
+ invokeExact((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, short.class)).
+ invokeExact((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) hs.get(am, methodType(short.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) hs.get(am, methodType(short.class, short.class, Class.class)).
+ invokeExact((short)0x0123, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ // Incorrect argument types
+ checkWMTE(() -> { // value reference class
+ short x = (short) hs.get(am, methodType(short.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, short.class)).
+ invokeExact((short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, short.class)).
+ invokeExact((short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) hs.get(am, methodType(short.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) hs.get(am, methodType(short.class, short.class, Class.class)).
+ invokeExact((short)0x0123, Void.class);
+ });
+ }
+ }
+
+
+ static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
+ short[] array = new short[10];
+ Arrays.fill(array, (short)0x0123);
+
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.get(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.get(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.get(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.get(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.get(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.get();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.get(array, 0, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.set(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ vh.set(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.set(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.set(array, Void.class, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(array, 0, (short)0x0123, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getVolatile(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getVolatile(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.getVolatile(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getVolatile(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getVolatile(array, 0, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setVolatile(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setVolatile(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setVolatile(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setVolatile(array, Void.class, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(array, 0, (short)0x0123, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getOpaque(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getOpaque(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.getOpaque(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getOpaque(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getOpaque(array, 0, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setOpaque(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setOpaque(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setOpaque(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setOpaque(array, Void.class, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(array, 0, (short)0x0123, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getAcquire(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getAcquire(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.getAcquire(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getAcquire(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAcquire(array, 0, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setRelease(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setRelease(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ vh.setRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setRelease(array, Void.class, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(array, 0, (short)0x0123, Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, 0, (short)0x0123, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(array, 0, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(array, 0, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.compareAndSet(array, Void.class, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(array, 0, (short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, 0, (short)0x0123, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetPlain(array, Void.class, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(array, 0, (short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, 0, (short)0x0123, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(array, 0, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(array, 0, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSet(array, Void.class, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(array, 0, (short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, 0, (short)0x0123, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, Void.class, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, (short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, 0, (short)0x0123, (short)0x0123);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetRelease(array, Void.class, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(array, 0, (short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.compareAndExchange(null, 0, (short)0x0123, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.compareAndExchange(Void.class, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ short x = (short) vh.compareAndExchange(array, 0, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ short x = (short) vh.compareAndExchange(array, 0, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.compareAndExchange(0, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.compareAndExchange(array, Void.class, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(array, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(array, 0, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.compareAndExchange(array, 0, (short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.compareAndExchangeAcquire(null, 0, (short)0x0123, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.compareAndExchangeAcquire(Void.class, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ short x = (short) vh.compareAndExchangeAcquire(array, 0, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ short x = (short) vh.compareAndExchangeAcquire(array, 0, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.compareAndExchangeAcquire(0, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.compareAndExchangeAcquire(array, Void.class, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(array, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(array, 0, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.compareAndExchangeAcquire(array, 0, (short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) vh.compareAndExchangeRelease(null, 0, (short)0x0123, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.compareAndExchangeRelease(Void.class, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ short x = (short) vh.compareAndExchangeRelease(array, 0, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ short x = (short) vh.compareAndExchangeRelease(array, 0, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.compareAndExchangeRelease(0, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.compareAndExchangeRelease(array, Void.class, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(array, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(array, 0, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.compareAndExchangeRelease(array, 0, (short)0x0123, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getAndSet(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getAndSet(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndSet(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ short x = (short) vh.getAndSet(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getAndSet(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndSet(array, 0, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getAndSetAcquire(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getAndSetAcquire(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndSetAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ short x = (short) vh.getAndSetAcquire(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getAndSetAcquire(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndSetAcquire(array, 0, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getAndSetRelease(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getAndSetRelease(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndSetRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ short x = (short) vh.getAndSetRelease(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getAndSetRelease(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndSetRelease(array, 0, (short)0x0123, Void.class);
+ });
+
+ // GetAndAdd
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getAndAdd(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getAndAdd(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndAdd(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.getAndAdd(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getAndAdd(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAdd(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndAdd(array, 0, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getAndAddAcquire(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getAndAddAcquire(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndAddAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.getAndAddAcquire(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getAndAddAcquire(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddAcquire(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndAddAcquire(array, 0, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getAndAddRelease(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getAndAddRelease(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndAddRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.getAndAddRelease(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getAndAddRelease(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndAddRelease(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndAddRelease(array, 0, (short)0x0123, Void.class);
+ });
+
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getAndBitwiseOr(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getAndBitwiseOr(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseOr(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.getAndBitwiseOr(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getAndBitwiseOr(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOr(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseOr(array, 0, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getAndBitwiseOrAcquire(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getAndBitwiseOrAcquire(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseOrAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.getAndBitwiseOrAcquire(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getAndBitwiseOrAcquire(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrAcquire(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseOrAcquire(array, 0, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseOrRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getAndBitwiseOrRelease(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getAndBitwiseOrRelease(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseOrRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.getAndBitwiseOrRelease(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getAndBitwiseOrRelease(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrRelease(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseOrRelease(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseOrRelease();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseOrRelease(array, 0, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getAndBitwiseAnd(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getAndBitwiseAnd(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseAnd(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.getAndBitwiseAnd(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getAndBitwiseAnd(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAnd(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseAnd(array, 0, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getAndBitwiseAndAcquire(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getAndBitwiseAndAcquire(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseAndAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.getAndBitwiseAndAcquire(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getAndBitwiseAndAcquire(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndAcquire(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseAndAcquire(array, 0, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseAndRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getAndBitwiseAndRelease(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getAndBitwiseAndRelease(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseAndRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.getAndBitwiseAndRelease(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getAndBitwiseAndRelease(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndRelease(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseAndRelease(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseAndRelease();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseAndRelease(array, 0, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getAndBitwiseXor(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getAndBitwiseXor(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseXor(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.getAndBitwiseXor(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getAndBitwiseXor(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXor(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseXor(array, 0, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getAndBitwiseXorAcquire(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getAndBitwiseXorAcquire(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseXorAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.getAndBitwiseXorAcquire(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getAndBitwiseXorAcquire(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorAcquire(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseXorAcquire(array, 0, (short)0x0123, Void.class);
+ });
+
+
+ // GetAndBitwiseXorRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) vh.getAndBitwiseXorRelease(null, 0, (short)0x0123);
+ });
+ checkCCE(() -> { // array reference class
+ short x = (short) vh.getAndBitwiseXorRelease(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) vh.getAndBitwiseXorRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) vh.getAndBitwiseXorRelease(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) vh.getAndBitwiseXorRelease(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorRelease(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndBitwiseXorRelease(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) vh.getAndBitwiseXorRelease();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) vh.getAndBitwiseXorRelease(array, 0, (short)0x0123, Void.class);
+ });
+ }
+
+ static void testArrayWrongMethodType(Handles hs) throws Throwable {
+ short[] array = new short[10];
+ Arrays.fill(array, (short)0x0123);
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) hs.get(am, methodType(short.class, short[].class, int.class)).
+ invokeExact((short[]) null, 0);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ short x = (short) hs.get(am, methodType(short.class, Class.class, int.class)).
+ invokeExact(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) hs.get(am, methodType(short.class, int.class, int.class)).
+ invokeExact(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) hs.get(am, methodType(short.class, short[].class, Class.class)).
+ invokeExact(array, Void.class);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, short[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, short[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) hs.get(am, methodType(short.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) hs.get(am, methodType(short.class, short[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ hs.get(am, methodType(void.class, short[].class, int.class, short.class)).
+ invokeExact((short[]) null, 0, (short)0x0123);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ hs.get(am, methodType(void.class, Class.class, int.class, short.class)).
+ invokeExact(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ hs.get(am, methodType(void.class, short[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, int.class, short.class)).
+ invokeExact(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ hs.get(am, methodType(void.class, short[].class, Class.class, short.class)).
+ invokeExact(array, Void.class, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, short[].class, int.class, Class.class)).
+ invokeExact(array, 0, (short)0x0123, Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, short[].class, int.class, short.class, short.class)).
+ invokeExact((short[]) null, 0, (short)0x0123, (short)0x0123);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, short.class, short.class)).
+ invokeExact(Void.class, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, short[].class, int.class, Class.class, short.class)).
+ invokeExact(array, 0, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, short[].class, int.class, short.class, Class.class)).
+ invokeExact(array, 0, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, short.class, short.class)).
+ invokeExact(0, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, short[].class, Class.class, short.class, short.class)).
+ invokeExact(array, Void.class, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, short[].class, int.class, short.class, short.class, Class.class)).
+ invokeExact(array, 0, (short)0x0123, (short)0x0123, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ short x = (short) hs.get(am, methodType(short.class, short[].class, int.class, short.class, short.class)).
+ invokeExact((short[]) null, 0, (short)0x0123, (short)0x0123);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ short x = (short) hs.get(am, methodType(short.class, Class.class, int.class, short.class, short.class)).
+ invokeExact(Void.class, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // expected reference class
+ short x = (short) hs.get(am, methodType(short.class, short[].class, int.class, Class.class, short.class)).
+ invokeExact(array, 0, Void.class, (short)0x0123);
+ });
+ checkWMTE(() -> { // actual reference class
+ short x = (short) hs.get(am, methodType(short.class, short[].class, int.class, short.class, Class.class)).
+ invokeExact(array, 0, (short)0x0123, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) hs.get(am, methodType(short.class, int.class, int.class, short.class, short.class)).
+ invokeExact(0, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) hs.get(am, methodType(short.class, short[].class, Class.class, short.class, short.class)).
+ invokeExact(array, Void.class, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, short[].class, int.class, short.class, short.class)).
+ invokeExact(array, 0, (short)0x0123, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, short[].class, int.class, short.class, short.class)).
+ invokeExact(array, 0, (short)0x0123, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) hs.get(am, methodType(short.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) hs.get(am, methodType(short.class, short[].class, int.class, short.class, short.class, Class.class)).
+ invokeExact(array, 0, (short)0x0123, (short)0x0123, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) hs.get(am, methodType(short.class, short[].class, int.class, short.class)).
+ invokeExact((short[]) null, 0, (short)0x0123);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ short x = (short) hs.get(am, methodType(short.class, Class.class, int.class, short.class)).
+ invokeExact(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) hs.get(am, methodType(short.class, short[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) hs.get(am, methodType(short.class, int.class, int.class, short.class)).
+ invokeExact(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) hs.get(am, methodType(short.class, short[].class, Class.class, short.class)).
+ invokeExact(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, short[].class, int.class, short.class)).
+ invokeExact(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, short[].class, int.class, short.class)).
+ invokeExact(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) hs.get(am, methodType(short.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) hs.get(am, methodType(short.class, short[].class, int.class, short.class, Class.class)).
+ invokeExact(array, 0, (short)0x0123, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) hs.get(am, methodType(short.class, short[].class, int.class, short.class)).
+ invokeExact((short[]) null, 0, (short)0x0123);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ short x = (short) hs.get(am, methodType(short.class, Class.class, int.class, short.class)).
+ invokeExact(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) hs.get(am, methodType(short.class, short[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) hs.get(am, methodType(short.class, int.class, int.class, short.class)).
+ invokeExact(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) hs.get(am, methodType(short.class, short[].class, Class.class, short.class)).
+ invokeExact(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, short[].class, int.class, short.class)).
+ invokeExact(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, short[].class, int.class, short.class)).
+ invokeExact(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) hs.get(am, methodType(short.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) hs.get(am, methodType(short.class, short[].class, int.class, short.class, Class.class)).
+ invokeExact(array, 0, (short)0x0123, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ short x = (short) hs.get(am, methodType(short.class, short[].class, int.class, short.class)).
+ invokeExact((short[]) null, 0, (short)0x0123);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ short x = (short) hs.get(am, methodType(short.class, Class.class, int.class, short.class)).
+ invokeExact(Void.class, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // value reference class
+ short x = (short) hs.get(am, methodType(short.class, short[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ short x = (short) hs.get(am, methodType(short.class, int.class, int.class, short.class)).
+ invokeExact(0, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // index reference class
+ short x = (short) hs.get(am, methodType(short.class, short[].class, Class.class, short.class)).
+ invokeExact(array, Void.class, (short)0x0123);
+ });
+ // Incorrect return type
+ checkWMTE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, short[].class, int.class, short.class)).
+ invokeExact(array, 0, (short)0x0123);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, short[].class, int.class, short.class)).
+ invokeExact(array, 0, (short)0x0123);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ short x = (short) hs.get(am, methodType(short.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ short x = (short) hs.get(am, methodType(short.class, short[].class, int.class, short.class, Class.class)).
+ invokeExact(array, 0, (short)0x0123, Void.class);
+ });
+ }
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeString.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeString.java
new file mode 100644
index 0000000..11a5a0f
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestMethodTypeString.java
@@ -0,0 +1,2056 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8156486
+ * @run testng/othervm VarHandleTestMethodTypeString
+ * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestMethodTypeString
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+import static java.lang.invoke.MethodType.*;
+
+public class VarHandleTestMethodTypeString extends VarHandleBaseTest {
+ static final String static_final_v = "foo";
+
+ static String static_v = "foo";
+
+ final String final_v = "foo";
+
+ String v = "foo";
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeString.class, "final_v", String.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodTypeString.class, "v", String.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeString.class, "static_final_v", String.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodTypeString.class, "static_v", String.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle(String[].class);
+ }
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestMethodTypeString::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestMethodTypeString::testArrayWrongMethodType,
+ false));
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceFieldWrongMethodType(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodTypeString::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodTypeString::testArrayWrongMethodType,
+ false));
+ }
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeString recv, VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ String x = (String) vh.get(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ String x = (String) vh.get(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ String x = (String) vh.get(0);
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void x = (Void) vh.get(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.get();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.get(recv, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.set(null, "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.set(Void.class, "foo");
+ });
+ checkCCE(() -> { // value reference class
+ vh.set(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(recv, "foo", Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ String x = (String) vh.getVolatile(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ String x = (String) vh.getVolatile(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ String x = (String) vh.getVolatile(0);
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getVolatile(recv, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setVolatile(null, "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setVolatile(Void.class, "foo");
+ });
+ checkCCE(() -> { // value reference class
+ vh.setVolatile(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(recv, "foo", Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ String x = (String) vh.getOpaque(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ String x = (String) vh.getOpaque(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ String x = (String) vh.getOpaque(0);
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getOpaque(recv, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setOpaque(null, "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setOpaque(Void.class, "foo");
+ });
+ checkCCE(() -> { // value reference class
+ vh.setOpaque(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(recv, "foo", Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ String x = (String) vh.getAcquire(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ String x = (String) vh.getAcquire(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ String x = (String) vh.getAcquire(0);
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getAcquire(recv, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setRelease(null, "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setRelease(Void.class, "foo");
+ });
+ checkCCE(() -> { // value reference class
+ vh.setRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(recv, "foo", Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, "foo", "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, "foo", "foo");
+ });
+ checkCCE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(recv, Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(recv, "foo", Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(recv, "foo", "foo", Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, "foo", "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, "foo", "foo");
+ });
+ checkCCE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, "foo", Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(recv, "foo", "foo", Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, "foo", "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, "foo", "foo");
+ });
+ checkCCE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(recv, Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(recv, "foo", Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(recv, "foo", "foo", Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, "foo", "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, "foo", "foo");
+ });
+ checkCCE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, "foo", Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(recv, "foo", "foo", Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, "foo", "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, "foo", "foo");
+ });
+ checkCCE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, "foo", Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(recv, "foo", "foo", Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ String x = (String) vh.compareAndExchange(null, "foo", "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ String x = (String) vh.compareAndExchange(Void.class, "foo", "foo");
+ });
+ checkCCE(() -> { // expected reference class
+ String x = (String) vh.compareAndExchange(recv, Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ String x = (String) vh.compareAndExchange(recv, "foo", Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ String x = (String) vh.compareAndExchange(0, "foo", "foo");
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(recv, "foo", "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(recv, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.compareAndExchange(recv, "foo", "foo", Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ String x = (String) vh.compareAndExchangeAcquire(null, "foo", "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ String x = (String) vh.compareAndExchangeAcquire(Void.class, "foo", "foo");
+ });
+ checkCCE(() -> { // expected reference class
+ String x = (String) vh.compareAndExchangeAcquire(recv, Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ String x = (String) vh.compareAndExchangeAcquire(recv, "foo", Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ String x = (String) vh.compareAndExchangeAcquire(0, "foo", "foo");
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(recv, "foo", "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(recv, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.compareAndExchangeAcquire(recv, "foo", "foo", Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ String x = (String) vh.compareAndExchangeRelease(null, "foo", "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ String x = (String) vh.compareAndExchangeRelease(Void.class, "foo", "foo");
+ });
+ checkCCE(() -> { // expected reference class
+ String x = (String) vh.compareAndExchangeRelease(recv, Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ String x = (String) vh.compareAndExchangeRelease(recv, "foo", Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ String x = (String) vh.compareAndExchangeRelease(0, "foo", "foo");
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(recv, "foo", "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(recv, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.compareAndExchangeRelease(recv, "foo", "foo", Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ String x = (String) vh.getAndSet(null, "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ String x = (String) vh.getAndSet(Void.class, "foo");
+ });
+ checkCCE(() -> { // value reference class
+ String x = (String) vh.getAndSet(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ String x = (String) vh.getAndSet(0, "foo");
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(recv, "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(recv, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getAndSet(recv, "foo", Void.class);
+ });
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ String x = (String) vh.getAndSetAcquire(null, "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ String x = (String) vh.getAndSetAcquire(Void.class, "foo");
+ });
+ checkCCE(() -> { // value reference class
+ String x = (String) vh.getAndSetAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ String x = (String) vh.getAndSetAcquire(0, "foo");
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(recv, "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(recv, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getAndSetAcquire(recv, "foo", Void.class);
+ });
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ String x = (String) vh.getAndSetRelease(null, "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ String x = (String) vh.getAndSetRelease(Void.class, "foo");
+ });
+ checkCCE(() -> { // value reference class
+ String x = (String) vh.getAndSetRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ String x = (String) vh.getAndSetRelease(0, "foo");
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(recv, "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(recv, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getAndSetRelease(recv, "foo", Void.class);
+ });
+
+
+ }
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeString recv, Handles hs) throws Throwable {
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ String x = (String) hs.get(am, methodType(String.class, VarHandleTestMethodTypeString.class)).
+ invokeExact((VarHandleTestMethodTypeString) null);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ String x = (String) hs.get(am, methodType(String.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ String x = (String) hs.get(am, methodType(String.class, int.class)).
+ invokeExact(0);
+ });
+ // Incorrect return type
+ hs.checkWMTEOrCCE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeString.class)).
+ invokeExact(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeString.class)).
+ invokeExact(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) hs.get(am, methodType(String.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) hs.get(am, methodType(String.class, VarHandleTestMethodTypeString.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeString.class, String.class)).
+ invokeExact((VarHandleTestMethodTypeString) null, "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ hs.get(am, methodType(void.class, Class.class, String.class)).
+ invokeExact(Void.class, "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // value reference class
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeString.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, String.class)).
+ invokeExact(0, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, VarHandleTestMethodTypeString.class, String.class, Class.class)).
+ invokeExact(recv, "foo", Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeString.class, String.class, String.class)).
+ invokeExact((VarHandleTestMethodTypeString) null, "foo", "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, String.class, String.class)).
+ invokeExact(Void.class, "foo", "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeString.class, Class.class, String.class)).
+ invokeExact(recv, Void.class, "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeString.class, String.class, Class.class)).
+ invokeExact(recv, "foo", Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , String.class, String.class)).
+ invokeExact(0, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeString.class, String.class, String.class, Class.class)).
+ invokeExact(recv, "foo", "foo", Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkNPE(() -> { // null receiver
+ String x = (String) hs.get(am, methodType(String.class, VarHandleTestMethodTypeString.class, String.class, String.class)).
+ invokeExact((VarHandleTestMethodTypeString) null, "foo", "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ String x = (String) hs.get(am, methodType(String.class, Class.class, String.class, String.class)).
+ invokeExact(Void.class, "foo", "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // expected reference class
+ String x = (String) hs.get(am, methodType(String.class, VarHandleTestMethodTypeString.class, Class.class, String.class)).
+ invokeExact(recv, Void.class, "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // actual reference class
+ String x = (String) hs.get(am, methodType(String.class, VarHandleTestMethodTypeString.class, String.class, Class.class)).
+ invokeExact(recv, "foo", Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ String x = (String) hs.get(am, methodType(String.class, int.class , String.class, String.class)).
+ invokeExact(0, "foo", "foo");
+ });
+ // Incorrect return type
+ hs.checkWMTEOrCCE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeString.class , String.class, String.class)).
+ invokeExact(recv, "foo", "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeString.class , String.class, String.class)).
+ invokeExact(recv, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) hs.get(am, methodType(String.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) hs.get(am, methodType(String.class, VarHandleTestMethodTypeString.class, String.class, String.class, Class.class)).
+ invokeExact(recv, "foo", "foo", Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkNPE(() -> { // null receiver
+ String x = (String) hs.get(am, methodType(String.class, VarHandleTestMethodTypeString.class, String.class)).
+ invokeExact((VarHandleTestMethodTypeString) null, "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ String x = (String) hs.get(am, methodType(String.class, Class.class, String.class)).
+ invokeExact(Void.class, "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // value reference class
+ String x = (String) hs.get(am, methodType(String.class, VarHandleTestMethodTypeString.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ String x = (String) hs.get(am, methodType(String.class, int.class, String.class)).
+ invokeExact(0, "foo");
+ });
+ // Incorrect return type
+ hs.checkWMTEOrCCE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeString.class, String.class)).
+ invokeExact(recv, "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeString.class, String.class)).
+ invokeExact(recv, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) hs.get(am, methodType(String.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) hs.get(am, methodType(String.class, VarHandleTestMethodTypeString.class, String.class)).
+ invokeExact(recv, "foo", Void.class);
+ });
+ }
+
+
+ }
+
+
+ static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void x = (Void) vh.get();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ String x = (String) vh.get(Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkCCE(() -> { // value reference class
+ vh.set(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set("foo", Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void x = (Void) vh.getVolatile();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getVolatile(Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkCCE(() -> { // value reference class
+ vh.setVolatile(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile("foo", Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void x = (Void) vh.getOpaque();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getOpaque(Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkCCE(() -> { // value reference class
+ vh.setOpaque(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque("foo", Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void x = (Void) vh.getAcquire();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getAcquire(Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkCCE(() -> { // value reference class
+ vh.setRelease(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease("foo", Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkCCE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ boolean r = vh.compareAndSet("foo", Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet("foo", "foo", Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkCCE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain("foo", Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain("foo", "foo", Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkCCE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet("foo", Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet("foo", "foo", Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkCCE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire("foo", Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire("foo", "foo", Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkCCE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease("foo", Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease("foo", "foo", Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkCCE(() -> { // expected reference class
+ String x = (String) vh.compareAndExchange(Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ String x = (String) vh.compareAndExchange("foo", Void.class);
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange("foo", "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange("foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.compareAndExchange("foo", "foo", Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkCCE(() -> { // expected reference class
+ String x = (String) vh.compareAndExchangeAcquire(Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ String x = (String) vh.compareAndExchangeAcquire("foo", Void.class);
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire("foo", "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire("foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.compareAndExchangeAcquire("foo", "foo", Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkCCE(() -> { // expected reference class
+ String x = (String) vh.compareAndExchangeRelease(Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ String x = (String) vh.compareAndExchangeRelease("foo", Void.class);
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease("foo", "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease("foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.compareAndExchangeRelease("foo", "foo", Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkCCE(() -> { // value reference class
+ String x = (String) vh.getAndSet(Void.class);
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.getAndSet("foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet("foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getAndSet("foo", Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkCCE(() -> { // value reference class
+ String x = (String) vh.getAndSetAcquire(Void.class);
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire("foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire("foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getAndSetAcquire("foo", Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkCCE(() -> { // value reference class
+ String x = (String) vh.getAndSetRelease(Void.class);
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease("foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease("foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getAndSetRelease("foo", Void.class);
+ });
+
+
+ }
+
+ static void testStaticFieldWrongMethodType(Handles hs) throws Throwable {
+ int i = 0;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect return type
+ hs.checkWMTEOrCCE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ String x = (String) hs.get(am, methodType(Class.class)).
+ invokeExact(Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ hs.checkWMTEOrCCE(() -> { // value reference class
+ hs.get(am, methodType(void.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, String.class, Class.class)).
+ invokeExact("foo", Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ hs.checkWMTEOrCCE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, String.class)).
+ invokeExact(Void.class, "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, String.class, Class.class)).
+ invokeExact("foo", Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, String.class, String.class, Class.class)).
+ invokeExact("foo", "foo", Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ hs.checkWMTEOrCCE(() -> { // expected reference class
+ String x = (String) hs.get(am, methodType(String.class, Class.class, String.class)).
+ invokeExact(Void.class, "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // actual reference class
+ String x = (String) hs.get(am, methodType(String.class, String.class, Class.class)).
+ invokeExact("foo", Void.class);
+ });
+ // Incorrect return type
+ hs.checkWMTEOrCCE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, String.class, String.class)).
+ invokeExact("foo", "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, String.class, String.class)).
+ invokeExact("foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) hs.get(am, methodType(String.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) hs.get(am, methodType(String.class, String.class, String.class, Class.class)).
+ invokeExact("foo", "foo", Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ hs.checkWMTEOrCCE(() -> { // value reference class
+ String x = (String) hs.get(am, methodType(String.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ hs.checkWMTEOrCCE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, String.class)).
+ invokeExact("foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, String.class)).
+ invokeExact("foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) hs.get(am, methodType(String.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) hs.get(am, methodType(String.class, String.class, Class.class)).
+ invokeExact("foo", Void.class);
+ });
+ }
+
+
+ }
+
+
+ static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
+ String[] array = new String[10];
+ Arrays.fill(array, "foo");
+
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ String x = (String) vh.get(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ String x = (String) vh.get(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ String x = (String) vh.get(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ String x = (String) vh.get(array, Void.class);
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void x = (Void) vh.get(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.get(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.get();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.get(array, 0, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.set(null, 0, "foo");
+ });
+ checkCCE(() -> { // array reference class
+ vh.set(Void.class, 0, "foo");
+ });
+ checkCCE(() -> { // value reference class
+ vh.set(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, 0, "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ vh.set(array, Void.class, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(array, 0, "foo", Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ String x = (String) vh.getVolatile(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ String x = (String) vh.getVolatile(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ String x = (String) vh.getVolatile(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ String x = (String) vh.getVolatile(array, Void.class);
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void x = (Void) vh.getVolatile(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getVolatile(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getVolatile(array, 0, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setVolatile(null, 0, "foo");
+ });
+ checkCCE(() -> { // array reference class
+ vh.setVolatile(Void.class, 0, "foo");
+ });
+ checkCCE(() -> { // value reference class
+ vh.setVolatile(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, 0, "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setVolatile(array, Void.class, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(array, 0, "foo", Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ String x = (String) vh.getOpaque(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ String x = (String) vh.getOpaque(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ String x = (String) vh.getOpaque(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ String x = (String) vh.getOpaque(array, Void.class);
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void x = (Void) vh.getOpaque(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getOpaque(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getOpaque(array, 0, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setOpaque(null, 0, "foo");
+ });
+ checkCCE(() -> { // array reference class
+ vh.setOpaque(Void.class, 0, "foo");
+ });
+ checkCCE(() -> { // value reference class
+ vh.setOpaque(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, 0, "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setOpaque(array, Void.class, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(array, 0, "foo", Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ String x = (String) vh.getAcquire(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ String x = (String) vh.getAcquire(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ String x = (String) vh.getAcquire(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ String x = (String) vh.getAcquire(array, Void.class);
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void x = (Void) vh.getAcquire(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAcquire(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getAcquire(array, 0, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setRelease(null, 0, "foo");
+ });
+ checkCCE(() -> { // array reference class
+ vh.setRelease(Void.class, 0, "foo");
+ });
+ checkCCE(() -> { // value reference class
+ vh.setRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, 0, "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setRelease(array, Void.class, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(array, 0, "foo", Void.class);
+ });
+
+
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, 0, "foo", "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, 0, "foo", "foo");
+ });
+ checkCCE(() -> { // expected reference class
+ boolean r = vh.compareAndSet(array, 0, Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ boolean r = vh.compareAndSet(array, 0, "foo", Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, 0, "foo", "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.compareAndSet(array, Void.class, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(array, 0, "foo", "foo", Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, 0, "foo", "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 0, "foo", "foo");
+ });
+ checkCCE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, "foo", Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, 0, "foo", "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetPlain(array, Void.class, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(array, 0, "foo", "foo", Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, 0, "foo", "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 0, "foo", "foo");
+ });
+ checkCCE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(array, 0, Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(array, 0, "foo", Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, 0, "foo", "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSet(array, Void.class, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(array, 0, "foo", "foo", Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, 0, "foo", "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 0, "foo", "foo");
+ });
+ checkCCE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, "foo", Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, 0, "foo", "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, Void.class, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, "foo", "foo", Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, 0, "foo", "foo");
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 0, "foo", "foo");
+ });
+ checkCCE(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, "foo", Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, 0, "foo", "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetRelease(array, Void.class, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(array, 0, "foo", "foo", Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ String x = (String) vh.compareAndExchange(null, 0, "foo", "foo");
+ });
+ checkCCE(() -> { // array reference class
+ String x = (String) vh.compareAndExchange(Void.class, 0, "foo", "foo");
+ });
+ checkCCE(() -> { // expected reference class
+ String x = (String) vh.compareAndExchange(array, 0, Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ String x = (String) vh.compareAndExchange(array, 0, "foo", Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ String x = (String) vh.compareAndExchange(0, 0, "foo", "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ String x = (String) vh.compareAndExchange(array, Void.class, "foo", "foo");
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(array, 0, "foo", "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchange(array, 0, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.compareAndExchange(array, 0, "foo", "foo", Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ String x = (String) vh.compareAndExchangeAcquire(null, 0, "foo", "foo");
+ });
+ checkCCE(() -> { // array reference class
+ String x = (String) vh.compareAndExchangeAcquire(Void.class, 0, "foo", "foo");
+ });
+ checkCCE(() -> { // expected reference class
+ String x = (String) vh.compareAndExchangeAcquire(array, 0, Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ String x = (String) vh.compareAndExchangeAcquire(array, 0, "foo", Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ String x = (String) vh.compareAndExchangeAcquire(0, 0, "foo", "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ String x = (String) vh.compareAndExchangeAcquire(array, Void.class, "foo", "foo");
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(array, 0, "foo", "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeAcquire(array, 0, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.compareAndExchangeAcquire(array, 0, "foo", "foo", Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ String x = (String) vh.compareAndExchangeRelease(null, 0, "foo", "foo");
+ });
+ checkCCE(() -> { // array reference class
+ String x = (String) vh.compareAndExchangeRelease(Void.class, 0, "foo", "foo");
+ });
+ checkCCE(() -> { // expected reference class
+ String x = (String) vh.compareAndExchangeRelease(array, 0, Void.class, "foo");
+ });
+ checkCCE(() -> { // actual reference class
+ String x = (String) vh.compareAndExchangeRelease(array, 0, "foo", Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ String x = (String) vh.compareAndExchangeRelease(0, 0, "foo", "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ String x = (String) vh.compareAndExchangeRelease(array, Void.class, "foo", "foo");
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(array, 0, "foo", "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.compareAndExchangeRelease(array, 0, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.compareAndExchangeRelease(array, 0, "foo", "foo", Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ String x = (String) vh.getAndSet(null, 0, "foo");
+ });
+ checkCCE(() -> { // array reference class
+ String x = (String) vh.getAndSet(Void.class, 0, "foo");
+ });
+ checkCCE(() -> { // value reference class
+ String x = (String) vh.getAndSet(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ String x = (String) vh.getAndSet(0, 0, "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ String x = (String) vh.getAndSet(array, Void.class, "foo");
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.getAndSet(array, 0, "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSet(array, 0, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getAndSet(array, 0, "foo", Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ String x = (String) vh.getAndSetAcquire(null, 0, "foo");
+ });
+ checkCCE(() -> { // array reference class
+ String x = (String) vh.getAndSetAcquire(Void.class, 0, "foo");
+ });
+ checkCCE(() -> { // value reference class
+ String x = (String) vh.getAndSetAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ String x = (String) vh.getAndSetAcquire(0, 0, "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ String x = (String) vh.getAndSetAcquire(array, Void.class, "foo");
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(array, 0, "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetAcquire(array, 0, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getAndSetAcquire(array, 0, "foo", Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ String x = (String) vh.getAndSetRelease(null, 0, "foo");
+ });
+ checkCCE(() -> { // array reference class
+ String x = (String) vh.getAndSetRelease(Void.class, 0, "foo");
+ });
+ checkCCE(() -> { // value reference class
+ String x = (String) vh.getAndSetRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ String x = (String) vh.getAndSetRelease(0, 0, "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ String x = (String) vh.getAndSetRelease(array, Void.class, "foo");
+ });
+ // Incorrect return type
+ checkCCE(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(array, 0, "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) vh.getAndSetRelease(array, 0, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) vh.getAndSetRelease(array, 0, "foo", Void.class);
+ });
+
+
+ }
+
+ static void testArrayWrongMethodType(Handles hs) throws Throwable {
+ String[] array = new String[10];
+ Arrays.fill(array, "foo");
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ String x = (String) hs.get(am, methodType(String.class, String[].class, int.class)).
+ invokeExact((String[]) null, 0);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ String x = (String) hs.get(am, methodType(String.class, Class.class, int.class)).
+ invokeExact(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ String x = (String) hs.get(am, methodType(String.class, int.class, int.class)).
+ invokeExact(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ String x = (String) hs.get(am, methodType(String.class, String[].class, Class.class)).
+ invokeExact(array, Void.class);
+ });
+ // Incorrect return type
+ hs.checkWMTEOrCCE(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, String[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, String[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) hs.get(am, methodType(String.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) hs.get(am, methodType(String.class, String[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ hs.get(am, methodType(void.class, String[].class, int.class, String.class)).
+ invokeExact((String[]) null, 0, "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ hs.get(am, methodType(void.class, Class.class, int.class, String.class)).
+ invokeExact(Void.class, 0, "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // value reference class
+ hs.get(am, methodType(void.class, String[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, int.class, String.class)).
+ invokeExact(0, 0, "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ hs.get(am, methodType(void.class, String[].class, Class.class, String.class)).
+ invokeExact(array, Void.class, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, String[].class, int.class, Class.class)).
+ invokeExact(array, 0, "foo", Void.class);
+ });
+ }
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, String[].class, int.class, String.class, String.class)).
+ invokeExact((String[]) null, 0, "foo", "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, String.class, String.class)).
+ invokeExact(Void.class, 0, "foo", "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, String[].class, int.class, Class.class, String.class)).
+ invokeExact(array, 0, Void.class, "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, String[].class, int.class, String.class, Class.class)).
+ invokeExact(array, 0, "foo", Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, String.class, String.class)).
+ invokeExact(0, 0, "foo", "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, String[].class, Class.class, String.class, String.class)).
+ invokeExact(array, Void.class, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, String[].class, int.class, String.class, String.class, Class.class)).
+ invokeExact(array, 0, "foo", "foo", Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ String x = (String) hs.get(am, methodType(String.class, String[].class, int.class, String.class, String.class)).
+ invokeExact((String[]) null, 0, "foo", "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ String x = (String) hs.get(am, methodType(String.class, Class.class, int.class, String.class, String.class)).
+ invokeExact(Void.class, 0, "foo", "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // expected reference class
+ String x = (String) hs.get(am, methodType(String.class, String[].class, int.class, Class.class, String.class)).
+ invokeExact(array, 0, Void.class, "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // actual reference class
+ String x = (String) hs.get(am, methodType(String.class, String[].class, int.class, String.class, Class.class)).
+ invokeExact(array, 0, "foo", Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ String x = (String) hs.get(am, methodType(String.class, int.class, int.class, String.class, String.class)).
+ invokeExact(0, 0, "foo", "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ String x = (String) hs.get(am, methodType(String.class, String[].class, Class.class, String.class, String.class)).
+ invokeExact(array, Void.class, "foo", "foo");
+ });
+ // Incorrect return type
+ hs.checkWMTEOrCCE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, String[].class, int.class, String.class, String.class)).
+ invokeExact(array, 0, "foo", "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, String[].class, int.class, String.class, String.class)).
+ invokeExact(array, 0, "foo", "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) hs.get(am, methodType(String.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) hs.get(am, methodType(String.class, String[].class, int.class, String.class, String.class, Class.class)).
+ invokeExact(array, 0, "foo", "foo", Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ String x = (String) hs.get(am, methodType(String.class, String[].class, int.class, String.class)).
+ invokeExact((String[]) null, 0, "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ String x = (String) hs.get(am, methodType(String.class, Class.class, int.class, String.class)).
+ invokeExact(Void.class, 0, "foo");
+ });
+ hs.checkWMTEOrCCE(() -> { // value reference class
+ String x = (String) hs.get(am, methodType(String.class, String[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ String x = (String) hs.get(am, methodType(String.class, int.class, int.class, String.class)).
+ invokeExact(0, 0, "foo");
+ });
+ checkWMTE(() -> { // index reference class
+ String x = (String) hs.get(am, methodType(String.class, String[].class, Class.class, String.class)).
+ invokeExact(array, Void.class, "foo");
+ });
+ // Incorrect return type
+ hs.checkWMTEOrCCE(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, String[].class, int.class, String.class)).
+ invokeExact(array, 0, "foo");
+ });
+ checkWMTE(() -> { // primitive class
+ boolean x = (boolean) hs.get(am, methodType(boolean.class, String[].class, int.class, String.class)).
+ invokeExact(array, 0, "foo");
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ String x = (String) hs.get(am, methodType(String.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ String x = (String) hs.get(am, methodType(String.class, String[].class, int.class, String.class, Class.class)).
+ invokeExact(array, 0, "foo", Void.class);
+ });
+ }
+
+
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestReflection.java b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestReflection.java
new file mode 100644
index 0000000..652272c
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/VarHandleTestReflection.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng VarHandleTestReflection
+ */
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandleInfo;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.lang.reflect.Method;
+import java.util.stream.Stream;
+
+public class VarHandleTestReflection extends VarHandleBaseTest {
+ String string;
+
+ @DataProvider
+ public static Object[][] accessModesProvider() {
+ return Stream.of(VarHandle.AccessMode.values()).
+ map(am -> new Object[]{am}).
+ toArray(Object[][]::new);
+ }
+
+ static VarHandle handle() throws Exception {
+ return MethodHandles.lookup().
+ findVarHandle(VarHandleTestReflection.class, "string", String.class);
+ }
+
+ @Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class)
+ public void methodInvocation(VarHandle.AccessMode accessMode) throws Exception {
+ VarHandle v = handle();
+
+ // Try a reflective invoke using a Method
+
+ Method vhm = VarHandle.class.getMethod(accessMode.methodName(), Object[].class);
+ vhm.invoke(v, new Object[]{});
+ }
+
+ @Test(dataProvider = "accessModesProvider", expectedExceptions = UnsupportedOperationException.class)
+ public void methodHandleInvoke(VarHandle.AccessMode accessMode) throws Throwable {
+ VarHandle v = handle();
+
+ // Try a reflective invoke using a MethodHandle
+
+ MethodHandle mh = MethodHandles.lookup().unreflect(
+ VarHandle.class.getMethod(accessMode.methodName(), Object[].class));
+ // Use invoke to avoid WrongMethodTypeException for
+ // non-signature-polymorphic return types
+ Object o = (Object) mh.invoke(v, new Object[]{});
+ }
+
+ @Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class)
+ public void methodInvocationFromMethodInfo(VarHandle.AccessMode accessMode) throws Exception {
+ VarHandle v = handle();
+
+ // Try a reflective invoke using a Method obtained from cracking
+ // a MethodHandle
+
+ MethodHandle mh = MethodHandles.lookup().unreflect(
+ VarHandle.class.getMethod(accessMode.methodName(), Object[].class));
+ MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh);
+ Method im = info.reflectAs(Method.class, MethodHandles.lookup());
+ im.invoke(v, new Object[]{});
+ }
+
+ @Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class)
+ public void reflectAsFromVarHandleInvoker(VarHandle.AccessMode accessMode) throws Exception {
+ VarHandle v = handle();
+
+ MethodHandle mh = MethodHandles.varHandleInvoker(
+ accessMode, v.accessModeType(accessMode));
+
+ MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh);
+
+ info.reflectAs(Method.class, MethodHandles.lookup());
+ }
+
+ @Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class)
+ public void reflectAsFromFindVirtual(VarHandle.AccessMode accessMode) throws Exception {
+ VarHandle v = handle();
+
+ MethodHandle mh = MethodHandles.publicLookup().findVirtual(
+ VarHandle.class, accessMode.methodName(), v.accessModeType(accessMode));
+
+ MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh);
+
+ info.reflectAs(Method.class, MethodHandles.lookup());
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/X-VarHandleTestAccess.java.template b/ojluni/src/test/java/lang/invoke/VarHandles/X-VarHandleTestAccess.java.template
new file mode 100644
index 0000000..5014fc1
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/X-VarHandleTestAccess.java.template
@@ -0,0 +1,1925 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=10 -Xint VarHandleTestAccess$Type$
+ * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccess$Type$
+ * @run testng/othervm -Diters=20000 VarHandleTestAccess$Type$
+ * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestAccess$Type$
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
+ static final $type$ static_final_v = $value1$;
+
+ static $type$ static_v;
+
+ final $type$ final_v = $value1$;
+
+ $type$ v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+#if[String]
+ VarHandle vhArrayObject;
+#end[String]
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccess$Type$.class, "final_v", $type$.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccess$Type$.class, "v", $type$.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccess$Type$.class, "static_final_v", $type$.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccess$Type$.class, "static_v", $type$.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle($type$[].class);
+#if[String]
+ vhArrayObject = MethodHandles.arrayElementVarHandle(Object[].class);
+#end[String]
+ }
+
+
+ @DataProvider
+ public Object[][] varHandlesProvider() throws Exception {
+ List<VarHandle> vhs = new ArrayList<>();
+ vhs.add(vhField);
+ vhs.add(vhStaticField);
+ vhs.add(vhArray);
+
+ return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "varHandlesProvider")
+ public void testIsAccessModeSupported(VarHandle vh) {
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
+
+#if[CAS]
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+#else[CAS]
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+#end[CAS]
+
+#if[AtomicAdd]
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+#else[AtomicAdd]
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+#end[AtomicAdd]
+
+#if[Bitwise]
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+#else[Bitwise]
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+#end[Bitwise]
+ }
+
+
+ @DataProvider
+ public Object[][] typesProvider() throws Exception {
+ List<Object[]> types = new ArrayList<>();
+ types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccess$Type$.class)});
+ types.add(new Object[] {vhStaticField, Arrays.asList()});
+ types.add(new Object[] {vhArray, Arrays.asList($type$[].class, int.class)});
+
+ return types.stream().toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "typesProvider")
+ public void testTypes(VarHandle vh, List<Class<?>> pts) {
+ assertEquals(vh.varType(), $type$.class);
+
+ assertEquals(vh.coordinateTypes(), pts);
+
+ testTypes(vh);
+ }
+
+
+ @Test
+ public void testLookupInstanceToStatic() {
+ checkIAE("Lookup of static final field to instance final field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccess$Type$.class, "final_v", $type$.class);
+ });
+
+ checkIAE("Lookup of static field to instance field", () -> {
+ MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestAccess$Type$.class, "v", $type$.class);
+ });
+ }
+
+ @Test
+ public void testLookupStaticToInstance() {
+ checkIAE("Lookup of instance final field to static final field", () -> {
+ MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccess$Type$.class, "static_final_v", $type$.class);
+ });
+
+ checkIAE("Lookup of instance field to static field", () -> {
+ vhStaticField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestAccess$Type$.class, "static_v", $type$.class);
+ });
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance final field",
+ vhFinalField, vh -> testInstanceFinalField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
+ vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static final field",
+ vhStaticFinalField, VarHandleTestAccess$Type$::testStaticFinalField));
+ cases.add(new VarHandleAccessTestCase("Static final field unsupported",
+ vhStaticFinalField, VarHandleTestAccess$Type$::testStaticFinalFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceField(this, vh)));
+ cases.add(new VarHandleAccessTestCase("Instance field unsupported",
+ vhField, vh -> testInstanceFieldUnsupported(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestAccess$Type$::testStaticField));
+ cases.add(new VarHandleAccessTestCase("Static field unsupported",
+ vhStaticField, VarHandleTestAccess$Type$::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestAccess$Type$::testArray));
+#if[String]
+ cases.add(new VarHandleAccessTestCase("Array Object[]",
+ vhArrayObject, VarHandleTestAccess$Type$::testArray));
+#end[String]
+ cases.add(new VarHandleAccessTestCase("Array unsupported",
+ vhArray, VarHandleTestAccess$Type$::testArrayUnsupported,
+ false));
+ cases.add(new VarHandleAccessTestCase("Array index out of bounds",
+ vhArray, VarHandleTestAccess$Type$::testArrayIndexOutOfBounds,
+ false));
+#if[String]
+ cases.add(new VarHandleAccessTestCase("Array store exception",
+ vhArrayObject, VarHandleTestAccess$Type$::testArrayStoreException,
+ false));
+#end[String]
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+
+
+ static void testInstanceFinalField(VarHandleTestAccess$Type$ recv, VarHandle vh) {
+ // Plain
+ {
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, $value1$, "get $type$ value");
+ }
+
+
+ // Volatile
+ {
+ $type$ x = ($type$) vh.getVolatile(recv);
+ assertEquals(x, $value1$, "getVolatile $type$ value");
+ }
+
+ // Lazy
+ {
+ $type$ x = ($type$) vh.getAcquire(recv);
+ assertEquals(x, $value1$, "getRelease $type$ value");
+ }
+
+ // Opaque
+ {
+ $type$ x = ($type$) vh.getOpaque(recv);
+ assertEquals(x, $value1$, "getOpaque $type$ value");
+ }
+ }
+
+ static void testInstanceFinalFieldUnsupported(VarHandleTestAccess$Type$ recv, VarHandle vh) {
+ checkUOE(() -> {
+ vh.set(recv, $value2$);
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile(recv, $value2$);
+ });
+
+ checkUOE(() -> {
+ vh.setRelease(recv, $value2$);
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque(recv, $value2$);
+ });
+
+#if[!CAS]
+ checkUOE(() -> {
+ boolean r = vh.compareAndSet(recv, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchange(recv, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(recv, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSet(recv, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(recv, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(recv, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.getAndSet(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.getAndSetAcquire(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.getAndSetRelease(recv, $value1$);
+ });
+#end[CAS]
+
+#if[!AtomicAdd]
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAdd(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAddAcquire(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAddRelease(recv, $value1$);
+ });
+#end[AtomicAdd]
+
+#if[!Bitwise]
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOr(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAnd(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXor(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(recv, $value1$);
+ });
+#end[Bitwise]
+ }
+
+
+ static void testStaticFinalField(VarHandle vh) {
+ // Plain
+ {
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, $value1$, "get $type$ value");
+ }
+
+
+ // Volatile
+ {
+ $type$ x = ($type$) vh.getVolatile();
+ assertEquals(x, $value1$, "getVolatile $type$ value");
+ }
+
+ // Lazy
+ {
+ $type$ x = ($type$) vh.getAcquire();
+ assertEquals(x, $value1$, "getRelease $type$ value");
+ }
+
+ // Opaque
+ {
+ $type$ x = ($type$) vh.getOpaque();
+ assertEquals(x, $value1$, "getOpaque $type$ value");
+ }
+ }
+
+ static void testStaticFinalFieldUnsupported(VarHandle vh) {
+ checkUOE(() -> {
+ vh.set($value2$);
+ });
+
+ checkUOE(() -> {
+ vh.setVolatile($value2$);
+ });
+
+ checkUOE(() -> {
+ vh.setRelease($value2$);
+ });
+
+ checkUOE(() -> {
+ vh.setOpaque($value2$);
+ });
+
+#if[!CAS]
+ checkUOE(() -> {
+ boolean r = vh.compareAndSet($value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchange($value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeRelease($value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetPlain($value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSet($value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire($value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetRelease($value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.getAndSet($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.getAndSetAcquire($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.getAndSetRelease($value1$);
+ });
+#end[CAS]
+
+#if[!AtomicAdd]
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAdd($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAddAcquire($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAddRelease($value1$);
+ });
+#end[AtomicAdd]
+
+#if[!Bitwise]
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOr($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAnd($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXor($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease($value1$);
+ });
+#end[Bitwise]
+ }
+
+
+ static void testInstanceField(VarHandleTestAccess$Type$ recv, VarHandle vh) {
+ // Plain
+ {
+ vh.set(recv, $value1$);
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, $value1$, "set $type$ value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(recv, $value2$);
+ $type$ x = ($type$) vh.getVolatile(recv);
+ assertEquals(x, $value2$, "setVolatile $type$ value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(recv, $value1$);
+ $type$ x = ($type$) vh.getAcquire(recv);
+ assertEquals(x, $value1$, "setRelease $type$ value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(recv, $value2$);
+ $type$ x = ($type$) vh.getOpaque(recv);
+ assertEquals(x, $value2$, "setOpaque $type$ value");
+ }
+
+#if[CAS]
+ vh.set(recv, $value1$);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(recv, $value1$, $value2$);
+ assertEquals(r, true, "success compareAndSet $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, $value2$, "success compareAndSet $type$ value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(recv, $value1$, $value3$);
+ assertEquals(r, false, "failing compareAndSet $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, $value2$, "failing compareAndSet $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchange(recv, $value2$, $value1$);
+ assertEquals(r, $value2$, "success compareAndExchange $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, $value1$, "success compareAndExchange $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchange(recv, $value2$, $value3$);
+ assertEquals(r, $value1$, "failing compareAndExchange $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value2$);
+ assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value3$);
+ assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value2$, $value1$);
+ assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value2$, $value3$);
+ assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(recv, $value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, $value2$, "weakCompareAndSetPlain $type$ value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(recv, $value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(recv, $value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(recv, $value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSet $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, $value1$, "weakCompareAndSet $type$ value");
+ }
+
+ // Compare set and get
+ {
+ vh.set(recv, $value1$);
+
+ $type$ o = ($type$) vh.getAndSet(recv, $value2$);
+ assertEquals(o, $value1$, "getAndSet $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, $value2$, "getAndSet $type$ value");
+ }
+
+ {
+ vh.set(recv, $value1$);
+
+ $type$ o = ($type$) vh.getAndSetAcquire(recv, $value2$);
+ assertEquals(o, $value1$, "getAndSetAcquire $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, $value2$, "getAndSetAcquire $type$ value");
+ }
+
+ {
+ vh.set(recv, $value1$);
+
+ $type$ o = ($type$) vh.getAndSetRelease(recv, $value2$);
+ assertEquals(o, $value1$, "getAndSetRelease $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, $value2$, "getAndSetRelease $type$ value");
+ }
+#end[CAS]
+
+#if[AtomicAdd]
+ // get and add, add and get
+ {
+ vh.set(recv, $value1$);
+
+ $type$ o = ($type$) vh.getAndAdd(recv, $value2$);
+ assertEquals(o, $value1$, "getAndAdd $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value");
+ }
+
+ {
+ vh.set(recv, $value1$);
+
+ $type$ o = ($type$) vh.getAndAddAcquire(recv, $value2$);
+ assertEquals(o, $value1$, "getAndAddAcquire $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value");
+ }
+
+ {
+ vh.set(recv, $value1$);
+
+ $type$ o = ($type$) vh.getAndAddRelease(recv, $value2$);
+ assertEquals(o, $value1$, "getAndAddRelease$type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value");
+ }
+#end[AtomicAdd]
+
+#if[Bitwise]
+ // get and bitwise or
+ {
+ vh.set(recv, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseOr(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOr $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value");
+ }
+
+ {
+ vh.set(recv, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value");
+ }
+
+ {
+ vh.set(recv, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(recv, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseAnd(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAnd $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value");
+ }
+
+ {
+ vh.set(recv, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value");
+ }
+
+ {
+ vh.set(recv, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(recv, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseXor(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXor $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value");
+ }
+
+ {
+ vh.set(recv, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value");
+ }
+
+ {
+ vh.set(recv, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$");
+ $type$ x = ($type$) vh.get(recv);
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value");
+ }
+#end[Bitwise]
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestAccess$Type$ recv, VarHandle vh) {
+#if[!CAS]
+ checkUOE(() -> {
+ boolean r = vh.compareAndSet(recv, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchange(recv, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(recv, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSet(recv, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(recv, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(recv, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.getAndSet(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.getAndSetAcquire(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.getAndSetRelease(recv, $value1$);
+ });
+#end[CAS]
+
+#if[!AtomicAdd]
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAdd(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAddAcquire(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAddRelease(recv, $value1$);
+ });
+#end[AtomicAdd]
+
+#if[!Bitwise]
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOr(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAnd(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXor(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(recv, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(recv, $value1$);
+ });
+#end[Bitwise]
+ }
+
+
+ static void testStaticField(VarHandle vh) {
+ // Plain
+ {
+ vh.set($value1$);
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, $value1$, "set $type$ value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile($value2$);
+ $type$ x = ($type$) vh.getVolatile();
+ assertEquals(x, $value2$, "setVolatile $type$ value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease($value1$);
+ $type$ x = ($type$) vh.getAcquire();
+ assertEquals(x, $value1$, "setRelease $type$ value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque($value2$);
+ $type$ x = ($type$) vh.getOpaque();
+ assertEquals(x, $value2$, "setOpaque $type$ value");
+ }
+
+#if[CAS]
+ vh.set($value1$);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet($value1$, $value2$);
+ assertEquals(r, true, "success compareAndSet $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, $value2$, "success compareAndSet $type$ value");
+ }
+
+ {
+ boolean r = vh.compareAndSet($value1$, $value3$);
+ assertEquals(r, false, "failing compareAndSet $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, $value2$, "failing compareAndSet $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchange($value2$, $value1$);
+ assertEquals(r, $value2$, "success compareAndExchange $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, $value1$, "success compareAndExchange $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchange($value2$, $value3$);
+ assertEquals(r, $value1$, "failing compareAndExchange $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value2$);
+ assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value3$);
+ assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeRelease($value2$, $value1$);
+ assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeRelease($value2$, $value3$);
+ assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain($value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, $value2$, "weakCompareAndSetPlain $type$ value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire($value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease($value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet($value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSet $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, $value1$, "weakCompareAndSet $type$");
+ }
+
+ // Compare set and get
+ {
+ vh.set($value1$);
+
+ $type$ o = ($type$) vh.getAndSet($value2$);
+ assertEquals(o, $value1$, "getAndSet $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, $value2$, "getAndSet $type$ value");
+ }
+
+ {
+ vh.set($value1$);
+
+ $type$ o = ($type$) vh.getAndSetAcquire($value2$);
+ assertEquals(o, $value1$, "getAndSetAcquire $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, $value2$, "getAndSetAcquire $type$ value");
+ }
+
+ {
+ vh.set($value1$);
+
+ $type$ o = ($type$) vh.getAndSetRelease($value2$);
+ assertEquals(o, $value1$, "getAndSetRelease $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, $value2$, "getAndSetRelease $type$ value");
+ }
+#end[CAS]
+
+#if[AtomicAdd]
+ // get and add, add and get
+ {
+ vh.set($value1$);
+
+ $type$ o = ($type$) vh.getAndAdd($value2$);
+ assertEquals(o, $value1$, "getAndAdd $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value");
+ }
+
+ {
+ vh.set($value1$);
+
+ $type$ o = ($type$) vh.getAndAddAcquire($value2$);
+ assertEquals(o, $value1$, "getAndAddAcquire $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value");
+ }
+
+ {
+ vh.set($value1$);
+
+ $type$ o = ($type$) vh.getAndAddRelease($value2$);
+ assertEquals(o, $value1$, "getAndAddRelease$type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value");
+ }
+#end[AtomicAdd]
+
+#if[Bitwise]
+ // get and bitwise or
+ {
+ vh.set($value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseOr($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOr $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value");
+ }
+
+ {
+ vh.set($value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value");
+ }
+
+ {
+ vh.set($value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set($value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseAnd($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAnd $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value");
+ }
+
+ {
+ vh.set($value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value");
+ }
+
+ {
+ vh.set($value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set($value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseXor($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXor $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value");
+ }
+
+ {
+ vh.set($value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value");
+ }
+
+ {
+ vh.set($value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$");
+ $type$ x = ($type$) vh.get();
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value");
+ }
+#end[Bitwise]
+ }
+
+ static void testStaticFieldUnsupported(VarHandle vh) {
+#if[!CAS]
+ checkUOE(() -> {
+ boolean r = vh.compareAndSet($value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchange($value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeRelease($value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetPlain($value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSet($value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire($value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetRelease($value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.getAndSet($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.getAndSetAcquire($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.getAndSetRelease($value1$);
+ });
+#end[CAS]
+
+#if[!AtomicAdd]
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAdd($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAddAcquire($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAddRelease($value1$);
+ });
+#end[AtomicAdd]
+
+#if[!Bitwise]
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOr($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAnd($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXor($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire($value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease($value1$);
+ });
+#end[Bitwise]
+ }
+
+
+ static void testArray(VarHandle vh) {
+ $type$[] array = new $type$[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ vh.set(array, i, $value1$);
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, $value1$, "get $type$ value");
+ }
+
+
+ // Volatile
+ {
+ vh.setVolatile(array, i, $value2$);
+ $type$ x = ($type$) vh.getVolatile(array, i);
+ assertEquals(x, $value2$, "setVolatile $type$ value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, $value1$);
+ $type$ x = ($type$) vh.getAcquire(array, i);
+ assertEquals(x, $value1$, "setRelease $type$ value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, $value2$);
+ $type$ x = ($type$) vh.getOpaque(array, i);
+ assertEquals(x, $value2$, "setOpaque $type$ value");
+ }
+
+#if[CAS]
+ vh.set(array, i, $value1$);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, $value1$, $value2$);
+ assertEquals(r, true, "success compareAndSet $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, $value2$, "success compareAndSet $type$ value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, $value1$, $value3$);
+ assertEquals(r, false, "failing compareAndSet $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, $value2$, "failing compareAndSet $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchange(array, i, $value2$, $value1$);
+ assertEquals(r, $value2$, "success compareAndExchange $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, $value1$, "success compareAndExchange $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchange(array, i, $value2$, $value3$);
+ assertEquals(r, $value1$, "failing compareAndExchange $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, $value1$, $value2$);
+ assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, $value1$, $value3$);
+ assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, $value2$, $value1$);
+ assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, $value2$, $value3$);
+ assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, $value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, $value2$, "weakCompareAndSetPlain $type$ value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, $value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, $value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, $value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSet $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, $value1$, "weakCompareAndSet $type$");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, $value1$);
+
+ $type$ o = ($type$) vh.getAndSet(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndSet $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, $value2$, "getAndSet $type$ value");
+ }
+
+ {
+ vh.set(array, i, $value1$);
+
+ $type$ o = ($type$) vh.getAndSetAcquire(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndSetAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, $value2$, "getAndSetAcquire $type$ value");
+ }
+
+ {
+ vh.set(array, i, $value1$);
+
+ $type$ o = ($type$) vh.getAndSetRelease(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndSetRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, $value2$, "getAndSetRelease $type$ value");
+ }
+#end[CAS]
+
+#if[AtomicAdd]
+ // get and add, add and get
+ {
+ vh.set(array, i, $value1$);
+
+ $type$ o = ($type$) vh.getAndAdd(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndAdd $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value");
+ }
+
+ {
+ vh.set(array, i, $value1$);
+
+ $type$ o = ($type$) vh.getAndAddAcquire(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndAddAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value");
+ }
+
+ {
+ vh.set(array, i, $value1$);
+
+ $type$ o = ($type$) vh.getAndAddRelease(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndAddRelease$type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value");
+ }
+#end[AtomicAdd]
+
+#if[Bitwise]
+ // get and bitwise or
+ {
+ vh.set(array, i, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseOr(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOr $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value");
+ }
+
+ {
+ vh.set(array, i, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value");
+ }
+
+ {
+ vh.set(array, i, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(array, i, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseAnd(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAnd $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value");
+ }
+
+ {
+ vh.set(array, i, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value");
+ }
+
+ {
+ vh.set(array, i, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(array, i, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseXor(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXor $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value");
+ }
+
+ {
+ vh.set(array, i, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value");
+ }
+
+ {
+ vh.set(array, i, $value1$);
+
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value");
+ }
+#end[Bitwise]
+ }
+ }
+
+ static void testArrayUnsupported(VarHandle vh) {
+ $type$[] array = new $type$[10];
+
+ int i = 0;
+#if[!CAS]
+ checkUOE(() -> {
+ boolean r = vh.compareAndSet(array, i, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchange(array, i, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, i, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSet(array, i, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, i, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, i, $value1$, $value2$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.getAndSet(array, i, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.getAndSetAcquire(array, i, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.getAndSetRelease(array, i, $value1$);
+ });
+#end[CAS]
+
+#if[!AtomicAdd]
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAdd(array, i, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAddAcquire(array, i, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAddRelease(array, i, $value1$);
+ });
+#end[AtomicAdd]
+
+#if[!Bitwise]
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOr(array, i, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, i, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, i, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAnd(array, i, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, i, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, i, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXor(array, i, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, i, $value1$);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, i, $value1$);
+ });
+#end[Bitwise]
+ }
+
+ static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
+ $type$[] array = new $type$[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ $type$ x = ($type$) vh.get(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.set(array, ci, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ x = ($type$) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ x = ($type$) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ x = ($type$) vh.getOpaque(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, $value1$);
+ });
+
+#if[CAS]
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, $value1$, $value2$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ r = ($type$) vh.compareAndExchange(array, ci, $value2$, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, ci, $value2$, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, ci, $value2$, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, $value1$, $value2$);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, $value1$, $value2$);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, $value1$, $value2$);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, $value1$, $value2$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndSet(array, ci, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndSetAcquire(array, ci, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndSetRelease(array, ci, $value1$);
+ });
+#end[CAS]
+
+#if[AtomicAdd]
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndAdd(array, ci, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndAddAcquire(array, ci, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndAddRelease(array, ci, $value1$);
+ });
+#end[AtomicAdd]
+
+#if[Bitwise]
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOr(array, ci, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, ci, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, ci, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAnd(array, ci, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, ci, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, ci, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXor(array, ci, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, ci, $value1$);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, ci, $value1$);
+ });
+#end[Bitwise]
+ }
+ }
+
+#if[String]
+ static void testArrayStoreException(VarHandle vh) throws Throwable {
+ Object[] array = new $type$[10];
+ Arrays.fill(array, $value1$);
+ Object value = new Object();
+
+ // Set
+ checkASE(() -> {
+ vh.set(array, 0, value);
+ });
+
+ // SetVolatile
+ checkASE(() -> {
+ vh.setVolatile(array, 0, value);
+ });
+
+ // SetOpaque
+ checkASE(() -> {
+ vh.setOpaque(array, 0, value);
+ });
+
+ // SetRelease
+ checkASE(() -> {
+ vh.setRelease(array, 0, value);
+ });
+
+ // CompareAndSet
+ checkASE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(array, 0, $value1$, value);
+ });
+
+ // WeakCompareAndSet
+ checkASE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, $value1$, value);
+ });
+
+ // WeakCompareAndSetVolatile
+ checkASE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(array, 0, $value1$, value);
+ });
+
+ // WeakCompareAndSetAcquire
+ checkASE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, $value1$, value);
+ });
+
+ // WeakCompareAndSetRelease
+ checkASE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, $value1$, value);
+ });
+
+ // CompareAndExchange
+ checkASE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.compareAndExchange(array, 0, $value1$, value);
+ });
+
+ // CompareAndExchangeAcquire
+ checkASE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.compareAndExchangeAcquire(array, 0, $value1$, value);
+ });
+
+ // CompareAndExchangeRelease
+ checkASE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.compareAndExchangeRelease(array, 0, $value1$, value);
+ });
+
+ // GetAndSet
+ checkASE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndSet(array, 0, value);
+ });
+
+ // GetAndSetAcquire
+ checkASE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndSetAcquire(array, 0, value);
+ });
+
+ // GetAndSetRelease
+ checkASE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndSetRelease(array, 0, value);
+ });
+ }
+#end[String]
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/X-VarHandleTestByteArrayView.java.template b/ojluni/src/test/java/lang/invoke/VarHandles/X-VarHandleTestByteArrayView.java.template
new file mode 100644
index 0000000..e476324
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/X-VarHandleTestByteArrayView.java.template
@@ -0,0 +1,2113 @@
+/*
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8154556
+ * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAs$Type$
+ * @run testng/othervm -Diters=20000 VarHandleTestByteArrayAs$Type$
+ * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestByteArrayAs$Type$
+ */
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
+ static final int SIZE = $BoxType$.BYTES;
+
+ static final $type$ VALUE_1 = $value1$;
+
+ static final $type$ VALUE_2 = $value2$;
+
+ static final $type$ VALUE_3 = $value3$;
+
+
+ @Override
+ public void setupVarHandleSources() {
+ // Combinations of VarHandle byte[] or ByteBuffer
+ vhss = new ArrayList<>();
+ for (MemoryMode endianess : Arrays.asList(MemoryMode.BIG_ENDIAN, MemoryMode.LITTLE_ENDIAN)) {
+
+ ByteOrder bo = endianess == MemoryMode.BIG_ENDIAN
+ ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
+ VarHandleSource aeh = new VarHandleSource(
+ MethodHandles.byteArrayViewVarHandle($type$[].class, bo),
+ endianess, MemoryMode.READ_WRITE);
+ vhss.add(aeh);
+
+ VarHandleSource bbh = new VarHandleSource(
+ MethodHandles.byteBufferViewVarHandle($type$[].class, bo),
+ endianess, MemoryMode.READ_WRITE);
+ vhss.add(bbh);
+ }
+ }
+
+
+ @Test(dataProvider = "varHandlesProvider")
+ public void testIsAccessModeSupported(VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
+
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
+
+#if[CAS]
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+#else[CAS]
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
+#end[CAS]
+
+#if[AtomicAdd]
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+#else[AtomicAdd]
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
+#end[AtomicAdd]
+
+#if[Bitwise]
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+#else[Bitwise]
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
+ assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
+#end[Bitwise]
+ }
+
+ @Test(dataProvider = "typesProvider")
+ public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
+ assertEquals(vh.varType(), $type$.class);
+
+ assertEquals(vh.coordinateTypes(), pts);
+
+ testTypes(vh);
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ for (ByteArrayViewSource<?> bav : bavss) {
+ for (VarHandleSource vh : vhss) {
+ if (vh.matches(bav)) {
+ if (bav instanceof ByteArraySource) {
+ ByteArraySource bas = (ByteArraySource) bav;
+
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read write", bav, vh, h -> testArrayReadWrite(bas, h),
+ true));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "null array", bav, vh, h -> testArrayNPE(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "unsupported", bav, vh, h -> testArrayUnsupported(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bas, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "misaligned access", bav, vh, h -> testArrayMisalignedAccess(bas, h),
+ false));
+ }
+ else {
+ ByteBufferSource bbs = (ByteBufferSource) bav;
+
+ if (MemoryMode.READ_WRITE.isSet(bav.memoryModes)) {
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read write", bav, vh, h -> testArrayReadWrite(bbs, h),
+ true));
+ }
+ else {
+ cases.add(new VarHandleSourceAccessTestCase(
+ "read only", bav, vh, h -> testArrayReadOnly(bbs, h),
+ true));
+ }
+
+ cases.add(new VarHandleSourceAccessTestCase(
+ "null buffer", bav, vh, h -> testArrayNPE(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "unsupported", bav, vh, h -> testArrayUnsupported(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bbs, h),
+ false));
+ cases.add(new VarHandleSourceAccessTestCase(
+ "misaligned access", bav, vh, h -> testArrayMisalignedAccess(bbs, h),
+ false));
+ }
+ }
+ }
+ }
+
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = null;
+ int ci = 1;
+
+ checkNPE(() -> {
+ $type$ x = ($type$) vh.get(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ x = ($type$) vh.getVolatile(array, ci);
+ });
+
+ checkNPE(() -> {
+ $type$ x = ($type$) vh.getAcquire(array, ci);
+ });
+
+ checkNPE(() -> {
+ $type$ x = ($type$) vh.getOpaque(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+#if[CAS]
+ checkNPE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+#end[CAS]
+
+#if[AtomicAdd]
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+#end[AtomicAdd]
+
+#if[Bitwise]
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+#end[Bitwise]
+ }
+
+ static void testArrayNPE(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = null;
+ int ci = 1;
+
+ checkNPE(() -> {
+ $type$ x = ($type$) vh.get(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ x = ($type$) vh.getVolatile(array, ci);
+ });
+
+ checkNPE(() -> {
+ $type$ x = ($type$) vh.getAcquire(array, ci);
+ });
+
+ checkNPE(() -> {
+ $type$ x = ($type$) vh.getOpaque(array, ci);
+ });
+
+ checkNPE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+#if[CAS]
+ checkNPE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+#end[CAS]
+
+#if[AtomicAdd]
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+#end[AtomicAdd]
+
+#if[Bitwise]
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkNPE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+#end[Bitwise]
+ }
+
+ static void testArrayUnsupported(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+ int ci = 1;
+
+#if[!CAS]
+ checkUOE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+#end[CAS]
+
+#if[!AtomicAdd]
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+#end[AtomicAdd]
+
+#if[!Bitwise]
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+#end[Bitwise]
+ }
+
+ static void testArrayUnsupported(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+ int ci = 0;
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+
+ if (readOnly) {
+ checkROBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+ }
+
+ if (readOnly) {
+ checkROBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+#if[CAS]
+
+ checkROBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkROBE(() -> {
+ $type$ o = ($type$) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ $type$ o = ($type$) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ $type$ o = ($type$) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+
+#else[CAS]
+ checkUOE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+#end[CAS]
+
+#if[AtomicAdd]
+ checkROBE(() -> {
+ $type$ o = ($type$) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ $type$ o = ($type$) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ $type$ o = ($type$) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+#else[AtomicAdd]
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+#end[AtomicAdd]
+
+#if[Bitwise]
+ checkROBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkROBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+#else[Bitwise]
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+#end[Bitwise]
+ }
+ else {
+#if[!CAS]
+ checkUOE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+#end[CAS]
+#if[!AtomicAdd]
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+#end[AtomicAdd]
+#if[!Bitwise]
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkUOE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+#end[Bitwise]
+ }
+ }
+
+
+ static void testArrayIndexOutOfBounds(ByteArraySource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int length = array.length - SIZE + 1;
+ for (int i : new int[]{-1, Integer.MIN_VALUE, length, length + 1, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ $type$ x = ($type$) vh.get(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ x = ($type$) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ $type$ x = ($type$) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ $type$ x = ($type$) vh.getOpaque(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+#if[CAS]
+
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+#end[CAS]
+
+#if[AtomicAdd]
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+#end[AtomicAdd]
+
+#if[Bitwise]
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+#end[Bitwise]
+
+ }
+ }
+
+ static void testArrayIndexOutOfBounds(ByteBufferSource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+
+ int length = array.limit() - SIZE + 1;
+ for (int i : new int[]{-1, Integer.MIN_VALUE, length, length + 1, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ checkIOOBE(() -> {
+ $type$ x = ($type$) vh.get(array, ci);
+ });
+
+ if (!readOnly) {
+ checkIOOBE(() -> {
+ vh.set(array, ci, VALUE_1);
+ });
+ }
+
+ checkIOOBE(() -> {
+ $type$ x = ($type$) vh.getVolatile(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ $type$ x = ($type$) vh.getAcquire(array, ci);
+ });
+
+ checkIOOBE(() -> {
+ $type$ x = ($type$) vh.getOpaque(array, ci);
+ });
+
+ if (!readOnly) {
+ checkIOOBE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+#if[CAS]
+ checkIOOBE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+#end[CAS]
+
+#if[AtomicAdd]
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+#end[AtomicAdd]
+
+#if[Bitwise]
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkIOOBE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+#end[Bitwise]
+ }
+ }
+ }
+
+ static void testArrayMisalignedAccess(ByteArraySource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int misalignmentAtZero = ByteBuffer.wrap(array).alignmentOffset(0, SIZE);
+
+ int length = array.length - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+ final int ci = i;
+
+ if (!iAligned) {
+ checkISE(() -> {
+ $type$ x = ($type$) vh.getVolatile(array, ci);
+ });
+
+ checkISE(() -> {
+ $type$ x = ($type$) vh.getAcquire(array, ci);
+ });
+
+ checkISE(() -> {
+ $type$ x = ($type$) vh.getOpaque(array, ci);
+ });
+
+ checkISE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+#if[CAS]
+
+ checkISE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+#end[CAS]
+
+#if[AtomicAdd]
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+#end[AtomicAdd]
+
+#if[Bitwise]
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+#end[Bitwise]
+ }
+ }
+ }
+
+ static void testArrayMisalignedAccess(ByteBufferSource bs, VarHandleSource vhs) throws Throwable {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes);
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+ final int ci = i;
+
+ if (!iAligned) {
+ checkISE(() -> {
+ $type$ x = ($type$) vh.getVolatile(array, ci);
+ });
+
+ checkISE(() -> {
+ $type$ x = ($type$) vh.getAcquire(array, ci);
+ });
+
+ checkISE(() -> {
+ $type$ x = ($type$) vh.getOpaque(array, ci);
+ });
+
+ if (!readOnly) {
+ checkISE(() -> {
+ vh.setVolatile(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ vh.setOpaque(array, ci, VALUE_1);
+ });
+
+#if[CAS]
+ checkISE(() -> {
+ boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndSet(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndSetAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndSetRelease(array, ci, VALUE_1);
+ });
+#end[CAS]
+
+#if[AtomicAdd]
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndAdd(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndAddAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndAddRelease(array, ci, VALUE_1);
+ });
+#end[AtomicAdd]
+
+#if[Bitwise]
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOr(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAnd(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXor(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
+ });
+
+ checkISE(() -> {
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
+ });
+#end[Bitwise]
+ }
+ }
+ }
+ }
+
+ static void testArrayReadWrite(ByteArraySource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ byte[] array = bs.s;
+
+ int misalignmentAtZero = ByteBuffer.wrap(array).alignmentOffset(0, SIZE);
+
+ bs.fill((byte) 0xff);
+ int length = array.length - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ // Plain
+ {
+ vh.set(array, i, VALUE_1);
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1, "get $type$ value");
+ }
+
+
+ if (iAligned) {
+ // Volatile
+ {
+ vh.setVolatile(array, i, VALUE_2);
+ $type$ x = ($type$) vh.getVolatile(array, i);
+ assertEquals(x, VALUE_2, "setVolatile $type$ value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, VALUE_1);
+ $type$ x = ($type$) vh.getAcquire(array, i);
+ assertEquals(x, VALUE_1, "setRelease $type$ value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, VALUE_2);
+ $type$ x = ($type$) vh.getOpaque(array, i);
+ assertEquals(x, VALUE_2, "setOpaque $type$ value");
+ }
+#if[CAS]
+
+ vh.set(array, i, VALUE_1);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, true, "success compareAndSet $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndSet $type$ value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, false, "failing compareAndSet $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndSet $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchange $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchange $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchange $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchange $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, VALUE_1, "success compareAndExchangeAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndExchangeAcquire $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchangeRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchangeRelease $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchangeRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchangeRelease $type$ value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetPlain $type$ value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSetAcquire $type$");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetRelease $type$");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSet $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSet $type$");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndSet(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSet $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSet $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndSetAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetAcquire $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndSetRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetRelease $type$ value");
+ }
+#end[CAS]
+
+#if[AtomicAdd]
+ // get and add, add and get
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndAdd(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAdd $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAdd $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndAddAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAddAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAddAcquire $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndAddRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAddRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAddRelease $type$ value");
+ }
+#end[AtomicAdd]
+
+#if[Bitwise]
+ // get and bitwise or
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseOr(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOr $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOr $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOrAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrAcquire $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOrRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrRelease $type$ value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseAnd(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAnd $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAnd $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAndAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndAcquire $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAndRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndRelease $type$ value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseXor(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXor $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXor $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXorAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorAcquire $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXorRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorRelease $type$ value");
+ }
+#end[Bitwise]
+ }
+ }
+ }
+
+
+ static void testArrayReadWrite(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ bs.fill((byte) 0xff);
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ // Plain
+ {
+ vh.set(array, i, VALUE_1);
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1, "get $type$ value");
+ }
+
+ if (iAligned) {
+ // Volatile
+ {
+ vh.setVolatile(array, i, VALUE_2);
+ $type$ x = ($type$) vh.getVolatile(array, i);
+ assertEquals(x, VALUE_2, "setVolatile $type$ value");
+ }
+
+ // Lazy
+ {
+ vh.setRelease(array, i, VALUE_1);
+ $type$ x = ($type$) vh.getAcquire(array, i);
+ assertEquals(x, VALUE_1, "setRelease $type$ value");
+ }
+
+ // Opaque
+ {
+ vh.setOpaque(array, i, VALUE_2);
+ $type$ x = ($type$) vh.getOpaque(array, i);
+ assertEquals(x, VALUE_2, "setOpaque $type$ value");
+ }
+#if[CAS]
+
+ vh.set(array, i, VALUE_1);
+
+ // Compare
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, true, "success compareAndSet $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndSet $type$ value");
+ }
+
+ {
+ boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, false, "failing compareAndSet $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndSet $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchange $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchange $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchange $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchange $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2);
+ assertEquals(r, VALUE_1, "success compareAndExchangeAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "success compareAndExchangeAcquire $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3);
+ assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1);
+ assertEquals(r, VALUE_2, "success compareAndExchangeRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1, "success compareAndExchangeRelease $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3);
+ assertEquals(r, VALUE_1, "failing compareAndExchangeRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1, "failing compareAndExchangeRelease $type$ value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetPlain $type$ value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSetAcquire $type$");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "weakCompareAndSetRelease $type$");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_1);
+ }
+ assertEquals(success, true, "weakCompareAndSet $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1, "weakCompareAndSet $type$");
+ }
+
+ // Compare set and get
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndSet(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSet $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSet $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndSetAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetAcquire $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndSetRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndSetRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_2, "getAndSetRelease $type$ value");
+ }
+#end[CAS]
+
+#if[AtomicAdd]
+ // get and add, add and get
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndAdd(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAdd $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAdd $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndAddAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAddAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAddAcquire $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndAddRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndAddRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 + VALUE_2, "getAndAddRelease $type$ value");
+ }
+#end[AtomicAdd]
+
+#if[Bitwise]
+ // get and bitwise or
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseOr(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOr $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOr $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOrAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrAcquire $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseOrRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrRelease $type$ value");
+ }
+
+ // get and bitwise and
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseAnd(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAnd $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAnd $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAndAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndAcquire $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseAndRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndRelease $type$ value");
+ }
+
+ // get and bitwise xor
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseXor(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXor $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXor $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXorAcquire $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorAcquire $type$ value");
+ }
+
+ {
+ vh.set(array, i, VALUE_1);
+
+ $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, i, VALUE_2);
+ assertEquals(o, VALUE_1, "getAndBitwiseXorRelease $type$");
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorRelease $type$ value");
+ }
+#end[Bitwise]
+ }
+ }
+ }
+
+ static void testArrayReadOnly(ByteBufferSource bs, VarHandleSource vhs) {
+ VarHandle vh = vhs.s;
+ ByteBuffer array = bs.s;
+
+ int misalignmentAtZero = array.alignmentOffset(0, SIZE);
+
+ ByteBuffer bb = ByteBuffer.allocate(SIZE);
+ bb.order(MemoryMode.BIG_ENDIAN.isSet(vhs.memoryModes) ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
+ bs.fill(bb.put$Type$(0, VALUE_2).array());
+
+ int length = array.limit() - SIZE + 1;
+ for (int i = 0; i < length; i++) {
+ boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0;
+
+ $type$ v = MemoryMode.BIG_ENDIAN.isSet(vhs.memoryModes)
+ ? rotateLeft(VALUE_2, (i % SIZE) << 3)
+ : rotateRight(VALUE_2, (i % SIZE) << 3);
+ // Plain
+ {
+ $type$ x = ($type$) vh.get(array, i);
+ assertEquals(x, v, "get $type$ value");
+ }
+
+ if (iAligned) {
+ // Volatile
+ {
+ $type$ x = ($type$) vh.getVolatile(array, i);
+ assertEquals(x, v, "getVolatile $type$ value");
+ }
+
+ // Lazy
+ {
+ $type$ x = ($type$) vh.getAcquire(array, i);
+ assertEquals(x, v, "getRelease $type$ value");
+ }
+
+ // Opaque
+ {
+ $type$ x = ($type$) vh.getOpaque(array, i);
+ assertEquals(x, v, "getOpaque $type$ value");
+ }
+ }
+ }
+ }
+
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/X-VarHandleTestMethodHandleAccess.java.template b/ojluni/src/test/java/lang/invoke/VarHandles/X-VarHandleTestMethodHandleAccess.java.template
new file mode 100644
index 0000000..c82d533
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/X-VarHandleTestMethodHandleAccess.java.template
@@ -0,0 +1,1110 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccess$Type$
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest {
+ static final $type$ static_final_v = $value1$;
+
+ static $type$ static_v;
+
+ final $type$ final_v = $value1$;
+
+ $type$ v;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccess$Type$.class, "final_v", $type$.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodHandleAccess$Type$.class, "v", $type$.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccess$Type$.class, "static_final_v", $type$.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodHandleAccess$Type$.class, "static_v", $type$.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle($type$[].class);
+ }
+
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceField(this, hs)));
+ cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
+ vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodHandleAccess$Type$::testStaticField));
+ cases.add(new MethodHandleAccessTestCase("Static field unsupported",
+ vhStaticField, f, VarHandleTestMethodHandleAccess$Type$::testStaticFieldUnsupported,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodHandleAccess$Type$::testArray));
+ cases.add(new MethodHandleAccessTestCase("Array unsupported",
+ vhArray, f, VarHandleTestMethodHandleAccess$Type$::testArrayUnsupported,
+ false));
+ cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
+ vhArray, f, VarHandleTestMethodHandleAccess$Type$::testArrayIndexOutOfBounds,
+ false));
+ }
+
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceField(VarHandleTestMethodHandleAccess$Type$ recv, Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, $value1$, "set $type$ value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, $value2$);
+ $type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
+ assertEquals(x, $value2$, "setVolatile $type$ value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, $value1$);
+ $type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
+ assertEquals(x, $value1$, "setRelease $type$ value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, $value2$);
+ $type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
+ assertEquals(x, $value2$, "setOpaque $type$ value");
+ }
+
+#if[CAS]
+ hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, $value1$, $value2$);
+ assertEquals(r, true, "success compareAndSet $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, $value2$, "success compareAndSet $type$ value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, $value1$, $value3$);
+ assertEquals(r, false, "failing compareAndSet $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, $value2$, "failing compareAndSet $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, $value2$, $value1$);
+ assertEquals(r, $value2$, "success compareAndExchange $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, $value1$, "success compareAndExchange $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, $value2$, $value3$);
+ assertEquals(r, $value1$, "failing compareAndExchange $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, $value1$, $value2$);
+ assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, $value1$, $value3$);
+ assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, $value2$, $value1$);
+ assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, $value2$, $value3$);
+ assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, $value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, $value2$, "weakCompareAndSetPlain $type$ 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, $value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, $value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, $value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSet $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, $value1$, "weakCompareAndSet $type$");
+ }
+
+ // Compare set and get
+ {
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, $value2$);
+ assertEquals(o, $value1$, "getAndSet $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, $value2$, "getAndSet $type$ value");
+ }
+#end[CAS]
+
+#if[AtomicAdd]
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, $value2$);
+ assertEquals(o, $value1$, "getAndAdd $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, $value2$);
+ assertEquals(o, $value1$, "getAndAddAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, $value2$);
+ assertEquals(o, $value1$, "getAndAddRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value");
+ }
+#end[AtomicAdd]
+
+#if[Bitwise]
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOr $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAnd $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXor $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value");
+ }
+#end[Bitwise]
+ }
+
+ static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccess$Type$ recv, Handles hs) throws Throwable {
+#if[!CAS]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ checkUOE(am, () -> {
+ boolean r = (boolean) hs.get(am).invokeExact(recv, $value1$, $value2$);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkUOE(am, () -> {
+ $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$, $value2$);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkUOE(am, () -> {
+ $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$);
+ });
+ }
+#end[CAS]
+
+#if[!AtomicAdd]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkUOE(am, () -> {
+ $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$);
+ });
+ }
+#end[AtomicAdd]
+
+#if[!Bitwise]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkUOE(am, () -> {
+ $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$);
+ });
+ }
+#end[Bitwise]
+ }
+
+
+ static void testStaticField(Handles hs) throws Throwable {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact($value1$);
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, $value1$, "set $type$ value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact($value2$);
+ $type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
+ assertEquals(x, $value2$, "setVolatile $type$ value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact($value1$);
+ $type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
+ assertEquals(x, $value1$, "setRelease $type$ value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact($value2$);
+ $type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
+ assertEquals(x, $value2$, "setOpaque $type$ value");
+ }
+
+#if[CAS]
+ hs.get(TestAccessMode.SET).invokeExact($value1$);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value2$);
+ assertEquals(r, true, "success compareAndSet $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, $value2$, "success compareAndSet $type$ value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value3$);
+ assertEquals(r, false, "failing compareAndSet $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, $value2$, "failing compareAndSet $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact($value2$, $value1$);
+ assertEquals(r, $value2$, "success compareAndExchange $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, $value1$, "success compareAndExchange $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact($value2$, $value3$);
+ assertEquals(r, $value1$, "failing compareAndExchange $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value2$);
+ assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value3$);
+ assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value1$);
+ assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value3$);
+ assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact($value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, $value2$, "weakCompareAndSetPlain $type$ value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact($value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact($value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact($value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSet $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, $value1$, "weakCompareAndSet $type$");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact($value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact($value2$);
+ assertEquals(o, $value1$, "getAndSet $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, $value2$, "getAndSet $type$ value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact($value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact($value2$);
+ assertEquals(o, $value1$, "getAndSetAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, $value2$, "getAndSetAcquire $type$ value");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact($value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact($value2$);
+ assertEquals(o, $value1$, "getAndSetRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, $value2$, "getAndSetRelease $type$ value");
+ }
+#end[CAS]
+
+#if[AtomicAdd]
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact($value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact($value2$);
+ assertEquals(o, $value1$, "getAndAdd $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact($value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact($value2$);
+ assertEquals(o, $value1$, "getAndAddAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact($value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact($value2$);
+ assertEquals(o, $value1$, "getAndAddRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value");
+ }
+#end[AtomicAdd]
+
+#if[Bitwise]
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact($value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOr $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact($value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact($value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact($value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAnd $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact($value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact($value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact($value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXor $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact($value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact($value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact($value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value");
+ }
+#end[Bitwise]
+ }
+
+ static void testStaticFieldUnsupported(Handles hs) throws Throwable {
+#if[!CAS]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ checkUOE(am, () -> {
+ boolean r = (boolean) hs.get(am).invokeExact($value1$, $value2$);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkUOE(am, () -> {
+ $type$ r = ($type$) hs.get(am).invokeExact($value1$, $value2$);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkUOE(am, () -> {
+ $type$ r = ($type$) hs.get(am).invokeExact($value1$);
+ });
+ }
+#end[CAS]
+
+#if[!AtomicAdd]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkUOE(am, () -> {
+ $type$ r = ($type$) hs.get(am).invokeExact($value1$);
+ });
+ }
+#end[AtomicAdd]
+
+#if[!Bitwise]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkUOE(am, () -> {
+ $type$ r = ($type$) hs.get(am).invokeExact($value1$);
+ });
+ }
+#end[Bitwise]
+ }
+
+
+ static void testArray(Handles hs) throws Throwable {
+ $type$[] array = new $type$[10];
+
+ for (int i = 0; i < array.length; i++) {
+ // Plain
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, $value1$, "get $type$ value");
+ }
+
+
+ // Volatile
+ {
+ hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, $value2$);
+ $type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
+ assertEquals(x, $value2$, "setVolatile $type$ value");
+ }
+
+ // Lazy
+ {
+ hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, $value1$);
+ $type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
+ assertEquals(x, $value1$, "setRelease $type$ value");
+ }
+
+ // Opaque
+ {
+ hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, $value2$);
+ $type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
+ assertEquals(x, $value2$, "setOpaque $type$ value");
+ }
+
+#if[CAS]
+ hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
+
+ // Compare
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$);
+ assertEquals(r, true, "success compareAndSet $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, $value2$, "success compareAndSet $type$ value");
+ }
+
+ {
+ boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value3$);
+ assertEquals(r, false, "failing compareAndSet $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, $value2$, "failing compareAndSet $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, $value2$, $value1$);
+ assertEquals(r, $value2$, "success compareAndExchange $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, $value1$, "success compareAndExchange $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, $value2$, $value3$);
+ assertEquals(r, $value1$, "failing compareAndExchange $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value2$);
+ assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value3$);
+ assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value1$);
+ assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
+ }
+
+ {
+ $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value3$);
+ assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, $value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetPlain $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, $value2$, "weakCompareAndSetPlain $type$ 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, $value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSetAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
+ }
+
+ {
+ 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, $value1$, $value2$);
+ }
+ assertEquals(success, true, "weakCompareAndSetRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
+ }
+
+ {
+ boolean success = false;
+ for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+ success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, $value2$, $value1$);
+ }
+ assertEquals(success, true, "weakCompareAndSet $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, $value1$, "weakCompareAndSet $type$");
+ }
+
+ // Compare set and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndSet $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, $value2$, "getAndSet $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndSetAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, $value2$, "getAndSetAcquire $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndSetRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, $value2$, "getAndSetRelease $type$ value");
+ }
+#end[CAS]
+
+#if[AtomicAdd]
+ // get and add, add and get
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndAdd $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndAddAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndAddRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value");
+ }
+#end[AtomicAdd]
+
+#if[Bitwise]
+ // get and bitwise or
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOr $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value");
+ }
+
+ // get and bitwise and
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAnd $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value");
+ }
+
+ // get and bitwise xor
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXor $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value");
+ }
+
+ {
+ hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
+
+ $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, $value2$);
+ assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$");
+ $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
+ assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value");
+ }
+#end[Bitwise]
+ }
+ }
+
+ static void testArrayUnsupported(Handles hs) throws Throwable {
+ $type$[] array = new $type$[10];
+
+ final int i = 0;
+#if[!CAS]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ checkUOE(am, () -> {
+ boolean r = (boolean) hs.get(am).invokeExact(array, i, $value1$, $value2$);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkUOE(am, () -> {
+ $type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$, $value2$);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkUOE(am, () -> {
+ $type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$);
+ });
+ }
+#end[CAS]
+
+#if[!AtomicAdd]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkUOE(am, () -> {
+ $type$ o = ($type$) hs.get(am).invokeExact(array, i, $value1$);
+ });
+ }
+#end[AtomicAdd]
+
+#if[!Bitwise]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkUOE(am, () -> {
+ $type$ o = ($type$) hs.get(am).invokeExact(array, i, $value1$);
+ });
+ }
+#end[Bitwise]
+ }
+
+ static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
+ $type$[] array = new $type$[10];
+
+ for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
+ final int ci = i;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ checkIOOBE(am, () -> {
+ $type$ x = ($type$) hs.get(am).invokeExact(array, ci);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ checkIOOBE(am, () -> {
+ hs.get(am).invokeExact(array, ci, $value1$);
+ });
+ }
+
+#if[CAS]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ checkIOOBE(am, () -> {
+ boolean r = (boolean) hs.get(am).invokeExact(array, ci, $value1$, $value2$);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkIOOBE(am, () -> {
+ $type$ r = ($type$) hs.get(am).invokeExact(array, ci, $value2$, $value1$);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkIOOBE(am, () -> {
+ $type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value1$);
+ });
+ }
+#end[CAS]
+
+#if[AtomicAdd]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkIOOBE(am, () -> {
+ $type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value3$);
+ });
+ }
+#end[AtomicAdd]
+
+#if[Bitwise]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkIOOBE(am, () -> {
+ $type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value3$);
+ });
+ }
+#end[Bitwise]
+ }
+ }
+}
+
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/X-VarHandleTestMethodType.java.template b/ojluni/src/test/java/lang/invoke/VarHandles/X-VarHandleTestMethodType.java.template
new file mode 100644
index 0000000..433fc45
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/X-VarHandleTestMethodType.java.template
@@ -0,0 +1,3290 @@
+/*
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8156486
+ * @run testng/othervm VarHandleTestMethodType$Type$
+ * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestMethodType$Type$
+ */
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+import static java.lang.invoke.MethodType.*;
+
+public class VarHandleTestMethodType$Type$ extends VarHandleBaseTest {
+ static final $type$ static_final_v = $value1$;
+
+ static $type$ static_v = $value1$;
+
+ final $type$ final_v = $value1$;
+
+ $type$ v = $value1$;
+
+ VarHandle vhFinalField;
+
+ VarHandle vhField;
+
+ VarHandle vhStaticField;
+
+ VarHandle vhStaticFinalField;
+
+ VarHandle vhArray;
+
+ @BeforeClass
+ public void setup() throws Exception {
+ vhFinalField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodType$Type$.class, "final_v", $type$.class);
+
+ vhField = MethodHandles.lookup().findVarHandle(
+ VarHandleTestMethodType$Type$.class, "v", $type$.class);
+
+ vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodType$Type$.class, "static_final_v", $type$.class);
+
+ vhStaticField = MethodHandles.lookup().findStaticVarHandle(
+ VarHandleTestMethodType$Type$.class, "static_v", $type$.class);
+
+ vhArray = MethodHandles.arrayElementVarHandle($type$[].class);
+ }
+
+ @DataProvider
+ public Object[][] accessTestCaseProvider() throws Exception {
+ List<AccessTestCase<?>> cases = new ArrayList<>();
+
+ cases.add(new VarHandleAccessTestCase("Instance field",
+ vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Static field",
+ vhStaticField, VarHandleTestMethodType$Type$::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new VarHandleAccessTestCase("Array",
+ vhArray, VarHandleTestMethodType$Type$::testArrayWrongMethodType,
+ false));
+
+ for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
+ cases.add(new MethodHandleAccessTestCase("Instance field",
+ vhField, f, hs -> testInstanceFieldWrongMethodType(this, hs),
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Static field",
+ vhStaticField, f, VarHandleTestMethodType$Type$::testStaticFieldWrongMethodType,
+ false));
+
+ cases.add(new MethodHandleAccessTestCase("Array",
+ vhArray, f, VarHandleTestMethodType$Type$::testArrayWrongMethodType,
+ false));
+ }
+ // Work around issue with jtreg summary reporting which truncates
+ // the String result of Object.toString to 30 characters, hence
+ // the first dummy argument
+ return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
+ }
+
+ @Test(dataProvider = "accessTestCaseProvider")
+ public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
+ T t = atc.get();
+ int iters = atc.requiresLoop() ? ITERS : 1;
+ for (int c = 0; c < iters; c++) {
+ atc.testAccess(t);
+ }
+ }
+
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodType$Type$ recv, VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.get(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.get(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ $type$ x = ($type$) vh.get(0);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void x = (Void) vh.get(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.get(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.get();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.get(recv, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.set(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.set(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ vh.set(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(recv, $value1$, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getVolatile(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getVolatile(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ $type$ x = ($type$) vh.getVolatile(0);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void x = (Void) vh.getVolatile(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getVolatile(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getVolatile(recv, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setVolatile(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setVolatile(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ vh.setVolatile(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(recv, $value1$, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getOpaque(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getOpaque(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ $type$ x = ($type$) vh.getOpaque(0);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void x = (Void) vh.getOpaque(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getOpaque(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getOpaque(recv, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setOpaque(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setOpaque(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ vh.setOpaque(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(recv, $value1$, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getAcquire(null);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAcquire(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ $type$ x = ($type$) vh.getAcquire(0);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void x = (Void) vh.getAcquire(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAcquire(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAcquire(recv, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ vh.setRelease(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ vh.setRelease(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ vh.setRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(recv, $value1$, Void.class);
+ });
+
+
+#if[CAS]
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, $value1$, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, $value1$, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ boolean r = vh.compareAndSet(recv, Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ boolean r = vh.compareAndSet(recv, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(recv, $value1$, $value1$, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, $value1$, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, $value1$, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(recv, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(recv, $value1$, $value1$, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, $value1$, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, $value1$, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(recv, Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(recv, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(recv, $value1$, $value1$, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, $value1$, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, $value1$, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(recv, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(recv, $value1$, $value1$, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, $value1$, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, $value1$, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(recv, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(recv, $value1$, $value1$, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.compareAndExchange(null, $value1$, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.compareAndExchange(Void.class, $value1$, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ $type$ x = ($type$) vh.compareAndExchange(recv, Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ $type$ x = ($type$) vh.compareAndExchange(recv, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.compareAndExchange(0, $value1$, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(recv, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchange(recv, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.compareAndExchange(recv, $value1$, $value1$, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.compareAndExchangeAcquire(null, $value1$, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.compareAndExchangeAcquire(Void.class, $value1$, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ $type$ x = ($type$) vh.compareAndExchangeAcquire(recv, Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ $type$ x = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.compareAndExchangeAcquire(0, $value1$, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(recv, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeAcquire(recv, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value1$, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.compareAndExchangeRelease(null, $value1$, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.compareAndExchangeRelease(Void.class, $value1$, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ $type$ x = ($type$) vh.compareAndExchangeRelease(recv, Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ $type$ x = ($type$) vh.compareAndExchangeRelease(recv, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.compareAndExchangeRelease(0, $value1$, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(recv, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeRelease(recv, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.compareAndExchangeRelease(recv, $value1$, $value1$, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getAndSet(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndSet(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndSet(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.getAndSet(0, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndSet(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndSet(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndSet(recv, $value1$, Void.class);
+ });
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getAndSetAcquire(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndSetAcquire(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndSetAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.getAndSetAcquire(0, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndSetAcquire(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndSetAcquire(recv, $value1$, Void.class);
+ });
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getAndSetRelease(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndSetRelease(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndSetRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.getAndSetRelease(0, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndSetRelease(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndSetRelease(recv, $value1$, Void.class);
+ });
+#end[CAS]
+
+#if[AtomicAdd]
+ // GetAndAdd
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getAndAdd(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndAdd(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndAdd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.getAndAdd(0, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndAdd(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndAdd(recv, $value1$, Void.class);
+ });
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getAndAddAcquire(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndAddAcquire(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndAddAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.getAndAddAcquire(0, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndAddAcquire(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndAddAcquire(recv, $value1$, Void.class);
+ });
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getAndAddRelease(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndAddRelease(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndAddRelease(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.getAndAddRelease(0, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndAddRelease(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndAddRelease(recv, $value1$, Void.class);
+ });
+#end[AtomicAdd]
+
+#if[Bitwise]
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getAndBitwiseOr(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndBitwiseOr(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseOr(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.getAndBitwiseOr(0, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseOr(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseOr(recv, $value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getAndBitwiseOrAcquire(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndBitwiseOrAcquire(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseOrAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.getAndBitwiseOrAcquire(0, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseOrAcquire(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseOrAcquire(recv, $value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseOrRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getAndBitwiseOrRelease(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndBitwiseOr(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseOr(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.getAndBitwiseOr(0, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseOr(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseOr(recv, $value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getAndBitwiseAnd(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndBitwiseAnd(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseAnd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.getAndBitwiseAnd(0, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseAnd(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseAnd(recv, $value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getAndBitwiseAndAcquire(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndBitwiseAndAcquire(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseAndAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.getAndBitwiseAndAcquire(0, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseAndAcquire(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseAndAcquire(recv, $value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseAndRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getAndBitwiseAndRelease(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndBitwiseAnd(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseAnd(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.getAndBitwiseAnd(0, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseAnd(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseAnd(recv, $value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getAndBitwiseXor(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndBitwiseXor(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseXor(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.getAndBitwiseXor(0, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseXor(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseXor(recv, $value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getAndBitwiseXorAcquire(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndBitwiseXorAcquire(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseXorAcquire(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.getAndBitwiseXorAcquire(0, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseXorAcquire(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseXorAcquire(recv, $value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseXorRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.getAndBitwiseXorRelease(null, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ $type$ x = ($type$) vh.getAndBitwiseXor(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseXor(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) vh.getAndBitwiseXor(0, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseXor(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseXor(recv, $value1$, Void.class);
+ });
+#end[Bitwise]
+ }
+
+ static void testInstanceFieldWrongMethodType(VarHandleTestMethodType$Type$ recv, Handles hs) throws Throwable {
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class)).
+ invokeExact((VarHandleTestMethodType$Type$) null);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class)).
+ invokeExact(0);
+ });
+ // Incorrect return type
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodType$Type$.class)).
+ invokeExact(recv);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, VarHandleTestMethodType$Type$.class)).
+ invokeExact(recv);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) hs.get(am, methodType($type$.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ hs.get(am, methodType(void.class, VarHandleTestMethodType$Type$.class, $type$.class)).
+ invokeExact((VarHandleTestMethodType$Type$) null, $value1$);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ hs.get(am, methodType(void.class, Class.class, $type$.class)).
+ invokeExact(Void.class, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // value reference class
+ hs.get(am, methodType(void.class, VarHandleTestMethodType$Type$.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, $type$.class)).
+ invokeExact(0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, VarHandleTestMethodType$Type$.class, $type$.class, Class.class)).
+ invokeExact(recv, $value1$, Void.class);
+ });
+ }
+
+#if[CAS]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodType$Type$.class, $type$.class, $type$.class)).
+ invokeExact((VarHandleTestMethodType$Type$) null, $value1$, $value1$);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, $type$.class, $type$.class)).
+ invokeExact(Void.class, $value1$, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodType$Type$.class, Class.class, $type$.class)).
+ invokeExact(recv, Void.class, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodType$Type$.class, $type$.class, Class.class)).
+ invokeExact(recv, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , $type$.class, $type$.class)).
+ invokeExact(0, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodType$Type$.class, $type$.class, $type$.class, Class.class)).
+ invokeExact(recv, $value1$, $value1$, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, $type$.class, $type$.class)).
+ invokeExact((VarHandleTestMethodType$Type$) null, $value1$, $value1$);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, $type$.class, $type$.class)).
+ invokeExact(Void.class, $value1$, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // expected reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, Class.class, $type$.class)).
+ invokeExact(recv, Void.class, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // actual reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, $type$.class, Class.class)).
+ invokeExact(recv, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class , $type$.class, $type$.class)).
+ invokeExact(0, $value1$, $value1$);
+ });
+ // Incorrect return type
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodType$Type$.class , $type$.class, $type$.class)).
+ invokeExact(recv, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, VarHandleTestMethodType$Type$.class , $type$.class, $type$.class)).
+ invokeExact(recv, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) hs.get(am, methodType($type$.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, $type$.class, $type$.class, Class.class)).
+ invokeExact(recv, $value1$, $value1$, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, $type$.class)).
+ invokeExact((VarHandleTestMethodType$Type$) null, $value1$);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, $type$.class)).
+ invokeExact(Void.class, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // value reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class, $type$.class)).
+ invokeExact(0, $value1$);
+ });
+ // Incorrect return type
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodType$Type$.class, $type$.class)).
+ invokeExact(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, VarHandleTestMethodType$Type$.class, $type$.class)).
+ invokeExact(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) hs.get(am, methodType($type$.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, $type$.class)).
+ invokeExact(recv, $value1$, Void.class);
+ });
+ }
+#end[CAS]
+
+#if[AtomicAdd]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, $type$.class)).
+ invokeExact((VarHandleTestMethodType$Type$) null, $value1$);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, $type$.class)).
+ invokeExact(Void.class, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // value reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class, $type$.class)).
+ invokeExact(0, $value1$);
+ });
+ // Incorrect return type
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodType$Type$.class, $type$.class)).
+ invokeExact(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, VarHandleTestMethodType$Type$.class, $type$.class)).
+ invokeExact(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) hs.get(am, methodType($type$.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, $type$.class)).
+ invokeExact(recv, $value1$, Void.class);
+ });
+ }
+#end[AtomicAdd]
+
+#if[Bitwise]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, $type$.class)).
+ invokeExact((VarHandleTestMethodType$Type$) null, $value1$);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, $type$.class)).
+ invokeExact(Void.class, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // value reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, Class.class)).
+ invokeExact(recv, Void.class);
+ });
+ checkWMTE(() -> { // reciever primitive class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class, $type$.class)).
+ invokeExact(0, $value1$);
+ });
+ // Incorrect return type
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodType$Type$.class, $type$.class)).
+ invokeExact(recv, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, VarHandleTestMethodType$Type$.class, $type$.class)).
+ invokeExact(recv, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) hs.get(am, methodType($type$.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, $type$.class)).
+ invokeExact(recv, $value1$, Void.class);
+ });
+ }
+#end[Bitwise]
+ }
+
+
+ static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
+ // Get
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void x = (Void) vh.get();
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.get();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.get(Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ vh.set(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set($value1$, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void x = (Void) vh.getVolatile();
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getVolatile(Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ vh.setVolatile(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile($value1$, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void x = (Void) vh.getOpaque();
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getOpaque(Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ vh.setOpaque(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque($value1$, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void x = (Void) vh.getAcquire();
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAcquire(Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ vh.setRelease(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease($value1$, Void.class);
+ });
+
+
+#if[CAS]
+ // CompareAndSet
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ boolean r = vh.compareAndSet(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ boolean r = vh.compareAndSet($value1$, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet($value1$, $value1$, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain($value1$, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain($value1$, $value1$, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet($value1$, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet($value1$, $value1$, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire($value1$, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire($value1$, $value1$, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease($value1$, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease($value1$, $value1$, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ $type$ x = ($type$) vh.compareAndExchange(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ $type$ x = ($type$) vh.compareAndExchange($value1$, Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange($value1$, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchange($value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.compareAndExchange($value1$, $value1$, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ $type$ x = ($type$) vh.compareAndExchangeAcquire(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ $type$ x = ($type$) vh.compareAndExchangeAcquire($value1$, Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire($value1$, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeAcquire($value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.compareAndExchangeAcquire($value1$, $value1$, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ $type$ x = ($type$) vh.compareAndExchangeRelease(Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ $type$ x = ($type$) vh.compareAndExchangeRelease($value1$, Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease($value1$, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeRelease($value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.compareAndExchangeRelease($value1$, $value1$, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndSet(Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndSet($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndSet($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndSet($value1$, Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndSetAcquire(Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndSetAcquire($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndSetAcquire($value1$, Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndSetRelease(Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndSetRelease($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndSetRelease($value1$, Void.class);
+ });
+#end[CAS]
+
+#if[AtomicAdd]
+ // GetAndAdd
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndAdd(Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndAdd($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndAdd($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndAdd($value1$, Void.class);
+ });
+
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndAddAcquire(Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndAddAcquire($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndAddAcquire($value1$, Void.class);
+ });
+
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndAddRelease(Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndAddRelease($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndAddRelease($value1$, Void.class);
+ });
+#end[AtomicAdd]
+
+#if[Bitwise]
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseOr(Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseOr($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseOr($value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseOrAcquire(Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseOrAcquire($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseOrAcquire($value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseOrReleaseRelease
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseOrRelease(Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrRelease($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseOrRelease($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseOrRelease();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseOrRelease($value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseAnd(Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseAnd($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseAnd($value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseAndAcquire(Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseAndAcquire($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseAndAcquire($value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseAndReleaseRelease
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseAndRelease(Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndRelease($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseAndRelease($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseAndRelease();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseAndRelease($value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseXor(Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseXor($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseXor($value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseXorAcquire(Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseXorAcquire($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseXorAcquire($value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseXorReleaseRelease
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseXorRelease(Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorRelease($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseXorRelease($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseXorRelease();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseXorRelease($value1$, Void.class);
+ });
+#end[Bitwise]
+ }
+
+ static void testStaticFieldWrongMethodType(Handles hs) throws Throwable {
+ int i = 0;
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect return type
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class)).
+ invokeExact();
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) hs.get(am, methodType(Class.class)).
+ invokeExact(Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // value reference class
+ hs.get(am, methodType(void.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, $type$.class, Class.class)).
+ invokeExact($value1$, Void.class);
+ });
+ }
+#if[CAS]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, $type$.class)).
+ invokeExact(Void.class, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, $type$.class, Class.class)).
+ invokeExact($value1$, Void.class);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, $type$.class, $type$.class, Class.class)).
+ invokeExact($value1$, $value1$, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // expected reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, $type$.class)).
+ invokeExact(Void.class, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // actual reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$.class, Class.class)).
+ invokeExact($value1$, Void.class);
+ });
+ // Incorrect return type
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, $type$.class, $type$.class)).
+ invokeExact($value1$, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, $type$.class, $type$.class)).
+ invokeExact($value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) hs.get(am, methodType($type$.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$.class, $type$.class, Class.class)).
+ invokeExact($value1$, $value1$, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // value reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, $type$.class)).
+ invokeExact($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, $type$.class)).
+ invokeExact($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) hs.get(am, methodType($type$.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$.class, Class.class)).
+ invokeExact($value1$, Void.class);
+ });
+ }
+#end[CAS]
+
+#if[AtomicAdd]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, $type$.class)).
+ invokeExact($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, $type$.class)).
+ invokeExact($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) hs.get(am, methodType($type$.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$.class, Class.class)).
+ invokeExact($value1$, Void.class);
+ });
+ }
+#end[AtomicAdd]
+
+#if[Bitwise]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ // Incorrect argument types
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class)).
+ invokeExact(Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, $type$.class)).
+ invokeExact($value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, $type$.class)).
+ invokeExact($value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) hs.get(am, methodType($type$.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$.class, Class.class)).
+ invokeExact($value1$, Void.class);
+ });
+ }
+#end[Bitwise]
+ }
+
+
+ static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
+ $type$[] array = new $type$[10];
+ Arrays.fill(array, $value1$);
+
+ // Get
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.get(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.get(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.get(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.get(array, Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void x = (Void) vh.get(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.get(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.get();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.get(array, 0, Void.class);
+ });
+
+
+ // Set
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.set(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ vh.set(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ vh.set(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.set(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.set(array, Void.class, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.set();
+ });
+ checkWMTE(() -> { // >
+ vh.set(array, 0, $value1$, Void.class);
+ });
+
+
+ // GetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getVolatile(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getVolatile(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.getVolatile(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getVolatile(array, Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void x = (Void) vh.getVolatile(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getVolatile(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getVolatile();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getVolatile(array, 0, Void.class);
+ });
+
+
+ // SetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setVolatile(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setVolatile(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ vh.setVolatile(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setVolatile(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setVolatile(array, Void.class, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setVolatile();
+ });
+ checkWMTE(() -> { // >
+ vh.setVolatile(array, 0, $value1$, Void.class);
+ });
+
+
+ // GetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getOpaque(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getOpaque(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.getOpaque(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getOpaque(array, Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void x = (Void) vh.getOpaque(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getOpaque(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getOpaque();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getOpaque(array, 0, Void.class);
+ });
+
+
+ // SetOpaque
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setOpaque(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setOpaque(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ vh.setOpaque(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setOpaque(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setOpaque(array, Void.class, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setOpaque();
+ });
+ checkWMTE(() -> { // >
+ vh.setOpaque(array, 0, $value1$, Void.class);
+ });
+
+
+ // GetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getAcquire(null, 0);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getAcquire(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.getAcquire(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getAcquire(array, Void.class);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void x = (Void) vh.getAcquire(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAcquire(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAcquire(array, 0, Void.class);
+ });
+
+
+ // SetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ vh.setRelease(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ vh.setRelease(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ vh.setRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ vh.setRelease(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ vh.setRelease(array, Void.class, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ vh.setRelease();
+ });
+ checkWMTE(() -> { // >
+ vh.setRelease(array, 0, $value1$, Void.class);
+ });
+
+
+#if[CAS]
+ // CompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.compareAndSet(null, 0, $value1$, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.compareAndSet(Void.class, 0, $value1$, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ boolean r = vh.compareAndSet(array, 0, Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ boolean r = vh.compareAndSet(array, 0, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.compareAndSet(0, 0, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.compareAndSet(array, Void.class, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.compareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.compareAndSet(array, 0, $value1$, $value1$, Void.class);
+ });
+
+
+ // WeakCompareAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetPlain(null, 0, $value1$, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetPlain(Void.class, 0, $value1$, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetPlain(array, 0, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetPlain(0, 0, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetPlain(array, Void.class, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetPlain();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetPlain(array, 0, $value1$, $value1$, Void.class);
+ });
+
+
+ // WeakCompareAndSetVolatile
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSet(null, 0, $value1$, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSet(Void.class, 0, $value1$, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSet(array, 0, Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSet(array, 0, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSet(0, 0, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSet(array, Void.class, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSet();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSet(array, 0, $value1$, $value1$, Void.class);
+ });
+
+
+ // WeakCompareAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetAcquire(null, 0, $value1$, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetAcquire(Void.class, 0, $value1$, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetAcquire(0, 0, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetAcquire(array, Void.class, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetAcquire(array, 0, $value1$, $value1$, Void.class);
+ });
+
+
+ // WeakCompareAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = vh.weakCompareAndSetRelease(null, 0, $value1$, $value1$);
+ });
+ checkCCE(() -> { // receiver reference class
+ boolean r = vh.weakCompareAndSetRelease(Void.class, 0, $value1$, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ boolean r = vh.weakCompareAndSetRelease(array, 0, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = vh.weakCompareAndSetRelease(0, 0, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = vh.weakCompareAndSetRelease(array, Void.class, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = vh.weakCompareAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ boolean r = vh.weakCompareAndSetRelease(array, 0, $value1$, $value1$, Void.class);
+ });
+
+
+ // CompareAndExchange
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.compareAndExchange(null, 0, $value1$, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.compareAndExchange(Void.class, 0, $value1$, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ $type$ x = ($type$) vh.compareAndExchange(array, 0, Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ $type$ x = ($type$) vh.compareAndExchange(array, 0, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.compareAndExchange(0, 0, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.compareAndExchange(array, Void.class, $value1$, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.compareAndExchange(array, 0, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchange(array, 0, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.compareAndExchange();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.compareAndExchange(array, 0, $value1$, $value1$, Void.class);
+ });
+
+
+ // CompareAndExchangeAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.compareAndExchangeAcquire(null, 0, $value1$, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.compareAndExchangeAcquire(Void.class, 0, $value1$, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ $type$ x = ($type$) vh.compareAndExchangeAcquire(array, 0, Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ $type$ x = ($type$) vh.compareAndExchangeAcquire(array, 0, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.compareAndExchangeAcquire(0, 0, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.compareAndExchangeAcquire(array, Void.class, $value1$, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeAcquire(array, 0, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeAcquire(array, 0, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.compareAndExchangeAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.compareAndExchangeAcquire(array, 0, $value1$, $value1$, Void.class);
+ });
+
+
+ // CompareAndExchangeRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) vh.compareAndExchangeRelease(null, 0, $value1$, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.compareAndExchangeRelease(Void.class, 0, $value1$, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // expected reference class
+ $type$ x = ($type$) vh.compareAndExchangeRelease(array, 0, Void.class, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // actual reference class
+ $type$ x = ($type$) vh.compareAndExchangeRelease(array, 0, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.compareAndExchangeRelease(0, 0, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.compareAndExchangeRelease(array, Void.class, $value1$, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.compareAndExchangeRelease(array, 0, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeRelease(array, 0, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.compareAndExchangeRelease();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.compareAndExchangeRelease(array, 0, $value1$, $value1$, Void.class);
+ });
+
+
+ // GetAndSet
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getAndSet(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getAndSet(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndSet(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ $type$ x = ($type$) vh.getAndSet(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getAndSet(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndSet(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndSet(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndSet();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndSet(array, 0, $value1$, Void.class);
+ });
+
+
+ // GetAndSetAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getAndSetAcquire(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getAndSetAcquire(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndSetAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ $type$ x = ($type$) vh.getAndSetAcquire(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getAndSetAcquire(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndSetAcquire(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndSetAcquire(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndSetAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndSetAcquire(array, 0, $value1$, Void.class);
+ });
+
+
+ // GetAndSetRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getAndSetRelease(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getAndSetRelease(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndSetRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // reciarrayever primitive class
+ $type$ x = ($type$) vh.getAndSetRelease(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getAndSetRelease(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndSetRelease(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndSetRelease(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndSetRelease();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndSetRelease(array, 0, $value1$, Void.class);
+ });
+#end[CAS]
+
+#if[AtomicAdd]
+ // GetAndAdd
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getAndAdd(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getAndAdd(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndAdd(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.getAndAdd(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getAndAdd(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndAdd(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndAdd(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndAdd();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndAdd(array, 0, $value1$, Void.class);
+ });
+
+
+ // GetAndAddAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getAndAddAcquire(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getAndAddAcquire(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndAddAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.getAndAddAcquire(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getAndAddAcquire(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndAddAcquire(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndAddAcquire(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndAddAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndAddAcquire(array, 0, $value1$, Void.class);
+ });
+
+
+ // GetAndAddRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getAndAddRelease(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getAndAddRelease(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndAddRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.getAndAddRelease(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getAndAddRelease(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndAddRelease(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndAddRelease(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndAddRelease();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndAddRelease(array, 0, $value1$, Void.class);
+ });
+#end[AtomicAdd]
+
+#if[Bitwise]
+ // GetAndBitwiseOr
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getAndBitwiseOr(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getAndBitwiseOr(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseOr(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.getAndBitwiseOr(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getAndBitwiseOr(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOr(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseOr(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseOr();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseOr(array, 0, $value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseOrAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getAndBitwiseOrAcquire(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getAndBitwiseOrAcquire(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseOrAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.getAndBitwiseOrAcquire(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getAndBitwiseOrAcquire(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrAcquire(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseOrAcquire(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseOrAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseOrAcquire(array, 0, $value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseOrRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getAndBitwiseOrRelease(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getAndBitwiseOrRelease(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseOrRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.getAndBitwiseOrRelease(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getAndBitwiseOrRelease(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseOrRelease(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseOrRelease(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseOrRelease();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseOrRelease(array, 0, $value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseAnd
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getAndBitwiseAnd(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getAndBitwiseAnd(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseAnd(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.getAndBitwiseAnd(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getAndBitwiseAnd(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAnd(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseAnd(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseAnd();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseAnd(array, 0, $value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseAndAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getAndBitwiseAndAcquire(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getAndBitwiseAndAcquire(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseAndAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.getAndBitwiseAndAcquire(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getAndBitwiseAndAcquire(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndAcquire(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseAndAcquire(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseAndAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseAndAcquire(array, 0, $value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseAndRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getAndBitwiseAndRelease(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getAndBitwiseAndRelease(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseAndRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.getAndBitwiseAndRelease(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getAndBitwiseAndRelease(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseAndRelease(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseAndRelease(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseAndRelease();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseAndRelease(array, 0, $value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseXor
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getAndBitwiseXor(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getAndBitwiseXor(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseXor(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.getAndBitwiseXor(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getAndBitwiseXor(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXor(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseXor(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseXor();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseXor(array, 0, $value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseXorAcquire
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getAndBitwiseXorAcquire(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getAndBitwiseXorAcquire(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseXorAcquire(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.getAndBitwiseXorAcquire(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getAndBitwiseXorAcquire(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorAcquire(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseXorAcquire(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseXorAcquire();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseXorAcquire(array, 0, $value1$, Void.class);
+ });
+
+
+ // GetAndBitwiseXorRelease
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) vh.getAndBitwiseXorRelease(null, 0, $value1$);
+ });
+ checkCCE(() -> { // array reference class
+ $type$ x = ($type$) vh.getAndBitwiseXorRelease(Void.class, 0, $value1$);
+ });
+ check{#if[String]?CCE:WMTE}(() -> { // value reference class
+ $type$ x = ($type$) vh.getAndBitwiseXorRelease(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) vh.getAndBitwiseXorRelease(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) vh.getAndBitwiseXorRelease(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ check{#if[String]?CCE:WMTE}(() -> { // reference class
+ Void r = (Void) vh.getAndBitwiseXorRelease(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndBitwiseXorRelease(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) vh.getAndBitwiseXorRelease();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) vh.getAndBitwiseXorRelease(array, 0, $value1$, Void.class);
+ });
+#end[Bitwise]
+ }
+
+ static void testArrayWrongMethodType(Handles hs) throws Throwable {
+ $type$[] array = new $type$[10];
+ Arrays.fill(array, $value1$);
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class)).
+ invokeExact(($type$[]) null, 0);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, int.class)).
+ invokeExact(Void.class, 0);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class, int.class)).
+ invokeExact(0, 0);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, Class.class)).
+ invokeExact(array, Void.class);
+ });
+ // Incorrect return type
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // reference class
+ Void x = (Void) hs.get(am, methodType(Void.class, $type$[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, $type$[].class, int.class)).
+ invokeExact(array, 0);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) hs.get(am, methodType($type$.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ hs.get(am, methodType(void.class, $type$[].class, int.class, $type$.class)).
+ invokeExact(($type$[]) null, 0, $value1$);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ hs.get(am, methodType(void.class, Class.class, int.class, $type$.class)).
+ invokeExact(Void.class, 0, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // value reference class
+ hs.get(am, methodType(void.class, $type$[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ hs.get(am, methodType(void.class, int.class, int.class, $type$.class)).
+ invokeExact(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ hs.get(am, methodType(void.class, $type$[].class, Class.class, $type$.class)).
+ invokeExact(array, Void.class, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ hs.get(am, methodType(void.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ hs.get(am, methodType(void.class, $type$[].class, int.class, Class.class)).
+ invokeExact(array, 0, $value1$, Void.class);
+ });
+ }
+#if[CAS]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, $type$[].class, int.class, $type$.class, $type$.class)).
+ invokeExact(($type$[]) null, 0, $value1$, $value1$);
+ });
+ hs.checkWMTEOrCCE(() -> { // receiver reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, $type$.class, $type$.class)).
+ invokeExact(Void.class, 0, $value1$, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // expected reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, $type$[].class, int.class, Class.class, $type$.class)).
+ invokeExact(array, 0, Void.class, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // actual reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, $type$[].class, int.class, $type$.class, Class.class)).
+ invokeExact(array, 0, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // receiver primitive class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, $type$.class, $type$.class)).
+ invokeExact(0, 0, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, $type$[].class, Class.class, $type$.class, $type$.class)).
+ invokeExact(array, Void.class, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ boolean r = (boolean) hs.get(am, methodType(boolean.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ boolean r = (boolean) hs.get(am, methodType(boolean.class, $type$[].class, int.class, $type$.class, $type$.class, Class.class)).
+ invokeExact(array, 0, $value1$, $value1$, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null receiver
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, $type$.class, $type$.class)).
+ invokeExact(($type$[]) null, 0, $value1$, $value1$);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, int.class, $type$.class, $type$.class)).
+ invokeExact(Void.class, 0, $value1$, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // expected reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, Class.class, $type$.class)).
+ invokeExact(array, 0, Void.class, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // actual reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, $type$.class, Class.class)).
+ invokeExact(array, 0, $value1$, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class, int.class, $type$.class, $type$.class)).
+ invokeExact(0, 0, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, Class.class, $type$.class, $type$.class)).
+ invokeExact(array, Void.class, $value1$, $value1$);
+ });
+ // Incorrect return type
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, $type$[].class, int.class, $type$.class, $type$.class)).
+ invokeExact(array, 0, $value1$, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, $type$[].class, int.class, $type$.class, $type$.class)).
+ invokeExact(array, 0, $value1$, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) hs.get(am, methodType($type$.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, $type$.class, $type$.class, Class.class)).
+ invokeExact(array, 0, $value1$, $value1$, Void.class);
+ });
+ }
+
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, $type$.class)).
+ invokeExact(($type$[]) null, 0, $value1$);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, int.class, $type$.class)).
+ invokeExact(Void.class, 0, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // value reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class, int.class, $type$.class)).
+ invokeExact(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, Class.class, $type$.class)).
+ invokeExact(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, $type$[].class, int.class, $type$.class)).
+ invokeExact(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, $type$[].class, int.class, $type$.class)).
+ invokeExact(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) hs.get(am, methodType($type$.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, $type$.class, Class.class)).
+ invokeExact(array, 0, $value1$, Void.class);
+ });
+ }
+#end[CAS]
+
+#if[AtomicAdd]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, $type$.class)).
+ invokeExact(($type$[]) null, 0, $value1$);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, int.class, $type$.class)).
+ invokeExact(Void.class, 0, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // value reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class, int.class, $type$.class)).
+ invokeExact(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, Class.class, $type$.class)).
+ invokeExact(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, $type$[].class, int.class, $type$.class)).
+ invokeExact(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, $type$[].class, int.class, $type$.class)).
+ invokeExact(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) hs.get(am, methodType($type$.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, $type$.class, Class.class)).
+ invokeExact(array, 0, $value1$, Void.class);
+ });
+ }
+#end[AtomicAdd]
+
+#if[Bitwise]
+ for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
+ // Incorrect argument types
+ checkNPE(() -> { // null array
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, $type$.class)).
+ invokeExact(($type$[]) null, 0, $value1$);
+ });
+ hs.checkWMTEOrCCE(() -> { // array reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, int.class, $type$.class)).
+ invokeExact(Void.class, 0, $value1$);
+ });
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // value reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, Class.class)).
+ invokeExact(array, 0, Void.class);
+ });
+ checkWMTE(() -> { // array primitive class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class, int.class, $type$.class)).
+ invokeExact(0, 0, $value1$);
+ });
+ checkWMTE(() -> { // index reference class
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, Class.class, $type$.class)).
+ invokeExact(array, Void.class, $value1$);
+ });
+ // Incorrect return type
+ {#if[String]?hs.checkWMTEOrCCE:checkWMTE}(() -> { // reference class
+ Void r = (Void) hs.get(am, methodType(Void.class, $type$[].class, int.class, $type$.class)).
+ invokeExact(array, 0, $value1$);
+ });
+ checkWMTE(() -> { // primitive class
+ $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, $type$[].class, int.class, $type$.class)).
+ invokeExact(array, 0, $value1$);
+ });
+ // Incorrect arity
+ checkWMTE(() -> { // 0
+ $type$ x = ($type$) hs.get(am, methodType($type$.class)).
+ invokeExact();
+ });
+ checkWMTE(() -> { // >
+ $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, $type$.class, Class.class)).
+ invokeExact(array, 0, $value1$, Void.class);
+ });
+ }
+#end[Bitwise]
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/TestFieldLookupAccessibility.java b/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/TestFieldLookupAccessibility.java
new file mode 100644
index 0000000..636751f
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/TestFieldLookupAccessibility.java
@@ -0,0 +1,226 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+ * @bug 8152645
+ * @summary test field lookup accessibility of MethodHandles and VarHandles
+ * @compile TestFieldLookupAccessibility.java
+ * pkg/A.java pkg/B_extends_A.java pkg/C.java
+ * pkg/subpkg/B_extends_A.java pkg/subpkg/C.java
+ * @run testng/othervm TestFieldLookupAccessibility
+ */
+
+import org.testng.Assert;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+import pkg.B_extends_A;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class TestFieldLookupAccessibility {
+
+ // The set of possible field lookup mechanisms
+ enum FieldLookup {
+ MH_GETTER() {
+ Object lookup(MethodHandles.Lookup l, Field f) throws Exception {
+ return l.findGetter(f.getDeclaringClass(), f.getName(), f.getType());
+ }
+
+ boolean isAccessible(Field f) {
+ return !Modifier.isStatic(f.getModifiers());
+ }
+ },
+ MH_SETTER() {
+ Object lookup(MethodHandles.Lookup l, Field f) throws Exception {
+ return l.findSetter(f.getDeclaringClass(), f.getName(), f.getType());
+ }
+
+ boolean isAccessible(Field f) {
+ return !Modifier.isStatic(f.getModifiers()) && !Modifier.isFinal(f.getModifiers());
+ }
+ },
+ MH_STATIC_GETTER() {
+ Object lookup(MethodHandles.Lookup l, Field f) throws Exception {
+ return l.findStaticGetter(f.getDeclaringClass(), f.getName(), f.getType());
+ }
+
+ boolean isAccessible(Field f) {
+ return Modifier.isStatic(f.getModifiers());
+ }
+ },
+ MH_STATIC_SETTER() {
+ Object lookup(MethodHandles.Lookup l, Field f) throws Exception {
+ return l.findStaticSetter(f.getDeclaringClass(), f.getName(), f.getType());
+ }
+
+ boolean isAccessible(Field f) {
+ return Modifier.isStatic(f.getModifiers()) && !Modifier.isFinal(f.getModifiers());
+ }
+ },
+ MH_UNREFLECT_GETTER() {
+ Object lookup(MethodHandles.Lookup l, Field f) throws Exception {
+ return l.unreflectGetter(f);
+ }
+ },
+ MH_UNREFLECT_GETTER_ACCESSIBLE() {
+ Object lookup(MethodHandles.Lookup l, Field f) throws Exception {
+ return l.unreflectGetter(cloneAndSetAccessible(f));
+ }
+ },
+ MH_UNREFLECT_SETTER() {
+ Object lookup(MethodHandles.Lookup l, Field f) throws Exception {
+ return l.unreflectSetter(f);
+ }
+
+ boolean isAccessible(Field f) {
+ return f.isAccessible() || !Modifier.isFinal(f.getModifiers());
+ }
+ },
+ MH_UNREFLECT_SETTER_ACCESSIBLE() {
+ Object lookup(MethodHandles.Lookup l, Field f) throws Exception {
+ return l.unreflectSetter(cloneAndSetAccessible(f));
+ }
+ },
+ VH() {
+ Object lookup(MethodHandles.Lookup l, Field f) throws Exception {
+ return l.findVarHandle(f.getDeclaringClass(), f.getName(), f.getType());
+ }
+
+ boolean isAccessible(Field f) {
+ return !Modifier.isStatic(f.getModifiers());
+ }
+ },
+ VH_STATIC() {
+ Object lookup(MethodHandles.Lookup l, Field f) throws Exception {
+ return l.findStaticVarHandle(f.getDeclaringClass(), f.getName(), f.getType());
+ }
+
+ boolean isAccessible(Field f) {
+ return Modifier.isStatic(f.getModifiers());
+ }
+ },
+ VH_UNREFLECT() {
+ Object lookup(MethodHandles.Lookup l, Field f) throws Exception {
+ return l.unreflectVarHandle(f);
+ }
+ };
+
+ // Look up a handle to a field
+ abstract Object lookup(MethodHandles.Lookup l, Field f) throws Exception;
+
+ boolean isAccessible(Field f) {
+ return true;
+ }
+
+ static Field cloneAndSetAccessible(Field f) throws Exception {
+ // Clone to avoid mutating source field
+ f = f.getDeclaringClass().getDeclaredField(f.getName());
+ f.setAccessible(true);
+ return f;
+ }
+ }
+
+ @DataProvider
+ public Object[][] lookupProvider() throws Exception {
+ Stream<List<Object>> baseCases = Stream.of(
+ // Look up from same package
+ List.of(pkg.A.class, pkg.A.lookup(), pkg.A.inaccessibleFields()),
+ List.of(pkg.A.class, pkg.A.lookup(), pkg.A.inaccessibleFields()),
+ List.of(pkg.A.class, B_extends_A.lookup(), B_extends_A.inaccessibleFields()),
+ List.of(pkg.A.class, pkg.C.lookup(), pkg.C.inaccessibleFields()),
+
+ // Look up from sub-package
+ List.of(pkg.A.class, pkg.subpkg.B_extends_A.lookup(), pkg.subpkg.B_extends_A.inaccessibleFields()),
+ List.of(pkg.A.class, pkg.subpkg.C.lookup(), pkg.subpkg.C.inaccessibleFields())
+ );
+
+ // Cross product base cases with the field lookup classes
+ return baseCases.
+ flatMap(l -> Stream.of(FieldLookup.values()).map(fl -> prepend(fl, l))).
+ toArray(Object[][]::new);
+ }
+
+ private static Object[] prepend(Object o, List<Object> l) {
+ List<Object> pl = new ArrayList<>();
+ pl.add(o);
+ pl.addAll(l);
+ return pl.toArray();
+ }
+
+ @Test(dataProvider = "lookupProvider")
+ public void test(FieldLookup fl, Class<?> src, MethodHandles.Lookup l, Set<String> inaccessibleFields) {
+ // Add to the expected failures all inaccessible fields due to accessibility modifiers
+ Set<String> expected = new HashSet<>(inaccessibleFields);
+ Map<Field, Throwable> actual = new HashMap<>();
+
+ for (Field f : fields(src)) {
+ // Add to the expected failures all inaccessible fields due to static/final modifiers
+ if (!fl.isAccessible(f)) {
+ expected.add(f.getName());
+ }
+
+ try {
+ fl.lookup(l, f);
+ }
+ catch (Throwable t) {
+ // Lookup failed, add to the actual failures
+ actual.put(f, t);
+ }
+ }
+
+ Set<String> actualFieldNames = actual.keySet().stream().map(Field::getName).
+ collect(Collectors.toSet());
+ if (!actualFieldNames.equals(expected)) {
+ if (actualFieldNames.isEmpty()) {
+ // Setting the accessibility bit of a Field grants access under
+ // all conditions for MethodHander getters and setters
+ if (fl != FieldLookup.MH_UNREFLECT_GETTER_ACCESSIBLE &&
+ fl != FieldLookup.MH_UNREFLECT_SETTER_ACCESSIBLE) {
+ Assert.assertEquals(actualFieldNames, expected, "No accessibility failures:");
+ }
+ }
+ else {
+ Assert.assertEquals(actualFieldNames, expected, "Accessibility failures differ:");
+ }
+ }
+ else {
+ if (!actual.values().stream().allMatch(IllegalAccessException.class::isInstance)) {
+ Assert.fail("Expecting an IllegalArgumentException for all failures " + actual);
+ }
+ }
+ }
+
+ static List<Field> fields(Class<?> src) {
+ return List.of(src.getDeclaredFields());
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/A.java b/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/A.java
new file mode 100644
index 0000000..c81bf4d
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/A.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package pkg;
+
+
+import java.lang.invoke.MethodHandles;
+import java.util.Set;
+
+public class A {
+ public static Object f_public_static;
+ protected static Object f_protected_static;
+ static /*package*/ Object f_package_static;
+ private static Object f_private_static;
+
+ public static final Object f_public_static_final = null;
+ protected static final Object f_protected_static_final = null;
+ static /*package*/ final Object f_package_static_final = null;
+ private static final Object f_private_static_final = null;
+
+ public Object f_public;
+ protected Object f_protected;
+ /*package*/ Object f_package;
+ private Object f_private;
+
+ public final Object f_public_final = null;
+ protected final Object f_protected_final = null;
+ /*package*/ final Object f_package_final = null;
+ private final Object f_private_final = null;
+
+ //
+
+ public static MethodHandles.Lookup lookup() {
+ return MethodHandles.lookup();
+ }
+
+ public static Set<String> inaccessibleFields() {
+ // All fields of pkg.A are accessible to itself
+ return Set.of();
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/B_extends_A.java b/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/B_extends_A.java
new file mode 100644
index 0000000..026f7cc
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/B_extends_A.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package pkg;
+
+
+import java.lang.invoke.MethodHandles;
+import java.util.Set;
+
+public class B_extends_A extends A {
+ public static MethodHandles.Lookup lookup() {
+ return MethodHandles.lookup();
+ }
+
+ public static Set<String> inaccessibleFields() {
+ // Only private fields of pkg.A are not accessible to subclass pkg.B
+ // Note: protected fields are also package accessible
+ return Set.of(
+ "f_private",
+ "f_private_final",
+ "f_private_static",
+ "f_private_static_final"
+ );
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/C.java b/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/C.java
new file mode 100644
index 0000000..fcf1f0b
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/C.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package pkg;
+
+
+import java.lang.invoke.MethodHandles;
+import java.util.Set;
+
+public class C {
+ public static MethodHandles.Lookup lookup() {
+ return MethodHandles.lookup();
+ }
+
+ public static Set<String> inaccessibleFields() {
+ // Only private fields of pkg.A are not accessible to independent
+ // class pkg.C
+ // Note: protected fields are also package accessible
+ return Set.of(
+ "f_private",
+ "f_private_final",
+ "f_private_static",
+ "f_private_static_final"
+ );
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/subpkg/B_extends_A.java b/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/subpkg/B_extends_A.java
new file mode 100644
index 0000000..0ee5fba
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/subpkg/B_extends_A.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package pkg.subpkg;
+
+
+import pkg.A;
+
+import java.lang.invoke.MethodHandles;
+import java.util.Set;
+
+public class B_extends_A extends A {
+ public static MethodHandles.Lookup lookup() {
+ return MethodHandles.lookup();
+ }
+
+ public static Set<String> inaccessibleFields() {
+ // Only public and protected fields of pkg.A are accessible to subclass
+ // pkg.subpkg.B
+ return Set.of(
+ "f_private",
+ "f_private_final",
+ "f_package",
+ "f_package_final",
+ "f_private_static",
+ "f_private_static_final",
+ "f_package_static",
+ "f_package_static_final"
+ );
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/subpkg/C.java b/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/subpkg/C.java
new file mode 100644
index 0000000..c2fd8ac
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/accessibility/pkg/subpkg/C.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package pkg.subpkg;
+
+
+import java.lang.invoke.MethodHandles;
+import java.util.Set;
+
+public class C {
+ public static MethodHandles.Lookup lookup() {
+ return MethodHandles.lookup();
+ }
+
+ public static Set<String> inaccessibleFields() {
+ // Only public fields of pkg.A are accessible to independent
+ // class pkg.subpkg.C
+ return Set.of(
+ "f_private",
+ "f_private_final",
+ "f_protected",
+ "f_protected_final",
+ "f_package",
+ "f_package_final",
+ "f_private_static",
+ "f_private_static_final",
+ "f_protected_static",
+ "f_protected_static_final",
+ "f_package_static",
+ "f_package_static_final"
+ );
+ }
+}
diff --git a/ojluni/src/test/java/lang/invoke/VarHandles/generate-vh-tests.sh b/ojluni/src/test/java/lang/invoke/VarHandles/generate-vh-tests.sh
new file mode 100644
index 0000000..5d489a1
--- /dev/null
+++ b/ojluni/src/test/java/lang/invoke/VarHandles/generate-vh-tests.sh
@@ -0,0 +1,167 @@
+#!/bin/bash
+
+javac -d . ../../../../../../make/jdk/src/classes/build/tools/spp/Spp.java
+
+SPP=build.tools.spp.Spp
+
+# Generates variable handle tests for objects and all primitive types
+# This is likely to be a temporary testing approach as it may be more
+# desirable to generate code using ASM which will allow more flexibility
+# in the kinds of tests that are generated.
+
+for type in boolean byte short char int long float double String
+do
+ Type="$(tr '[:lower:]' '[:upper:]' <<< ${type:0:1})${type:1}"
+ args="-K$type -Dtype=$type -DType=$Type"
+
+ args="$args -KCAS"
+
+ case $type in
+ byte|short|char|int|long|float|double)
+ args="$args -KAtomicAdd"
+ ;;
+ esac
+
+ case $type in
+ boolean|byte|short|char|int|long)
+ args="$args -KBitwise"
+ ;;
+ esac
+
+ wrong_primitive_type=boolean
+
+ case $type in
+ boolean)
+ value1=true
+ value2=false
+ value3=false
+ wrong_primitive_type=int
+ ;;
+ byte)
+ value1=(byte)0x01
+ value2=(byte)0x23
+ value3=(byte)0x45
+ ;;
+ short)
+ value1=(short)0x0123
+ value2=(short)0x4567
+ value3=(short)0x89AB
+ ;;
+ char)
+ value1=\'\\\\u0123\'
+ value2=\'\\\\u4567\'
+ value3=\'\\\\u89AB\'
+ ;;
+ int)
+ value1=0x01234567
+ value2=0x89ABCDEF
+ value3=0xCAFEBABE
+ ;;
+ long)
+ value1=0x0123456789ABCDEFL
+ value2=0xCAFEBABECAFEBABEL
+ value3=0xDEADBEEFDEADBEEFL
+ ;;
+ float)
+ value1=1.0f
+ value2=2.0f
+ value3=3.0f
+ ;;
+ double)
+ value1=1.0d
+ value2=2.0d
+ value3=3.0d
+ ;;
+ String)
+ value1=\"foo\"
+ value2=\"bar\"
+ value3=\"baz\"
+ ;;
+ esac
+
+ args="$args -Dvalue1=$value1 -Dvalue2=$value2 -Dvalue3=$value3 -Dwrong_primitive_type=$wrong_primitive_type"
+
+ echo $args
+ java $SPP -nel $args < X-VarHandleTestAccess.java.template > VarHandleTestAccess${Type}.java
+ java $SPP -nel $args < X-VarHandleTestMethodHandleAccess.java.template > VarHandleTestMethodHandleAccess${Type}.java
+ java $SPP -nel $args < X-VarHandleTestMethodType.java.template > VarHandleTestMethodType${Type}.java
+done
+
+for type in short char int long float double
+do
+ Type="$(tr '[:lower:]' '[:upper:]' <<< ${type:0:1})${type:1}"
+ args="-K$type -Dtype=$type -DType=$Type"
+
+ BoxType=$Type
+ case $type in
+ char)
+ BoxType=Character
+ ;;
+ int)
+ BoxType=Integer
+ ;;
+ esac
+ args="$args -DBoxType=$BoxType"
+
+ case $type in
+ int|long|float|double)
+ args="$args -KCAS"
+ ;;
+ esac
+
+ case $type in
+ int|long)
+ args="$args -KAtomicAdd"
+ ;;
+ esac
+
+ case $type in
+ int|long)
+ args="$args -KBitwise"
+ ;;
+ esac
+
+ # The value of `value3` is chosen such that when added to `value1` or `value2`
+ # it will result in carrying of bits over to the next byte, thereby detecting
+ # possible errors in endianness conversion e.g. if say for atomic addition the
+ # augend is incorrectly processed
+ case $type in
+ short)
+ value1=(short)0x0102
+ value2=(short)0x1112
+ value3=(short)0xFFFE
+ ;;
+ char)
+ value1=(char)0x0102
+ value2=(char)0x1112
+ value3=(char)0xFFFE
+ ;;
+ int)
+ value1=0x01020304
+ value2=0x11121314
+ value3=0xFFFEFDFC
+ ;;
+ long)
+ value1=0x0102030405060708L
+ value2=0x1112131415161718L
+ value3=0xFFFEFDFCFBFAF9F8L
+ ;;
+ float)
+ value1=0x01020304
+ value2=0x11121314
+ value3=0xFFFEFDFC
+ ;;
+ double)
+ value1=0x0102030405060708L
+ value2=0x1112131415161718L
+ value3=0xFFFEFDFCFBFAF9F8L
+ ;;
+ esac
+
+ args="$args -Dvalue1=$value1 -Dvalue2=$value2 -Dvalue3=$value3"
+
+ echo $args
+ java $SPP -nel $args < X-VarHandleTestByteArrayView.java.template > VarHandleTestByteArrayAs${Type}.java
+done
+
+rm -fr build