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