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