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