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