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