1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @run testng/othervm -Diters=10    -Xint                   VarHandleTestAccess$Type$
  27  * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccess$Type$
  28  * @run testng/othervm -Diters=20000                         VarHandleTestAccess$Type$
  29  * @run testng/othervm -Diters=20000 -XX:-TieredCompilation  VarHandleTestAccess$Type$
  30  */
  31 
  32 import org.testng.annotations.BeforeClass;
  33 import org.testng.annotations.DataProvider;
  34 import org.testng.annotations.Test;
  35 
  36 import java.lang.invoke.MethodHandles;
  37 import java.lang.invoke.VarHandle;
  38 import java.util.ArrayList;
  39 import java.util.Arrays;
  40 import java.util.List;
  41 
  42 import static org.testng.Assert.*;
  43 
  44 public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
  45     static final $type$ static_final_v = $value1$;
  46 
  47     static $type$ static_v;
  48 
  49     final $type$ final_v = $value1$;
  50 
  51     $type$ v;
  52 
  53     VarHandle vhFinalField;
  54 
  55     VarHandle vhField;
  56 
  57     VarHandle vhStaticField;
  58 
  59     VarHandle vhStaticFinalField;
  60 
  61     VarHandle vhArray;
  62 
  63     @BeforeClass
  64     public void setup() throws Exception {
  65         vhFinalField = MethodHandles.lookup().findVarHandle(
  66                 VarHandleTestAccess$Type$.class, "final_v", $type$.class);
  67 
  68         vhField = MethodHandles.lookup().findVarHandle(
  69                 VarHandleTestAccess$Type$.class, "v", $type$.class);
  70 
  71         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
  72             VarHandleTestAccess$Type$.class, "static_final_v", $type$.class);
  73 
  74         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
  75             VarHandleTestAccess$Type$.class, "static_v", $type$.class);
  76 
  77         vhArray = MethodHandles.arrayElementVarHandle($type$[].class);
  78     }
  79 
  80 
  81     @DataProvider
  82     public Object[][] varHandlesProvider() throws Exception {
  83         List<VarHandle> vhs = new ArrayList<>();
  84         vhs.add(vhField);
  85         vhs.add(vhStaticField);
  86         vhs.add(vhArray);
  87 
  88         return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
  89     }
  90 
  91     @Test(dataProvider = "varHandlesProvider")
  92     public void testIsAccessModeSupported(VarHandle vh) {
  93         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
  94         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
  95         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
  96         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
  97         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
  98         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
  99         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
 100         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
 101 
 102 #if[CAS]
 103         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
 104         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
 105         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
 106         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
 107         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
 108         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
 109         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
 110         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
 111         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
 112         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
 113         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
 114 #else[CAS]
 115         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
 116         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
 117         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
 118         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
 119         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
 120         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
 121         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
 122         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
 123         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
 124         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
 125         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
 126 #end[CAS]
 127 
 128 #if[AtomicAdd]
 129         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
 130         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
 131         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
 132 #else[AtomicAdd]
 133         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
 134         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
 135         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
 136 #end[AtomicAdd]
 137 
 138 #if[Bitwise]
 139         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
 140         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
 141         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
 142         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
 143         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
 144         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
 145         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
 146         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
 147         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
 148 #else[Bitwise]
 149         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
 150         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
 151         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
 152         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
 153         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
 154         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
 155         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
 156         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
 157         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
 158 #end[Bitwise]
 159     }
 160 
 161 
 162     @DataProvider
 163     public Object[][] typesProvider() throws Exception {
 164         List<Object[]> types = new ArrayList<>();
 165         types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccess$Type$.class)});
 166         types.add(new Object[] {vhStaticField, Arrays.asList()});
 167         types.add(new Object[] {vhArray, Arrays.asList($type$[].class, int.class)});
 168 
 169         return types.stream().toArray(Object[][]::new);
 170     }
 171 
 172     @Test(dataProvider = "typesProvider")
 173     public void testTypes(VarHandle vh, List<Class<?>> pts) {
 174         assertEquals(vh.varType(), $type$.class);
 175 
 176         assertEquals(vh.coordinateTypes(), pts);
 177 
 178         testTypes(vh);
 179     }
 180 
 181 
 182     @Test
 183     public void testLookupInstanceToStatic() {
 184         checkIAE("Lookup of static final field to instance final field", () -> {
 185             MethodHandles.lookup().findStaticVarHandle(
 186                     VarHandleTestAccess$Type$.class, "final_v", $type$.class);
 187         });
 188 
 189         checkIAE("Lookup of static field to instance field", () -> {
 190             MethodHandles.lookup().findStaticVarHandle(
 191                     VarHandleTestAccess$Type$.class, "v", $type$.class);
 192         });
 193     }
 194 
 195     @Test
 196     public void testLookupStaticToInstance() {
 197         checkIAE("Lookup of instance final field to static final field", () -> {
 198             MethodHandles.lookup().findVarHandle(
 199                 VarHandleTestAccess$Type$.class, "static_final_v", $type$.class);
 200         });
 201 
 202         checkIAE("Lookup of instance field to static field", () -> {
 203             vhStaticField = MethodHandles.lookup().findVarHandle(
 204                 VarHandleTestAccess$Type$.class, "static_v", $type$.class);
 205         });
 206     }
 207 
 208 
 209     @DataProvider
 210     public Object[][] accessTestCaseProvider() throws Exception {
 211         List<AccessTestCase<?>> cases = new ArrayList<>();
 212 
 213         cases.add(new VarHandleAccessTestCase("Instance final field",
 214                                               vhFinalField, vh -> testInstanceFinalField(this, vh)));
 215         cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
 216                                               vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
 217                                               false));
 218 
 219         cases.add(new VarHandleAccessTestCase("Static final field",
 220                                               vhStaticFinalField, VarHandleTestAccess$Type$::testStaticFinalField));
 221         cases.add(new VarHandleAccessTestCase("Static final field unsupported",
 222                                               vhStaticFinalField, VarHandleTestAccess$Type$::testStaticFinalFieldUnsupported,
 223                                               false));
 224 
 225         cases.add(new VarHandleAccessTestCase("Instance field",
 226                                               vhField, vh -> testInstanceField(this, vh)));
 227         cases.add(new VarHandleAccessTestCase("Instance field unsupported",
 228                                               vhField, vh -> testInstanceFieldUnsupported(this, vh),
 229                                               false));
 230 
 231         cases.add(new VarHandleAccessTestCase("Static field",
 232                                               vhStaticField, VarHandleTestAccess$Type$::testStaticField));
 233         cases.add(new VarHandleAccessTestCase("Static field unsupported",
 234                                               vhStaticField, VarHandleTestAccess$Type$::testStaticFieldUnsupported,
 235                                               false));
 236 
 237         cases.add(new VarHandleAccessTestCase("Array",
 238                                               vhArray, VarHandleTestAccess$Type$::testArray));
 239         cases.add(new VarHandleAccessTestCase("Array unsupported",
 240                                               vhArray, VarHandleTestAccess$Type$::testArrayUnsupported,
 241                                               false));
 242         cases.add(new VarHandleAccessTestCase("Array index out of bounds",
 243                                               vhArray, VarHandleTestAccess$Type$::testArrayIndexOutOfBounds,
 244                                               false));
 245 
 246         // Work around issue with jtreg summary reporting which truncates
 247         // the String result of Object.toString to 30 characters, hence
 248         // the first dummy argument
 249         return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
 250     }
 251 
 252     @Test(dataProvider = "accessTestCaseProvider")
 253     public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
 254         T t = atc.get();
 255         int iters = atc.requiresLoop() ? ITERS : 1;
 256         for (int c = 0; c < iters; c++) {
 257             atc.testAccess(t);
 258         }
 259     }
 260 
 261 
 262 
 263 
 264     static void testInstanceFinalField(VarHandleTestAccess$Type$ recv, VarHandle vh) {
 265         // Plain
 266         {
 267             $type$ x = ($type$) vh.get(recv);
 268             assertEquals(x, $value1$, "get $type$ value");
 269         }
 270 
 271 
 272         // Volatile
 273         {
 274             $type$ x = ($type$) vh.getVolatile(recv);
 275             assertEquals(x, $value1$, "getVolatile $type$ value");
 276         }
 277 
 278         // Lazy
 279         {
 280             $type$ x = ($type$) vh.getAcquire(recv);
 281             assertEquals(x, $value1$, "getRelease $type$ value");
 282         }
 283 
 284         // Opaque
 285         {
 286             $type$ x = ($type$) vh.getOpaque(recv);
 287             assertEquals(x, $value1$, "getOpaque $type$ value");
 288         }
 289     }
 290 
 291     static void testInstanceFinalFieldUnsupported(VarHandleTestAccess$Type$ recv, VarHandle vh) {
 292         checkUOE(() -> {
 293             vh.set(recv, $value2$);
 294         });
 295 
 296         checkUOE(() -> {
 297             vh.setVolatile(recv, $value2$);
 298         });
 299 
 300         checkUOE(() -> {
 301             vh.setRelease(recv, $value2$);
 302         });
 303 
 304         checkUOE(() -> {
 305             vh.setOpaque(recv, $value2$);
 306         });
 307 
 308 #if[!CAS]
 309         checkUOE(() -> {
 310             boolean r = vh.compareAndSet(recv, $value1$, $value2$);
 311         });
 312 
 313         checkUOE(() -> {
 314             $type$ r = ($type$) vh.compareAndExchange(recv, $value1$, $value2$);
 315         });
 316 
 317         checkUOE(() -> {
 318             $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value2$);
 319         });
 320 
 321         checkUOE(() -> {
 322             $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value1$, $value2$);
 323         });
 324 
 325         checkUOE(() -> {
 326             boolean r = vh.weakCompareAndSetPlain(recv, $value1$, $value2$);
 327         });
 328 
 329         checkUOE(() -> {
 330             boolean r = vh.weakCompareAndSet(recv, $value1$, $value2$);
 331         });
 332 
 333         checkUOE(() -> {
 334             boolean r = vh.weakCompareAndSetAcquire(recv, $value1$, $value2$);
 335         });
 336 
 337         checkUOE(() -> {
 338             boolean r = vh.weakCompareAndSetRelease(recv, $value1$, $value2$);
 339         });
 340 
 341         checkUOE(() -> {
 342             $type$ r = ($type$) vh.getAndSet(recv, $value1$);
 343         });
 344 
 345         checkUOE(() -> {
 346             $type$ r = ($type$) vh.getAndSetAcquire(recv, $value1$);
 347         });
 348 
 349         checkUOE(() -> {
 350             $type$ r = ($type$) vh.getAndSetRelease(recv, $value1$);
 351         });
 352 #end[CAS]
 353 
 354 #if[!AtomicAdd]
 355         checkUOE(() -> {
 356             $type$ o = ($type$) vh.getAndAdd(recv, $value1$);
 357         });
 358 
 359         checkUOE(() -> {
 360             $type$ o = ($type$) vh.getAndAddAcquire(recv, $value1$);
 361         });
 362 
 363         checkUOE(() -> {
 364             $type$ o = ($type$) vh.getAndAddRelease(recv, $value1$);
 365         });
 366 #end[AtomicAdd]
 367 
 368 #if[!Bitwise]
 369         checkUOE(() -> {
 370             $type$ o = ($type$) vh.getAndBitwiseOr(recv, $value1$);
 371         });
 372 
 373         checkUOE(() -> {
 374             $type$ o = ($type$) vh.getAndBitwiseOrAcquire(recv, $value1$);
 375         });
 376 
 377         checkUOE(() -> {
 378             $type$ o = ($type$) vh.getAndBitwiseOrRelease(recv, $value1$);
 379         });
 380 
 381         checkUOE(() -> {
 382             $type$ o = ($type$) vh.getAndBitwiseAnd(recv, $value1$);
 383         });
 384 
 385         checkUOE(() -> {
 386             $type$ o = ($type$) vh.getAndBitwiseAndAcquire(recv, $value1$);
 387         });
 388 
 389         checkUOE(() -> {
 390             $type$ o = ($type$) vh.getAndBitwiseAndRelease(recv, $value1$);
 391         });
 392 
 393         checkUOE(() -> {
 394             $type$ o = ($type$) vh.getAndBitwiseXor(recv, $value1$);
 395         });
 396 
 397         checkUOE(() -> {
 398             $type$ o = ($type$) vh.getAndBitwiseXorAcquire(recv, $value1$);
 399         });
 400 
 401         checkUOE(() -> {
 402             $type$ o = ($type$) vh.getAndBitwiseXorRelease(recv, $value1$);
 403         });
 404 #end[Bitwise]
 405     }
 406 
 407 
 408     static void testStaticFinalField(VarHandle vh) {
 409         // Plain
 410         {
 411             $type$ x = ($type$) vh.get();
 412             assertEquals(x, $value1$, "get $type$ value");
 413         }
 414 
 415 
 416         // Volatile
 417         {
 418             $type$ x = ($type$) vh.getVolatile();
 419             assertEquals(x, $value1$, "getVolatile $type$ value");
 420         }
 421 
 422         // Lazy
 423         {
 424             $type$ x = ($type$) vh.getAcquire();
 425             assertEquals(x, $value1$, "getRelease $type$ value");
 426         }
 427 
 428         // Opaque
 429         {
 430             $type$ x = ($type$) vh.getOpaque();
 431             assertEquals(x, $value1$, "getOpaque $type$ value");
 432         }
 433     }
 434 
 435     static void testStaticFinalFieldUnsupported(VarHandle vh) {
 436         checkUOE(() -> {
 437             vh.set($value2$);
 438         });
 439 
 440         checkUOE(() -> {
 441             vh.setVolatile($value2$);
 442         });
 443 
 444         checkUOE(() -> {
 445             vh.setRelease($value2$);
 446         });
 447 
 448         checkUOE(() -> {
 449             vh.setOpaque($value2$);
 450         });
 451 
 452 #if[!CAS]
 453         checkUOE(() -> {
 454             boolean r = vh.compareAndSet($value1$, $value2$);
 455         });
 456 
 457         checkUOE(() -> {
 458             $type$ r = ($type$) vh.compareAndExchange($value1$, $value2$);
 459         });
 460 
 461         checkUOE(() -> {
 462             $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value2$);
 463         });
 464 
 465         checkUOE(() -> {
 466             $type$ r = ($type$) vh.compareAndExchangeRelease($value1$, $value2$);
 467         });
 468 
 469         checkUOE(() -> {
 470             boolean r = vh.weakCompareAndSetPlain($value1$, $value2$);
 471         });
 472 
 473         checkUOE(() -> {
 474             boolean r = vh.weakCompareAndSet($value1$, $value2$);
 475         });
 476 
 477         checkUOE(() -> {
 478             boolean r = vh.weakCompareAndSetAcquire($value1$, $value2$);
 479         });
 480 
 481         checkUOE(() -> {
 482             boolean r = vh.weakCompareAndSetRelease($value1$, $value2$);
 483         });
 484 
 485         checkUOE(() -> {
 486             $type$ r = ($type$) vh.getAndSet($value1$);
 487         });
 488 
 489         checkUOE(() -> {
 490             $type$ r = ($type$) vh.getAndSetAcquire($value1$);
 491         });
 492 
 493         checkUOE(() -> {
 494             $type$ r = ($type$) vh.getAndSetRelease($value1$);
 495         });
 496 #end[CAS]
 497 
 498 #if[!AtomicAdd]
 499         checkUOE(() -> {
 500             $type$ o = ($type$) vh.getAndAdd($value1$);
 501         });
 502 
 503         checkUOE(() -> {
 504             $type$ o = ($type$) vh.getAndAddAcquire($value1$);
 505         });
 506 
 507         checkUOE(() -> {
 508             $type$ o = ($type$) vh.getAndAddRelease($value1$);
 509         });
 510 #end[AtomicAdd]
 511 
 512 #if[!Bitwise]
 513         checkUOE(() -> {
 514             $type$ o = ($type$) vh.getAndBitwiseOr($value1$);
 515         });
 516 
 517         checkUOE(() -> {
 518             $type$ o = ($type$) vh.getAndBitwiseOrAcquire($value1$);
 519         });
 520 
 521         checkUOE(() -> {
 522             $type$ o = ($type$) vh.getAndBitwiseOrRelease($value1$);
 523         });
 524 
 525         checkUOE(() -> {
 526             $type$ o = ($type$) vh.getAndBitwiseAnd($value1$);
 527         });
 528 
 529         checkUOE(() -> {
 530             $type$ o = ($type$) vh.getAndBitwiseAndAcquire($value1$);
 531         });
 532 
 533         checkUOE(() -> {
 534             $type$ o = ($type$) vh.getAndBitwiseAndRelease($value1$);
 535         });
 536 
 537         checkUOE(() -> {
 538             $type$ o = ($type$) vh.getAndBitwiseXor($value1$);
 539         });
 540 
 541         checkUOE(() -> {
 542             $type$ o = ($type$) vh.getAndBitwiseXorAcquire($value1$);
 543         });
 544 
 545         checkUOE(() -> {
 546             $type$ o = ($type$) vh.getAndBitwiseXorRelease($value1$);
 547         });
 548 #end[Bitwise]
 549     }
 550 
 551 
 552     static void testInstanceField(VarHandleTestAccess$Type$ recv, VarHandle vh) {
 553         // Plain
 554         {
 555             vh.set(recv, $value1$);
 556             $type$ x = ($type$) vh.get(recv);
 557             assertEquals(x, $value1$, "set $type$ value");
 558         }
 559 
 560 
 561         // Volatile
 562         {
 563             vh.setVolatile(recv, $value2$);
 564             $type$ x = ($type$) vh.getVolatile(recv);
 565             assertEquals(x, $value2$, "setVolatile $type$ value");
 566         }
 567 
 568         // Lazy
 569         {
 570             vh.setRelease(recv, $value1$);
 571             $type$ x = ($type$) vh.getAcquire(recv);
 572             assertEquals(x, $value1$, "setRelease $type$ value");
 573         }
 574 
 575         // Opaque
 576         {
 577             vh.setOpaque(recv, $value2$);
 578             $type$ x = ($type$) vh.getOpaque(recv);
 579             assertEquals(x, $value2$, "setOpaque $type$ value");
 580         }
 581 
 582 #if[CAS]
 583         vh.set(recv, $value1$);
 584 
 585         // Compare
 586         {
 587             boolean r = vh.compareAndSet(recv, $value1$, $value2$);
 588             assertEquals(r, true, "success compareAndSet $type$");
 589             $type$ x = ($type$) vh.get(recv);
 590             assertEquals(x, $value2$, "success compareAndSet $type$ value");
 591         }
 592 
 593         {
 594             boolean r = vh.compareAndSet(recv, $value1$, $value3$);
 595             assertEquals(r, false, "failing compareAndSet $type$");
 596             $type$ x = ($type$) vh.get(recv);
 597             assertEquals(x, $value2$, "failing compareAndSet $type$ value");
 598         }
 599 
 600         {
 601             $type$ r = ($type$) vh.compareAndExchange(recv, $value2$, $value1$);
 602             assertEquals(r, $value2$, "success compareAndExchange $type$");
 603             $type$ x = ($type$) vh.get(recv);
 604             assertEquals(x, $value1$, "success compareAndExchange $type$ value");
 605         }
 606 
 607         {
 608             $type$ r = ($type$) vh.compareAndExchange(recv, $value2$, $value3$);
 609             assertEquals(r, $value1$, "failing compareAndExchange $type$");
 610             $type$ x = ($type$) vh.get(recv);
 611             assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
 612         }
 613 
 614         {
 615             $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value2$);
 616             assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
 617             $type$ x = ($type$) vh.get(recv);
 618             assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
 619         }
 620 
 621         {
 622             $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value3$);
 623             assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
 624             $type$ x = ($type$) vh.get(recv);
 625             assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
 626         }
 627 
 628         {
 629             $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value2$, $value1$);
 630             assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
 631             $type$ x = ($type$) vh.get(recv);
 632             assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
 633         }
 634 
 635         {
 636             $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value2$, $value3$);
 637             assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
 638             $type$ x = ($type$) vh.get(recv);
 639             assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
 640         }
 641 
 642         {
 643             boolean success = false;
 644             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 645                 success = vh.weakCompareAndSetPlain(recv, $value1$, $value2$);
 646             }
 647             assertEquals(success, true, "weakCompareAndSetPlain $type$");
 648             $type$ x = ($type$) vh.get(recv);
 649             assertEquals(x, $value2$, "weakCompareAndSetPlain $type$ value");
 650         }
 651 
 652         {
 653             boolean success = false;
 654             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 655                 success = vh.weakCompareAndSetAcquire(recv, $value2$, $value1$);
 656             }
 657             assertEquals(success, true, "weakCompareAndSetAcquire $type$");
 658             $type$ x = ($type$) vh.get(recv);
 659             assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
 660         }
 661 
 662         {
 663             boolean success = false;
 664             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 665                 success = vh.weakCompareAndSetRelease(recv, $value1$, $value2$);
 666             }
 667             assertEquals(success, true, "weakCompareAndSetRelease $type$");
 668             $type$ x = ($type$) vh.get(recv);
 669             assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
 670         }
 671 
 672         {
 673             boolean success = false;
 674             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 675                 success = vh.weakCompareAndSet(recv, $value2$, $value1$);
 676             }
 677             assertEquals(success, true, "weakCompareAndSet $type$");
 678             $type$ x = ($type$) vh.get(recv);
 679             assertEquals(x, $value1$, "weakCompareAndSet $type$ value");
 680         }
 681 
 682         // Compare set and get
 683         {
 684             vh.set(recv, $value1$);
 685 
 686             $type$ o = ($type$) vh.getAndSet(recv, $value2$);
 687             assertEquals(o, $value1$, "getAndSet $type$");
 688             $type$ x = ($type$) vh.get(recv);
 689             assertEquals(x, $value2$, "getAndSet $type$ value");
 690         }
 691 
 692         {
 693             vh.set(recv, $value1$);
 694 
 695             $type$ o = ($type$) vh.getAndSetAcquire(recv, $value2$);
 696             assertEquals(o, $value1$, "getAndSetAcquire $type$");
 697             $type$ x = ($type$) vh.get(recv);
 698             assertEquals(x, $value2$, "getAndSetAcquire $type$ value");
 699         }
 700 
 701         {
 702             vh.set(recv, $value1$);
 703 
 704             $type$ o = ($type$) vh.getAndSetRelease(recv, $value2$);
 705             assertEquals(o, $value1$, "getAndSetRelease $type$");
 706             $type$ x = ($type$) vh.get(recv);
 707             assertEquals(x, $value2$, "getAndSetRelease $type$ value");
 708         }
 709 #end[CAS]
 710 
 711 #if[AtomicAdd]
 712         // get and add, add and get
 713         {
 714             vh.set(recv, $value1$);
 715 
 716             $type$ o = ($type$) vh.getAndAdd(recv, $value2$);
 717             assertEquals(o, $value1$, "getAndAdd $type$");
 718             $type$ x = ($type$) vh.get(recv);
 719             assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value");
 720         }
 721 
 722         {
 723             vh.set(recv, $value1$);
 724 
 725             $type$ o = ($type$) vh.getAndAddAcquire(recv, $value2$);
 726             assertEquals(o, $value1$, "getAndAddAcquire $type$");
 727             $type$ x = ($type$) vh.get(recv);
 728             assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value");
 729         }
 730 
 731         {
 732             vh.set(recv, $value1$);
 733 
 734             $type$ o = ($type$) vh.getAndAddRelease(recv, $value2$);
 735             assertEquals(o, $value1$, "getAndAddRelease$type$");
 736             $type$ x = ($type$) vh.get(recv);
 737             assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value");
 738         }
 739 #end[AtomicAdd]
 740 
 741 #if[Bitwise]
 742         // get and bitwise or
 743         {
 744             vh.set(recv, $value1$);
 745 
 746             $type$ o = ($type$) vh.getAndBitwiseOr(recv, $value2$);
 747             assertEquals(o, $value1$, "getAndBitwiseOr $type$");
 748             $type$ x = ($type$) vh.get(recv);
 749             assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value");
 750         }
 751 
 752         {
 753             vh.set(recv, $value1$);
 754 
 755             $type$ o = ($type$) vh.getAndBitwiseOrAcquire(recv, $value2$);
 756             assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$");
 757             $type$ x = ($type$) vh.get(recv);
 758             assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value");
 759         }
 760 
 761         {
 762             vh.set(recv, $value1$);
 763 
 764             $type$ o = ($type$) vh.getAndBitwiseOrRelease(recv, $value2$);
 765             assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$");
 766             $type$ x = ($type$) vh.get(recv);
 767             assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value");
 768         }
 769 
 770         // get and bitwise and
 771         {
 772             vh.set(recv, $value1$);
 773 
 774             $type$ o = ($type$) vh.getAndBitwiseAnd(recv, $value2$);
 775             assertEquals(o, $value1$, "getAndBitwiseAnd $type$");
 776             $type$ x = ($type$) vh.get(recv);
 777             assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value");
 778         }
 779 
 780         {
 781             vh.set(recv, $value1$);
 782 
 783             $type$ o = ($type$) vh.getAndBitwiseAndAcquire(recv, $value2$);
 784             assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$");
 785             $type$ x = ($type$) vh.get(recv);
 786             assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value");
 787         }
 788 
 789         {
 790             vh.set(recv, $value1$);
 791 
 792             $type$ o = ($type$) vh.getAndBitwiseAndRelease(recv, $value2$);
 793             assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$");
 794             $type$ x = ($type$) vh.get(recv);
 795             assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value");
 796         }
 797 
 798         // get and bitwise xor
 799         {
 800             vh.set(recv, $value1$);
 801 
 802             $type$ o = ($type$) vh.getAndBitwiseXor(recv, $value2$);
 803             assertEquals(o, $value1$, "getAndBitwiseXor $type$");
 804             $type$ x = ($type$) vh.get(recv);
 805             assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value");
 806         }
 807 
 808         {
 809             vh.set(recv, $value1$);
 810 
 811             $type$ o = ($type$) vh.getAndBitwiseXorAcquire(recv, $value2$);
 812             assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$");
 813             $type$ x = ($type$) vh.get(recv);
 814             assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value");
 815         }
 816 
 817         {
 818             vh.set(recv, $value1$);
 819 
 820             $type$ o = ($type$) vh.getAndBitwiseXorRelease(recv, $value2$);
 821             assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$");
 822             $type$ x = ($type$) vh.get(recv);
 823             assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value");
 824         }
 825 #end[Bitwise]
 826     }
 827 
 828     static void testInstanceFieldUnsupported(VarHandleTestAccess$Type$ recv, VarHandle vh) {
 829 #if[!CAS]
 830         checkUOE(() -> {
 831             boolean r = vh.compareAndSet(recv, $value1$, $value2$);
 832         });
 833 
 834         checkUOE(() -> {
 835             $type$ r = ($type$) vh.compareAndExchange(recv, $value1$, $value2$);
 836         });
 837 
 838         checkUOE(() -> {
 839             $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value2$);
 840         });
 841 
 842         checkUOE(() -> {
 843             $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value1$, $value2$);
 844         });
 845 
 846         checkUOE(() -> {
 847             boolean r = vh.weakCompareAndSetPlain(recv, $value1$, $value2$);
 848         });
 849 
 850         checkUOE(() -> {
 851             boolean r = vh.weakCompareAndSet(recv, $value1$, $value2$);
 852         });
 853 
 854         checkUOE(() -> {
 855             boolean r = vh.weakCompareAndSetAcquire(recv, $value1$, $value2$);
 856         });
 857 
 858         checkUOE(() -> {
 859             boolean r = vh.weakCompareAndSetRelease(recv, $value1$, $value2$);
 860         });
 861 
 862         checkUOE(() -> {
 863             $type$ r = ($type$) vh.getAndSet(recv, $value1$);
 864         });
 865 
 866         checkUOE(() -> {
 867             $type$ r = ($type$) vh.getAndSetAcquire(recv, $value1$);
 868         });
 869 
 870         checkUOE(() -> {
 871             $type$ r = ($type$) vh.getAndSetRelease(recv, $value1$);
 872         });
 873 #end[CAS]
 874 
 875 #if[!AtomicAdd]
 876         checkUOE(() -> {
 877             $type$ o = ($type$) vh.getAndAdd(recv, $value1$);
 878         });
 879 
 880         checkUOE(() -> {
 881             $type$ o = ($type$) vh.getAndAddAcquire(recv, $value1$);
 882         });
 883 
 884         checkUOE(() -> {
 885             $type$ o = ($type$) vh.getAndAddRelease(recv, $value1$);
 886         });
 887 #end[AtomicAdd]
 888 
 889 #if[!Bitwise]
 890         checkUOE(() -> {
 891             $type$ o = ($type$) vh.getAndBitwiseOr(recv, $value1$);
 892         });
 893 
 894         checkUOE(() -> {
 895             $type$ o = ($type$) vh.getAndBitwiseOrAcquire(recv, $value1$);
 896         });
 897 
 898         checkUOE(() -> {
 899             $type$ o = ($type$) vh.getAndBitwiseOrRelease(recv, $value1$);
 900         });
 901 
 902         checkUOE(() -> {
 903             $type$ o = ($type$) vh.getAndBitwiseAnd(recv, $value1$);
 904         });
 905 
 906         checkUOE(() -> {
 907             $type$ o = ($type$) vh.getAndBitwiseAndAcquire(recv, $value1$);
 908         });
 909 
 910         checkUOE(() -> {
 911             $type$ o = ($type$) vh.getAndBitwiseAndRelease(recv, $value1$);
 912         });
 913 
 914         checkUOE(() -> {
 915             $type$ o = ($type$) vh.getAndBitwiseXor(recv, $value1$);
 916         });
 917 
 918         checkUOE(() -> {
 919             $type$ o = ($type$) vh.getAndBitwiseXorAcquire(recv, $value1$);
 920         });
 921 
 922         checkUOE(() -> {
 923             $type$ o = ($type$) vh.getAndBitwiseXorRelease(recv, $value1$);
 924         });
 925 #end[Bitwise]
 926     }
 927 
 928 
 929     static void testStaticField(VarHandle vh) {
 930         // Plain
 931         {
 932             vh.set($value1$);
 933             $type$ x = ($type$) vh.get();
 934             assertEquals(x, $value1$, "set $type$ value");
 935         }
 936 
 937 
 938         // Volatile
 939         {
 940             vh.setVolatile($value2$);
 941             $type$ x = ($type$) vh.getVolatile();
 942             assertEquals(x, $value2$, "setVolatile $type$ value");
 943         }
 944 
 945         // Lazy
 946         {
 947             vh.setRelease($value1$);
 948             $type$ x = ($type$) vh.getAcquire();
 949             assertEquals(x, $value1$, "setRelease $type$ value");
 950         }
 951 
 952         // Opaque
 953         {
 954             vh.setOpaque($value2$);
 955             $type$ x = ($type$) vh.getOpaque();
 956             assertEquals(x, $value2$, "setOpaque $type$ value");
 957         }
 958 
 959 #if[CAS]
 960         vh.set($value1$);
 961 
 962         // Compare
 963         {
 964             boolean r = vh.compareAndSet($value1$, $value2$);
 965             assertEquals(r, true, "success compareAndSet $type$");
 966             $type$ x = ($type$) vh.get();
 967             assertEquals(x, $value2$, "success compareAndSet $type$ value");
 968         }
 969 
 970         {
 971             boolean r = vh.compareAndSet($value1$, $value3$);
 972             assertEquals(r, false, "failing compareAndSet $type$");
 973             $type$ x = ($type$) vh.get();
 974             assertEquals(x, $value2$, "failing compareAndSet $type$ value");
 975         }
 976 
 977         {
 978             $type$ r = ($type$) vh.compareAndExchange($value2$, $value1$);
 979             assertEquals(r, $value2$, "success compareAndExchange $type$");
 980             $type$ x = ($type$) vh.get();
 981             assertEquals(x, $value1$, "success compareAndExchange $type$ value");
 982         }
 983 
 984         {
 985             $type$ r = ($type$) vh.compareAndExchange($value2$, $value3$);
 986             assertEquals(r, $value1$, "failing compareAndExchange $type$");
 987             $type$ x = ($type$) vh.get();
 988             assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
 989         }
 990 
 991         {
 992             $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value2$);
 993             assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
 994             $type$ x = ($type$) vh.get();
 995             assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
 996         }
 997 
 998         {
 999             $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value3$);
