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