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