1 /*
   2  * Copyright (c) 2015, 2023, 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  * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations
  27  *          to hit compilation thresholds
  28  * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessByte
  29  */
  30 
  31 import org.testng.annotations.BeforeClass;
  32 import org.testng.annotations.DataProvider;
  33 import org.testng.annotations.Test;
  34 
  35 import java.lang.invoke.MethodHandle;
  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 VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest {
  45     static final byte static_final_v = (byte)0x01;
  46 
  47     static byte static_v;
  48 
  49     final byte final_v = (byte)0x01;
  50 
  51     byte v;
  52 
  53     VarHandle vhFinalField;
  54 
  55     VarHandle vhField;
  56 
  57     VarHandle vhStaticField;
  58 
  59     VarHandle vhStaticFinalField;
  60 
  61     VarHandle vhArray;
  62 
  63     @BeforeClass
  64     public void setup() throws Exception {
  65         vhFinalField = MethodHandles.lookup().findVarHandle(
  66                 VarHandleTestMethodHandleAccessByte.class, "final_v", byte.class);
  67 
  68         vhField = MethodHandles.lookup().findVarHandle(
  69                 VarHandleTestMethodHandleAccessByte.class, "v", byte.class);
  70 
  71         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
  72             VarHandleTestMethodHandleAccessByte.class, "static_final_v", byte.class);
  73 
  74         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
  75             VarHandleTestMethodHandleAccessByte.class, "static_v", byte.class);
  76 
  77         vhArray = MethodHandles.arrayElementVarHandle(byte[].class);
  78     }
  79 
  80 
  81     @DataProvider
  82     public Object[][] accessTestCaseProvider() throws Exception {
  83         List<AccessTestCase<?>> cases = new ArrayList<>();
  84 
  85         for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
  86             cases.add(new MethodHandleAccessTestCase("Instance field",
  87                                                      vhField, f, hs -> testInstanceField(this, hs)));
  88             cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
  89                                                      vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
  90                                                      false));
  91 
  92             cases.add(new MethodHandleAccessTestCase("Static field",
  93                                                      vhStaticField, f, VarHandleTestMethodHandleAccessByte::testStaticField));
  94             cases.add(new MethodHandleAccessTestCase("Static field unsupported",
  95                                                      vhStaticField, f, VarHandleTestMethodHandleAccessByte::testStaticFieldUnsupported,
  96                                                      false));
  97 
  98             cases.add(new MethodHandleAccessTestCase("Array",
  99                                                      vhArray, f, VarHandleTestMethodHandleAccessByte::testArray));
 100             cases.add(new MethodHandleAccessTestCase("Array unsupported",
 101                                                      vhArray, f, VarHandleTestMethodHandleAccessByte::testArrayUnsupported,
 102                                                      false));
 103             cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
 104                                                      vhArray, f, VarHandleTestMethodHandleAccessByte::testArrayIndexOutOfBounds,
 105                                                      false));
 106         }
 107 
 108         // Work around issue with jtreg summary reporting which truncates
 109         // the String result of Object.toString to 30 characters, hence
 110         // the first dummy argument
 111         return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
 112     }
 113 
 114     @Test(dataProvider = "accessTestCaseProvider")
 115     public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
 116         T t = atc.get();
 117         int iters = atc.requiresLoop() ? ITERS : 1;
 118         for (int c = 0; c < iters; c++) {
 119             atc.testAccess(t);
 120         }
 121     }
 122 
 123 
 124     static void testInstanceField(VarHandleTestMethodHandleAccessByte recv, Handles hs) throws Throwable {
 125         // Plain
 126         {
 127             hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
 128             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 129             assertEquals(x, (byte)0x01, "set byte value");
 130         }
 131 
 132 
 133         // Volatile
 134         {
 135             hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, (byte)0x23);
 136             byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
 137             assertEquals(x, (byte)0x23, "setVolatile byte value");
 138         }
 139 
 140         // Lazy
 141         {
 142             hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, (byte)0x01);
 143             byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
 144             assertEquals(x, (byte)0x01, "setRelease byte value");
 145         }
 146 
 147         // Opaque
 148         {
 149             hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, (byte)0x23);
 150             byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
 151             assertEquals(x, (byte)0x23, "setOpaque byte value");
 152         }
 153 
 154         hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
 155 
 156         // Compare
 157         {
 158             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (byte)0x01, (byte)0x23);
 159             assertEquals(r, true, "success compareAndSet byte");
 160             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 161             assertEquals(x, (byte)0x23, "success compareAndSet byte value");
 162         }
 163 
 164         {
 165             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (byte)0x01, (byte)0x45);
 166             assertEquals(r, false, "failing compareAndSet byte");
 167             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 168             assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
 169         }
 170 
 171         {
 172             byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (byte)0x23, (byte)0x01);
 173             assertEquals(r, (byte)0x23, "success compareAndExchange byte");
 174             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 175             assertEquals(x, (byte)0x01, "success compareAndExchange byte value");
 176         }
 177 
 178         {
 179             byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (byte)0x23, (byte)0x45);
 180             assertEquals(r, (byte)0x01, "failing compareAndExchange byte");
 181             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 182             assertEquals(x, (byte)0x01, "failing compareAndExchange byte value");
 183         }
 184 
 185         {
 186             byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (byte)0x01, (byte)0x23);
 187             assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
 188             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 189             assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
 190         }
 191 
 192         {
 193             byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (byte)0x01, (byte)0x45);
 194             assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
 195             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 196             assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
 197         }
 198 
 199         {
 200             byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (byte)0x23, (byte)0x01);
 201             assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
 202             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 203             assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
 204         }
 205 
 206         {
 207             byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (byte)0x23, (byte)0x45);
 208             assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
 209             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 210             assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
 211         }
 212 
 213         {
 214             MethodHandle mh = hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN);
 215             boolean success = false;
 216             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 217                 success = (boolean) mh.invokeExact(recv, (byte)0x01, (byte)0x23);
 218                 if (!success) weakDelay();
 219             }
 220             assertEquals(success, true, "success weakCompareAndSetPlain byte");
 221             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 222             assertEquals(x, (byte)0x23, "success weakCompareAndSetPlain byte value");
 223         }
 224 
 225         {
 226             boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, (byte)0x01, (byte)0x45);
 227             assertEquals(success, false, "failing weakCompareAndSetPlain byte");
 228             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 229             assertEquals(x, (byte)0x23, "failing weakCompareAndSetPlain byte value");
 230         }
 231 
 232         {
 233             MethodHandle mh = hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE);
 234             boolean success = false;
 235             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 236                 success = (boolean) mh.invokeExact(recv, (byte)0x23, (byte)0x01);
 237                 if (!success) weakDelay();
 238             }
 239             assertEquals(success, true, "success weakCompareAndSetAcquire byte");
 240             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 241             assertEquals(x, (byte)0x01, "success weakCompareAndSetAcquire byte");
 242         }
 243 
 244         {
 245             boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, (byte)0x23, (byte)0x45);
 246             assertEquals(success, false, "failing weakCompareAndSetAcquire byte");
 247             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 248             assertEquals(x, (byte)0x01, "failing weakCompareAndSetAcquire byte value");
 249         }
 250 
 251         {
 252             MethodHandle mh = hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE);
 253             boolean success = false;
 254             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 255                 success = (boolean) mh.invokeExact(recv, (byte)0x01, (byte)0x23);
 256                 if (!success) weakDelay();
 257             }
 258             assertEquals(success, true, "success weakCompareAndSetRelease byte");
 259             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 260             assertEquals(x, (byte)0x23, "success weakCompareAndSetRelease byte");
 261         }
 262 
 263         {
 264             boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, (byte)0x01, (byte)0x45);
 265             assertEquals(success, false, "failing weakCompareAndSetRelease byte");
 266             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 267             assertEquals(x, (byte)0x23, "failing weakCompareAndSetRelease byte value");
 268         }
 269 
 270         {
 271             boolean success = false;
 272             MethodHandle mh = hs.get(TestAccessMode.WEAK_COMPARE_AND_SET);
 273             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 274                 success = (boolean) mh.invokeExact(recv, (byte)0x23, (byte)0x01);
 275                 if (!success) weakDelay();
 276             }
 277             assertEquals(success, true, "success weakCompareAndSet byte");
 278             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 279             assertEquals(x, (byte)0x01, "success weakCompareAndSet byte");
 280         }
 281 
 282         {
 283             boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, (byte)0x23, (byte)0x45);
 284             assertEquals(success, false, "failing weakCompareAndSet byte");
 285             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 286             assertEquals(x, (byte)0x01, "failing weakCompareAndSet byte value");
 287         }
 288 
 289         // Compare set and get
 290         {
 291             byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, (byte)0x23);
 292             assertEquals(o, (byte)0x01, "getAndSet byte");
 293             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 294             assertEquals(x, (byte)0x23, "getAndSet byte value");
 295         }
 296 
 297         // get and add, add and get
 298         {
 299             hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
 300 
 301             byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, (byte)0x23);
 302             assertEquals(o, (byte)0x01, "getAndAdd byte");
 303             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 304             assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value");
 305         }
 306 
 307         {
 308             hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
 309 
 310             byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, (byte)0x23);
 311             assertEquals(o, (byte)0x01, "getAndAddAcquire byte");
 312             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 313             assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value");
 314         }
 315 
 316         {
 317             hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
 318 
 319             byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, (byte)0x23);
 320             assertEquals(o, (byte)0x01, "getAndAddRelease byte");
 321             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 322             assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value");
 323         }
 324 
 325         // get and bitwise or
 326         {
 327             hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
 328 
 329             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, (byte)0x23);
 330             assertEquals(o, (byte)0x01, "getAndBitwiseOr byte");
 331             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 332             assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value");
 333         }
 334 
 335         {
 336             hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
 337 
 338             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, (byte)0x23);
 339             assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte");
 340             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 341             assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value");
 342         }
 343 
 344         {
 345             hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
 346 
 347             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, (byte)0x23);
 348             assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte");
 349             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 350             assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value");
 351         }
 352 
 353         // get and bitwise and
 354         {
 355             hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
 356 
 357             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, (byte)0x23);
 358             assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte");
 359             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 360             assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value");
 361         }
 362 
 363         {
 364             hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
 365 
 366             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, (byte)0x23);
 367             assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte");
 368             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 369             assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value");
 370         }
 371 
 372         {
 373             hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
 374 
 375             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, (byte)0x23);
 376             assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte");
 377             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 378             assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value");
 379         }
 380 
 381         // get and bitwise xor
 382         {
 383             hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
 384 
 385             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, (byte)0x23);
 386             assertEquals(o, (byte)0x01, "getAndBitwiseXor byte");
 387             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 388             assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value");
 389         }
 390 
 391         {
 392             hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
 393 
 394             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, (byte)0x23);
 395             assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte");
 396             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 397             assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value");
 398         }
 399 
 400         {
 401             hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
 402 
 403             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, (byte)0x23);
 404             assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte");
 405             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
 406             assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value");
 407         }
 408     }
 409 
 410     static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessByte recv, Handles hs) throws Throwable {
 411 
 412 
 413     }
 414 
 415 
 416     static void testStaticField(Handles hs) throws Throwable {
 417         // Plain
 418         {
 419             hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
 420             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 421             assertEquals(x, (byte)0x01, "set byte value");
 422         }
 423 
 424 
 425         // Volatile
 426         {
 427             hs.get(TestAccessMode.SET_VOLATILE).invokeExact((byte)0x23);
 428             byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
 429             assertEquals(x, (byte)0x23, "setVolatile byte value");
 430         }
 431 
 432         // Lazy
 433         {
 434             hs.get(TestAccessMode.SET_RELEASE).invokeExact((byte)0x01);
 435             byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
 436             assertEquals(x, (byte)0x01, "setRelease byte value");
 437         }
 438 
 439         // Opaque
 440         {
 441             hs.get(TestAccessMode.SET_OPAQUE).invokeExact((byte)0x23);
 442             byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
 443             assertEquals(x, (byte)0x23, "setOpaque byte value");
 444         }
 445 
 446         hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
 447 
 448         // Compare
 449         {
 450             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((byte)0x01, (byte)0x23);
 451             assertEquals(r, true, "success compareAndSet byte");
 452             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 453             assertEquals(x, (byte)0x23, "success compareAndSet byte value");
 454         }
 455 
 456         {
 457             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((byte)0x01, (byte)0x45);
 458             assertEquals(r, false, "failing compareAndSet byte");
 459             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 460             assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
 461         }
 462 
 463         {
 464             byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((byte)0x23, (byte)0x01);
 465             assertEquals(r, (byte)0x23, "success compareAndExchange byte");
 466             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 467             assertEquals(x, (byte)0x01, "success compareAndExchange byte value");
 468         }
 469 
 470         {
 471             byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((byte)0x23, (byte)0x45);
 472             assertEquals(r, (byte)0x01, "failing compareAndExchange byte");
 473             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 474             assertEquals(x, (byte)0x01, "failing compareAndExchange byte value");
 475         }
 476 
 477         {
 478             byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((byte)0x01, (byte)0x23);
 479             assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
 480             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 481             assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
 482         }
 483 
 484         {
 485             byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((byte)0x01, (byte)0x45);
 486             assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
 487             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 488             assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
 489         }
 490 
 491         {
 492             byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((byte)0x23, (byte)0x01);
 493             assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
 494             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 495             assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
 496         }
 497 
 498         {
 499             byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((byte)0x23, (byte)0x45);
 500             assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
 501             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 502             assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
 503         }
 504 
 505         {
 506             MethodHandle mh = hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN);
 507             boolean success = false;
 508             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 509                 success = (boolean) mh.invokeExact((byte)0x01, (byte)0x23);
 510                 if (!success) weakDelay();
 511             }
 512             assertEquals(success, true, "success weakCompareAndSetPlain byte");
 513             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 514             assertEquals(x, (byte)0x23, "success weakCompareAndSetPlain byte value");
 515         }
 516 
 517         {
 518             boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact((byte)0x01, (byte)0x45);
 519             assertEquals(success, false, "failing weakCompareAndSetPlain byte");
 520             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 521             assertEquals(x, (byte)0x23, "failing weakCompareAndSetPlain byte value");
 522         }
 523 
 524         {
 525             MethodHandle mh = hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE);
 526             boolean success = false;
 527             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 528                 success = (boolean) mh.invokeExact((byte)0x23, (byte)0x01);
 529                 if (!success) weakDelay();
 530             }
 531             assertEquals(success, true, "success weakCompareAndSetAcquire byte");
 532             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 533             assertEquals(x, (byte)0x01, "success weakCompareAndSetAcquire byte");
 534         }
 535 
 536         {
 537             MethodHandle mh = hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE);
 538             boolean success = (boolean) mh.invokeExact((byte)0x23, (byte)0x45);
 539             assertEquals(success, false, "failing weakCompareAndSetAcquire byte");
 540             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 541             assertEquals(x, (byte)0x01, "failing weakCompareAndSetAcquire byte value");
 542         }
 543 
 544         {
 545             MethodHandle mh = hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE);
 546             boolean success = false;
 547             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 548                 success = (boolean) mh.invokeExact((byte)0x01, (byte)0x23);
 549                 if (!success) weakDelay();
 550             }
 551             assertEquals(success, true, "success weakCompareAndSetRelease byte");
 552             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 553             assertEquals(x, (byte)0x23, "success weakCompareAndSetRelease byte");
 554         }
 555 
 556         {
 557             boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact((byte)0x01, (byte)0x45);
 558             assertEquals(success, false, "failing weakCompareAndSetRelease byte");
 559             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 560             assertEquals(x, (byte)0x23, "failing weakCompareAndSetRelease byte value");
 561         }
 562 
 563         {
 564             MethodHandle mh = hs.get(TestAccessMode.WEAK_COMPARE_AND_SET);
 565             boolean success = false;
 566             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 567                 success = (boolean) mh.invokeExact((byte)0x23, (byte)0x01);
 568                 if (!success) weakDelay();
 569             }
 570             assertEquals(success, true, "success weakCompareAndSet byte");
 571             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 572             assertEquals(x, (byte)0x01, "success weakCompareAndSet byte");
 573         }
 574 
 575         {
 576             boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact((byte)0x23, (byte)0x45);
 577             assertEquals(success, false, "failing weakCompareAndSet byte");
 578             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 579             assertEquals(x, (byte)0x01, "failing weakCompareAndSetRe byte value");
 580         }
 581 
 582         // Compare set and get
 583         {
 584             hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
 585 
 586             byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact((byte)0x23);
 587             assertEquals(o, (byte)0x01, "getAndSet byte");
 588             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 589             assertEquals(x, (byte)0x23, "getAndSet byte value");
 590         }
 591 
 592         // Compare set and get
 593         {
 594             hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
 595 
 596             byte o = (byte) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact((byte)0x23);
 597             assertEquals(o, (byte)0x01, "getAndSetAcquire byte");
 598             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 599             assertEquals(x, (byte)0x23, "getAndSetAcquire byte value");
 600         }
 601 
 602         // Compare set and get
 603         {
 604             hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
 605 
 606             byte o = (byte) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact((byte)0x23);
 607             assertEquals(o, (byte)0x01, "getAndSetRelease byte");
 608             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 609             assertEquals(x, (byte)0x23, "getAndSetRelease byte value");
 610         }
 611 
 612         // get and add, add and get
 613         {
 614             hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
 615 
 616             byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact((byte)0x23);
 617             assertEquals(o, (byte)0x01, "getAndAdd byte");
 618             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 619             assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value");
 620         }
 621 
 622         {
 623             hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
 624 
 625             byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact((byte)0x23);
 626             assertEquals(o, (byte)0x01, "getAndAddAcquire byte");
 627             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 628             assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value");
 629         }
 630 
 631         {
 632             hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
 633 
 634             byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact((byte)0x23);
 635             assertEquals(o, (byte)0x01, "getAndAddRelease byte");
 636             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 637             assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value");
 638         }
 639 
 640         // get and bitwise or
 641         {
 642             hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
 643 
 644             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact((byte)0x23);
 645             assertEquals(o, (byte)0x01, "getAndBitwiseOr byte");
 646             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 647             assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value");
 648         }
 649 
 650         {
 651             hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
 652 
 653             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact((byte)0x23);
 654             assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte");
 655             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 656             assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value");
 657         }
 658 
 659         {
 660             hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
 661 
 662             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact((byte)0x23);
 663             assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte");
 664             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 665             assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value");
 666         }
 667 
 668         // get and bitwise and
 669         {
 670             hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
 671 
 672             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact((byte)0x23);
 673             assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte");
 674             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 675             assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value");
 676         }
 677 
 678         {
 679             hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
 680 
 681             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact((byte)0x23);
 682             assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte");
 683             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 684             assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value");
 685         }
 686 
 687         {
 688             hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
 689 
 690             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact((byte)0x23);
 691             assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte");
 692             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 693             assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value");
 694         }
 695 
 696         // get and bitwise xor
 697         {
 698             hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
 699 
 700             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact((byte)0x23);
 701             assertEquals(o, (byte)0x01, "getAndBitwiseXor byte");
 702             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 703             assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value");
 704         }
 705 
 706         {
 707             hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
 708 
 709             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact((byte)0x23);
 710             assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte");
 711             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 712             assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value");
 713         }
 714 
 715         {
 716             hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
 717 
 718             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact((byte)0x23);
 719             assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte");
 720             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
 721             assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value");
 722         }
 723     }
 724 
 725     static void testStaticFieldUnsupported(Handles hs) throws Throwable {
 726 
 727 
 728     }
 729 
 730 
 731     static void testArray(Handles hs) throws Throwable {
 732         byte[] array = new byte[10];
 733 
 734         for (int i = 0; i < array.length; i++) {
 735             // Plain
 736             {
 737                 hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
 738                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 739                 assertEquals(x, (byte)0x01, "get byte value");
 740             }
 741 
 742 
 743             // Volatile
 744             {
 745                 hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, (byte)0x23);
 746                 byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
 747                 assertEquals(x, (byte)0x23, "setVolatile byte value");
 748             }
 749 
 750             // Lazy
 751             {
 752                 hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, (byte)0x01);
 753                 byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
 754                 assertEquals(x, (byte)0x01, "setRelease byte value");
 755             }
 756 
 757             // Opaque
 758             {
 759                 hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, (byte)0x23);
 760                 byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
 761                 assertEquals(x, (byte)0x23, "setOpaque byte value");
 762             }
 763 
 764             hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
 765 
 766             // Compare
 767             {
 768                 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (byte)0x01, (byte)0x23);
 769                 assertEquals(r, true, "success compareAndSet byte");
 770                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 771                 assertEquals(x, (byte)0x23, "success compareAndSet byte value");
 772             }
 773 
 774             {
 775                 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (byte)0x01, (byte)0x45);
 776                 assertEquals(r, false, "failing compareAndSet byte");
 777                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 778                 assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
 779             }
 780 
 781             {
 782                 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (byte)0x23, (byte)0x01);
 783                 assertEquals(r, (byte)0x23, "success compareAndExchange byte");
 784                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 785                 assertEquals(x, (byte)0x01, "success compareAndExchange byte value");
 786             }
 787 
 788             {
 789                 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (byte)0x23, (byte)0x45);
 790                 assertEquals(r, (byte)0x01, "failing compareAndExchange byte");
 791                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 792                 assertEquals(x, (byte)0x01, "failing compareAndExchange byte value");
 793             }
 794 
 795             {
 796                 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (byte)0x01, (byte)0x23);
 797                 assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
 798                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 799                 assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
 800             }
 801 
 802             {
 803                 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (byte)0x01, (byte)0x45);
 804                 assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
 805                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 806                 assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
 807             }
 808 
 809             {
 810                 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (byte)0x23, (byte)0x01);
 811                 assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
 812                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 813                 assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
 814             }
 815 
 816             {
 817                 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (byte)0x23, (byte)0x45);
 818                 assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
 819                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 820                 assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
 821             }
 822 
 823             {
 824                 MethodHandle mh = hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN);
 825                 boolean success = false;
 826                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 827                     success = (boolean) mh.invokeExact(array, i, (byte)0x01, (byte)0x23);
 828                     if (!success) weakDelay();
 829                 }
 830                 assertEquals(success, true, "success weakCompareAndSetPlain byte");
 831                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 832                 assertEquals(x, (byte)0x23, "success weakCompareAndSetPlain byte value");
 833             }
 834 
 835             {
 836                 boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, (byte)0x01, (byte)0x45);
 837                 assertEquals(success, false, "failing weakCompareAndSetPlain byte");
 838                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 839                 assertEquals(x, (byte)0x23, "failing weakCompareAndSetPlain byte value");
 840             }
 841 
 842             {
 843                 MethodHandle mh = hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE);
 844                 boolean success = false;
 845                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 846                     success = (boolean) mh.invokeExact(array, i, (byte)0x23, (byte)0x01);
 847                     if (!success) weakDelay();
 848                 }
 849                 assertEquals(success, true, "success weakCompareAndSetAcquire byte");
 850                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 851                 assertEquals(x, (byte)0x01, "success weakCompareAndSetAcquire byte");
 852             }
 853 
 854             {
 855                 boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, (byte)0x23, (byte)0x45);
 856                 assertEquals(success, false, "failing weakCompareAndSetAcquire byte");
 857                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 858                 assertEquals(x, (byte)0x01, "failing weakCompareAndSetAcquire byte value");
 859             }
 860 
 861             {
 862                 MethodHandle mh = hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE);
 863                 boolean success = false;
 864                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 865                     success = (boolean) mh.invokeExact(array, i, (byte)0x01, (byte)0x23);
 866                     if (!success) weakDelay();
 867                 }
 868                 assertEquals(success, true, "success weakCompareAndSetRelease byte");
 869                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 870                 assertEquals(x, (byte)0x23, "success weakCompareAndSetRelease byte");
 871             }
 872 
 873             {
 874                 boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, (byte)0x01, (byte)0x45);
 875                 assertEquals(success, false, "failing weakCompareAndSetAcquire byte");
 876                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 877                 assertEquals(x, (byte)0x23, "failing weakCompareAndSetAcquire byte value");
 878             }
 879 
 880             {
 881                 MethodHandle mh = hs.get(TestAccessMode.WEAK_COMPARE_AND_SET);
 882                 boolean success = false;
 883                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 884                     success = (boolean) mh.invokeExact(array, i, (byte)0x23, (byte)0x01);
 885                     if (!success) weakDelay();
 886                 }
 887                 assertEquals(success, true, "success weakCompareAndSet byte");
 888                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 889                 assertEquals(x, (byte)0x01, "success weakCompareAndSet byte");
 890             }
 891 
 892             {
 893                 boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, (byte)0x23, (byte)0x45);
 894                 assertEquals(success, false, "failing weakCompareAndSet byte");
 895                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 896                 assertEquals(x, (byte)0x01, "failing weakCompareAndSet byte value");
 897             }
 898 
 899             // Compare set and get
 900             {
 901                 hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
 902 
 903                 byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, (byte)0x23);
 904                 assertEquals(o, (byte)0x01, "getAndSet byte");
 905                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 906                 assertEquals(x, (byte)0x23, "getAndSet byte value");
 907             }
 908 
 909             {
 910                 hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
 911 
 912                 byte o = (byte) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, (byte)0x23);
 913                 assertEquals(o, (byte)0x01, "getAndSetAcquire byte");
 914                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 915                 assertEquals(x, (byte)0x23, "getAndSetAcquire byte value");
 916             }
 917 
 918             {
 919                 hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
 920 
 921                 byte o = (byte) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, (byte)0x23);
 922                 assertEquals(o, (byte)0x01, "getAndSetRelease byte");
 923                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 924                 assertEquals(x, (byte)0x23, "getAndSetRelease byte value");
 925             }
 926 
 927             // get and add, add and get
 928             {
 929                 hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
 930 
 931                 byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, (byte)0x23);
 932                 assertEquals(o, (byte)0x01, "getAndAdd byte");
 933                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 934                 assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value");
 935             }
 936 
 937             {
 938                 hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
 939 
 940                 byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, (byte)0x23);
 941                 assertEquals(o, (byte)0x01, "getAndAddAcquire byte");
 942                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 943                 assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value");
 944             }
 945 
 946             {
 947                 hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
 948 
 949                 byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, (byte)0x23);
 950                 assertEquals(o, (byte)0x01, "getAndAddRelease byte");
 951                 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 952                 assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value");
 953             }
 954 
 955         // get and bitwise or
 956         {
 957             hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
 958 
 959             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, (byte)0x23);
 960             assertEquals(o, (byte)0x01, "getAndBitwiseOr byte");
 961             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 962             assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value");
 963         }
 964 
 965         {
 966             hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
 967 
 968             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, (byte)0x23);
 969             assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte");
 970             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 971             assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value");
 972         }
 973 
 974         {
 975             hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
 976 
 977             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, (byte)0x23);
 978             assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte");
 979             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 980             assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value");
 981         }
 982 
 983         // get and bitwise and
 984         {
 985             hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
 986 
 987             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, (byte)0x23);
 988             assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte");
 989             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 990             assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value");
 991         }
 992 
 993         {
 994             hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
 995 
 996             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, (byte)0x23);
 997             assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte");
 998             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
 999             assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value");
