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 VarHandleTestAccessByte 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 67 @BeforeClass setup()68 public void setup() throws Exception { 69 vhFinalField = MethodHandles.lookup().findVarHandle( 70 VarHandleTestAccessByte.class, "final_v", byte.class); 71 72 vhField = MethodHandles.lookup().findVarHandle( 73 VarHandleTestAccessByte.class, "v", byte.class); 74 75 vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( 76 VarHandleTestAccessByte.class, "static_final_v", byte.class); 77 78 vhStaticField = MethodHandles.lookup().findStaticVarHandle( 79 VarHandleTestAccessByte.class, "static_v", byte.class); 80 81 vhArray = MethodHandles.arrayElementVarHandle(byte[].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(VarHandleTestAccessByte.class)}); 138 types.add(new Object[] {vhStaticField, Arrays.asList()}); 139 types.add(new Object[] {vhArray, Arrays.asList(byte[].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(), byte.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 VarHandleTestAccessByte.class, "final_v", byte.class); 159 }); 160 161 checkIAE("Lookup of static field to instance field", () -> { 162 MethodHandles.lookup().findStaticVarHandle( 163 VarHandleTestAccessByte.class, "v", byte.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 VarHandleTestAccessByte.class, "static_final_v", byte.class); 172 }); 173 174 checkIAE("Lookup of instance field to static field", () -> { 175 vhStaticField = MethodHandles.lookup().findVarHandle( 176 VarHandleTestAccessByte.class, "static_v", byte.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, VarHandleTestAccessByte::testStaticFinalField)); 193 cases.add(new VarHandleAccessTestCase("Static final field unsupported", 194 vhStaticFinalField, VarHandleTestAccessByte::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, VarHandleTestAccessByte::testStaticField)); 205 cases.add(new VarHandleAccessTestCase("Static field unsupported", 206 vhStaticField, VarHandleTestAccessByte::testStaticFieldUnsupported, 207 false)); 208 209 cases.add(new VarHandleAccessTestCase("Array", 210 vhArray, VarHandleTestAccessByte::testArray)); 211 cases.add(new VarHandleAccessTestCase("Array unsupported", 212 vhArray, VarHandleTestAccessByte::testArrayUnsupported, 213 false)); 214 cases.add(new VarHandleAccessTestCase("Array index out of bounds", 215 vhArray, VarHandleTestAccessByte::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(VarHandleTestAccessByte recv, VarHandle vh)235 static void testInstanceFinalField(VarHandleTestAccessByte recv, VarHandle vh) { 236 // Plain 237 { 238 byte x = (byte) vh.get(recv); 239 assertEquals(x, (byte)0x01, "get byte value"); 240 } 241 242 243 // Volatile 244 { 245 byte x = (byte) vh.getVolatile(recv); 246 assertEquals(x, (byte)0x01, "getVolatile byte value"); 247 } 248 249 // Lazy 250 { 251 byte x = (byte) vh.getAcquire(recv); 252 assertEquals(x, (byte)0x01, "getRelease byte value"); 253 } 254 255 // Opaque 256 { 257 byte x = (byte) vh.getOpaque(recv); 258 assertEquals(x, (byte)0x01, "getOpaque byte value"); 259 } 260 } 261 testInstanceFinalFieldUnsupported(VarHandleTestAccessByte recv, VarHandle vh)262 static void testInstanceFinalFieldUnsupported(VarHandleTestAccessByte recv, VarHandle vh) { 263 checkUOE(() -> { 264 vh.set(recv, (byte)0x23); 265 }); 266 267 checkUOE(() -> { 268 vh.setVolatile(recv, (byte)0x23); 269 }); 270 271 checkUOE(() -> { 272 vh.setRelease(recv, (byte)0x23); 273 }); 274 275 checkUOE(() -> { 276 vh.setOpaque(recv, (byte)0x23); 277 }); 278 279 280 281 } 282 283 testStaticFinalField(VarHandle vh)284 static void testStaticFinalField(VarHandle vh) { 285 // Plain 286 { 287 byte x = (byte) vh.get(); 288 assertEquals(x, (byte)0x01, "get byte value"); 289 } 290 291 292 // Volatile 293 { 294 byte x = (byte) vh.getVolatile(); 295 assertEquals(x, (byte)0x01, "getVolatile byte value"); 296 } 297 298 // Lazy 299 { 300 byte x = (byte) vh.getAcquire(); 301 assertEquals(x, (byte)0x01, "getRelease byte value"); 302 } 303 304 // Opaque 305 { 306 byte x = (byte) vh.getOpaque(); 307 assertEquals(x, (byte)0x01, "getOpaque byte value"); 308 } 309 } 310 testStaticFinalFieldUnsupported(VarHandle vh)311 static void testStaticFinalFieldUnsupported(VarHandle vh) { 312 checkUOE(() -> { 313 vh.set((byte)0x23); 314 }); 315 316 checkUOE(() -> { 317 vh.setVolatile((byte)0x23); 318 }); 319 320 checkUOE(() -> { 321 vh.setRelease((byte)0x23); 322 }); 323 324 checkUOE(() -> { 325 vh.setOpaque((byte)0x23); 326 }); 327 328 329 330 } 331 332 testInstanceField(VarHandleTestAccessByte recv, VarHandle vh)333 static void testInstanceField(VarHandleTestAccessByte recv, VarHandle vh) { 334 // Plain 335 { 336 vh.set(recv, (byte)0x01); 337 byte x = (byte) vh.get(recv); 338 assertEquals(x, (byte)0x01, "set byte value"); 339 } 340 341 342 // Volatile 343 { 344 vh.setVolatile(recv, (byte)0x23); 345 byte x = (byte) vh.getVolatile(recv); 346 assertEquals(x, (byte)0x23, "setVolatile byte value"); 347 } 348 349 // Lazy 350 { 351 vh.setRelease(recv, (byte)0x01); 352 byte x = (byte) vh.getAcquire(recv); 353 assertEquals(x, (byte)0x01, "setRelease byte value"); 354 } 355 356 // Opaque 357 { 358 vh.setOpaque(recv, (byte)0x23); 359 byte x = (byte) vh.getOpaque(recv); 360 assertEquals(x, (byte)0x23, "setOpaque byte value"); 361 } 362 363 vh.set(recv, (byte)0x01); 364 365 // Compare 366 { 367 boolean r = vh.compareAndSet(recv, (byte)0x01, (byte)0x23); 368 assertEquals(r, true, "success compareAndSet byte"); 369 byte x = (byte) vh.get(recv); 370 assertEquals(x, (byte)0x23, "success compareAndSet byte value"); 371 } 372 373 { 374 boolean r = vh.compareAndSet(recv, (byte)0x01, (byte)0x45); 375 assertEquals(r, false, "failing compareAndSet byte"); 376 byte x = (byte) vh.get(recv); 377 assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); 378 } 379 380 { 381 byte r = (byte) vh.compareAndExchange(recv, (byte)0x23, (byte)0x01); 382 assertEquals(r, (byte)0x23, "success compareAndExchange byte"); 383 byte x = (byte) vh.get(recv); 384 assertEquals(x, (byte)0x01, "success compareAndExchange byte value"); 385 } 386 387 { 388 byte r = (byte) vh.compareAndExchange(recv, (byte)0x23, (byte)0x45); 389 assertEquals(r, (byte)0x01, "failing compareAndExchange byte"); 390 byte x = (byte) vh.get(recv); 391 assertEquals(x, (byte)0x01, "failing compareAndExchange byte value"); 392 } 393 394 { 395 byte r = (byte) vh.compareAndExchangeAcquire(recv, (byte)0x01, (byte)0x23); 396 assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); 397 byte x = (byte) vh.get(recv); 398 assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); 399 } 400 401 { 402 byte r = (byte) vh.compareAndExchangeAcquire(recv, (byte)0x01, (byte)0x45); 403 assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); 404 byte x = (byte) vh.get(recv); 405 assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); 406 } 407 408 { 409 byte r = (byte) vh.compareAndExchangeRelease(recv, (byte)0x23, (byte)0x01); 410 assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); 411 byte x = (byte) vh.get(recv); 412 assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); 413 } 414 415 { 416 byte r = (byte) vh.compareAndExchangeRelease(recv, (byte)0x23, (byte)0x45); 417 assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); 418 byte x = (byte) vh.get(recv); 419 assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value"); 420 } 421 422 { 423 boolean success = false; 424 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 425 success = vh.weakCompareAndSetPlain(recv, (byte)0x01, (byte)0x23); 426 } 427 assertEquals(success, true, "weakCompareAndSetPlain byte"); 428 byte x = (byte) vh.get(recv); 429 assertEquals(x, (byte)0x23, "weakCompareAndSetPlain byte value"); 430 } 431 432 { 433 boolean success = false; 434 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 435 success = vh.weakCompareAndSetAcquire(recv, (byte)0x23, (byte)0x01); 436 } 437 assertEquals(success, true, "weakCompareAndSetAcquire byte"); 438 byte x = (byte) vh.get(recv); 439 assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte"); 440 } 441 442 { 443 boolean success = false; 444 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 445 success = vh.weakCompareAndSetRelease(recv, (byte)0x01, (byte)0x23); 446 } 447 assertEquals(success, true, "weakCompareAndSetRelease byte"); 448 byte x = (byte) vh.get(recv); 449 assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte"); 450 } 451 452 { 453 boolean success = false; 454 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 455 success = vh.weakCompareAndSet(recv, (byte)0x23, (byte)0x01); 456 } 457 assertEquals(success, true, "weakCompareAndSet byte"); 458 byte x = (byte) vh.get(recv); 459 assertEquals(x, (byte)0x01, "weakCompareAndSet byte value"); 460 } 461 462 // Compare set and get 463 { 464 vh.set(recv, (byte)0x01); 465 466 byte o = (byte) vh.getAndSet(recv, (byte)0x23); 467 assertEquals(o, (byte)0x01, "getAndSet byte"); 468 byte x = (byte) vh.get(recv); 469 assertEquals(x, (byte)0x23, "getAndSet byte value"); 470 } 471 472 { 473 vh.set(recv, (byte)0x01); 474 475 byte o = (byte) vh.getAndSetAcquire(recv, (byte)0x23); 476 assertEquals(o, (byte)0x01, "getAndSetAcquire byte"); 477 byte x = (byte) vh.get(recv); 478 assertEquals(x, (byte)0x23, "getAndSetAcquire byte value"); 479 } 480 481 { 482 vh.set(recv, (byte)0x01); 483 484 byte o = (byte) vh.getAndSetRelease(recv, (byte)0x23); 485 assertEquals(o, (byte)0x01, "getAndSetRelease byte"); 486 byte x = (byte) vh.get(recv); 487 assertEquals(x, (byte)0x23, "getAndSetRelease byte value"); 488 } 489 490 // get and add, add and get 491 { 492 vh.set(recv, (byte)0x01); 493 494 byte o = (byte) vh.getAndAdd(recv, (byte)0x23); 495 assertEquals(o, (byte)0x01, "getAndAdd byte"); 496 byte x = (byte) vh.get(recv); 497 assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value"); 498 } 499 500 { 501 vh.set(recv, (byte)0x01); 502 503 byte o = (byte) vh.getAndAddAcquire(recv, (byte)0x23); 504 assertEquals(o, (byte)0x01, "getAndAddAcquire byte"); 505 byte x = (byte) vh.get(recv); 506 assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value"); 507 } 508 509 { 510 vh.set(recv, (byte)0x01); 511 512 byte o = (byte) vh.getAndAddRelease(recv, (byte)0x23); 513 assertEquals(o, (byte)0x01, "getAndAddReleasebyte"); 514 byte x = (byte) vh.get(recv); 515 assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value"); 516 } 517 518 // get and bitwise or 519 { 520 vh.set(recv, (byte)0x01); 521 522 byte o = (byte) vh.getAndBitwiseOr(recv, (byte)0x23); 523 assertEquals(o, (byte)0x01, "getAndBitwiseOr byte"); 524 byte x = (byte) vh.get(recv); 525 assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value"); 526 } 527 528 { 529 vh.set(recv, (byte)0x01); 530 531 byte o = (byte) vh.getAndBitwiseOrAcquire(recv, (byte)0x23); 532 assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte"); 533 byte x = (byte) vh.get(recv); 534 assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value"); 535 } 536 537 { 538 vh.set(recv, (byte)0x01); 539 540 byte o = (byte) vh.getAndBitwiseOrRelease(recv, (byte)0x23); 541 assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte"); 542 byte x = (byte) vh.get(recv); 543 assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value"); 544 } 545 546 // get and bitwise and 547 { 548 vh.set(recv, (byte)0x01); 549 550 byte o = (byte) vh.getAndBitwiseAnd(recv, (byte)0x23); 551 assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte"); 552 byte x = (byte) vh.get(recv); 553 assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value"); 554 } 555 556 { 557 vh.set(recv, (byte)0x01); 558 559 byte o = (byte) vh.getAndBitwiseAndAcquire(recv, (byte)0x23); 560 assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte"); 561 byte x = (byte) vh.get(recv); 562 assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value"); 563 } 564 565 { 566 vh.set(recv, (byte)0x01); 567 568 byte o = (byte) vh.getAndBitwiseAndRelease(recv, (byte)0x23); 569 assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte"); 570 byte x = (byte) vh.get(recv); 571 assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value"); 572 } 573 574 // get and bitwise xor 575 { 576 vh.set(recv, (byte)0x01); 577 578 byte o = (byte) vh.getAndBitwiseXor(recv, (byte)0x23); 579 assertEquals(o, (byte)0x01, "getAndBitwiseXor byte"); 580 byte x = (byte) vh.get(recv); 581 assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value"); 582 } 583 584 { 585 vh.set(recv, (byte)0x01); 586 587 byte o = (byte) vh.getAndBitwiseXorAcquire(recv, (byte)0x23); 588 assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte"); 589 byte x = (byte) vh.get(recv); 590 assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value"); 591 } 592 593 { 594 vh.set(recv, (byte)0x01); 595 596 byte o = (byte) vh.getAndBitwiseXorRelease(recv, (byte)0x23); 597 assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte"); 598 byte x = (byte) vh.get(recv); 599 assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value"); 600 } 601 } 602 testInstanceFieldUnsupported(VarHandleTestAccessByte recv, VarHandle vh)603 static void testInstanceFieldUnsupported(VarHandleTestAccessByte recv, VarHandle vh) { 604 605 606 } 607 608 testStaticField(VarHandle vh)609 static void testStaticField(VarHandle vh) { 610 // Plain 611 { 612 vh.set((byte)0x01); 613 byte x = (byte) vh.get(); 614 assertEquals(x, (byte)0x01, "set byte value"); 615 } 616 617 618 // Volatile 619 { 620 vh.setVolatile((byte)0x23); 621 byte x = (byte) vh.getVolatile(); 622 assertEquals(x, (byte)0x23, "setVolatile byte value"); 623 } 624 625 // Lazy 626 { 627 vh.setRelease((byte)0x01); 628 byte x = (byte) vh.getAcquire(); 629 assertEquals(x, (byte)0x01, "setRelease byte value"); 630 } 631 632 // Opaque 633 { 634 vh.setOpaque((byte)0x23); 635 byte x = (byte) vh.getOpaque(); 636 assertEquals(x, (byte)0x23, "setOpaque byte value"); 637 } 638 639 vh.set((byte)0x01); 640 641 // Compare 642 { 643 boolean r = vh.compareAndSet((byte)0x01, (byte)0x23); 644 assertEquals(r, true, "success compareAndSet byte"); 645 byte x = (byte) vh.get(); 646 assertEquals(x, (byte)0x23, "success compareAndSet byte value"); 647 } 648 649 { 650 boolean r = vh.compareAndSet((byte)0x01, (byte)0x45); 651 assertEquals(r, false, "failing compareAndSet byte"); 652 byte x = (byte) vh.get(); 653 assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); 654 } 655 656 { 657 byte r = (byte) vh.compareAndExchange((byte)0x23, (byte)0x01); 658 assertEquals(r, (byte)0x23, "success compareAndExchange byte"); 659 byte x = (byte) vh.get(); 660 assertEquals(x, (byte)0x01, "success compareAndExchange byte value"); 661 } 662 663 { 664 byte r = (byte) vh.compareAndExchange((byte)0x23, (byte)0x45); 665 assertEquals(r, (byte)0x01, "failing compareAndExchange byte"); 666 byte x = (byte) vh.get(); 667 assertEquals(x, (byte)0x01, "failing compareAndExchange byte value"); 668 } 669 670 { 671 byte r = (byte) vh.compareAndExchangeAcquire((byte)0x01, (byte)0x23); 672 assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); 673 byte x = (byte) vh.get(); 674 assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); 675 } 676 677 { 678 byte r = (byte) vh.compareAndExchangeAcquire((byte)0x01, (byte)0x45); 679 assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); 680 byte x = (byte) vh.get(); 681 assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); 682 } 683 684 { 685 byte r = (byte) vh.compareAndExchangeRelease((byte)0x23, (byte)0x01); 686 assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); 687 byte x = (byte) vh.get(); 688 assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); 689 } 690 691 { 692 byte r = (byte) vh.compareAndExchangeRelease((byte)0x23, (byte)0x45); 693 assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); 694 byte x = (byte) vh.get(); 695 assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value"); 696 } 697 698 { 699 boolean success = false; 700 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 701 success = vh.weakCompareAndSetPlain((byte)0x01, (byte)0x23); 702 } 703 assertEquals(success, true, "weakCompareAndSetPlain byte"); 704 byte x = (byte) vh.get(); 705 assertEquals(x, (byte)0x23, "weakCompareAndSetPlain byte value"); 706 } 707 708 { 709 boolean success = false; 710 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 711 success = vh.weakCompareAndSetAcquire((byte)0x23, (byte)0x01); 712 } 713 assertEquals(success, true, "weakCompareAndSetAcquire byte"); 714 byte x = (byte) vh.get(); 715 assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte"); 716 } 717 718 { 719 boolean success = false; 720 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 721 success = vh.weakCompareAndSetRelease((byte)0x01, (byte)0x23); 722 } 723 assertEquals(success, true, "weakCompareAndSetRelease byte"); 724 byte x = (byte) vh.get(); 725 assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte"); 726 } 727 728 { 729 boolean success = false; 730 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 731 success = vh.weakCompareAndSet((byte)0x23, (byte)0x01); 732 } 733 assertEquals(success, true, "weakCompareAndSet byte"); 734 byte x = (byte) vh.get(); 735 assertEquals(x, (byte)0x01, "weakCompareAndSet byte"); 736 } 737 738 // Compare set and get 739 { 740 vh.set((byte)0x01); 741 742 byte o = (byte) vh.getAndSet((byte)0x23); 743 assertEquals(o, (byte)0x01, "getAndSet byte"); 744 byte x = (byte) vh.get(); 745 assertEquals(x, (byte)0x23, "getAndSet byte value"); 746 } 747 748 { 749 vh.set((byte)0x01); 750 751 byte o = (byte) vh.getAndSetAcquire((byte)0x23); 752 assertEquals(o, (byte)0x01, "getAndSetAcquire byte"); 753 byte x = (byte) vh.get(); 754 assertEquals(x, (byte)0x23, "getAndSetAcquire byte value"); 755 } 756 757 { 758 vh.set((byte)0x01); 759 760 byte o = (byte) vh.getAndSetRelease((byte)0x23); 761 assertEquals(o, (byte)0x01, "getAndSetRelease byte"); 762 byte x = (byte) vh.get(); 763 assertEquals(x, (byte)0x23, "getAndSetRelease byte value"); 764 } 765 766 // get and add, add and get 767 { 768 vh.set((byte)0x01); 769 770 byte o = (byte) vh.getAndAdd((byte)0x23); 771 assertEquals(o, (byte)0x01, "getAndAdd byte"); 772 byte x = (byte) vh.get(); 773 assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value"); 774 } 775 776 { 777 vh.set((byte)0x01); 778 779 byte o = (byte) vh.getAndAddAcquire((byte)0x23); 780 assertEquals(o, (byte)0x01, "getAndAddAcquire byte"); 781 byte x = (byte) vh.get(); 782 assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value"); 783 } 784 785 { 786 vh.set((byte)0x01); 787 788 byte o = (byte) vh.getAndAddRelease((byte)0x23); 789 assertEquals(o, (byte)0x01, "getAndAddReleasebyte"); 790 byte x = (byte) vh.get(); 791 assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value"); 792 } 793 794 // get and bitwise or 795 { 796 vh.set((byte)0x01); 797 798 byte o = (byte) vh.getAndBitwiseOr((byte)0x23); 799 assertEquals(o, (byte)0x01, "getAndBitwiseOr byte"); 800 byte x = (byte) vh.get(); 801 assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value"); 802 } 803 804 { 805 vh.set((byte)0x01); 806 807 byte o = (byte) vh.getAndBitwiseOrAcquire((byte)0x23); 808 assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte"); 809 byte x = (byte) vh.get(); 810 assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value"); 811 } 812 813 { 814 vh.set((byte)0x01); 815 816 byte o = (byte) vh.getAndBitwiseOrRelease((byte)0x23); 817 assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte"); 818 byte x = (byte) vh.get(); 819 assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value"); 820 } 821 822 // get and bitwise and 823 { 824 vh.set((byte)0x01); 825 826 byte o = (byte) vh.getAndBitwiseAnd((byte)0x23); 827 assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte"); 828 byte x = (byte) vh.get(); 829 assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value"); 830 } 831 832 { 833 vh.set((byte)0x01); 834 835 byte o = (byte) vh.getAndBitwiseAndAcquire((byte)0x23); 836 assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte"); 837 byte x = (byte) vh.get(); 838 assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value"); 839 } 840 841 { 842 vh.set((byte)0x01); 843 844 byte o = (byte) vh.getAndBitwiseAndRelease((byte)0x23); 845 assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte"); 846 byte x = (byte) vh.get(); 847 assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value"); 848 } 849 850 // get and bitwise xor 851 { 852 vh.set((byte)0x01); 853 854 byte o = (byte) vh.getAndBitwiseXor((byte)0x23); 855 assertEquals(o, (byte)0x01, "getAndBitwiseXor byte"); 856 byte x = (byte) vh.get(); 857 assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value"); 858 } 859 860 { 861 vh.set((byte)0x01); 862 863 byte o = (byte) vh.getAndBitwiseXorAcquire((byte)0x23); 864 assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte"); 865 byte x = (byte) vh.get(); 866 assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value"); 867 } 868 869 { 870 vh.set((byte)0x01); 871 872 byte o = (byte) vh.getAndBitwiseXorRelease((byte)0x23); 873 assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte"); 874 byte x = (byte) vh.get(); 875 assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte 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 byte[] array = new byte[10]; 887 888 for (int i = 0; i < array.length; i++) { 889 // Plain 890 { 891 vh.set(array, i, (byte)0x01); 892 byte x = (byte) vh.get(array, i); 893 assertEquals(x, (byte)0x01, "get byte value"); 894 } 895 896 897 // Volatile 898 { 899 vh.setVolatile(array, i, (byte)0x23); 900 byte x = (byte) vh.getVolatile(array, i); 901 assertEquals(x, (byte)0x23, "setVolatile byte value"); 902 } 903 904 // Lazy 905 { 906 vh.setRelease(array, i, (byte)0x01); 907 byte x = (byte) vh.getAcquire(array, i); 908 assertEquals(x, (byte)0x01, "setRelease byte value"); 909 } 910 911 // Opaque 912 { 913 vh.setOpaque(array, i, (byte)0x23); 914 byte x = (byte) vh.getOpaque(array, i); 915 assertEquals(x, (byte)0x23, "setOpaque byte value"); 916 } 917 918 vh.set(array, i, (byte)0x01); 919 920 // Compare 921 { 922 boolean r = vh.compareAndSet(array, i, (byte)0x01, (byte)0x23); 923 assertEquals(r, true, "success compareAndSet byte"); 924 byte x = (byte) vh.get(array, i); 925 assertEquals(x, (byte)0x23, "success compareAndSet byte value"); 926 } 927 928 { 929 boolean r = vh.compareAndSet(array, i, (byte)0x01, (byte)0x45); 930 assertEquals(r, false, "failing compareAndSet byte"); 931 byte x = (byte) vh.get(array, i); 932 assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); 933 } 934 935 { 936 byte r = (byte) vh.compareAndExchange(array, i, (byte)0x23, (byte)0x01); 937 assertEquals(r, (byte)0x23, "success compareAndExchange byte"); 938 byte x = (byte) vh.get(array, i); 939 assertEquals(x, (byte)0x01, "success compareAndExchange byte value"); 940 } 941 942 { 943 byte r = (byte) vh.compareAndExchange(array, i, (byte)0x23, (byte)0x45); 944 assertEquals(r, (byte)0x01, "failing compareAndExchange byte"); 945 byte x = (byte) vh.get(array, i); 946 assertEquals(x, (byte)0x01, "failing compareAndExchange byte value"); 947 } 948 949 { 950 byte r = (byte) vh.compareAndExchangeAcquire(array, i, (byte)0x01, (byte)0x23); 951 assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); 952 byte x = (byte) vh.get(array, i); 953 assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); 954 } 955 956 { 957 byte r = (byte) vh.compareAndExchangeAcquire(array, i, (byte)0x01, (byte)0x45); 958 assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); 959 byte x = (byte) vh.get(array, i); 960 assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); 961 } 962 963 { 964 byte r = (byte) vh.compareAndExchangeRelease(array, i, (byte)0x23, (byte)0x01); 965 assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); 966 byte x = (byte) vh.get(array, i); 967 assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); 968 } 969 970 { 971 byte r = (byte) vh.compareAndExchangeRelease(array, i, (byte)0x23, (byte)0x45); 972 assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); 973 byte x = (byte) vh.get(array, i); 974 assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value"); 975 } 976 977 { 978 boolean success = false; 979 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 980 success = vh.weakCompareAndSetPlain(array, i, (byte)0x01, (byte)0x23); 981 } 982 assertEquals(success, true, "weakCompareAndSetPlain byte"); 983 byte x = (byte) vh.get(array, i); 984 assertEquals(x, (byte)0x23, "weakCompareAndSetPlain byte value"); 985 } 986 987 { 988 boolean success = false; 989 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 990 success = vh.weakCompareAndSetAcquire(array, i, (byte)0x23, (byte)0x01); 991 } 992 assertEquals(success, true, "weakCompareAndSetAcquire byte"); 993 byte x = (byte) vh.get(array, i); 994 assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte"); 995 } 996 997 { 998 boolean success = false; 999 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 1000 success = vh.weakCompareAndSetRelease(array, i, (byte)0x01, (byte)0x23); 1001 } 1002 assertEquals(success, true, "weakCompareAndSetRelease byte"); 1003 byte x = (byte) vh.get(array, i); 1004 assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte"); 1005 } 1006 1007 { 1008 boolean success = false; 1009 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 1010 success = vh.weakCompareAndSet(array, i, (byte)0x23, (byte)0x01); 1011 } 1012 assertEquals(success, true, "weakCompareAndSet byte"); 1013 byte x = (byte) vh.get(array, i); 1014 assertEquals(x, (byte)0x01, "weakCompareAndSet byte"); 1015 } 1016 1017 // Compare set and get 1018 { 1019 vh.set(array, i, (byte)0x01); 1020 1021 byte o = (byte) vh.getAndSet(array, i, (byte)0x23); 1022 assertEquals(o, (byte)0x01, "getAndSet byte"); 1023 byte x = (byte) vh.get(array, i); 1024 assertEquals(x, (byte)0x23, "getAndSet byte value"); 1025 } 1026 1027 { 1028 vh.set(array, i, (byte)0x01); 1029 1030 byte o = (byte) vh.getAndSetAcquire(array, i, (byte)0x23); 1031 assertEquals(o, (byte)0x01, "getAndSetAcquire byte"); 1032 byte x = (byte) vh.get(array, i); 1033 assertEquals(x, (byte)0x23, "getAndSetAcquire byte value"); 1034 } 1035 1036 { 1037 vh.set(array, i, (byte)0x01); 1038 1039 byte o = (byte) vh.getAndSetRelease(array, i, (byte)0x23); 1040 assertEquals(o, (byte)0x01, "getAndSetRelease byte"); 1041 byte x = (byte) vh.get(array, i); 1042 assertEquals(x, (byte)0x23, "getAndSetRelease byte value"); 1043 } 1044 1045 // get and add, add and get 1046 { 1047 vh.set(array, i, (byte)0x01); 1048 1049 byte o = (byte) vh.getAndAdd(array, i, (byte)0x23); 1050 assertEquals(o, (byte)0x01, "getAndAdd byte"); 1051 byte x = (byte) vh.get(array, i); 1052 assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value"); 1053 } 1054 1055 { 1056 vh.set(array, i, (byte)0x01); 1057 1058 byte o = (byte) vh.getAndAddAcquire(array, i, (byte)0x23); 1059 assertEquals(o, (byte)0x01, "getAndAddAcquire byte"); 1060 byte x = (byte) vh.get(array, i); 1061 assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value"); 1062 } 1063 1064 { 1065 vh.set(array, i, (byte)0x01); 1066 1067 byte o = (byte) vh.getAndAddRelease(array, i, (byte)0x23); 1068 assertEquals(o, (byte)0x01, "getAndAddReleasebyte"); 1069 byte x = (byte) vh.get(array, i); 1070 assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value"); 1071 } 1072 1073 // get and bitwise or 1074 { 1075 vh.set(array, i, (byte)0x01); 1076 1077 byte o = (byte) vh.getAndBitwiseOr(array, i, (byte)0x23); 1078 assertEquals(o, (byte)0x01, "getAndBitwiseOr byte"); 1079 byte x = (byte) vh.get(array, i); 1080 assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value"); 1081 } 1082 1083 { 1084 vh.set(array, i, (byte)0x01); 1085 1086 byte o = (byte) vh.getAndBitwiseOrAcquire(array, i, (byte)0x23); 1087 assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte"); 1088 byte x = (byte) vh.get(array, i); 1089 assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value"); 1090 } 1091 1092 { 1093 vh.set(array, i, (byte)0x01); 1094 1095 byte o = (byte) vh.getAndBitwiseOrRelease(array, i, (byte)0x23); 1096 assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte"); 1097 byte x = (byte) vh.get(array, i); 1098 assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value"); 1099 } 1100 1101 // get and bitwise and 1102 { 1103 vh.set(array, i, (byte)0x01); 1104 1105 byte o = (byte) vh.getAndBitwiseAnd(array, i, (byte)0x23); 1106 assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte"); 1107 byte x = (byte) vh.get(array, i); 1108 assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value"); 1109 } 1110 1111 { 1112 vh.set(array, i, (byte)0x01); 1113 1114 byte o = (byte) vh.getAndBitwiseAndAcquire(array, i, (byte)0x23); 1115 assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte"); 1116 byte x = (byte) vh.get(array, i); 1117 assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value"); 1118 } 1119 1120 { 1121 vh.set(array, i, (byte)0x01); 1122 1123 byte o = (byte) vh.getAndBitwiseAndRelease(array, i, (byte)0x23); 1124 assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte"); 1125 byte x = (byte) vh.get(array, i); 1126 assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value"); 1127 } 1128 1129 // get and bitwise xor 1130 { 1131 vh.set(array, i, (byte)0x01); 1132 1133 byte o = (byte) vh.getAndBitwiseXor(array, i, (byte)0x23); 1134 assertEquals(o, (byte)0x01, "getAndBitwiseXor byte"); 1135 byte x = (byte) vh.get(array, i); 1136 assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value"); 1137 } 1138 1139 { 1140 vh.set(array, i, (byte)0x01); 1141 1142 byte o = (byte) vh.getAndBitwiseXorAcquire(array, i, (byte)0x23); 1143 assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte"); 1144 byte x = (byte) vh.get(array, i); 1145 assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value"); 1146 } 1147 1148 { 1149 vh.set(array, i, (byte)0x01); 1150 1151 byte o = (byte) vh.getAndBitwiseXorRelease(array, i, (byte)0x23); 1152 assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte"); 1153 byte x = (byte) vh.get(array, i); 1154 assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value"); 1155 } 1156 } 1157 } 1158 testArrayUnsupported(VarHandle vh)1159 static void testArrayUnsupported(VarHandle vh) { 1160 byte[] array = new byte[10]; 1161 1162 int i = 0; 1163 1164 1165 } 1166 testArrayIndexOutOfBounds(VarHandle vh)1167 static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable { 1168 byte[] array = new byte[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 byte x = (byte) vh.get(array, ci); 1175 }); 1176 1177 checkIOOBE(() -> { 1178 vh.set(array, ci, (byte)0x01); 1179 }); 1180 1181 checkIOOBE(() -> { 1182 byte x = (byte) vh.getVolatile(array, ci); 1183 }); 1184 1185 checkIOOBE(() -> { 1186 vh.setVolatile(array, ci, (byte)0x01); 1187 }); 1188 1189 checkIOOBE(() -> { 1190 byte x = (byte) vh.getAcquire(array, ci); 1191 }); 1192 1193 checkIOOBE(() -> { 1194 vh.setRelease(array, ci, (byte)0x01); 1195 }); 1196 1197 checkIOOBE(() -> { 1198 byte x = (byte) vh.getOpaque(array, ci); 1199 }); 1200 1201 checkIOOBE(() -> { 1202 vh.setOpaque(array, ci, (byte)0x01); 1203 }); 1204 1205 checkIOOBE(() -> { 1206 boolean r = vh.compareAndSet(array, ci, (byte)0x01, (byte)0x23); 1207 }); 1208 1209 checkIOOBE(() -> { 1210 byte r = (byte) vh.compareAndExchange(array, ci, (byte)0x23, (byte)0x01); 1211 }); 1212 1213 checkIOOBE(() -> { 1214 byte r = (byte) vh.compareAndExchangeAcquire(array, ci, (byte)0x23, (byte)0x01); 1215 }); 1216 1217 checkIOOBE(() -> { 1218 byte r = (byte) vh.compareAndExchangeRelease(array, ci, (byte)0x23, (byte)0x01); 1219 }); 1220 1221 checkIOOBE(() -> { 1222 boolean r = vh.weakCompareAndSetPlain(array, ci, (byte)0x01, (byte)0x23); 1223 }); 1224 1225 checkIOOBE(() -> { 1226 boolean r = vh.weakCompareAndSet(array, ci, (byte)0x01, (byte)0x23); 1227 }); 1228 1229 checkIOOBE(() -> { 1230 boolean r = vh.weakCompareAndSetAcquire(array, ci, (byte)0x01, (byte)0x23); 1231 }); 1232 1233 checkIOOBE(() -> { 1234 boolean r = vh.weakCompareAndSetRelease(array, ci, (byte)0x01, (byte)0x23); 1235 }); 1236 1237 checkIOOBE(() -> { 1238 byte o = (byte) vh.getAndSet(array, ci, (byte)0x01); 1239 }); 1240 1241 checkIOOBE(() -> { 1242 byte o = (byte) vh.getAndSetAcquire(array, ci, (byte)0x01); 1243 }); 1244 1245 checkIOOBE(() -> { 1246 byte o = (byte) vh.getAndSetRelease(array, ci, (byte)0x01); 1247 }); 1248 1249 checkIOOBE(() -> { 1250 byte o = (byte) vh.getAndAdd(array, ci, (byte)0x01); 1251 }); 1252 1253 checkIOOBE(() -> { 1254 byte o = (byte) vh.getAndAddAcquire(array, ci, (byte)0x01); 1255 }); 1256 1257 checkIOOBE(() -> { 1258 byte o = (byte) vh.getAndAddRelease(array, ci, (byte)0x01); 1259 }); 1260 1261 checkIOOBE(() -> { 1262 byte o = (byte) vh.getAndBitwiseOr(array, ci, (byte)0x01); 1263 }); 1264 1265 checkIOOBE(() -> { 1266 byte o = (byte) vh.getAndBitwiseOrAcquire(array, ci, (byte)0x01); 1267 }); 1268 1269 checkIOOBE(() -> { 1270 byte o = (byte) vh.getAndBitwiseOrRelease(array, ci, (byte)0x01); 1271 }); 1272 1273 checkIOOBE(() -> { 1274 byte o = (byte) vh.getAndBitwiseAnd(array, ci, (byte)0x01); 1275 }); 1276 1277 checkIOOBE(() -> { 1278 byte o = (byte) vh.getAndBitwiseAndAcquire(array, ci, (byte)0x01); 1279 }); 1280 1281 checkIOOBE(() -> { 1282 byte o = (byte) vh.getAndBitwiseAndRelease(array, ci, (byte)0x01); 1283 }); 1284 1285 checkIOOBE(() -> { 1286 byte o = (byte) vh.getAndBitwiseXor(array, ci, (byte)0x01); 1287 }); 1288 1289 checkIOOBE(() -> { 1290 byte o = (byte) vh.getAndBitwiseXorAcquire(array, ci, (byte)0x01); 1291 }); 1292 1293 checkIOOBE(() -> { 1294 byte o = (byte) vh.getAndBitwiseXorRelease(array, ci, (byte)0x01); 1295 }); 1296 } 1297 } 1298 1299 } 1300 1301