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