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