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