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