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