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