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 -XDallowWithFieldOperator Value.java
  27  * @run testng/othervm -XX:+EnableValhalla -Diters=2000 VarHandleTestMethodHandleAccessLong
  28  */
  29 
  30 import org.testng.annotations.BeforeClass;
  31 import org.testng.annotations.DataProvider;
  32 import org.testng.annotations.Test;
  33 
  34 import java.lang.invoke.MethodHandles;
  35 import java.lang.invoke.VarHandle;
  36 import java.util.ArrayList;
  37 import java.util.Arrays;
  38 import java.util.List;
  39 
  40 import static org.testng.Assert.*;
  41 
  42 public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest {
  43     static final long static_final_v = 0x0123456789ABCDEFL;
  44 
  45     static long static_v;
  46 
  47     final long final_v = 0x0123456789ABCDEFL;
  48 
  49     long v;
  50 
  51     VarHandle vhFinalField;
  52 
  53     VarHandle vhField;
  54 
  55     VarHandle vhStaticField;
  56 
  57     VarHandle vhStaticFinalField;
  58 
  59     VarHandle vhArray;
  60 
  61     VarHandle vhValueTypeField;
  62 
  63     @BeforeClass
  64     public void setup() throws Exception {
  65         vhFinalField = MethodHandles.lookup().findVarHandle(
  66                 VarHandleTestMethodHandleAccessLong.class, "final_v", long.class);
  67 
  68         vhField = MethodHandles.lookup().findVarHandle(
  69                 VarHandleTestMethodHandleAccessLong.class, "v", long.class);
  70 
  71         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
  72             VarHandleTestMethodHandleAccessLong.class, "static_final_v", long.class);
  73 
  74         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
  75             VarHandleTestMethodHandleAccessLong.class, "static_v", long.class);
  76 
  77         vhArray = MethodHandles.arrayElementVarHandle(long[].class);
  78 
  79         vhValueTypeField = MethodHandles.lookup().findVarHandle(
  80                     Value.class, "long_v", long.class);
  81     }
  82 
  83 
  84     @DataProvider
  85     public Object[][] accessTestCaseProvider() throws Exception {
  86         List<AccessTestCase<?>> cases = new ArrayList<>();
  87 
  88         for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
  89             cases.add(new MethodHandleAccessTestCase("Instance field",
  90                                                      vhField, f, hs -> testInstanceField(this, hs)));
  91             cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
  92                                                      vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
  93                                                      false));
  94 
  95             cases.add(new MethodHandleAccessTestCase("Static field",
  96                                                      vhStaticField, f, VarHandleTestMethodHandleAccessLong::testStaticField));
  97             cases.add(new MethodHandleAccessTestCase("Static field unsupported",
  98                                                      vhStaticField, f, VarHandleTestMethodHandleAccessLong::testStaticFieldUnsupported,
  99                                                      false));
 100 
 101             cases.add(new MethodHandleAccessTestCase("Array",
 102                                                      vhArray, f, VarHandleTestMethodHandleAccessLong::testArray));
 103             cases.add(new MethodHandleAccessTestCase("Array unsupported",
 104                                                      vhArray, f, VarHandleTestMethodHandleAccessLong::testArrayUnsupported,
 105                                                      false));
 106             cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
 107                                                      vhArray, f, VarHandleTestMethodHandleAccessLong::testArrayIndexOutOfBounds,
 108                                                      false));
 109         cases.add(new MethodHandleAccessTestCase("Value type field",
 110                                                  vhValueTypeField, f, hs -> testValueTypeField(Value.getInstance(), hs)));
 111         cases.add(new MethodHandleAccessTestCase("Value type field unsupported",
 112                                                  vhValueTypeField, f, hs -> testValueTypeFieldUnsupported(Value.getInstance(), hs),
 113                                                  false));
 114         }
 115 
 116         // Work around issue with jtreg summary reporting which truncates
 117         // the String result of Object.toString to 30 characters, hence
 118         // the first dummy argument
 119         return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
 120     }
 121 
 122     @Test(dataProvider = "accessTestCaseProvider")
 123     public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
 124         T t = atc.get();
 125         int iters = atc.requiresLoop() ? ITERS : 1;
 126         for (int c = 0; c < iters; c++) {
 127             atc.testAccess(t);
 128         }
 129     }
 130 
 131 
 132     static void testInstanceField(VarHandleTestMethodHandleAccessLong recv, Handles hs) throws Throwable {
 133         // Plain
 134         {
 135             hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
 136             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 137             assertEquals(x, 0x0123456789ABCDEFL, "set long value");
 138         }
 139 
 140 
 141         // Volatile
 142         {
 143             hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
 144             long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
 145             assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
 146         }
 147 
 148         // Lazy
 149         {
 150             hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 0x0123456789ABCDEFL);
 151             long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
 152             assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
 153         }
 154 
 155         // Opaque
 156         {
 157             hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
 158             long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
 159             assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
 160         }
 161 
 162         hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
 163 
 164         // Compare
 165         {
 166             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 167             assertEquals(r, true, "success compareAndSet long");
 168             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 169             assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
 170         }
 171 
 172         {
 173             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
 174             assertEquals(r, false, "failing compareAndSet long");
 175             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 176             assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
 177         }
 178 
 179         {
 180             long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 181             assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
 182             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 183             assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
 184         }
 185 
 186         {
 187             long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
 188             assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
 189             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 190             assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
 191         }
 192 
 193         {
 194             long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 195             assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
 196             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 197             assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
 198         }
 199 
 200         {
 201             long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
 202             assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
 203             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 204             assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
 205         }
 206 
 207         {
 208             long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 209             assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
 210             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 211             assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
 212         }
 213 
 214         {
 215             long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
 216             assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
 217             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 218             assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
 219         }
 220 
 221         {
 222             boolean success = false;
 223             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 224                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 225             }
 226             assertEquals(success, true, "weakCompareAndSetPlain long");
 227             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 228             assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetPlain long value");
 229         }
 230 
 231         {
 232             boolean success = false;
 233             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 234                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 235             }
 236             assertEquals(success, true, "weakCompareAndSetAcquire long");
 237             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 238             assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
 239         }
 240 
 241         {
 242             boolean success = false;
 243             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 244                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 245             }
 246             assertEquals(success, true, "weakCompareAndSetRelease long");
 247             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 248             assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
 249         }
 250 
 251         {
 252             boolean success = false;
 253             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 254                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 255             }
 256             assertEquals(success, true, "weakCompareAndSet long");
 257             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 258             assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSet long");
 259         }
 260 
 261         // Compare set and get
 262         {
 263             long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 0xCAFEBABECAFEBABEL);
 264             assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
 265             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 266             assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
 267         }
 268 
 269         // get and add, add and get
 270         {
 271             hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
 272 
 273             long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 0xCAFEBABECAFEBABEL);
 274             assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
 275             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 276             assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value");
 277         }
 278 
 279         {
 280             hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
 281 
 282             long o = (long) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
 283             assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long");
 284             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 285             assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value");
 286         }
 287 
 288         {
 289             hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
 290 
 291             long o = (long) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
 292             assertEquals(o, 0x0123456789ABCDEFL, "getAndAddRelease long");
 293             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 294             assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value");
 295         }
 296 
 297         // get and bitwise or
 298         {
 299             hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
 300 
 301             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, 0xCAFEBABECAFEBABEL);
 302             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long");
 303             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 304             assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value");
 305         }
 306 
 307         {
 308             hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
 309 
 310             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
 311             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long");
 312             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 313             assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value");
 314         }
 315 
 316         {
 317             hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
 318 
 319             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
 320             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long");
 321             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 322             assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value");
 323         }
 324 
 325         // get and bitwise and
 326         {
 327             hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
 328 
 329             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, 0xCAFEBABECAFEBABEL);
 330             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long");
 331             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 332             assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value");
 333         }
 334 
 335         {
 336             hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
 337 
 338             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
 339             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long");
 340             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 341             assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value");
 342         }
 343 
 344         {
 345             hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
 346 
 347             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
 348             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long");
 349             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 350             assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value");
 351         }
 352 
 353         // get and bitwise xor
 354         {
 355             hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
 356 
 357             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, 0xCAFEBABECAFEBABEL);
 358             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long");
 359             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 360             assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value");
 361         }
 362 
 363         {
 364             hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
 365 
 366             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
 367             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long");
 368             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 369             assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value");
 370         }
 371 
 372         {
 373             hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
 374 
 375             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
 376             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long");
 377             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 378             assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value");
 379         }
 380     }
 381 
 382     static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessLong recv, Handles hs) throws Throwable {
 383 
 384 
 385     }
 386 
 387     static void testValueTypeField(Value recv, Handles hs) throws Throwable {
 388         // Plain
 389         {
 390             long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
 391             assertEquals(x, 0x0123456789ABCDEFL, "get long value");
 392         }
 393     }
 394 
 395     static void testValueTypeFieldUnsupported(Value recv, Handles hs) throws Throwable {
 396         // Plain
 397         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
 398             checkUOE(am, () -> {
 399                 hs.get(am).invokeExact(recv, 0x0123456789ABCDEFL);
 400             });
 401         }
 402 
 403 
 404     }
 405 
 406     static void testStaticField(Handles hs) throws Throwable {
 407         // Plain
 408         {
 409             hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
 410             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 411             assertEquals(x, 0x0123456789ABCDEFL, "set long value");
 412         }
 413 
 414 
 415         // Volatile
 416         {
 417             hs.get(TestAccessMode.SET_VOLATILE).invokeExact(0xCAFEBABECAFEBABEL);
 418             long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
 419             assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
 420         }
 421 
 422         // Lazy
 423         {
 424             hs.get(TestAccessMode.SET_RELEASE).invokeExact(0x0123456789ABCDEFL);
 425             long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
 426             assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
 427         }
 428 
 429         // Opaque
 430         {
 431             hs.get(TestAccessMode.SET_OPAQUE).invokeExact(0xCAFEBABECAFEBABEL);
 432             long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
 433             assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
 434         }
 435 
 436         hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
 437 
 438         // Compare
 439         {
 440             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 441             assertEquals(r, true, "success compareAndSet long");
 442             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 443             assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
 444         }
 445 
 446         {
 447             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
 448             assertEquals(r, false, "failing compareAndSet long");
 449             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 450             assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
 451         }
 452 
 453         {
 454             long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 455             assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
 456             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 457             assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
 458         }
 459 
 460         {
 461             long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
 462             assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
 463             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 464             assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
 465         }
 466 
 467         {
 468             long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 469             assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
 470             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 471             assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
 472         }
 473 
 474         {
 475             long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
 476             assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
 477             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 478             assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
 479         }
 480 
 481         {
 482             long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 483             assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
 484             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 485             assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
 486         }
 487 
 488         {
 489             long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
 490             assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
 491             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 492             assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
 493         }
 494 
 495         {
 496             boolean success = false;
 497             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 498                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 499             }
 500             assertEquals(success, true, "weakCompareAndSetPlain long");
 501             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 502             assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetPlain long value");
 503         }
 504 
 505         {
 506             boolean success = false;
 507             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 508                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 509             }
 510             assertEquals(success, true, "weakCompareAndSetAcquire long");
 511             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 512             assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
 513         }
 514 
 515         {
 516             boolean success = false;
 517             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 518                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 519             }
 520             assertEquals(success, true, "weakCompareAndSetRelease long");
 521             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 522             assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
 523         }
 524 
 525         {
 526             boolean success = false;
 527             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 528                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 529             }
 530             assertEquals(success, true, "weakCompareAndSet long");
 531             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 532             assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSet long");
 533         }
 534 
 535         // Compare set and get
 536         {
 537             hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
 538 
 539             long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(0xCAFEBABECAFEBABEL);
 540             assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
 541             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 542             assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
 543         }
 544 
 545         // Compare set and get
 546         {
 547             hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
 548 
 549             long o = (long) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL);
 550             assertEquals(o, 0x0123456789ABCDEFL, "getAndSetAcquire long");
 551             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 552             assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetAcquire long value");
 553         }
 554 
 555         // Compare set and get
 556         {
 557             hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
 558 
 559             long o = (long) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(0xCAFEBABECAFEBABEL);
 560             assertEquals(o, 0x0123456789ABCDEFL, "getAndSetRelease long");
 561             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 562             assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetRelease long value");
 563         }
 564 
 565         // get and add, add and get
 566         {
 567             hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
 568 
 569             long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(0xCAFEBABECAFEBABEL);
 570             assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
 571             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 572             assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value");
 573         }
 574 
 575         {
 576             hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
 577 
 578             long o = (long) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL);
 579             assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long");
 580             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 581             assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value");
 582         }
 583 
 584         {
 585             hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
 586 
 587             long o = (long) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(0xCAFEBABECAFEBABEL);
 588             assertEquals(o, 0x0123456789ABCDEFL, "getAndAddRelease long");
 589             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 590             assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value");
 591         }
 592 
 593         // get and bitwise or
 594         {
 595             hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
 596 
 597             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(0xCAFEBABECAFEBABEL);
 598             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long");
 599             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 600             assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value");
 601         }
 602 
 603         {
 604             hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
 605 
 606             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL);
 607             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long");
 608             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 609             assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value");
 610         }
 611 
 612         {
 613             hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
 614 
 615             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(0xCAFEBABECAFEBABEL);
 616             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long");
 617             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 618             assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value");
 619         }
 620 
 621         // get and bitwise and
 622         {
 623             hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
 624 
 625             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(0xCAFEBABECAFEBABEL);
 626             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long");
 627             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 628             assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value");
 629         }
 630 
 631         {
 632             hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
 633 
 634             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL);
 635             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long");
 636             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 637             assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value");
 638         }
 639 
 640         {
 641             hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
 642 
 643             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(0xCAFEBABECAFEBABEL);
 644             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long");
 645             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 646             assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value");
 647         }
 648 
 649         // get and bitwise xor
 650         {
 651             hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
 652 
 653             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(0xCAFEBABECAFEBABEL);
 654             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long");
 655             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 656             assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value");
 657         }
 658 
 659         {
 660             hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
 661 
 662             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL);
 663             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long");
 664             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 665             assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value");
 666         }
 667 
 668         {
 669             hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
 670 
 671             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(0xCAFEBABECAFEBABEL);
 672             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long");
 673             long x = (long) hs.get(TestAccessMode.GET).invokeExact();
 674             assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value");
 675         }
 676     }
 677 
 678     static void testStaticFieldUnsupported(Handles hs) throws Throwable {
 679 
 680 
 681     }
 682 
 683 
 684     static void testArray(Handles hs) throws Throwable {
 685         long[] array = new long[10];
 686 
 687         for (int i = 0; i < array.length; i++) {
 688             // Plain
 689             {
 690                 hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
 691                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 692                 assertEquals(x, 0x0123456789ABCDEFL, "get long value");
 693             }
 694 
 695 
 696             // Volatile
 697             {
 698                 hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
 699                 long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
 700                 assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
 701             }
 702 
 703             // Lazy
 704             {
 705                 hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 0x0123456789ABCDEFL);
 706                 long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
 707                 assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value");
 708             }
 709 
 710             // Opaque
 711             {
 712                 hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
 713                 long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
 714                 assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value");
 715             }
 716 
 717             hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
 718 
 719             // Compare
 720             {
 721                 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 722                 assertEquals(r, true, "success compareAndSet long");
 723                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 724                 assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value");
 725             }
 726 
 727             {
 728                 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
 729                 assertEquals(r, false, "failing compareAndSet long");
 730                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 731                 assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value");
 732             }
 733 
 734             {
 735                 long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 736                 assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long");
 737                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 738                 assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value");
 739             }
 740 
 741             {
 742                 long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
 743                 assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long");
 744                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 745                 assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value");
 746             }
 747 
 748             {
 749                 long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 750                 assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long");
 751                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 752                 assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value");
 753             }
 754 
 755             {
 756                 long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL);
 757                 assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long");
 758                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 759                 assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value");
 760             }
 761 
 762             {
 763                 long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 764                 assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long");
 765                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 766                 assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value");
 767             }
 768 
 769             {
 770                 long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL);
 771                 assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long");
 772                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 773                 assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value");
 774             }
 775 
 776             {
 777                 boolean success = false;
 778                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 779                     success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 780                 }
 781                 assertEquals(success, true, "weakCompareAndSetPlain long");
 782                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 783                 assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetPlain long value");
 784             }
 785 
 786             {
 787                 boolean success = false;
 788                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 789                     success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 790                 }
 791                 assertEquals(success, true, "weakCompareAndSetAcquire long");
 792                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 793                 assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long");
 794             }
 795 
 796             {
 797                 boolean success = false;
 798                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 799                     success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 800                 }
 801                 assertEquals(success, true, "weakCompareAndSetRelease long");
 802                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 803                 assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long");
 804             }
 805 
 806             {
 807                 boolean success = false;
 808                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 809                     success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 810                 }
 811                 assertEquals(success, true, "weakCompareAndSet long");
 812                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 813                 assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSet long");
 814             }
 815 
 816             // Compare set and get
 817             {
 818                 hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
 819 
 820                 long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
 821                 assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long");
 822                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 823                 assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value");
 824             }
 825 
 826             {
 827                 hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
 828 
 829                 long o = (long) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
 830                 assertEquals(o, 0x0123456789ABCDEFL, "getAndSetAcquire long");
 831                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 832                 assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetAcquire long value");
 833             }
 834 
 835             {
 836                 hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
 837 
 838                 long o = (long) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
 839                 assertEquals(o, 0x0123456789ABCDEFL, "getAndSetRelease long");
 840                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 841                 assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetRelease long value");
 842             }
 843 
 844             // get and add, add and get
 845             {
 846                 hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
 847 
 848                 long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
 849                 assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long");
 850                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 851                 assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value");
 852             }
 853 
 854             {
 855                 hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
 856 
 857                 long o = (long) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
 858                 assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long");
 859                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 860                 assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value");
 861             }
 862 
 863             {
 864                 hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
 865 
 866                 long o = (long) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
 867                 assertEquals(o, 0x0123456789ABCDEFL, "getAndAddRelease long");
 868                 long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 869                 assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value");
 870             }
 871 
 872         // get and bitwise or
 873         {
 874             hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
 875 
 876             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
 877             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long");
 878             long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 879             assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value");
 880         }
 881 
 882         {
 883             hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
 884 
 885             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
 886             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long");
 887             long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 888             assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value");
 889         }
 890 
 891         {
 892             hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
 893 
 894             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
 895             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long");
 896             long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 897             assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value");
 898         }
 899 
 900         // get and bitwise and
 901         {
 902             hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
 903 
 904             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
 905             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long");
 906             long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 907             assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value");
 908         }
 909 
 910         {
 911             hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
 912 
 913             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
 914             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long");
 915             long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 916             assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value");
 917         }
 918 
 919         {
 920             hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
 921 
 922             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
 923             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long");
 924             long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 925             assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value");
 926         }
 927 
 928         // get and bitwise xor
 929         {
 930             hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
 931 
 932             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
 933             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long");
 934             long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 935             assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value");
 936         }
 937 
 938         {
 939             hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
 940 
 941             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
 942             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long");
 943             long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 944             assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value");
 945         }
 946 
 947         {
 948             hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL);
 949 
 950             long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL);
 951             assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long");
 952             long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
 953             assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value");
 954         }
 955         }
 956     }
 957 
 958     static void testArrayUnsupported(Handles hs) throws Throwable {
 959         long[] array = new long[10];
 960 
 961         final int i = 0;
 962 
 963 
 964     }
 965 
 966     static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
 967         long[] array = new long[10];
 968 
 969         for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
 970             final int ci = i;
 971 
 972             for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
 973                 checkIOOBE(am, () -> {
 974                     long x = (long) hs.get(am).invokeExact(array, ci);
 975                 });
 976             }
 977 
 978             for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
 979                 checkIOOBE(am, () -> {
 980                     hs.get(am).invokeExact(array, ci, 0x0123456789ABCDEFL);
 981                 });
 982             }
 983 
 984             for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
 985                 checkIOOBE(am, () -> {
 986                     boolean r = (boolean) hs.get(am).invokeExact(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL);
 987                 });
 988             }
 989 
 990             for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
 991                 checkIOOBE(am, () -> {
 992                     long r = (long) hs.get(am).invokeExact(array, ci, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL);
 993                 });
 994             }
 995 
 996             for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
 997                 checkIOOBE(am, () -> {
 998                     long o = (long) hs.get(am).invokeExact(array, ci, 0x0123456789ABCDEFL);
 999                 });
1000             }
1001 
1002             for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
1003                 checkIOOBE(am, () -> {
1004                     long o = (long) hs.get(am).invokeExact(array, ci, 0xDEADBEEFDEADBEEFL);
1005                 });
1006             }
1007 
1008             for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
1009                 checkIOOBE(am, () -> {
1010                     long o = (long) hs.get(am).invokeExact(array, ci, 0xDEADBEEFDEADBEEFL);
1011                 });
1012             }
1013         }
1014     }
1015 }
1016