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