1000             assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
1001             $type$ x = ($type$) vh.get();
1002             assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
1003         }
1004 
1005         {
1006             $type$ r = ($type$) vh.compareAndExchangeRelease($value2$, $value1$);
1007             assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
1008             $type$ x = ($type$) vh.get();
1009             assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
1010         }
1011 
1012         {
1013             $type$ r = ($type$) vh.compareAndExchangeRelease($value2$, $value3$);
1014             assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
1015             $type$ x = ($type$) vh.get();
1016             assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
1017         }
1018 
1019         {
1020             boolean success = false;
1021             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1022                 success = vh.weakCompareAndSetPlain($value1$, $value2$);
1023             }
1024             assertEquals(success, true, "weakCompareAndSetPlain $type$");
1025             $type$ x = ($type$) vh.get();
1026             assertEquals(x, $value2$, "weakCompareAndSetPlain $type$ value");
1027         }
1028 
1029         {
1030             boolean success = false;
1031             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1032                 success = vh.weakCompareAndSetAcquire($value2$, $value1$);
1033             }
1034             assertEquals(success, true, "weakCompareAndSetAcquire $type$");
1035             $type$ x = ($type$) vh.get();
1036             assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
1037         }
1038 
1039         {
1040             boolean success = false;
1041             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1042                 success = vh.weakCompareAndSetRelease($value1$, $value2$);
1043             }
1044             assertEquals(success, true, "weakCompareAndSetRelease $type$");
1045             $type$ x = ($type$) vh.get();
1046             assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
1047         }
1048 
1049         {
1050             boolean success = false;
1051             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1052                 success = vh.weakCompareAndSet($value2$, $value1$);
1053             }
1054             assertEquals(success, true, "weakCompareAndSet $type$");
1055             $type$ x = ($type$) vh.get();
1056             assertEquals(x, $value1$, "weakCompareAndSet $type$");
1057         }
1058 
1059         // Compare set and get
1060         {
1061             vh.set($value1$);
1062 
1063             $type$ o = ($type$) vh.getAndSet($value2$);
1064             assertEquals(o, $value1$, "getAndSet $type$");
1065             $type$ x = ($type$) vh.get();
1066             assertEquals(x, $value2$, "getAndSet $type$ value");
1067         }
1068 
1069         {
1070             vh.set($value1$);
1071 
1072             $type$ o = ($type$) vh.getAndSetAcquire($value2$);
1073             assertEquals(o, $value1$, "getAndSetAcquire $type$");
1074             $type$ x = ($type$) vh.get();
1075             assertEquals(x, $value2$, "getAndSetAcquire $type$ value");
1076         }
1077 
1078         {
1079             vh.set($value1$);
1080 
1081             $type$ o = ($type$) vh.getAndSetRelease($value2$);
1082             assertEquals(o, $value1$, "getAndSetRelease $type$");
1083             $type$ x = ($type$) vh.get();
1084             assertEquals(x, $value2$, "getAndSetRelease $type$ value");
1085         }
1086 #end[CAS]
1087 
1088 #if[AtomicAdd]
1089         // get and add, add and get
1090         {
1091             vh.set($value1$);
1092 
1093             $type$ o = ($type$) vh.getAndAdd($value2$);
1094             assertEquals(o, $value1$, "getAndAdd $type$");
1095             $type$ x = ($type$) vh.get();
1096             assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value");
1097         }
1098 
1099         {
1100             vh.set($value1$);
1101 
1102             $type$ o = ($type$) vh.getAndAddAcquire($value2$);
1103             assertEquals(o, $value1$, "getAndAddAcquire $type$");
1104             $type$ x = ($type$) vh.get();
1105             assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value");
1106         }
1107 
1108         {
1109             vh.set($value1$);
1110 
1111             $type$ o = ($type$) vh.getAndAddRelease($value2$);
1112             assertEquals(o, $value1$, "getAndAddRelease$type$");
1113             $type$ x = ($type$) vh.get();
1114             assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value");
1115         }
1116 #end[AtomicAdd]
1117 
1118 #if[Bitwise]
1119         // get and bitwise or
1120         {
1121             vh.set($value1$);
1122 
1123             $type$ o = ($type$) vh.getAndBitwiseOr($value2$);
1124             assertEquals(o, $value1$, "getAndBitwiseOr $type$");
1125             $type$ x = ($type$) vh.get();
1126             assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value");
1127         }
1128 
1129         {
1130             vh.set($value1$);
1131 
1132             $type$ o = ($type$) vh.getAndBitwiseOrAcquire($value2$);
1133             assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$");
1134             $type$ x = ($type$) vh.get();
1135             assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value");
1136         }
1137 
1138         {
1139             vh.set($value1$);
1140 
1141             $type$ o = ($type$) vh.getAndBitwiseOrRelease($value2$);
1142             assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$");
1143             $type$ x = ($type$) vh.get();
1144             assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value");
1145         }
1146 
1147         // get and bitwise and
1148         {
1149             vh.set($value1$);
1150 
1151             $type$ o = ($type$) vh.getAndBitwiseAnd($value2$);
1152             assertEquals(o, $value1$, "getAndBitwiseAnd $type$");
1153             $type$ x = ($type$) vh.get();
1154             assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value");
1155         }
1156 
1157         {
1158             vh.set($value1$);
1159 
1160             $type$ o = ($type$) vh.getAndBitwiseAndAcquire($value2$);
1161             assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$");
1162             $type$ x = ($type$) vh.get();
1163             assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value");
1164         }
1165 
1166         {
1167             vh.set($value1$);
1168 
1169             $type$ o = ($type$) vh.getAndBitwiseAndRelease($value2$);
1170             assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$");
1171             $type$ x = ($type$) vh.get();
1172             assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value");
1173         }
1174 
1175         // get and bitwise xor
1176         {
1177             vh.set($value1$);
1178 
1179             $type$ o = ($type$) vh.getAndBitwiseXor($value2$);
1180             assertEquals(o, $value1$, "getAndBitwiseXor $type$");
1181             $type$ x = ($type$) vh.get();
1182             assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value");
1183         }
1184 
1185         {
1186             vh.set($value1$);
1187 
1188             $type$ o = ($type$) vh.getAndBitwiseXorAcquire($value2$);
1189             assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$");
1190             $type$ x = ($type$) vh.get();
1191             assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value");
1192         }
1193 
1194         {
1195             vh.set($value1$);
1196 
1197             $type$ o = ($type$) vh.getAndBitwiseXorRelease($value2$);
1198             assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$");
1199             $type$ x = ($type$) vh.get();
1200             assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value");
1201         }
1202 #end[Bitwise]
1203     }
1204 
1205     static void testStaticFieldUnsupported(VarHandle vh) {
1206 #if[!CAS]
1207         checkUOE(() -> {
1208             boolean r = vh.compareAndSet($value1$, $value2$);
1209         });
1210 
1211         checkUOE(() -> {
1212             $type$ r = ($type$) vh.compareAndExchange($value1$, $value2$);
1213         });
1214 
1215         checkUOE(() -> {
1216             $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value2$);
1217         });
1218 
1219         checkUOE(() -> {
1220             $type$ r = ($type$) vh.compareAndExchangeRelease($value1$, $value2$);
1221         });
1222 
1223         checkUOE(() -> {
1224             boolean r = vh.weakCompareAndSetPlain($value1$, $value2$);
1225         });
1226 
1227         checkUOE(() -> {
1228             boolean r = vh.weakCompareAndSet($value1$, $value2$);
1229         });
1230 
1231         checkUOE(() -> {
1232             boolean r = vh.weakCompareAndSetAcquire($value1$, $value2$);
1233         });
1234 
1235         checkUOE(() -> {
1236             boolean r = vh.weakCompareAndSetRelease($value1$, $value2$);
1237         });
1238 
1239         checkUOE(() -> {
1240             $type$ r = ($type$) vh.getAndSet($value1$);
1241         });
1242 
1243         checkUOE(() -> {
1244             $type$ r = ($type$) vh.getAndSetAcquire($value1$);
1245         });
1246 
1247         checkUOE(() -> {
1248             $type$ r = ($type$) vh.getAndSetRelease($value1$);
1249         });
1250 #end[CAS]
1251 
1252 #if[!AtomicAdd]
1253         checkUOE(() -> {
1254             $type$ o = ($type$) vh.getAndAdd($value1$);
1255         });
1256 
1257         checkUOE(() -> {
1258             $type$ o = ($type$) vh.getAndAddAcquire($value1$);
1259         });
1260 
1261         checkUOE(() -> {
1262             $type$ o = ($type$) vh.getAndAddRelease($value1$);
1263         });
1264 #end[AtomicAdd]
1265 
1266 #if[!Bitwise]
1267         checkUOE(() -> {
1268             $type$ o = ($type$) vh.getAndBitwiseOr($value1$);
1269         });
1270 
1271         checkUOE(() -> {
1272             $type$ o = ($type$) vh.getAndBitwiseOrAcquire($value1$);
1273         });
1274 
1275         checkUOE(() -> {
1276             $type$ o = ($type$) vh.getAndBitwiseOrRelease($value1$);
1277         });
1278 
1279         checkUOE(() -> {
1280             $type$ o = ($type$) vh.getAndBitwiseAnd($value1$);
1281         });
1282 
1283         checkUOE(() -> {
1284             $type$ o = ($type$) vh.getAndBitwiseAndAcquire($value1$);
1285         });
1286 
1287         checkUOE(() -> {
1288             $type$ o = ($type$) vh.getAndBitwiseAndRelease($value1$);
1289         });
1290 
1291         checkUOE(() -> {
1292             $type$ o = ($type$) vh.getAndBitwiseXor($value1$);
1293         });
1294 
1295         checkUOE(() -> {
1296             $type$ o = ($type$) vh.getAndBitwiseXorAcquire($value1$);
1297         });
1298 
1299         checkUOE(() -> {
1300             $type$ o = ($type$) vh.getAndBitwiseXorRelease($value1$);
1301         });
1302 #end[Bitwise]
1303     }
1304 
1305 
1306     static void testArray(VarHandle vh) {
1307         $type$[] array = new $type$[10];
1308 
1309         for (int i = 0; i < array.length; i++) {
1310             // Plain
1311             {
1312                 vh.set(array, i, $value1$);
1313                 $type$ x = ($type$) vh.get(array, i);
1314                 assertEquals(x, $value1$, "get $type$ value");
1315             }
1316 
1317 
1318             // Volatile
1319             {
1320                 vh.setVolatile(array, i, $value2$);
1321                 $type$ x = ($type$) vh.getVolatile(array, i);
1322                 assertEquals(x, $value2$, "setVolatile $type$ value");
1323             }
1324 
1325             // Lazy
1326             {
1327                 vh.setRelease(array, i, $value1$);
1328                 $type$ x = ($type$) vh.getAcquire(array, i);
1329                 assertEquals(x, $value1$, "setRelease $type$ value");
1330             }
1331 
1332             // Opaque
1333             {
1334                 vh.setOpaque(array, i, $value2$);
1335                 $type$ x = ($type$) vh.getOpaque(array, i);
1336                 assertEquals(x, $value2$, "setOpaque $type$ value");
1337             }
1338 
1339 #if[CAS]
1340             vh.set(array, i, $value1$);
1341 
1342             // Compare
1343             {
1344                 boolean r = vh.compareAndSet(array, i, $value1$, $value2$);
1345                 assertEquals(r, true, "success compareAndSet $type$");
1346                 $type$ x = ($type$) vh.get(array, i);
1347                 assertEquals(x, $value2$, "success compareAndSet $type$ value");
1348             }
1349 
1350             {
1351                 boolean r = vh.compareAndSet(array, i, $value1$, $value3$);
1352                 assertEquals(r, false, "failing compareAndSet $type$");
1353                 $type$ x = ($type$) vh.get(array, i);
1354                 assertEquals(x, $value2$, "failing compareAndSet $type$ value");
1355             }
1356 
1357             {
1358                 $type$ r = ($type$) vh.compareAndExchange(array, i, $value2$, $value1$);
1359                 assertEquals(r, $value2$, "success compareAndExchange $type$");
1360                 $type$ x = ($type$) vh.get(array, i);
1361                 assertEquals(x, $value1$, "success compareAndExchange $type$ value");
1362             }
1363 
1364             {
1365                 $type$ r = ($type$) vh.compareAndExchange(array, i, $value2$, $value3$);
1366                 assertEquals(r, $value1$, "failing compareAndExchange $type$");
1367                 $type$ x = ($type$) vh.get(array, i);
1368                 assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
1369             }
1370 
1371             {
1372                 $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, $value1$, $value2$);
1373                 assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
1374                 $type$ x = ($type$) vh.get(array, i);
1375                 assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
1376             }
1377 
1378             {
1379                 $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, $value1$, $value3$);
1380                 assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
1381                 $type$ x = ($type$) vh.get(array, i);
1382                 assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
1383             }
1384 
1385             {
1386                 $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, $value2$, $value1$);
1387                 assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
1388                 $type$ x = ($type$) vh.get(array, i);
1389                 assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
1390             }
1391 
1392             {
1393                 $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, $value2$, $value3$);
1394                 assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
1395                 $type$ x = ($type$) vh.get(array, i);
1396                 assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
1397             }
1398 
1399             {
1400                 boolean success = false;
1401                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1402                     success = vh.weakCompareAndSetPlain(array, i, $value1$, $value2$);
1403                 }
1404                 assertEquals(success, true, "weakCompareAndSetPlain $type$");
1405                 $type$ x = ($type$) vh.get(array, i);
1406                 assertEquals(x, $value2$, "weakCompareAndSetPlain $type$ value");
1407             }
1408 
1409             {
1410                 boolean success = false;
1411                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1412                     success = vh.weakCompareAndSetAcquire(array, i, $value2$, $value1$);
1413                 }
1414                 assertEquals(success, true, "weakCompareAndSetAcquire $type$");
1415                 $type$ x = ($type$) vh.get(array, i);
1416                 assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
1417             }
1418 
1419             {
1420                 boolean success = false;
1421                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1422                     success = vh.weakCompareAndSetRelease(array, i, $value1$, $value2$);
1423                 }
1424                 assertEquals(success, true, "weakCompareAndSetRelease $type$");
1425                 $type$ x = ($type$) vh.get(array, i);
1426                 assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
1427             }
1428 
1429             {
1430                 boolean success = false;
1431                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1432                     success = vh.weakCompareAndSet(array, i, $value2$, $value1$);
1433                 }
1434                 assertEquals(success, true, "weakCompareAndSet $type$");
1435                 $type$ x = ($type$) vh.get(array, i);
1436                 assertEquals(x, $value1$, "weakCompareAndSet $type$");
1437             }
1438 
1439             // Compare set and get
1440             {
1441                 vh.set(array, i, $value1$);
1442 
1443                 $type$ o = ($type$) vh.getAndSet(array, i, $value2$);
1444                 assertEquals(o, $value1$, "getAndSet $type$");
1445                 $type$ x = ($type$) vh.get(array, i);
1446                 assertEquals(x, $value2$, "getAndSet $type$ value");
1447             }
1448 
1449             {
1450                 vh.set(array, i, $value1$);
1451 
1452                 $type$ o = ($type$) vh.getAndSetAcquire(array, i, $value2$);
1453                 assertEquals(o, $value1$, "getAndSetAcquire $type$");
1454                 $type$ x = ($type$) vh.get(array, i);
1455                 assertEquals(x, $value2$, "getAndSetAcquire $type$ value");
1456             }
1457 
1458             {
1459                 vh.set(array, i, $value1$);
1460 
1461                 $type$ o = ($type$) vh.getAndSetRelease(array, i, $value2$);
1462                 assertEquals(o, $value1$, "getAndSetRelease $type$");
1463                 $type$ x = ($type$) vh.get(array, i);
1464                 assertEquals(x, $value2$, "getAndSetRelease $type$ value");
1465             }
1466 #end[CAS]
1467 
1468 #if[AtomicAdd]
1469             // get and add, add and get
1470             {
1471                 vh.set(array, i, $value1$);
1472 
1473                 $type$ o = ($type$) vh.getAndAdd(array, i, $value2$);
1474                 assertEquals(o, $value1$, "getAndAdd $type$");
1475                 $type$ x = ($type$) vh.get(array, i);
1476                 assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value");
1477             }
1478 
1479             {
1480                 vh.set(array, i, $value1$);
1481 
1482                 $type$ o = ($type$) vh.getAndAddAcquire(array, i, $value2$);
1483                 assertEquals(o, $value1$, "getAndAddAcquire $type$");
1484                 $type$ x = ($type$) vh.get(array, i);
1485                 assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value");
1486             }
1487 
1488             {
1489                 vh.set(array, i, $value1$);
1490 
1491                 $type$ o = ($type$) vh.getAndAddRelease(array, i, $value2$);
1492                 assertEquals(o, $value1$, "getAndAddRelease$type$");
1493                 $type$ x = ($type$) vh.get(array, i);
1494                 assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value");
1495             }
1496 #end[AtomicAdd]
1497 
1498 #if[Bitwise]
1499             // get and bitwise or
1500             {
1501                 vh.set(array, i, $value1$);
1502 
1503                 $type$ o = ($type$) vh.getAndBitwiseOr(array, i, $value2$);
1504                 assertEquals(o, $value1$, "getAndBitwiseOr $type$");
1505                 $type$ x = ($type$) vh.get(array, i);
1506                 assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value");
1507             }
1508 
1509             {
1510                 vh.set(array, i, $value1$);
1511 
1512                 $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, i, $value2$);
1513                 assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$");
1514                 $type$ x = ($type$) vh.get(array, i);
1515                 assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value");
1516             }
1517 
1518             {
1519                 vh.set(array, i, $value1$);
1520 
1521                 $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, i, $value2$);
1522                 assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$");
1523                 $type$ x = ($type$) vh.get(array, i);
1524                 assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value");
1525             }
1526 
1527             // get and bitwise and
1528             {
1529                 vh.set(array, i, $value1$);
1530 
1531                 $type$ o = ($type$) vh.getAndBitwiseAnd(array, i, $value2$);
1532                 assertEquals(o, $value1$, "getAndBitwiseAnd $type$");
1533                 $type$ x = ($type$) vh.get(array, i);
1534                 assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value");
1535             }
1536 
1537             {
1538                 vh.set(array, i, $value1$);
1539 
1540                 $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, i, $value2$);
1541                 assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$");
1542                 $type$ x = ($type$) vh.get(array, i);
1543                 assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value");
1544             }
1545 
1546             {
1547                 vh.set(array, i, $value1$);
1548 
1549                 $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, i, $value2$);
1550                 assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$");
1551                 $type$ x = ($type$) vh.get(array, i);
1552                 assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value");
1553             }
1554 
1555             // get and bitwise xor
1556             {
1557                 vh.set(array, i, $value1$);
1558 
1559                 $type$ o = ($type$) vh.getAndBitwiseXor(array, i, $value2$);
1560                 assertEquals(o, $value1$, "getAndBitwiseXor $type$");
1561                 $type$ x = ($type$) vh.get(array, i);
1562                 assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value");
1563             }
1564 
1565             {
1566                 vh.set(array, i, $value1$);
1567 
1568                 $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, i, $value2$);
1569                 assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$");
1570                 $type$ x = ($type$) vh.get(array, i);
1571                 assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value");
1572             }
1573 
1574             {
1575                 vh.set(array, i, $value1$);
1576 
1577                 $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, i, $value2$);
1578                 assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$");
1579                 $type$ x = ($type$) vh.get(array, i);
1580                 assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value");
1581             }
1582 #end[Bitwise]
1583         }
1584     }
1585 
1586     static void testArrayUnsupported(VarHandle vh) {
1587         $type$[] array = new $type$[10];
1588 
1589         int i = 0;
1590 #if[!CAS]
1591         checkUOE(() -> {
1592             boolean r = vh.compareAndSet(array, i, $value1$, $value2$);
1593         });
1594 
1595         checkUOE(() -> {
1596             $type$ r = ($type$) vh.compareAndExchange(array, i, $value1$, $value2$);
1597         });
1598 
1599         checkUOE(() -> {
1600             $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, $value1$, $value2$);
1601         });
1602 
1603         checkUOE(() -> {
1604             $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, $value1$, $value2$);
1605         });
1606 
1607         checkUOE(() -> {
1608             boolean r = vh.weakCompareAndSetPlain(array, i, $value1$, $value2$);
1609         });
1610 
1611         checkUOE(() -> {
1612             boolean r = vh.weakCompareAndSet(array, i, $value1$, $value2$);
1613         });
1614 
1615         checkUOE(() -> {
1616             boolean r = vh.weakCompareAndSetAcquire(array, i, $value1$, $value2$);
1617         });
1618 
1619         checkUOE(() -> {
1620             boolean r = vh.weakCompareAndSetRelease(array, i, $value1$, $value2$);
1621         });
1622 
1623         checkUOE(() -> {
1624             $type$ r = ($type$) vh.getAndSet(array, i, $value1$);
1625         });
1626 
1627         checkUOE(() -> {
1628             $type$ r = ($type$) vh.getAndSetAcquire(array, i, $value1$);
1629         });
1630 
1631         checkUOE(() -> {
1632             $type$ r = ($type$) vh.getAndSetRelease(array, i, $value1$);
1633         });
1634 #end[CAS]
1635 
1636 #if[!AtomicAdd]
1637         checkUOE(() -> {
1638             $type$ o = ($type$) vh.getAndAdd(array, i, $value1$);
1639         });
1640 
1641         checkUOE(() -> {
1642             $type$ o = ($type$) vh.getAndAddAcquire(array, i, $value1$);
1643         });
1644 
1645         checkUOE(() -> {
1646             $type$ o = ($type$) vh.getAndAddRelease(array, i, $value1$);
1647         });
1648 #end[AtomicAdd]
1649 
1650 #if[!Bitwise]
1651         checkUOE(() -> {
1652             $type$ o = ($type$) vh.getAndBitwiseOr(array, i, $value1$);
1653         });
1654 
1655         checkUOE(() -> {
1656             $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, i, $value1$);
1657         });
1658 
1659         checkUOE(() -> {
1660             $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, i, $value1$);
1661         });
1662 
1663         checkUOE(() -> {
1664             $type$ o = ($type$) vh.getAndBitwiseAnd(array, i, $value1$);
1665         });
1666 
1667         checkUOE(() -> {
1668             $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, i, $value1$);
1669         });
1670 
1671         checkUOE(() -> {
1672             $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, i, $value1$);
1673         });
1674 
1675         checkUOE(() -> {
1676             $type$ o = ($type$) vh.getAndBitwiseXor(array, i, $value1$);
1677         });
1678 
1679         checkUOE(() -> {
1680             $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, i, $value1$);
1681         });
1682 
1683         checkUOE(() -> {
1684             $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, i, $value1$);
1685         });
1686 #end[Bitwise]
1687     }
1688 
1689     static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
1690         $type$[] array = new $type$[10];
1691 
1692         for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
1693             final int ci = i;
1694 
1695             checkIOOBE(() -> {
1696                 $type$ x = ($type$) vh.get(array, ci);
1697             });
1698 
1699             checkIOOBE(() -> {
1700                 vh.set(array, ci, $value1$);
1701             });
1702 
1703             checkIOOBE(() -> {
1704                 $type$ x = ($type$) vh.getVolatile(array, ci);
1705             });
1706 
1707             checkIOOBE(() -> {
1708                 vh.setVolatile(array, ci, $value1$);
1709             });
1710 
1711             checkIOOBE(() -> {
1712                 $type$ x = ($type$) vh.getAcquire(array, ci);
1713             });
1714 
1715             checkIOOBE(() -> {
1716                 vh.setRelease(array, ci, $value1$);
1717             });
1718 
1719             checkIOOBE(() -> {
1720                 $type$ x = ($type$) vh.getOpaque(array, ci);
1721             });
1722 
1723             checkIOOBE(() -> {
1724                 vh.setOpaque(array, ci, $value1$);
1725             });
1726 
1727 #if[CAS]
1728             checkIOOBE(() -> {
1729                 boolean r = vh.compareAndSet(array, ci, $value1$, $value2$);
1730             });
1731 
1732             checkIOOBE(() -> {
1733                 $type$ r = ($type$) vh.compareAndExchange(array, ci, $value2$, $value1$);
1734             });
1735 
1736             checkIOOBE(() -> {
1737                 $type$ r = ($type$) vh.compareAndExchangeAcquire(array, ci, $value2$, $value1$);
1738             });
1739 
1740             checkIOOBE(() -> {
1741                 $type$ r = ($type$) vh.compareAndExchangeRelease(array, ci, $value2$, $value1$);
1742             });
1743 
1744             checkIOOBE(() -> {
1745                 boolean r = vh.weakCompareAndSetPlain(array, ci, $value1$, $value2$);
1746             });
1747 
1748             checkIOOBE(() -> {
1749                 boolean r = vh.weakCompareAndSet(array, ci, $value1$, $value2$);
1750             });
1751 
1752             checkIOOBE(() -> {
1753                 boolean r = vh.weakCompareAndSetAcquire(array, ci, $value1$, $value2$);
1754             });
1755 
1756             checkIOOBE(() -> {
1757                 boolean r = vh.weakCompareAndSetRelease(array, ci, $value1$, $value2$);
1758             });
1759 
1760             checkIOOBE(() -> {
1761                 $type$ o = ($type$) vh.getAndSet(array, ci, $value1$);
1762             });
1763 
1764             checkIOOBE(() -> {
1765                 $type$ o = ($type$) vh.getAndSetAcquire(array, ci, $value1$);
1766             });
1767 
1768             checkIOOBE(() -> {
1769                 $type$ o = ($type$) vh.getAndSetRelease(array, ci, $value1$);
1770             });
1771 #end[CAS]
1772 
1773 #if[AtomicAdd]
1774             checkIOOBE(() -> {
1775                 $type$ o = ($type$) vh.getAndAdd(array, ci, $value1$);
1776             });
1777 
1778             checkIOOBE(() -> {
1779                 $type$ o = ($type$) vh.getAndAddAcquire(array, ci, $value1$);
1780             });
1781 
1782             checkIOOBE(() -> {
1783                 $type$ o = ($type$) vh.getAndAddRelease(array, ci, $value1$);
1784             });
1785 #end[AtomicAdd]
1786 
1787 #if[Bitwise]
1788             checkIOOBE(() -> {
1789                 $type$ o = ($type$) vh.getAndBitwiseOr(array, ci, $value1$);
1790             });
1791 
1792             checkIOOBE(() -> {
1793                 $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, ci, $value1$);
1794             });
1795 
1796             checkIOOBE(() -> {
1797                 $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, ci, $value1$);
1798             });
1799 
1800             checkIOOBE(() -> {
1801                 $type$ o = ($type$) vh.getAndBitwiseAnd(array, ci, $value1$);
1802             });
1803 
1804             checkIOOBE(() -> {
1805                 $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, ci, $value1$);
1806             });
1807 
1808             checkIOOBE(() -> {
1809                 $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, ci, $value1$);
1810             });
1811 
1812             checkIOOBE(() -> {
1813                 $type$ o = ($type$) vh.getAndBitwiseXor(array, ci, $value1$);
1814             });
1815 
1816             checkIOOBE(() -> {
1817                 $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, ci, $value1$);
1818             });
1819 
1820             checkIOOBE(() -> {
1821                 $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, ci, $value1$);
1822             });
1823 #end[Bitwise]
1824         }
1825     }
1826 }
1827