rev 55900 : 8207257: Add VarHandle access test for value type declared in ref type
Reviewed-by: tbd

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