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