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