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