1 /*
   2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @compile -XDenableValueTypes Value.java
  27  * @run testng/othervm -Xverify:none -Diters=10    -Xint                   VarHandleTestAccessLong
  28  */
  29 /* Disabled temporarily for lworld
  30  * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessLong
  31  * @run testng/othervm -Diters=20000                         VarHandleTestAccessLong
  32  * @run testng/othervm -Diters=20000 -XX:-TieredCompilation  VarHandleTestAccessLong
  33  */
  34 
  35 import org.testng.annotations.BeforeClass;
  36 import org.testng.annotations.DataProvider;
  37 import org.testng.annotations.Test;
  38 
  39 import java.lang.invoke.MethodHandles;
  40 import java.lang.invoke.VarHandle;
  41 import java.util.ArrayList;
  42 import java.util.Arrays;
  43 import java.util.List;
  44 
  45 import static org.testng.Assert.*;
  46 
  47 public class VarHandleTestAccessLong extends VarHandleBaseTest {
  48     static final long static_final_v = 0x0123456789ABCDEFL;
  49 
  50     static long static_v;
  51 
  52     final long final_v = 0x0123456789ABCDEFL;
  53 
  54     long v;
  55 
  56     VarHandle vhFinalField;
  57 
  58     VarHandle vhField;
  59 
  60     VarHandle vhStaticField;
  61 
  62     VarHandle vhStaticFinalField;
  63 
  64     VarHandle vhArray;
  65 
  66     VarHandle vhValueTypeField;
  67 
  68     @BeforeClass
  69     public void setup() throws Exception {
  70         vhFinalField = MethodHandles.lookup().findVarHandle(
  71                 VarHandleTestAccessLong.class, "final_v", long.class);
  72 
  73         vhField = MethodHandles.lookup().findVarHandle(
  74                 VarHandleTestAccessLong.class, "v", long.class);
  75 
  76         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
  77             VarHandleTestAccessLong.class, "static_final_v", long.class);
  78 
  79         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
  80             VarHandleTestAccessLong.class, "static_v", long.class);
  81 
  82         vhArray = MethodHandles.arrayElementVarHandle(long[].class);
  83 
  84         vhValueTypeField = MethodHandles.lookup().findVarHandle(
  85                     Value.class, "long_v", long.class);
  86     }
  87 
  88 
  89     @DataProvider
  90     public Object[][] varHandlesProvider() throws Exception {
  91         List<VarHandle> vhs = new ArrayList<>();
  92         vhs.add(vhField);
  93         vhs.add(vhStaticField);
  94         vhs.add(vhArray);
  95 
  96         return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
  97     }
  98 
  99     @Test(dataProvider = "varHandlesProvider")
 100     public void testIsAccessModeSupported(VarHandle vh) {
 101         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
 102         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
 103         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
 104         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
 105         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
 106         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
 107         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
 108         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
 109 
 110         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
 111         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
 112         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
 113         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
 114         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
 115         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
 116         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
 117         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
 118         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
 119         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
 120         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
 121 
 122         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
 123         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
 124         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
 125 
 126         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
 127         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
 128         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
 129         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
 130         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
 131         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
 132         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
 133         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
 134         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
 135     }
 136 
 137 
 138     @DataProvider
 139     public Object[][] typesProvider() throws Exception {
 140         List<Object[]> types = new ArrayList<>();
 141         types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessLong.class)});
 142         types.add(new Object[] {vhStaticField, Arrays.asList()});
 143         types.add(new Object[] {vhArray, Arrays.asList(long[].class, int.class)});
 144 
 145         return types.stream().toArray(Object[][]::new);
 146     }
 147 
 148     @Test(dataProvider = "typesProvider")
 149     public void testTypes(VarHandle vh, List<Class<?>> pts) {
 150         assertEquals(vh.varType(), long.class);
 151 
 152         assertEquals(vh.coordinateTypes(), pts);
 153 
 154         testTypes(vh);
 155     }
 156 
 157 
 158     @Test
 159     public void testLookupInstanceToStatic() {
 160         checkIAE("Lookup of static final field to instance final field", () -> {
 161             MethodHandles.lookup().findStaticVarHandle(
 162                     VarHandleTestAccessLong.class, "final_v", long.class);
 163         });
 164 
 165         checkIAE("Lookup of static field to instance field", () -> {
 166             MethodHandles.lookup().findStaticVarHandle(
 167                     VarHandleTestAccessLong.class, "v", long.class);
 168         });
 169     }
 170 
 171     @Test
 172     public void testLookupStaticToInstance() {
 173         checkIAE("Lookup of instance final field to static final field", () -> {
 174             MethodHandles.lookup().findVarHandle(
 175                 VarHandleTestAccessLong.class, "static_final_v", long.class);
 176         });
 177 
 178         checkIAE("Lookup of instance field to static field", () -> {
 179             vhStaticField = MethodHandles.lookup().findVarHandle(
 180                 VarHandleTestAccessLong.class, "static_v", long.class);
 181         });
 182     }
 183 
 184 
 185     @DataProvider
 186     public Object[][] accessTestCaseProvider() throws Exception {
 187         List<AccessTestCase<?>> cases = new ArrayList<>();
 188 
 189         cases.add(new VarHandleAccessTestCase("Instance final field",
 190                                               vhFinalField, vh -> testInstanceFinalField(this, vh)));
 191         cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
 192                                               vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
 193                                               false));
 194 
 195         cases.add(new VarHandleAccessTestCase("Static final field",
 196                                               vhStaticFinalField, VarHandleTestAccessLong::testStaticFinalField));
 197         cases.add(new VarHandleAccessTestCase("Static final field unsupported",
 198                                               vhStaticFinalField, VarHandleTestAccessLong::testStaticFinalFieldUnsupported,
 199                                               false));
 200 
 201         cases.add(new VarHandleAccessTestCase("Instance field",
 202                                               vhField, vh -> testInstanceField(this, vh)));
 203         cases.add(new VarHandleAccessTestCase("Instance field unsupported",
 204                                               vhField, vh -> testInstanceFieldUnsupported(this, vh),
 205                                               false));
 206 
 207         cases.add(new VarHandleAccessTestCase("Static field",
 208                                               vhStaticField, VarHandleTestAccessLong::testStaticField));
 209         cases.add(new VarHandleAccessTestCase("Static field unsupported",
 210                                               vhStaticField, VarHandleTestAccessLong::testStaticFieldUnsupported,
 211                                               false));
 212 
 213         cases.add(new VarHandleAccessTestCase("Array",
 214                                               vhArray, VarHandleTestAccessLong::testArray));
 215         cases.add(new VarHandleAccessTestCase("Array unsupported",
 216                                               vhArray, VarHandleTestAccessLong::testArrayUnsupported,
 217                                               false));
 218         cases.add(new VarHandleAccessTestCase("Array index out of bounds",
 219                                               vhArray, VarHandleTestAccessLong::testArrayIndexOutOfBounds,
 220                                               false));
 221         cases.add(new VarHandleAccessTestCase("Value type field",
 222                                               vhValueTypeField, vh -> testValueTypeField(Value.VT, vh)));
 223         cases.add(new VarHandleAccessTestCase("Value type field unsupported",
 224                                               vhValueTypeField, vh -> testValueTypeFieldUnsupported(Value.VT, vh),
 225                                               false));
 226 
 227         // Work around issue with jtreg summary reporting which truncates
 228         // the String result of Object.toString to 30 characters, hence
 229         // the first dummy argument
 230         return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
 231     }
 232 
 233     @Test(dataProvider = "accessTestCaseProvider")
 234     public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
 235         T t = atc.get();
 236         int iters = atc.requiresLoop() ? ITERS : 1;
 237         for (int c = 0; c < iters; c++) {
 238             atc.testAccess(t);
 239         }
 240     }
 241 
 242 
 243 
 244 
 245     static void testInstanceFinalField(VarHandleTestAccessLong recv, VarHandle vh) {
 246         // Plain
 247         {
 248             long x = (long) vh.get(recv);
 249             assertEquals(x, 0x0123456789ABCDEFL, "get long value");
 250         }
 251 
 252 
 253         // Volatile
 254         {
 255             long x = (long) vh.getVolatile(recv);
 256             assertEquals(x, 0x0123456789ABCDEFL, "getVolatile long value");
 257         }
 258 
 259         // Lazy
 260         {
 261             long x = (long) vh.getAcquire(recv);
 262             assertEquals(x, 0x0123456789ABCDEFL, "getRelease long value");
 263         }
 264 
 265         // Opaque
 266         {
 267             long x = (long) vh.getOpaque(recv);
 268             assertEquals(x, 0x0123456789ABCDEFL, "getOpaque long value");
 269         }
 270     }
 271 
 272     static void testInstanceFinalFieldUnsupported(VarHandleTestAccessLong recv, VarHandle vh) {
 273         checkUOE(() -> {
 274             vh.set(recv, 0xCAFEBABECAFEBABEL);
 275         });
 276 
 277         checkUOE(() -> {
 278             vh.setVolatile(recv, 0xCAFEBABECAFEBABEL);
 279         });
 280 
 281         checkUOE(() -> {
 282             vh.setRelease(recv, 0xCAFEBABECAFEBABEL);
 283         });
 284 
 285         checkUOE(() -> {
 286             vh.setOpaque(recv, 0xCAFEBABECAFEBABEL);
 287         });
 288 
 289 
 290 
 291     }
 292 
 293     static void testValueTypeField(Value recv, VarHandle vh) {
 294         // Plain
 295         {
 296             long x = (long) vh.get(recv);
 297             assertEquals(x, 0x0123456789ABCDEFL, "get long value");
 298         }
 299     }
 300 
 301     static void testValueTypeFieldUnsupported(Value recv, VarHandle vh) {
 302         checkUOE(() -> {
 303             vh.set(recv, 0xCAFEBABECAFEBABEL);
 304         });
 305     }
 306 
 307     static void testStaticFinalField(VarHandle vh) {
 308         // Plain
 309         {
 310             long x = (long) vh.get();
 311             assertEquals(x, 0x0123456789ABCDEFL, "get long value");
 312         }
 313 
 314 
 315         // Volatile
 316         {
 317             long x = (long) vh.getVolatile();
 318             assertEquals(x, 0x0123456789ABCDEFL, "getVolatile long value");
 319         }
 320 
 321         // Lazy
 322         {
 323             long x = (long) vh.getAcquire();
 324             assertEquals(x, 0x0123456789ABCDEFL, "getRelease long value");
 325         }
 326 
 327         // Opaque
 328         {
 329             long x = (long) vh.getOpaque();
 330             assertEquals(x, 0x0123456789ABCDEFL, "getOpaque long value");
 331         }
 332     }
 333 
 334     static void testStaticFinalFieldUnsupported(VarHandle vh) {
 335         checkUOE(() -> {
 336             vh.set(0xCAFEBABECAFEBABEL);
 337         });
 338 
 339         checkUOE(() -> {
 340             vh.setVolatile(0xCAFEBABECAFEBABEL);
 341         });
 342 
 343         checkUOE(() -> {
 344             vh.setRelease(0xCAFEBABECAFEBABEL);
 345         });
 346 
 347         checkUOE(() -> {
 348             vh.setOpaque(0xCAFEBABECAFEBABEL);
 349         });
 350 
 351 
 352 
 353     }
 354 
 355 
 356     static void testInstanceField(VarHandleTestAccessLong recv, VarHandle vh) {
 357         // Plain
 358         {
 359             vh.set(recv, 0x0123456789ABCDEFL);
 360             long x = (long) vh.get(recv);
 361             assertEquals(x, 0x0123456789ABCDEFL, "set long value");
 362         }
 363 
 364 
 365         // Volatile
 366         {
 367             vh.setVolatile(recv, 0xCAFEBABECAFEBABEL);
 368             long x = (long) vh.getVolatile(recv);
 369             assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
 370         }
 371 
 372         // Lazy
 373         {
 374             vh.setRelease(recv, 0x0123456789ABCDEFL);
 375             long x = (long) vh.getAcquire(recv);
 376             assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
 377         }
 378 
 379         // Opaque
 380         {
 381             vh.setOpaque(recv, 0xCAFEBABECAFEBABEL);
 382             long x = (long) vh.getOpaque(recv);
 383             assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
 384         }
 385 
 386         vh.set(recv, 0x0123456789ABCDEFL);
 387 
 388         // Compare
 389         {
 390             boolean r = vh.compareAndSet(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 391             assertEquals(r, true, "success compareAndSet long");
 392             long x = (long) vh.get(recv);
 393             assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
 394         }
 395 
 396         {
 397             boolean r = vh.compareAndSet(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
 398             assertEquals(r, false, "failing compareAndSet long");
 399             long x = (long) vh.get(recv);
 400             assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
 401         }
 402 
 403         {
 404             long r = (long) vh.compareAndExchange(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 405             assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
 406             long x = (long) vh.get(recv);
 407             assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
 408         }
 409 
 410         {
 411             long r = (long) vh.compareAndExchange(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
 412             assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
 413             long x = (long) vh.get(recv);
 414             assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
 415         }
 416 
 417         {
 418             long r = (long) vh.compareAndExchangeAcquire(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 419             assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
 420             long x = (long) vh.get(recv);
 421             assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
 422         }
 423 
 424         {
 425             long r = (long) vh.compareAndExchangeAcquire(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
 426             assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
 427             long x = (long) vh.get(recv);
 428             assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
 429         }
 430 
 431         {
 432             long r = (long) vh.compareAndExchangeRelease(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 433             assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
 434             long x = (long) vh.get(recv);
 435             assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
 436         }
 437 
 438         {
 439             long r = (long) vh.compareAndExchangeRelease(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
 440             assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
 441             long x = (long) vh.get(recv);
 442             assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
 443         }
 444 
 445         {
 446             boolean success = false;
 447             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 448                 success = vh.weakCompareAndSetPlain(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 449             }
 450             assertEquals(success, true, "weakCompareAndSetPlain long");
 451             long x = (long) vh.get(recv);
 452             assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetPlain long value");
 453         }
 454 
 455         {
 456             boolean success = false;
 457             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 458                 success = vh.weakCompareAndSetAcquire(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 459             }
 460             assertEquals(success, true, "weakCompareAndSetAcquire long");
 461             long x = (long) vh.get(recv);
 462             assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
 463         }
 464 
 465         {
 466             boolean success = false;
 467             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 468                 success = vh.weakCompareAndSetRelease(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 469             }
 470             assertEquals(success, true, "weakCompareAndSetRelease long");
 471             long x = (long) vh.get(recv);
 472             assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
 473         }
 474 
 475         {
 476             boolean success = false;
 477             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 478                 success = vh.weakCompareAndSet(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 479             }
 480             assertEquals(success, true, "weakCompareAndSet long");
 481             long x = (long) vh.get(recv);
 482             assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSet long value");
 483         }
 484 
 485         // Compare set and get
 486         {
 487             vh.set(recv, 0x0123456789ABCDEFL);
 488 
 489             long o = (long) vh.getAndSet(recv, 0xCAFEBABECAFEBABEL);
 490             assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
 491             long x = (long) vh.get(recv);
 492             assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
 493         }
 494 
 495         {
 496             vh.set(recv, 0x0123456789ABCDEFL);
 497 
 498             long o = (long) vh.getAndSetAcquire(recv, 0xCAFEBABECAFEBABEL);
 499             assertEquals(o, 0x0123456789ABCDEFL, "getAndSetAcquire long");
 500             long x = (long) vh.get(recv);
 501             assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetAcquire long value");
 502         }
 503 
 504         {
 505             vh.set(recv, 0x0123456789ABCDEFL);
 506 
 507             long o = (long) vh.getAndSetRelease(recv, 0xCAFEBABECAFEBABEL);
 508             assertEquals(o, 0x0123456789ABCDEFL, "getAndSetRelease long");
 509             long x = (long) vh.get(recv);
 510             assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetRelease long value");
 511         }
 512 
 513         // get and add, add and get
 514         {
 515             vh.set(recv, 0x0123456789ABCDEFL);
 516 
 517             long o = (long) vh.getAndAdd(recv, 0xCAFEBABECAFEBABEL);
 518             assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
 519             long x = (long) vh.get(recv);
 520             assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value");
 521         }
 522 
 523         {
 524             vh.set(recv, 0x0123456789ABCDEFL);
 525 
 526             long o = (long) vh.getAndAddAcquire(recv, 0xCAFEBABECAFEBABEL);
 527             assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long");
 528             long x = (long) vh.get(recv);
 529             assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value");
 530         }
 531 
 532         {
 533             vh.set(recv, 0x0123456789ABCDEFL);
 534 
 535             long o = (long) vh.getAndAddRelease(recv, 0xCAFEBABECAFEBABEL);
 536             assertEquals(o, 0x0123456789ABCDEFL, "getAndAddReleaselong");
 537             long x = (long) vh.get(recv);
 538             assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value");
 539         }
 540 
 541         // get and bitwise or
 542         {
 543             vh.set(recv, 0x0123456789ABCDEFL);
 544 
 545             long o = (long) vh.getAndBitwiseOr(recv, 0xCAFEBABECAFEBABEL);
 546             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long");
 547             long x = (long) vh.get(recv);
 548             assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value");
 549         }
 550 
 551         {
 552             vh.set(recv, 0x0123456789ABCDEFL);
 553 
 554             long o = (long) vh.getAndBitwiseOrAcquire(recv, 0xCAFEBABECAFEBABEL);
 555             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long");
 556             long x = (long) vh.get(recv);
 557             assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value");
 558         }
 559 
 560         {
 561             vh.set(recv, 0x0123456789ABCDEFL);
 562 
 563             long o = (long) vh.getAndBitwiseOrRelease(recv, 0xCAFEBABECAFEBABEL);
 564             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long");
 565             long x = (long) vh.get(recv);
 566             assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value");
 567         }
 568 
 569         // get and bitwise and
 570         {
 571             vh.set(recv, 0x0123456789ABCDEFL);
 572 
 573             long o = (long) vh.getAndBitwiseAnd(recv, 0xCAFEBABECAFEBABEL);
 574             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long");
 575             long x = (long) vh.get(recv);
 576             assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value");
 577         }
 578 
 579         {
 580             vh.set(recv, 0x0123456789ABCDEFL);
 581 
 582             long o = (long) vh.getAndBitwiseAndAcquire(recv, 0xCAFEBABECAFEBABEL);
 583             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long");
 584             long x = (long) vh.get(recv);
 585             assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value");
 586         }
 587 
 588         {
 589             vh.set(recv, 0x0123456789ABCDEFL);
 590 
 591             long o = (long) vh.getAndBitwiseAndRelease(recv, 0xCAFEBABECAFEBABEL);
 592             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long");
 593             long x = (long) vh.get(recv);
 594             assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value");
 595         }
 596 
 597         // get and bitwise xor
 598         {
 599             vh.set(recv, 0x0123456789ABCDEFL);
 600 
 601             long o = (long) vh.getAndBitwiseXor(recv, 0xCAFEBABECAFEBABEL);
 602             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long");
 603             long x = (long) vh.get(recv);
 604             assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value");
 605         }
 606 
 607         {
 608             vh.set(recv, 0x0123456789ABCDEFL);
 609 
 610             long o = (long) vh.getAndBitwiseXorAcquire(recv, 0xCAFEBABECAFEBABEL);
 611             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long");
 612             long x = (long) vh.get(recv);
 613             assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value");
 614         }
 615 
 616         {
 617             vh.set(recv, 0x0123456789ABCDEFL);
 618 
 619             long o = (long) vh.getAndBitwiseXorRelease(recv, 0xCAFEBABECAFEBABEL);
 620             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long");
 621             long x = (long) vh.get(recv);
 622             assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value");
 623         }
 624     }
 625 
 626     static void testInstanceFieldUnsupported(VarHandleTestAccessLong recv, VarHandle vh) {
 627 
 628 
 629     }
 630 
 631 
 632     static void testStaticField(VarHandle vh) {
 633         // Plain
 634         {
 635             vh.set(0x0123456789ABCDEFL);
 636             long x = (long) vh.get();
 637             assertEquals(x, 0x0123456789ABCDEFL, "set long value");
 638         }
 639 
 640 
 641         // Volatile
 642         {
 643             vh.setVolatile(0xCAFEBABECAFEBABEL);
 644             long x = (long) vh.getVolatile();
 645             assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
 646         }
 647 
 648         // Lazy
 649         {
 650             vh.setRelease(0x0123456789ABCDEFL);
 651             long x = (long) vh.getAcquire();
 652             assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
 653         }
 654 
 655         // Opaque
 656         {
 657             vh.setOpaque(0xCAFEBABECAFEBABEL);
 658             long x = (long) vh.getOpaque();
 659             assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
 660         }
 661 
 662         vh.set(0x0123456789ABCDEFL);
 663 
 664         // Compare
 665         {
 666             boolean r = vh.compareAndSet(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 667             assertEquals(r, true, "success compareAndSet long");
 668             long x = (long) vh.get();
 669             assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
 670         }
 671 
 672         {
 673             boolean r = vh.compareAndSet(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
 674             assertEquals(r, false, "failing compareAndSet long");
 675             long x = (long) vh.get();
 676             assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
 677         }
 678 
 679         {
 680             long r = (long) vh.compareAndExchange(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 681             assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
 682             long x = (long) vh.get();
 683             assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
 684         }
 685 
 686         {
 687             long r = (long) vh.compareAndExchange(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
 688             assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
 689             long x = (long) vh.get();
 690             assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
 691         }
 692 
 693         {
 694             long r = (long) vh.compareAndExchangeAcquire(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 695             assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
 696             long x = (long) vh.get();
 697             assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
 698         }
 699 
 700         {
 701             long r = (long) vh.compareAndExchangeAcquire(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
 702             assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
 703             long x = (long) vh.get();
 704             assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
 705         }
 706 
 707         {
 708             long r = (long) vh.compareAndExchangeRelease(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 709             assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
 710             long x = (long) vh.get();
 711             assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
 712         }
 713 
 714         {
 715             long r = (long) vh.compareAndExchangeRelease(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
 716             assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
 717             long x = (long) vh.get();
 718             assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
 719         }
 720 
 721         {
 722             boolean success = false;
 723             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 724                 success = vh.weakCompareAndSetPlain(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 725             }
 726             assertEquals(success, true, "weakCompareAndSetPlain long");
 727             long x = (long) vh.get();
 728             assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetPlain long value");
 729         }
 730 
 731         {
 732             boolean success = false;
 733             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 734                 success = vh.weakCompareAndSetAcquire(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 735             }
 736             assertEquals(success, true, "weakCompareAndSetAcquire long");
 737             long x = (long) vh.get();
 738             assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
 739         }
 740 
 741         {
 742             boolean success = false;
 743             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 744                 success = vh.weakCompareAndSetRelease(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 745             }
 746             assertEquals(success, true, "weakCompareAndSetRelease long");
 747             long x = (long) vh.get();
 748             assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
 749         }
 750 
 751         {
 752             boolean success = false;
 753             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 754                 success = vh.weakCompareAndSet(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 755             }
 756             assertEquals(success, true, "weakCompareAndSet long");
 757             long x = (long) vh.get();
 758             assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSet long");
 759         }
 760 
 761         // Compare set and get
 762         {
 763             vh.set(0x0123456789ABCDEFL);
 764 
 765             long o = (long) vh.getAndSet(0xCAFEBABECAFEBABEL);
 766             assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
 767             long x = (long) vh.get();
 768             assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
 769         }
 770 
 771         {
 772             vh.set(0x0123456789ABCDEFL);
 773 
 774             long o = (long) vh.getAndSetAcquire(0xCAFEBABECAFEBABEL);
 775             assertEquals(o, 0x0123456789ABCDEFL, "getAndSetAcquire long");
 776             long x = (long) vh.get();
 777             assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetAcquire long value");
 778         }
 779 
 780         {
 781             vh.set(0x0123456789ABCDEFL);
 782 
 783             long o = (long) vh.getAndSetRelease(0xCAFEBABECAFEBABEL);
 784             assertEquals(o, 0x0123456789ABCDEFL, "getAndSetRelease long");
 785             long x = (long) vh.get();
 786             assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetRelease long value");
 787         }
 788 
 789         // get and add, add and get
 790         {
 791             vh.set(0x0123456789ABCDEFL);
 792 
 793             long o = (long) vh.getAndAdd(0xCAFEBABECAFEBABEL);
 794             assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
 795             long x = (long) vh.get();
 796             assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value");
 797         }
 798 
 799         {
 800             vh.set(0x0123456789ABCDEFL);
 801 
 802             long o = (long) vh.getAndAddAcquire(0xCAFEBABECAFEBABEL);
 803             assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long");
 804             long x = (long) vh.get();
 805             assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value");
 806         }
 807 
 808         {
 809             vh.set(0x0123456789ABCDEFL);
 810 
 811             long o = (long) vh.getAndAddRelease(0xCAFEBABECAFEBABEL);
 812             assertEquals(o, 0x0123456789ABCDEFL, "getAndAddReleaselong");
 813             long x = (long) vh.get();
 814             assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value");
 815         }
 816 
 817         // get and bitwise or
 818         {
 819             vh.set(0x0123456789ABCDEFL);
 820 
 821             long o = (long) vh.getAndBitwiseOr(0xCAFEBABECAFEBABEL);
 822             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long");
 823             long x = (long) vh.get();
 824             assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value");
 825         }
 826 
 827         {
 828             vh.set(0x0123456789ABCDEFL);
 829 
 830             long o = (long) vh.getAndBitwiseOrAcquire(0xCAFEBABECAFEBABEL);
 831             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long");
 832             long x = (long) vh.get();
 833             assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value");
 834         }
 835 
 836         {
 837             vh.set(0x0123456789ABCDEFL);
 838 
 839             long o = (long) vh.getAndBitwiseOrRelease(0xCAFEBABECAFEBABEL);
 840             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long");
 841             long x = (long) vh.get();
 842             assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value");
 843         }
 844 
 845         // get and bitwise and
 846         {
 847             vh.set(0x0123456789ABCDEFL);
 848 
 849             long o = (long) vh.getAndBitwiseAnd(0xCAFEBABECAFEBABEL);
 850             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long");
 851             long x = (long) vh.get();
 852             assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value");
 853         }
 854 
 855         {
 856             vh.set(0x0123456789ABCDEFL);
 857 
 858             long o = (long) vh.getAndBitwiseAndAcquire(0xCAFEBABECAFEBABEL);
 859             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long");
 860             long x = (long) vh.get();
 861             assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value");
 862         }
 863 
 864         {
 865             vh.set(0x0123456789ABCDEFL);
 866 
 867             long o = (long) vh.getAndBitwiseAndRelease(0xCAFEBABECAFEBABEL);
 868             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long");
 869             long x = (long) vh.get();
 870             assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value");
 871         }
 872 
 873         // get and bitwise xor
 874         {
 875             vh.set(0x0123456789ABCDEFL);
 876 
 877             long o = (long) vh.getAndBitwiseXor(0xCAFEBABECAFEBABEL);
 878             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long");
 879             long x = (long) vh.get();
 880             assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value");
 881         }
 882 
 883         {
 884             vh.set(0x0123456789ABCDEFL);
 885 
 886             long o = (long) vh.getAndBitwiseXorAcquire(0xCAFEBABECAFEBABEL);
 887             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long");
 888             long x = (long) vh.get();
 889             assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value");
 890         }
 891 
 892         {
 893             vh.set(0x0123456789ABCDEFL);
 894 
 895             long o = (long) vh.getAndBitwiseXorRelease(0xCAFEBABECAFEBABEL);
 896             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long");
 897             long x = (long) vh.get();
 898             assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value");
 899         }
 900     }
 901 
 902     static void testStaticFieldUnsupported(VarHandle vh) {
 903 
 904 
 905     }
 906 
 907 
 908     static void testArray(VarHandle vh) {
 909         long[] array = new long[10];
 910 
 911         for (int i = 0; i < array.length; i++) {
 912             // Plain
 913             {
 914                 vh.set(array, i, 0x0123456789ABCDEFL);
 915                 long x = (long) vh.get(array, i);
 916                 assertEquals(x, 0x0123456789ABCDEFL, "get long value");
 917             }
 918 
 919 
 920             // Volatile
 921             {
 922                 vh.setVolatile(array, i, 0xCAFEBABECAFEBABEL);
 923                 long x = (long) vh.getVolatile(array, i);
 924                 assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
 925             }
 926 
 927             // Lazy
 928             {
 929                 vh.setRelease(array, i, 0x0123456789ABCDEFL);
 930                 long x = (long) vh.getAcquire(array, i);
 931                 assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
 932             }
 933 
 934             // Opaque
 935             {
 936                 vh.setOpaque(array, i, 0xCAFEBABECAFEBABEL);
 937                 long x = (long) vh.getOpaque(array, i);
 938                 assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
 939             }
 940 
 941             vh.set(array, i, 0x0123456789ABCDEFL);
 942 
 943             // Compare
 944             {
 945                 boolean r = vh.compareAndSet(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 946                 assertEquals(r, true, "success compareAndSet long");
 947                 long x = (long) vh.get(array, i);
 948                 assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
 949             }
 950 
 951             {
 952                 boolean r = vh.compareAndSet(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
 953                 assertEquals(r, false, "failing compareAndSet long");
 954                 long x = (long) vh.get(array, i);
 955                 assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
 956             }
 957 
 958             {
 959                 long r = (long) vh.compareAndExchange(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 960                 assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
 961                 long x = (long) vh.get(array, i);
 962                 assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
 963             }
 964 
 965             {
 966                 long r = (long) vh.compareAndExchange(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
 967                 assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
 968                 long x = (long) vh.get(array, i);
 969                 assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
 970             }
 971 
 972             {
 973                 long r = (long) vh.compareAndExchangeAcquire(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 974                 assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
 975                 long x = (long) vh.get(array, i);
 976                 assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
 977             }
 978 
 979             {
 980                 long r = (long) vh.compareAndExchangeAcquire(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
 981                 assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
 982                 long x = (long) vh.get(array, i);
 983                 assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
 984             }
 985 
 986             {
 987                 long r = (long) vh.compareAndExchangeRelease(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 988                 assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
 989                 long x = (long) vh.get(array, i);
 990                 assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
 991             }
 992 
 993             {
 994                 long r = (long) vh.compareAndExchangeRelease(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
 995                 assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
 996                 long x = (long) vh.get(array, i);
 997                 assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
 998             }
 999 
1000             {
1001                 boolean success = false;
1002                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1003                     success = vh.weakCompareAndSetPlain(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
1004                 }
1005                 assertEquals(success, true, "weakCompareAndSetPlain long");
1006                 long x = (long) vh.get(array, i);
1007                 assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetPlain long value");
1008             }
1009 
1010             {
1011                 boolean success = false;
1012                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1013                     success = vh.weakCompareAndSetAcquire(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
1014                 }
1015                 assertEquals(success, true, "weakCompareAndSetAcquire long");
1016                 long x = (long) vh.get(array, i);
1017                 assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
1018             }
1019 
1020             {
1021                 boolean success = false;
1022                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1023                     success = vh.weakCompareAndSetRelease(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
1024                 }
1025                 assertEquals(success, true, "weakCompareAndSetRelease long");
1026                 long x = (long) vh.get(array, i);
1027                 assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
1028             }
1029 
1030             {
1031                 boolean success = false;
1032                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1033                     success = vh.weakCompareAndSet(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
1034                 }
1035                 assertEquals(success, true, "weakCompareAndSet long");
1036                 long x = (long) vh.get(array, i);
1037                 assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSet long");
1038             }
1039 
1040             // Compare set and get
1041             {
1042                 vh.set(array, i, 0x0123456789ABCDEFL);
1043 
1044                 long o = (long) vh.getAndSet(array, i, 0xCAFEBABECAFEBABEL);
1045                 assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
1046                 long x = (long) vh.get(array, i);
1047                 assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
1048             }
1049 
1050             {
1051                 vh.set(array, i, 0x0123456789ABCDEFL);
1052 
1053                 long o = (long) vh.getAndSetAcquire(array, i, 0xCAFEBABECAFEBABEL);
1054                 assertEquals(o, 0x0123456789ABCDEFL, "getAndSetAcquire long");
1055                 long x = (long) vh.get(array, i);
1056                 assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetAcquire long value");
1057             }
1058 
1059             {
1060                 vh.set(array, i, 0x0123456789ABCDEFL);
1061 
1062                 long o = (long) vh.getAndSetRelease(array, i, 0xCAFEBABECAFEBABEL);
1063                 assertEquals(o, 0x0123456789ABCDEFL, "getAndSetRelease long");
1064                 long x = (long) vh.get(array, i);
1065                 assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetRelease long value");
1066             }
1067 
1068             // get and add, add and get
1069             {
1070                 vh.set(array, i, 0x0123456789ABCDEFL);
1071 
1072                 long o = (long) vh.getAndAdd(array, i, 0xCAFEBABECAFEBABEL);
1073                 assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
1074                 long x = (long) vh.get(array, i);
1075                 assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value");
1076             }
1077 
1078             {
1079                 vh.set(array, i, 0x0123456789ABCDEFL);
1080 
1081                 long o = (long) vh.getAndAddAcquire(array, i, 0xCAFEBABECAFEBABEL);
1082                 assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long");
1083                 long x = (long) vh.get(array, i);
1084                 assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value");
1085             }
1086 
1087             {
1088                 vh.set(array, i, 0x0123456789ABCDEFL);
1089 
1090                 long o = (long) vh.getAndAddRelease(array, i, 0xCAFEBABECAFEBABEL);
1091                 assertEquals(o, 0x0123456789ABCDEFL, "getAndAddReleaselong");
1092                 long x = (long) vh.get(array, i);
1093                 assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value");
1094             }
1095 
1096             // get and bitwise or
1097             {
1098                 vh.set(array, i, 0x0123456789ABCDEFL);
1099 
1100                 long o = (long) vh.getAndBitwiseOr(array, i, 0xCAFEBABECAFEBABEL);
1101                 assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long");
1102                 long x = (long) vh.get(array, i);
1103                 assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value");
1104             }
1105 
1106             {
1107                 vh.set(array, i, 0x0123456789ABCDEFL);
1108 
1109                 long o = (long) vh.getAndBitwiseOrAcquire(array, i, 0xCAFEBABECAFEBABEL);
1110                 assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long");
1111                 long x = (long) vh.get(array, i);
1112                 assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value");
1113             }
1114 
1115             {
1116                 vh.set(array, i, 0x0123456789ABCDEFL);
1117 
1118                 long o = (long) vh.getAndBitwiseOrRelease(array, i, 0xCAFEBABECAFEBABEL);
1119                 assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long");
1120                 long x = (long) vh.get(array, i);
1121                 assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value");
1122             }
1123 
1124             // get and bitwise and
1125             {
1126                 vh.set(array, i, 0x0123456789ABCDEFL);
1127 
1128                 long o = (long) vh.getAndBitwiseAnd(array, i, 0xCAFEBABECAFEBABEL);
1129                 assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long");
1130                 long x = (long) vh.get(array, i);
1131                 assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value");
1132             }
1133 
1134             {
1135                 vh.set(array, i, 0x0123456789ABCDEFL);
1136 
1137                 long o = (long) vh.getAndBitwiseAndAcquire(array, i, 0xCAFEBABECAFEBABEL);
1138                 assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long");
1139                 long x = (long) vh.get(array, i);
1140                 assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value");
1141             }
1142 
1143             {
1144                 vh.set(array, i, 0x0123456789ABCDEFL);
1145 
1146                 long o = (long) vh.getAndBitwiseAndRelease(array, i, 0xCAFEBABECAFEBABEL);
1147                 assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long");
1148                 long x = (long) vh.get(array, i);
1149                 assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value");
1150             }
1151 
1152             // get and bitwise xor
1153             {
1154                 vh.set(array, i, 0x0123456789ABCDEFL);
1155 
1156                 long o = (long) vh.getAndBitwiseXor(array, i, 0xCAFEBABECAFEBABEL);
1157                 assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long");
1158                 long x = (long) vh.get(array, i);
1159                 assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value");
1160             }
1161 
1162             {
1163                 vh.set(array, i, 0x0123456789ABCDEFL);
1164 
1165                 long o = (long) vh.getAndBitwiseXorAcquire(array, i, 0xCAFEBABECAFEBABEL);
1166                 assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long");
1167                 long x = (long) vh.get(array, i);
1168                 assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value");
1169             }
1170 
1171             {
1172                 vh.set(array, i, 0x0123456789ABCDEFL);
1173 
1174                 long o = (long) vh.getAndBitwiseXorRelease(array, i, 0xCAFEBABECAFEBABEL);
1175                 assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long");
1176                 long x = (long) vh.get(array, i);
1177                 assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value");
1178             }
1179         }
1180     }
1181 
1182     static void testArrayUnsupported(VarHandle vh) {
1183         long[] array = new long[10];
1184 
1185         int i = 0;
1186 
1187 
1188     }
1189 
1190     static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
1191         long[] array = new long[10];
1192 
1193         for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
1194             final int ci = i;
1195 
1196             checkIOOBE(() -> {
1197                 long x = (long) vh.get(array, ci);
1198             });
1199 
1200             checkIOOBE(() -> {
1201                 vh.set(array, ci, 0x0123456789ABCDEFL);
1202             });
1203 
1204             checkIOOBE(() -> {
1205                 long x = (long) vh.getVolatile(array, ci);
1206             });
1207 
1208             checkIOOBE(() -> {
1209                 vh.setVolatile(array, ci, 0x0123456789ABCDEFL);
1210             });
1211 
1212             checkIOOBE(() -> {
1213                 long x = (long) vh.getAcquire(array, ci);
1214             });
1215 
1216             checkIOOBE(() -> {
1217                 vh.setRelease(array, ci, 0x0123456789ABCDEFL);
1218             });
1219 
1220             checkIOOBE(() -> {
1221                 long x = (long) vh.getOpaque(array, ci);
1222             });
1223 
1224             checkIOOBE(() -> {
1225                 vh.setOpaque(array, ci, 0x0123456789ABCDEFL);
1226             });
1227 
1228             checkIOOBE(() -> {
1229                 boolean r = vh.compareAndSet(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
1230             });
1231 
1232             checkIOOBE(() -> {
1233                 long r = (long) vh.compareAndExchange(array, ci, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
1234             });
1235 
1236             checkIOOBE(() -> {
1237                 long r = (long) vh.compareAndExchangeAcquire(array, ci, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
1238             });
1239 
1240             checkIOOBE(() -> {
1241                 long r = (long) vh.compareAndExchangeRelease(array, ci, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
1242             });
1243 
1244             checkIOOBE(() -> {
1245                 boolean r = vh.weakCompareAndSetPlain(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
1246             });
1247 
1248             checkIOOBE(() -> {
1249                 boolean r = vh.weakCompareAndSet(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
1250             });
1251 
1252             checkIOOBE(() -> {
1253                 boolean r = vh.weakCompareAndSetAcquire(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
1254             });
1255 
1256             checkIOOBE(() -> {
1257                 boolean r = vh.weakCompareAndSetRelease(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
1258             });
1259 
1260             checkIOOBE(() -> {
1261                 long o = (long) vh.getAndSet(array, ci, 0x0123456789ABCDEFL);
1262             });
1263 
1264             checkIOOBE(() -> {
1265                 long o = (long) vh.getAndSetAcquire(array, ci, 0x0123456789ABCDEFL);
1266             });
1267 
1268             checkIOOBE(() -> {
1269                 long o = (long) vh.getAndSetRelease(array, ci, 0x0123456789ABCDEFL);
1270             });
1271 
1272             checkIOOBE(() -> {
1273                 long o = (long) vh.getAndAdd(array, ci, 0x0123456789ABCDEFL);
1274             });
1275 
1276             checkIOOBE(() -> {
1277                 long o = (long) vh.getAndAddAcquire(array, ci, 0x0123456789ABCDEFL);
1278             });
1279 
1280             checkIOOBE(() -> {
1281                 long o = (long) vh.getAndAddRelease(array, ci, 0x0123456789ABCDEFL);
1282             });
1283 
1284             checkIOOBE(() -> {
1285                 long o = (long) vh.getAndBitwiseOr(array, ci, 0x0123456789ABCDEFL);
1286             });
1287 
1288             checkIOOBE(() -> {
1289                 long o = (long) vh.getAndBitwiseOrAcquire(array, ci, 0x0123456789ABCDEFL);
1290             });
1291 
1292             checkIOOBE(() -> {
1293                 long o = (long) vh.getAndBitwiseOrRelease(array, ci, 0x0123456789ABCDEFL);
1294             });
1295 
1296             checkIOOBE(() -> {
1297                 long o = (long) vh.getAndBitwiseAnd(array, ci, 0x0123456789ABCDEFL);
1298             });
1299 
1300             checkIOOBE(() -> {
1301                 long o = (long) vh.getAndBitwiseAndAcquire(array, ci, 0x0123456789ABCDEFL);
1302             });
1303 
1304             checkIOOBE(() -> {
1305                 long o = (long) vh.getAndBitwiseAndRelease(array, ci, 0x0123456789ABCDEFL);
1306             });
1307 
1308             checkIOOBE(() -> {
1309                 long o = (long) vh.getAndBitwiseXor(array, ci, 0x0123456789ABCDEFL);
1310             });
1311 
1312             checkIOOBE(() -> {
1313                 long o = (long) vh.getAndBitwiseXorAcquire(array, ci, 0x0123456789ABCDEFL);
1314             });
1315 
1316             checkIOOBE(() -> {
1317                 long o = (long) vh.getAndBitwiseXorRelease(array, ci, 0x0123456789ABCDEFL);
1318             });
1319         }
1320     }
1321 }
1322 
--- EOF ---