1 /*
   2  * Copyright (c) 2015, 2016, 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=20000 VarHandleTestMethodHandleAccessBoolean
  27  */
  28 
  29 import org.testng.annotations.BeforeClass;
  30 import org.testng.annotations.DataProvider;
  31 import org.testng.annotations.Test;
  32 
  33 import java.lang.invoke.MethodHandles;
  34 import java.lang.invoke.VarHandle;
  35 import java.util.ArrayList;
  36 import java.util.Arrays;
  37 import java.util.List;
  38 
  39 import static org.testng.Assert.*;
  40 
  41 public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
  42     static final boolean static_final_v = true;
  43 
  44     static boolean static_v;
  45 
  46     final boolean final_v = true;
  47 
  48     boolean v;
  49 
  50     VarHandle vhFinalField;
  51 
  52     VarHandle vhField;
  53 
  54     VarHandle vhStaticField;
  55 
  56     VarHandle vhStaticFinalField;
  57 
  58     VarHandle vhArray;
  59 
  60     @BeforeClass
  61     public void setup() throws Exception {
  62         vhFinalField = MethodHandles.lookup().findVarHandle(
  63                 VarHandleTestMethodHandleAccessBoolean.class, "final_v", boolean.class);
  64 
  65         vhField = MethodHandles.lookup().findVarHandle(
  66                 VarHandleTestMethodHandleAccessBoolean.class, "v", boolean.class);
  67 
  68         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
  69             VarHandleTestMethodHandleAccessBoolean.class, "static_final_v", boolean.class);
  70 
  71         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
  72             VarHandleTestMethodHandleAccessBoolean.class, "static_v", boolean.class);
  73 
  74         vhArray = MethodHandles.arrayElementVarHandle(boolean[].class);
  75     }
  76 
  77 
  78     @DataProvider
  79     public Object[][] accessTestCaseProvider() throws Exception {
  80         List<AccessTestCase<?>> cases = new ArrayList<>();
  81 
  82         for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
  83             cases.add(new MethodHandleAccessTestCase("Instance field",
  84                                                      vhField, f, hs -> testInstanceField(this, hs)));
  85             cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
  86                                                      vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
  87                                                      false));
  88 
  89             cases.add(new MethodHandleAccessTestCase("Static field",
  90                                                      vhStaticField, f, VarHandleTestMethodHandleAccessBoolean::testStaticField));
  91             cases.add(new MethodHandleAccessTestCase("Static field unsupported",
  92                                                      vhStaticField, f, VarHandleTestMethodHandleAccessBoolean::testStaticFieldUnsupported,
  93                                                      false));
  94 
  95             cases.add(new MethodHandleAccessTestCase("Array",
  96                                                      vhArray, f, VarHandleTestMethodHandleAccessBoolean::testArray));
  97             cases.add(new MethodHandleAccessTestCase("Array unsupported",
  98                                                      vhArray, f, VarHandleTestMethodHandleAccessBoolean::testArrayUnsupported,
  99                                                      false));
 100             cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
 101                                                      vhArray, f, VarHandleTestMethodHandleAccessBoolean::testArrayIndexOutOfBounds,
 102                                                      false));
 103         }
 104 
 105         // Work around issue with jtreg summary reporting which truncates
 106         // the String result of Object.toString to 30 characters, hence
 107         // the first dummy argument
 108         return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
 109     }
 110 
 111     @Test(dataProvider = "accessTestCaseProvider")
 112     public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
 113         T t = atc.get();
 114         int iters = atc.requiresLoop() ? ITERS : 1;
 115         for (int c = 0; c < iters; c++) {
 116             atc.testAccess(t);
 117         }
 118     }
 119 
 120 
 121     static void testInstanceField(VarHandleTestMethodHandleAccessBoolean recv, Handles hs) throws Throwable {
 122         // Plain
 123         {
 124             hs.get(TestAccessMode.SET).invokeExact(recv, true);
 125             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
 126             assertEquals(x, true, "set boolean value");
 127         }
 128 
 129 
 130         // Volatile
 131         {
 132             hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, false);
 133             boolean x = (boolean) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
 134             assertEquals(x, false, "setVolatile boolean value");
 135         }
 136 
 137         // Lazy
 138         {
 139             hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, true);
 140             boolean x = (boolean) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
 141             assertEquals(x, true, "setRelease boolean value");
 142         }
 143 
 144         // Opaque
 145         {
 146             hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, false);
 147             boolean x = (boolean) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
 148             assertEquals(x, false, "setOpaque boolean value");
 149         }
 150 
 151         hs.get(TestAccessMode.SET).invokeExact(recv, true);
 152 
 153         // Compare
 154         {
 155             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, true, false);
 156             assertEquals(r, true, "success compareAndSet boolean");
 157             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
 158             assertEquals(x, false, "success compareAndSet boolean value");
 159         }
 160 
 161         {
 162             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, true, false);
 163             assertEquals(r, false, "failing compareAndSet boolean");
 164             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
 165             assertEquals(x, false, "failing compareAndSet boolean value");
 166         }
 167 
 168         {
 169             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, false, true);
 170             assertEquals(r, false, "success compareAndExchangeVolatile boolean");
 171             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
 172             assertEquals(x, true, "success compareAndExchangeVolatile boolean value");
 173         }
 174 
 175         {
 176             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, false, false);
 177             assertEquals(r, true, "failing compareAndExchangeVolatile boolean");
 178             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
 179             assertEquals(x, true, "failing compareAndExchangeVolatile boolean value");
 180         }
 181 
 182         {
 183             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, true, false);
 184             assertEquals(r, true, "success compareAndExchangeAcquire boolean");
 185             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
 186             assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
 187         }
 188 
 189         {
 190             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, true, false);
 191             assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
 192             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
 193             assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
 194         }
 195 
 196         {
 197             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, false, true);
 198             assertEquals(r, false, "success compareAndExchangeRelease boolean");
 199             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
 200             assertEquals(x, true, "success compareAndExchangeRelease boolean value");
 201         }
 202 
 203         {
 204             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, false, false);
 205             assertEquals(r, true, "failing compareAndExchangeRelease boolean");
 206             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
 207             assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
 208         }
 209 
 210         {
 211             boolean success = false;
 212             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 213                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, true, false);
 214             }
 215             assertEquals(success, true, "weakCompareAndSet boolean");
 216             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
 217             assertEquals(x, false, "weakCompareAndSet boolean value");
 218         }
 219 
 220         {
 221             boolean success = false;
 222             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 223                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, false, true);
 224             }
 225             assertEquals(success, true, "weakCompareAndSetAcquire boolean");
 226             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
 227             assertEquals(x, true, "weakCompareAndSetAcquire boolean");
 228         }
 229 
 230         {
 231             boolean success = false;
 232             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 233                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, true, false);
 234             }
 235             assertEquals(success, true, "weakCompareAndSetRelease boolean");
 236             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
 237             assertEquals(x, false, "weakCompareAndSetRelease boolean");
 238         }
 239 
 240         // Compare set and get
 241         {
 242             boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, true);
 243             assertEquals(o, false, "getAndSet boolean");
 244             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
 245             assertEquals(x, true, "getAndSet boolean value");
 246         }
 247 
 248     }
 249 
 250     static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessBoolean recv, Handles hs) throws Throwable {
 251 
 252         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
 253             checkUOE(am, () -> {
 254                 boolean r = (boolean) hs.get(am).invokeExact(recv, true);
 255             });
 256         }
 257     }
 258 
 259 
 260     static void testStaticField(Handles hs) throws Throwable {
 261         // Plain
 262         {
 263             hs.get(TestAccessMode.SET).invokeExact(true);
 264             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
 265             assertEquals(x, true, "set boolean value");
 266         }
 267 
 268 
 269         // Volatile
 270         {
 271             hs.get(TestAccessMode.SET_VOLATILE).invokeExact(false);
 272             boolean x = (boolean) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
 273             assertEquals(x, false, "setVolatile boolean value");
 274         }
 275 
 276         // Lazy
 277         {
 278             hs.get(TestAccessMode.SET_RELEASE).invokeExact(true);
 279             boolean x = (boolean) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
 280             assertEquals(x, true, "setRelease boolean value");
 281         }
 282 
 283         // Opaque
 284         {
 285             hs.get(TestAccessMode.SET_OPAQUE).invokeExact(false);
 286             boolean x = (boolean) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
 287             assertEquals(x, false, "setOpaque boolean value");
 288         }
 289 
 290         hs.get(TestAccessMode.SET).invokeExact(true);
 291 
 292         // Compare
 293         {
 294             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(true, false);
 295             assertEquals(r, true, "success compareAndSet boolean");
 296             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
 297             assertEquals(x, false, "success compareAndSet boolean value");
 298         }
 299 
 300         {
 301             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(true, false);
 302             assertEquals(r, false, "failing compareAndSet boolean");
 303             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
 304             assertEquals(x, false, "failing compareAndSet boolean value");
 305         }
 306 
 307         {
 308             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(false, true);
 309             assertEquals(r, false, "success compareAndExchangeVolatile boolean");
 310             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
 311             assertEquals(x, true, "success compareAndExchangeVolatile boolean value");
 312         }
 313 
 314         {
 315             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(false, false);
 316             assertEquals(r, true, "failing compareAndExchangeVolatile boolean");
 317             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
 318             assertEquals(x, true, "failing compareAndExchangeVolatile boolean value");
 319         }
 320 
 321         {
 322             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(true, false);
 323             assertEquals(r, true, "success compareAndExchangeAcquire boolean");
 324             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
 325             assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
 326         }
 327 
 328         {
 329             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(true, false);
 330             assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
 331             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
 332             assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
 333         }
 334 
 335         {
 336             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(false, true);
 337             assertEquals(r, false, "success compareAndExchangeRelease boolean");
 338             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
 339             assertEquals(x, true, "success compareAndExchangeRelease boolean value");
 340         }
 341 
 342         {
 343             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(false, false);
 344             assertEquals(r, true, "failing compareAndExchangeRelease boolean");
 345             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
 346             assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
 347         }
 348 
 349         {
 350             boolean success = false;
 351             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 352                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(true, false);
 353             }
 354             assertEquals(success, true, "weakCompareAndSet boolean");
 355             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
 356             assertEquals(x, false, "weakCompareAndSet boolean value");
 357         }
 358 
 359         {
 360             boolean success = false;
 361             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 362                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(false, true);
 363             }
 364             assertEquals(success, true, "weakCompareAndSetAcquire boolean");
 365             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
 366             assertEquals(x, true, "weakCompareAndSetAcquire boolean");
 367         }
 368 
 369         {
 370             boolean success = false;
 371             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 372                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(true, false);
 373             }
 374             assertEquals(success, true, "weakCompareAndSetRelease boolean");
 375             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
 376             assertEquals(x, false, "weakCompareAndSetRelease boolean");
 377         }
 378 
 379         // Compare set and get
 380         {
 381             boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact( true);
 382             assertEquals(o, false, "getAndSet boolean");
 383             boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
 384             assertEquals(x, true, "getAndSet boolean value");
 385         }
 386 
 387     }
 388 
 389     static void testStaticFieldUnsupported(Handles hs) throws Throwable {
 390 
 391         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
 392             checkUOE(am, () -> {
 393                 boolean r = (boolean) hs.get(am).invokeExact(true);
 394             });
 395         }
 396     }
 397 
 398 
 399     static void testArray(Handles hs) throws Throwable {
 400         boolean[] array = new boolean[10];
 401 
 402         for (int i = 0; i < array.length; i++) {
 403             // Plain
 404             {
 405                 hs.get(TestAccessMode.SET).invokeExact(array, i, true);
 406                 boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
 407                 assertEquals(x, true, "get boolean value");
 408             }
 409 
 410 
 411             // Volatile
 412             {
 413                 hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, false);
 414                 boolean x = (boolean) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
 415                 assertEquals(x, false, "setVolatile boolean value");
 416             }
 417 
 418             // Lazy
 419             {
 420                 hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, true);
 421                 boolean x = (boolean) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
 422                 assertEquals(x, true, "setRelease boolean value");
 423             }
 424 
 425             // Opaque
 426             {
 427                 hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, false);
 428                 boolean x = (boolean) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
 429                 assertEquals(x, false, "setOpaque boolean value");
 430             }
 431 
 432             hs.get(TestAccessMode.SET).invokeExact(array, i, true);
 433 
 434             // Compare
 435             {
 436                 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, true, false);
 437                 assertEquals(r, true, "success compareAndSet boolean");
 438                 boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
 439                 assertEquals(x, false, "success compareAndSet boolean value");
 440             }
 441 
 442             {
 443                 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, true, false);
 444                 assertEquals(r, false, "failing compareAndSet boolean");
 445                 boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
 446                 assertEquals(x, false, "failing compareAndSet boolean value");
 447             }
 448 
 449             {
 450                 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, false, true);
 451                 assertEquals(r, false, "success compareAndExchangeVolatile boolean");
 452                 boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
 453                 assertEquals(x, true, "success compareAndExchangeVolatile boolean value");
 454             }
 455 
 456             {
 457                 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, false, false);
 458                 assertEquals(r, true, "failing compareAndExchangeVolatile boolean");
 459                 boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
 460                 assertEquals(x, true, "failing compareAndExchangeVolatile boolean value");
 461             }
 462 
 463             {
 464                 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, true, false);
 465                 assertEquals(r, true, "success compareAndExchangeAcquire boolean");
 466                 boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
 467                 assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
 468             }
 469 
 470             {
 471                 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, true, false);
 472                 assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
 473                 boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
 474                 assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
 475             }
 476 
 477             {
 478                 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, false, true);
 479                 assertEquals(r, false, "success compareAndExchangeRelease boolean");
 480                 boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
 481                 assertEquals(x, true, "success compareAndExchangeRelease boolean value");
 482             }
 483 
 484             {
 485                 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, false, false);
 486                 assertEquals(r, true, "failing compareAndExchangeRelease boolean");
 487                 boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
 488                 assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
 489             }
 490 
 491             {
 492                 boolean success = false;
 493                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 494                     success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, true, false);
 495                 }
 496                 assertEquals(success, true, "weakCompareAndSet boolean");
 497                 boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
 498                 assertEquals(x, false, "weakCompareAndSet boolean value");
 499             }
 500 
 501             {
 502                 boolean success = false;
 503                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 504                     success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, false, true);
 505                 }
 506                 assertEquals(success, true, "weakCompareAndSetAcquire boolean");
 507                 boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
 508                 assertEquals(x, true, "weakCompareAndSetAcquire boolean");
 509             }
 510 
 511             {
 512                 boolean success = false;
 513                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 514                     success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, true, false);
 515                 }
 516                 assertEquals(success, true, "weakCompareAndSetRelease boolean");
 517                 boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
 518                 assertEquals(x, false, "weakCompareAndSetRelease boolean");
 519             }
 520 
 521             // Compare set and get
 522             {
 523                 boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, true);
 524                 assertEquals(o, false, "getAndSet boolean");
 525                 boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
 526                 assertEquals(x, true, "getAndSet boolean value");
 527             }
 528 
 529         }
 530     }
 531 
 532     static void testArrayUnsupported(Handles hs) throws Throwable {
 533         boolean[] array = new boolean[10];
 534 
 535         final int i = 0;
 536 
 537         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
 538             checkUOE(am, () -> {
 539                 boolean o = (boolean) hs.get(am).invokeExact(array, i, true);
 540             });
 541         }
 542     }
 543 
 544     static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
 545         boolean[] array = new boolean[10];
 546 
 547         for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
 548             final int ci = i;
 549 
 550             for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
 551                 checkIOOBE(am, () -> {
 552                     boolean x = (boolean) hs.get(am).invokeExact(array, ci);
 553                 });
 554             }
 555 
 556             for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
 557                 checkIOOBE(am, () -> {
 558                     hs.get(am).invokeExact(array, ci, true);
 559                 });
 560             }
 561 
 562             for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
 563                 checkIOOBE(am, () -> {
 564                     boolean r = (boolean) hs.get(am).invokeExact(array, ci, true, false);
 565                 });
 566             }
 567 
 568             for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
 569                 checkIOOBE(am, () -> {
 570                     boolean r = (boolean) hs.get(am).invokeExact(array, ci, false, true);
 571                 });
 572             }
 573 
 574             for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
 575                 checkIOOBE(am, () -> {
 576                     boolean o = (boolean) hs.get(am).invokeExact(array, ci, true);
 577                 });
 578             }
 579 
 580         }
 581     }
 582 }
 583