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