1000         }
1001 
1002         {
1003             hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
1004 
1005             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, (byte)0x23);
1006             assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte");
1007             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
1008             assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value");
1009         }
1010 
1011         // get and bitwise xor
1012         {
1013             hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
1014 
1015             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, (byte)0x23);
1016             assertEquals(o, (byte)0x01, "getAndBitwiseXor byte");
1017             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
1018             assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value");
1019         }
1020 
1021         {
1022             hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
1023 
1024             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, (byte)0x23);
1025             assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte");
1026             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
1027             assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value");
1028         }
1029 
1030         {
1031             hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
1032 
1033             byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, (byte)0x23);
1034             assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte");
1035             byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
1036             assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value");
1037         }
1038         }
1039     }
1040 
1041     static void testArrayUnsupported(Handles hs) throws Throwable {
1042         byte[] array = new byte[10];
1043 
1044         final int i = 0;
1045 
1046 
1047     }
1048 
1049     static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
1050         byte[] array = new byte[10];
1051 
1052         for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
1053             final int ci = i;
1054 
1055             for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
1056                 checkAIOOBE(am, () -> {
1057                     byte x = (byte) hs.get(am).invokeExact(array, ci);
1058                 });
1059             }
1060 
1061             for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
1062                 checkAIOOBE(am, () -> {
1063                     hs.get(am).invokeExact(array, ci, (byte)0x01);
1064                 });
1065             }
1066 
1067             for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
1068                 checkAIOOBE(am, () -> {
1069                     boolean r = (boolean) hs.get(am).invokeExact(array, ci, (byte)0x01, (byte)0x23);
1070                 });
1071             }
1072 
1073             for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1074                 checkAIOOBE(am, () -> {
1075                     byte r = (byte) hs.get(am).invokeExact(array, ci, (byte)0x23, (byte)0x01);
1076                 });
1077             }
1078 
1079             for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1080                 checkAIOOBE(am, () -> {
1081                     byte o = (byte) hs.get(am).invokeExact(array, ci, (byte)0x01);
1082                 });
1083             }
1084 
1085             for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
1086                 checkAIOOBE(am, () -> {
1087                     byte o = (byte) hs.get(am).invokeExact(array, ci, (byte)0x45);
1088                 });
1089             }
1090 
1091             for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
1092                 checkAIOOBE(am, () -> {
1093                     byte o = (byte) hs.get(am).invokeExact(array, ci, (byte)0x45);
1094                 });
1095             }
1096         }
1097     }
1098 }
1099