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