1 /* 2 * Copyright (c) 2015, 2024, 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 -Xint VarHandleTestAccessChar 29 * 30 * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations 31 * to hit compilation thresholds 32 * 33 * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessChar 34 * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessChar 35 * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessChar 36 */ 37 38 import org.testng.annotations.BeforeClass; 39 import org.testng.annotations.DataProvider; 40 import org.testng.annotations.Test; 41 42 import java.lang.invoke.MethodHandles; 43 import java.lang.invoke.VarHandle; 44 import java.util.ArrayList; 45 import java.util.Arrays; 46 import java.util.List; 47 48 import static org.testng.Assert.*; 49 50 public class VarHandleTestAccessChar extends VarHandleBaseTest { 51 static final char static_final_v = '\u0123'; 52 53 static char static_v; 54 55 final char final_v = '\u0123'; 56 57 char v; 58 59 static final char static_final_v2 = '\u0123'; 60 61 static char static_v2; 62 63 final char final_v2 = '\u0123'; 64 65 char v2; 66 67 VarHandle vhFinalField; 68 69 VarHandle vhField; 70 71 VarHandle vhStaticField; 72 73 VarHandle vhStaticFinalField; 74 75 VarHandle vhArray; 76 77 78 VarHandle[] allocate(boolean same) { 79 List<VarHandle> vhs = new ArrayList<>(); 80 81 String postfix = same ? "" : "2"; 82 VarHandle vh; 83 try { 84 vh = MethodHandles.lookup().findVarHandle( 85 VarHandleTestAccessChar.class, "final_v" + postfix, char.class); 86 vhs.add(vh); 87 88 vh = MethodHandles.lookup().findVarHandle( 89 VarHandleTestAccessChar.class, "v" + postfix, char.class); 90 vhs.add(vh); 91 92 vh = MethodHandles.lookup().findStaticVarHandle( 93 VarHandleTestAccessChar.class, "static_final_v" + postfix, char.class); 94 vhs.add(vh); 95 96 vh = MethodHandles.lookup().findStaticVarHandle( 97 VarHandleTestAccessChar.class, "static_v" + postfix, char.class); 98 vhs.add(vh); 99 100 if (same) { 101 vh = MethodHandles.arrayElementVarHandle(char[].class); 102 } 103 else { 104 vh = MethodHandles.arrayElementVarHandle(String[].class); 105 } 106 vhs.add(vh); 107 } catch (Exception e) { 108 throw new InternalError(e); 109 } 110 return vhs.toArray(new VarHandle[0]); 111 } 112 113 @BeforeClass 114 public void setup() throws Exception { 115 vhFinalField = MethodHandles.lookup().findVarHandle( 116 VarHandleTestAccessChar.class, "final_v", char.class); 117 118 vhField = MethodHandles.lookup().findVarHandle( 119 VarHandleTestAccessChar.class, "v", char.class); 120 121 vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( 122 VarHandleTestAccessChar.class, "static_final_v", char.class); 123 124 vhStaticField = MethodHandles.lookup().findStaticVarHandle( 125 VarHandleTestAccessChar.class, "static_v", char.class); 126 127 vhArray = MethodHandles.arrayElementVarHandle(char[].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(VarHandleTestAccessChar.class)}); 204 types.add(new Object[] {vhStaticField, Arrays.asList()}); 205 types.add(new Object[] {vhArray, Arrays.asList(char[].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(), char.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 VarHandleTestAccessChar.class, "final_v", char.class); 225 }); 226 227 checkIAE("Lookup of static field to instance field", () -> { 228 MethodHandles.lookup().findStaticVarHandle( 229 VarHandleTestAccessChar.class, "v", char.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 VarHandleTestAccessChar.class, "static_final_v", char.class); 238 }); 239 240 checkIAE("Lookup of instance field to static field", () -> { 241 vhStaticField = MethodHandles.lookup().findVarHandle( 242 VarHandleTestAccessChar.class, "static_v", char.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, VarHandleTestAccessChar::testStaticFinalField)); 259 cases.add(new VarHandleAccessTestCase("Static final field unsupported", 260 vhStaticFinalField, VarHandleTestAccessChar::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, VarHandleTestAccessChar::testStaticField)); 271 cases.add(new VarHandleAccessTestCase("Static field unsupported", 272 vhStaticField, VarHandleTestAccessChar::testStaticFieldUnsupported, 273 false)); 274 275 cases.add(new VarHandleAccessTestCase("Array", 276 vhArray, VarHandleTestAccessChar::testArray)); 277 cases.add(new VarHandleAccessTestCase("Array unsupported", 278 vhArray, VarHandleTestAccessChar::testArrayUnsupported, 279 false)); 280 cases.add(new VarHandleAccessTestCase("Array index out of bounds", 281 vhArray, VarHandleTestAccessChar::testArrayIndexOutOfBounds, 282 false)); 283 // Work around issue with jtreg summary reporting which truncates 284 // the String result of Object.toString to 30 characters, hence 285 // the first dummy argument 286 return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); 287 } 288 289 @Test(dataProvider = "accessTestCaseProvider") 290 public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable { 291 T t = atc.get(); 292 int iters = atc.requiresLoop() ? ITERS : 1; 293 for (int c = 0; c < iters; c++) { 294 atc.testAccess(t); 295 } 296 } 297 298 static void testInstanceFinalField(VarHandleTestAccessChar recv, VarHandle vh) { 299 // Plain 300 { 301 char x = (char) vh.get(recv); 302 assertEquals(x, '\u0123', "get char value"); 303 } 304 305 306 // Volatile 307 { 308 char x = (char) vh.getVolatile(recv); 309 assertEquals(x, '\u0123', "getVolatile char value"); 310 } 311 312 // Lazy 313 { 314 char x = (char) vh.getAcquire(recv); 315 assertEquals(x, '\u0123', "getRelease char value"); 316 } 317 318 // Opaque 319 { 320 char x = (char) vh.getOpaque(recv); 321 assertEquals(x, '\u0123', "getOpaque char value"); 322 } 323 } 324 325 static void testInstanceFinalFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh) { 326 checkUOE(() -> { 327 vh.set(recv, '\u4567'); 328 }); 329 330 checkUOE(() -> { 331 vh.setVolatile(recv, '\u4567'); 332 }); 333 334 checkUOE(() -> { 335 vh.setRelease(recv, '\u4567'); 336 }); 337 338 checkUOE(() -> { 339 vh.setOpaque(recv, '\u4567'); 340 }); 341 342 343 344 } 345 346 347 static void testStaticFinalField(VarHandle vh) { 348 // Plain 349 { 350 char x = (char) vh.get(); 351 assertEquals(x, '\u0123', "get char value"); 352 } 353 354 355 // Volatile 356 { 357 char x = (char) vh.getVolatile(); 358 assertEquals(x, '\u0123', "getVolatile char value"); 359 } 360 361 // Lazy 362 { 363 char x = (char) vh.getAcquire(); 364 assertEquals(x, '\u0123', "getRelease char value"); 365 } 366 367 // Opaque 368 { 369 char x = (char) vh.getOpaque(); 370 assertEquals(x, '\u0123', "getOpaque char value"); 371 } 372 } 373 374 static void testStaticFinalFieldUnsupported(VarHandle vh) { 375 checkUOE(() -> { 376 vh.set('\u4567'); 377 }); 378 379 checkUOE(() -> { 380 vh.setVolatile('\u4567'); 381 }); 382 383 checkUOE(() -> { 384 vh.setRelease('\u4567'); 385 }); 386 387 checkUOE(() -> { 388 vh.setOpaque('\u4567'); 389 }); 390 391 392 393 } 394 395 396 static void testInstanceField(VarHandleTestAccessChar recv, VarHandle vh) { 397 // Plain 398 { 399 vh.set(recv, '\u0123'); 400 char x = (char) vh.get(recv); 401 assertEquals(x, '\u0123', "set char value"); 402 } 403 404 405 // Volatile 406 { 407 vh.setVolatile(recv, '\u4567'); 408 char x = (char) vh.getVolatile(recv); 409 assertEquals(x, '\u4567', "setVolatile char value"); 410 } 411 412 // Lazy 413 { 414 vh.setRelease(recv, '\u0123'); 415 char x = (char) vh.getAcquire(recv); 416 assertEquals(x, '\u0123', "setRelease char value"); 417 } 418 419 // Opaque 420 { 421 vh.setOpaque(recv, '\u4567'); 422 char x = (char) vh.getOpaque(recv); 423 assertEquals(x, '\u4567', "setOpaque char value"); 424 } 425 426 vh.set(recv, '\u0123'); 427 428 // Compare 429 { 430 boolean r = vh.compareAndSet(recv, '\u0123', '\u4567'); 431 assertEquals(r, true, "success compareAndSet char"); 432 char x = (char) vh.get(recv); 433 assertEquals(x, '\u4567', "success compareAndSet char value"); 434 } 435 436 { 437 boolean r = vh.compareAndSet(recv, '\u0123', '\u89AB'); 438 assertEquals(r, false, "failing compareAndSet char"); 439 char x = (char) vh.get(recv); 440 assertEquals(x, '\u4567', "failing compareAndSet char value"); 441 } 442 443 { 444 char r = (char) vh.compareAndExchange(recv, '\u4567', '\u0123'); 445 assertEquals(r, '\u4567', "success compareAndExchange char"); 446 char x = (char) vh.get(recv); 447 assertEquals(x, '\u0123', "success compareAndExchange char value"); 448 } 449 450 { 451 char r = (char) vh.compareAndExchange(recv, '\u4567', '\u89AB'); 452 assertEquals(r, '\u0123', "failing compareAndExchange char"); 453 char x = (char) vh.get(recv); 454 assertEquals(x, '\u0123', "failing compareAndExchange char value"); 455 } 456 457 { 458 char r = (char) vh.compareAndExchangeAcquire(recv, '\u0123', '\u4567'); 459 assertEquals(r, '\u0123', "success compareAndExchangeAcquire char"); 460 char x = (char) vh.get(recv); 461 assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value"); 462 } 463 464 { 465 char r = (char) vh.compareAndExchangeAcquire(recv, '\u0123', '\u89AB'); 466 assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char"); 467 char x = (char) vh.get(recv); 468 assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value"); 469 } 470 471 { 472 char r = (char) vh.compareAndExchangeRelease(recv, '\u4567', '\u0123'); 473 assertEquals(r, '\u4567', "success compareAndExchangeRelease char"); 474 char x = (char) vh.get(recv); 475 assertEquals(x, '\u0123', "success compareAndExchangeRelease char value"); 476 } 477 478 { 479 char r = (char) vh.compareAndExchangeRelease(recv, '\u4567', '\u89AB'); 480 assertEquals(r, '\u0123', "failing compareAndExchangeRelease char"); 481 char x = (char) vh.get(recv); 482 assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value"); 483 } 484 485 { 486 boolean success = false; 487 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 488 success = vh.weakCompareAndSetPlain(recv, '\u0123', '\u4567'); 489 if (!success) weakDelay(); 490 } 491 assertEquals(success, true, "success weakCompareAndSetPlain char"); 492 char x = (char) vh.get(recv); 493 assertEquals(x, '\u4567', "success weakCompareAndSetPlain char value"); 494 } 495 496 { 497 boolean success = vh.weakCompareAndSetPlain(recv, '\u0123', '\u89AB'); 498 assertEquals(success, false, "failing weakCompareAndSetPlain char"); 499 char x = (char) vh.get(recv); 500 assertEquals(x, '\u4567', "failing weakCompareAndSetPlain char value"); 501 } 502 503 { 504 boolean success = false; 505 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 506 success = vh.weakCompareAndSetAcquire(recv, '\u4567', '\u0123'); 507 if (!success) weakDelay(); 508 } 509 assertEquals(success, true, "success weakCompareAndSetAcquire char"); 510 char x = (char) vh.get(recv); 511 assertEquals(x, '\u0123', "success weakCompareAndSetAcquire char"); 512 } 513 514 { 515 boolean success = vh.weakCompareAndSetAcquire(recv, '\u4567', '\u89AB'); 516 assertEquals(success, false, "failing weakCompareAndSetAcquire char"); 517 char x = (char) vh.get(recv); 518 assertEquals(x, '\u0123', "failing weakCompareAndSetAcquire char value"); 519 } 520 521 { 522 boolean success = false; 523 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 524 success = vh.weakCompareAndSetRelease(recv, '\u0123', '\u4567'); 525 if (!success) weakDelay(); 526 } 527 assertEquals(success, true, "success weakCompareAndSetRelease char"); 528 char x = (char) vh.get(recv); 529 assertEquals(x, '\u4567', "success weakCompareAndSetRelease char"); 530 } 531 532 { 533 boolean success = vh.weakCompareAndSetRelease(recv, '\u0123', '\u89AB'); 534 assertEquals(success, false, "failing weakCompareAndSetRelease char"); 535 char x = (char) vh.get(recv); 536 assertEquals(x, '\u4567', "failing weakCompareAndSetRelease char value"); 537 } 538 539 { 540 boolean success = false; 541 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 542 success = vh.weakCompareAndSet(recv, '\u4567', '\u0123'); 543 if (!success) weakDelay(); 544 } 545 assertEquals(success, true, "success weakCompareAndSet char"); 546 char x = (char) vh.get(recv); 547 assertEquals(x, '\u0123', "success weakCompareAndSet char value"); 548 } 549 550 { 551 boolean success = vh.weakCompareAndSet(recv, '\u4567', '\u89AB'); 552 assertEquals(success, false, "failing weakCompareAndSet char"); 553 char x = (char) vh.get(recv); 554 assertEquals(x, '\u0123', "failing weakCompareAndSet char value"); 555 } 556 557 // Compare set and get 558 { 559 vh.set(recv, '\u0123'); 560 561 char o = (char) vh.getAndSet(recv, '\u4567'); 562 assertEquals(o, '\u0123', "getAndSet char"); 563 char x = (char) vh.get(recv); 564 assertEquals(x, '\u4567', "getAndSet char value"); 565 } 566 567 { 568 vh.set(recv, '\u0123'); 569 570 char o = (char) vh.getAndSetAcquire(recv, '\u4567'); 571 assertEquals(o, '\u0123', "getAndSetAcquire char"); 572 char x = (char) vh.get(recv); 573 assertEquals(x, '\u4567', "getAndSetAcquire char value"); 574 } 575 576 { 577 vh.set(recv, '\u0123'); 578 579 char o = (char) vh.getAndSetRelease(recv, '\u4567'); 580 assertEquals(o, '\u0123', "getAndSetRelease char"); 581 char x = (char) vh.get(recv); 582 assertEquals(x, '\u4567', "getAndSetRelease char value"); 583 } 584 585 // get and add, add and get 586 { 587 vh.set(recv, '\u0123'); 588 589 char o = (char) vh.getAndAdd(recv, '\u4567'); 590 assertEquals(o, '\u0123', "getAndAdd char"); 591 char x = (char) vh.get(recv); 592 assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value"); 593 } 594 595 { 596 vh.set(recv, '\u0123'); 597 598 char o = (char) vh.getAndAddAcquire(recv, '\u4567'); 599 assertEquals(o, '\u0123', "getAndAddAcquire char"); 600 char x = (char) vh.get(recv); 601 assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value"); 602 } 603 604 { 605 vh.set(recv, '\u0123'); 606 607 char o = (char) vh.getAndAddRelease(recv, '\u4567'); 608 assertEquals(o, '\u0123', "getAndAddReleasechar"); 609 char x = (char) vh.get(recv); 610 assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value"); 611 } 612 613 // get and bitwise or 614 { 615 vh.set(recv, '\u0123'); 616 617 char o = (char) vh.getAndBitwiseOr(recv, '\u4567'); 618 assertEquals(o, '\u0123', "getAndBitwiseOr char"); 619 char x = (char) vh.get(recv); 620 assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value"); 621 } 622 623 { 624 vh.set(recv, '\u0123'); 625 626 char o = (char) vh.getAndBitwiseOrAcquire(recv, '\u4567'); 627 assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char"); 628 char x = (char) vh.get(recv); 629 assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value"); 630 } 631 632 { 633 vh.set(recv, '\u0123'); 634 635 char o = (char) vh.getAndBitwiseOrRelease(recv, '\u4567'); 636 assertEquals(o, '\u0123', "getAndBitwiseOrRelease char"); 637 char x = (char) vh.get(recv); 638 assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value"); 639 } 640 641 // get and bitwise and 642 { 643 vh.set(recv, '\u0123'); 644 645 char o = (char) vh.getAndBitwiseAnd(recv, '\u4567'); 646 assertEquals(o, '\u0123', "getAndBitwiseAnd char"); 647 char x = (char) vh.get(recv); 648 assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value"); 649 } 650 651 { 652 vh.set(recv, '\u0123'); 653 654 char o = (char) vh.getAndBitwiseAndAcquire(recv, '\u4567'); 655 assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char"); 656 char x = (char) vh.get(recv); 657 assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value"); 658 } 659 660 { 661 vh.set(recv, '\u0123'); 662 663 char o = (char) vh.getAndBitwiseAndRelease(recv, '\u4567'); 664 assertEquals(o, '\u0123', "getAndBitwiseAndRelease char"); 665 char x = (char) vh.get(recv); 666 assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value"); 667 } 668 669 // get and bitwise xor 670 { 671 vh.set(recv, '\u0123'); 672 673 char o = (char) vh.getAndBitwiseXor(recv, '\u4567'); 674 assertEquals(o, '\u0123', "getAndBitwiseXor char"); 675 char x = (char) vh.get(recv); 676 assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value"); 677 } 678 679 { 680 vh.set(recv, '\u0123'); 681 682 char o = (char) vh.getAndBitwiseXorAcquire(recv, '\u4567'); 683 assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char"); 684 char x = (char) vh.get(recv); 685 assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value"); 686 } 687 688 { 689 vh.set(recv, '\u0123'); 690 691 char o = (char) vh.getAndBitwiseXorRelease(recv, '\u4567'); 692 assertEquals(o, '\u0123', "getAndBitwiseXorRelease char"); 693 char x = (char) vh.get(recv); 694 assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value"); 695 } 696 } 697 698 static void testInstanceFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh) { 699 700 701 } 702 703 704 static void testStaticField(VarHandle vh) { 705 // Plain 706 { 707 vh.set('\u0123'); 708 char x = (char) vh.get(); 709 assertEquals(x, '\u0123', "set char value"); 710 } 711 712 713 // Volatile 714 { 715 vh.setVolatile('\u4567'); 716 char x = (char) vh.getVolatile(); 717 assertEquals(x, '\u4567', "setVolatile char value"); 718 } 719 720 // Lazy 721 { 722 vh.setRelease('\u0123'); 723 char x = (char) vh.getAcquire(); 724 assertEquals(x, '\u0123', "setRelease char value"); 725 } 726 727 // Opaque 728 { 729 vh.setOpaque('\u4567'); 730 char x = (char) vh.getOpaque(); 731 assertEquals(x, '\u4567', "setOpaque char value"); 732 } 733 734 vh.set('\u0123'); 735 736 // Compare 737 { 738 boolean r = vh.compareAndSet('\u0123', '\u4567'); 739 assertEquals(r, true, "success compareAndSet char"); 740 char x = (char) vh.get(); 741 assertEquals(x, '\u4567', "success compareAndSet char value"); 742 } 743 744 { 745 boolean r = vh.compareAndSet('\u0123', '\u89AB'); 746 assertEquals(r, false, "failing compareAndSet char"); 747 char x = (char) vh.get(); 748 assertEquals(x, '\u4567', "failing compareAndSet char value"); 749 } 750 751 { 752 char r = (char) vh.compareAndExchange('\u4567', '\u0123'); 753 assertEquals(r, '\u4567', "success compareAndExchange char"); 754 char x = (char) vh.get(); 755 assertEquals(x, '\u0123', "success compareAndExchange char value"); 756 } 757 758 { 759 char r = (char) vh.compareAndExchange('\u4567', '\u89AB'); 760 assertEquals(r, '\u0123', "failing compareAndExchange char"); 761 char x = (char) vh.get(); 762 assertEquals(x, '\u0123', "failing compareAndExchange char value"); 763 } 764 765 { 766 char r = (char) vh.compareAndExchangeAcquire('\u0123', '\u4567'); 767 assertEquals(r, '\u0123', "success compareAndExchangeAcquire char"); 768 char x = (char) vh.get(); 769 assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value"); 770 } 771 772 { 773 char r = (char) vh.compareAndExchangeAcquire('\u0123', '\u89AB'); 774 assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char"); 775 char x = (char) vh.get(); 776 assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value"); 777 } 778 779 { 780 char r = (char) vh.compareAndExchangeRelease('\u4567', '\u0123'); 781 assertEquals(r, '\u4567', "success compareAndExchangeRelease char"); 782 char x = (char) vh.get(); 783 assertEquals(x, '\u0123', "success compareAndExchangeRelease char value"); 784 } 785 786 { 787 char r = (char) vh.compareAndExchangeRelease('\u4567', '\u89AB'); 788 assertEquals(r, '\u0123', "failing compareAndExchangeRelease char"); 789 char x = (char) vh.get(); 790 assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value"); 791 } 792 793 { 794 boolean success = false; 795 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 796 success = vh.weakCompareAndSetPlain('\u0123', '\u4567'); 797 if (!success) weakDelay(); 798 } 799 assertEquals(success, true, "success weakCompareAndSetPlain char"); 800 char x = (char) vh.get(); 801 assertEquals(x, '\u4567', "success weakCompareAndSetPlain char value"); 802 } 803 804 { 805 boolean success = vh.weakCompareAndSetPlain('\u0123', '\u89AB'); 806 assertEquals(success, false, "failing weakCompareAndSetPlain char"); 807 char x = (char) vh.get(); 808 assertEquals(x, '\u4567', "failing weakCompareAndSetPlain char value"); 809 } 810 811 { 812 boolean success = false; 813 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 814 success = vh.weakCompareAndSetAcquire('\u4567', '\u0123'); 815 if (!success) weakDelay(); 816 } 817 assertEquals(success, true, "success weakCompareAndSetAcquire char"); 818 char x = (char) vh.get(); 819 assertEquals(x, '\u0123', "success weakCompareAndSetAcquire char"); 820 } 821 822 { 823 boolean success = vh.weakCompareAndSetAcquire('\u4567', '\u89AB'); 824 assertEquals(success, false, "failing weakCompareAndSetAcquire char"); 825 char x = (char) vh.get(); 826 assertEquals(x, '\u0123', "failing weakCompareAndSetAcquire char value"); 827 } 828 829 { 830 boolean success = false; 831 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 832 success = vh.weakCompareAndSetRelease('\u0123', '\u4567'); 833 if (!success) weakDelay(); 834 } 835 assertEquals(success, true, "success weakCompareAndSetRelease char"); 836 char x = (char) vh.get(); 837 assertEquals(x, '\u4567', "success weakCompareAndSetRelease char"); 838 } 839 840 { 841 boolean success = vh.weakCompareAndSetRelease('\u0123', '\u89AB'); 842 assertEquals(success, false, "failing weakCompareAndSetRelease char"); 843 char x = (char) vh.get(); 844 assertEquals(x, '\u4567', "failing weakCompareAndSetRelease char value"); 845 } 846 847 { 848 boolean success = false; 849 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 850 success = vh.weakCompareAndSet('\u4567', '\u0123'); 851 if (!success) weakDelay(); 852 } 853 assertEquals(success, true, "success weakCompareAndSet char"); 854 char x = (char) vh.get(); 855 assertEquals(x, '\u0123', "success weakCompareAndSet char"); 856 } 857 858 { 859 boolean success = vh.weakCompareAndSet('\u4567', '\u89AB'); 860 assertEquals(success, false, "failing weakCompareAndSet char"); 861 char x = (char) vh.get(); 862 assertEquals(x, '\u0123', "failing weakCompareAndSet char value"); 863 } 864 865 // Compare set and get 866 { 867 vh.set('\u0123'); 868 869 char o = (char) vh.getAndSet('\u4567'); 870 assertEquals(o, '\u0123', "getAndSet char"); 871 char x = (char) vh.get(); 872 assertEquals(x, '\u4567', "getAndSet char value"); 873 } 874 875 { 876 vh.set('\u0123'); 877 878 char o = (char) vh.getAndSetAcquire('\u4567'); 879 assertEquals(o, '\u0123', "getAndSetAcquire char"); 880 char x = (char) vh.get(); 881 assertEquals(x, '\u4567', "getAndSetAcquire char value"); 882 } 883 884 { 885 vh.set('\u0123'); 886 887 char o = (char) vh.getAndSetRelease('\u4567'); 888 assertEquals(o, '\u0123', "getAndSetRelease char"); 889 char x = (char) vh.get(); 890 assertEquals(x, '\u4567', "getAndSetRelease char value"); 891 } 892 893 // get and add, add and get 894 { 895 vh.set('\u0123'); 896 897 char o = (char) vh.getAndAdd('\u4567'); 898 assertEquals(o, '\u0123', "getAndAdd char"); 899 char x = (char) vh.get(); 900 assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value"); 901 } 902 903 { 904 vh.set('\u0123'); 905 906 char o = (char) vh.getAndAddAcquire('\u4567'); 907 assertEquals(o, '\u0123', "getAndAddAcquire char"); 908 char x = (char) vh.get(); 909 assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value"); 910 } 911 912 { 913 vh.set('\u0123'); 914 915 char o = (char) vh.getAndAddRelease('\u4567'); 916 assertEquals(o, '\u0123', "getAndAddReleasechar"); 917 char x = (char) vh.get(); 918 assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value"); 919 } 920 921 // get and bitwise or 922 { 923 vh.set('\u0123'); 924 925 char o = (char) vh.getAndBitwiseOr('\u4567'); 926 assertEquals(o, '\u0123', "getAndBitwiseOr char"); 927 char x = (char) vh.get(); 928 assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value"); 929 } 930 931 { 932 vh.set('\u0123'); 933 934 char o = (char) vh.getAndBitwiseOrAcquire('\u4567'); 935 assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char"); 936 char x = (char) vh.get(); 937 assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value"); 938 } 939 940 { 941 vh.set('\u0123'); 942 943 char o = (char) vh.getAndBitwiseOrRelease('\u4567'); 944 assertEquals(o, '\u0123', "getAndBitwiseOrRelease char"); 945 char x = (char) vh.get(); 946 assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value"); 947 } 948 949 // get and bitwise and 950 { 951 vh.set('\u0123'); 952 953 char o = (char) vh.getAndBitwiseAnd('\u4567'); 954 assertEquals(o, '\u0123', "getAndBitwiseAnd char"); 955 char x = (char) vh.get(); 956 assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value"); 957 } 958 959 { 960 vh.set('\u0123'); 961 962 char o = (char) vh.getAndBitwiseAndAcquire('\u4567'); 963 assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char"); 964 char x = (char) vh.get(); 965 assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value"); 966 } 967 968 { 969 vh.set('\u0123'); 970 971 char o = (char) vh.getAndBitwiseAndRelease('\u4567'); 972 assertEquals(o, '\u0123', "getAndBitwiseAndRelease char"); 973 char x = (char) vh.get(); 974 assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value"); 975 } 976 977 // get and bitwise xor 978 { 979 vh.set('\u0123'); 980 981 char o = (char) vh.getAndBitwiseXor('\u4567'); 982 assertEquals(o, '\u0123', "getAndBitwiseXor char"); 983 char x = (char) vh.get(); 984 assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value"); 985 } 986 987 { 988 vh.set('\u0123'); 989 990 char o = (char) vh.getAndBitwiseXorAcquire('\u4567'); 991 assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char"); 992 char x = (char) vh.get(); 993 assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value"); 994 } 995 996 { 997 vh.set('\u0123'); 998 999 char o = (char) vh.getAndBitwiseXorRelease('\u4567'); 1000 assertEquals(o, '\u0123', "getAndBitwiseXorRelease char"); 1001 char x = (char) vh.get(); 1002 assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value"); 1003 } 1004 } 1005 1006 static void testStaticFieldUnsupported(VarHandle vh) { 1007 1008 1009 } 1010 1011 1012 static void testArray(VarHandle vh) { 1013 char[] array = new char[10]; 1014 1015 for (int i = 0; i < array.length; i++) { 1016 // Plain 1017 { 1018 vh.set(array, i, '\u0123'); 1019 char x = (char) vh.get(array, i); 1020 assertEquals(x, '\u0123', "get char value"); 1021 } 1022 1023 1024 // Volatile 1025 { 1026 vh.setVolatile(array, i, '\u4567'); 1027 char x = (char) vh.getVolatile(array, i); 1028 assertEquals(x, '\u4567', "setVolatile char value"); 1029 } 1030 1031 // Lazy 1032 { 1033 vh.setRelease(array, i, '\u0123'); 1034 char x = (char) vh.getAcquire(array, i); 1035 assertEquals(x, '\u0123', "setRelease char value"); 1036 } 1037 1038 // Opaque 1039 { 1040 vh.setOpaque(array, i, '\u4567'); 1041 char x = (char) vh.getOpaque(array, i); 1042 assertEquals(x, '\u4567', "setOpaque char value"); 1043 } 1044 1045 vh.set(array, i, '\u0123'); 1046 1047 // Compare 1048 { 1049 boolean r = vh.compareAndSet(array, i, '\u0123', '\u4567'); 1050 assertEquals(r, true, "success compareAndSet char"); 1051 char x = (char) vh.get(array, i); 1052 assertEquals(x, '\u4567', "success compareAndSet char value"); 1053 } 1054 1055 { 1056 boolean r = vh.compareAndSet(array, i, '\u0123', '\u89AB'); 1057 assertEquals(r, false, "failing compareAndSet char"); 1058 char x = (char) vh.get(array, i); 1059 assertEquals(x, '\u4567', "failing compareAndSet char value"); 1060 } 1061 1062 { 1063 char r = (char) vh.compareAndExchange(array, i, '\u4567', '\u0123'); 1064 assertEquals(r, '\u4567', "success compareAndExchange char"); 1065 char x = (char) vh.get(array, i); 1066 assertEquals(x, '\u0123', "success compareAndExchange char value"); 1067 } 1068 1069 { 1070 char r = (char) vh.compareAndExchange(array, i, '\u4567', '\u89AB'); 1071 assertEquals(r, '\u0123', "failing compareAndExchange char"); 1072 char x = (char) vh.get(array, i); 1073 assertEquals(x, '\u0123', "failing compareAndExchange char value"); 1074 } 1075 1076 { 1077 char r = (char) vh.compareAndExchangeAcquire(array, i, '\u0123', '\u4567'); 1078 assertEquals(r, '\u0123', "success compareAndExchangeAcquire char"); 1079 char x = (char) vh.get(array, i); 1080 assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value"); 1081 } 1082 1083 { 1084 char r = (char) vh.compareAndExchangeAcquire(array, i, '\u0123', '\u89AB'); 1085 assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char"); 1086 char x = (char) vh.get(array, i); 1087 assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value"); 1088 } 1089 1090 { 1091 char r = (char) vh.compareAndExchangeRelease(array, i, '\u4567', '\u0123'); 1092 assertEquals(r, '\u4567', "success compareAndExchangeRelease char"); 1093 char x = (char) vh.get(array, i); 1094 assertEquals(x, '\u0123', "success compareAndExchangeRelease char value"); 1095 } 1096 1097 { 1098 char r = (char) vh.compareAndExchangeRelease(array, i, '\u4567', '\u89AB'); 1099 assertEquals(r, '\u0123', "failing compareAndExchangeRelease char"); 1100 char x = (char) vh.get(array, i); 1101 assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value"); 1102 } 1103 1104 { 1105 boolean success = false; 1106 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 1107 success = vh.weakCompareAndSetPlain(array, i, '\u0123', '\u4567'); 1108 if (!success) weakDelay(); 1109 } 1110 assertEquals(success, true, "success weakCompareAndSetPlain char"); 1111 char x = (char) vh.get(array, i); 1112 assertEquals(x, '\u4567', "success weakCompareAndSetPlain char value"); 1113 } 1114 1115 { 1116 boolean success = vh.weakCompareAndSetPlain(array, i, '\u0123', '\u89AB'); 1117 assertEquals(success, false, "failing weakCompareAndSetPlain char"); 1118 char x = (char) vh.get(array, i); 1119 assertEquals(x, '\u4567', "failing weakCompareAndSetPlain char value"); 1120 } 1121 1122 { 1123 boolean success = false; 1124 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 1125 success = vh.weakCompareAndSetAcquire(array, i, '\u4567', '\u0123'); 1126 if (!success) weakDelay(); 1127 } 1128 assertEquals(success, true, "success weakCompareAndSetAcquire char"); 1129 char x = (char) vh.get(array, i); 1130 assertEquals(x, '\u0123', "success weakCompareAndSetAcquire char"); 1131 } 1132 1133 { 1134 boolean success = vh.weakCompareAndSetAcquire(array, i, '\u4567', '\u89AB'); 1135 assertEquals(success, false, "failing weakCompareAndSetAcquire char"); 1136 char x = (char) vh.get(array, i); 1137 assertEquals(x, '\u0123', "failing weakCompareAndSetAcquire char value"); 1138 } 1139 1140 { 1141 boolean success = false; 1142 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 1143 success = vh.weakCompareAndSetRelease(array, i, '\u0123', '\u4567'); 1144 if (!success) weakDelay(); 1145 } 1146 assertEquals(success, true, "success weakCompareAndSetRelease char"); 1147 char x = (char) vh.get(array, i); 1148 assertEquals(x, '\u4567', "success weakCompareAndSetRelease char"); 1149 } 1150 1151 { 1152 boolean success = vh.weakCompareAndSetRelease(array, i, '\u0123', '\u89AB'); 1153 assertEquals(success, false, "failing weakCompareAndSetRelease char"); 1154 char x = (char) vh.get(array, i); 1155 assertEquals(x, '\u4567', "failing weakCompareAndSetRelease char value"); 1156 } 1157 1158 { 1159 boolean success = false; 1160 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { 1161 success = vh.weakCompareAndSet(array, i, '\u4567', '\u0123'); 1162 if (!success) weakDelay(); 1163 } 1164 assertEquals(success, true, "success weakCompareAndSet char"); 1165 char x = (char) vh.get(array, i); 1166 assertEquals(x, '\u0123', "success weakCompareAndSet char"); 1167 } 1168 1169 { 1170 boolean success = vh.weakCompareAndSet(array, i, '\u4567', '\u89AB'); 1171 assertEquals(success, false, "failing weakCompareAndSet char"); 1172 char x = (char) vh.get(array, i); 1173 assertEquals(x, '\u0123', "failing weakCompareAndSet char value"); 1174 } 1175 1176 // Compare set and get 1177 { 1178 vh.set(array, i, '\u0123'); 1179 1180 char o = (char) vh.getAndSet(array, i, '\u4567'); 1181 assertEquals(o, '\u0123', "getAndSet char"); 1182 char x = (char) vh.get(array, i); 1183 assertEquals(x, '\u4567', "getAndSet char value"); 1184 } 1185 1186 { 1187 vh.set(array, i, '\u0123'); 1188 1189 char o = (char) vh.getAndSetAcquire(array, i, '\u4567'); 1190 assertEquals(o, '\u0123', "getAndSetAcquire char"); 1191 char x = (char) vh.get(array, i); 1192 assertEquals(x, '\u4567', "getAndSetAcquire char value"); 1193 } 1194 1195 { 1196 vh.set(array, i, '\u0123'); 1197 1198 char o = (char) vh.getAndSetRelease(array, i, '\u4567'); 1199 assertEquals(o, '\u0123', "getAndSetRelease char"); 1200 char x = (char) vh.get(array, i); 1201 assertEquals(x, '\u4567', "getAndSetRelease char value"); 1202 } 1203 1204 // get and add, add and get 1205 { 1206 vh.set(array, i, '\u0123'); 1207 1208 char o = (char) vh.getAndAdd(array, i, '\u4567'); 1209 assertEquals(o, '\u0123', "getAndAdd char"); 1210 char x = (char) vh.get(array, i); 1211 assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value"); 1212 } 1213 1214 { 1215 vh.set(array, i, '\u0123'); 1216 1217 char o = (char) vh.getAndAddAcquire(array, i, '\u4567'); 1218 assertEquals(o, '\u0123', "getAndAddAcquire char"); 1219 char x = (char) vh.get(array, i); 1220 assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value"); 1221 } 1222 1223 { 1224 vh.set(array, i, '\u0123'); 1225 1226 char o = (char) vh.getAndAddRelease(array, i, '\u4567'); 1227 assertEquals(o, '\u0123', "getAndAddReleasechar"); 1228 char x = (char) vh.get(array, i); 1229 assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value"); 1230 } 1231 1232 // get and bitwise or 1233 { 1234 vh.set(array, i, '\u0123'); 1235 1236 char o = (char) vh.getAndBitwiseOr(array, i, '\u4567'); 1237 assertEquals(o, '\u0123', "getAndBitwiseOr char"); 1238 char x = (char) vh.get(array, i); 1239 assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value"); 1240 } 1241 1242 { 1243 vh.set(array, i, '\u0123'); 1244 1245 char o = (char) vh.getAndBitwiseOrAcquire(array, i, '\u4567'); 1246 assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char"); 1247 char x = (char) vh.get(array, i); 1248 assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value"); 1249 } 1250 1251 { 1252 vh.set(array, i, '\u0123'); 1253 1254 char o = (char) vh.getAndBitwiseOrRelease(array, i, '\u4567'); 1255 assertEquals(o, '\u0123', "getAndBitwiseOrRelease char"); 1256 char x = (char) vh.get(array, i); 1257 assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value"); 1258 } 1259 1260 // get and bitwise and 1261 { 1262 vh.set(array, i, '\u0123'); 1263 1264 char o = (char) vh.getAndBitwiseAnd(array, i, '\u4567'); 1265 assertEquals(o, '\u0123', "getAndBitwiseAnd char"); 1266 char x = (char) vh.get(array, i); 1267 assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value"); 1268 } 1269 1270 { 1271 vh.set(array, i, '\u0123'); 1272 1273 char o = (char) vh.getAndBitwiseAndAcquire(array, i, '\u4567'); 1274 assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char"); 1275 char x = (char) vh.get(array, i); 1276 assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value"); 1277 } 1278 1279 { 1280 vh.set(array, i, '\u0123'); 1281 1282 char o = (char) vh.getAndBitwiseAndRelease(array, i, '\u4567'); 1283 assertEquals(o, '\u0123', "getAndBitwiseAndRelease char"); 1284 char x = (char) vh.get(array, i); 1285 assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value"); 1286 } 1287 1288 // get and bitwise xor 1289 { 1290 vh.set(array, i, '\u0123'); 1291 1292 char o = (char) vh.getAndBitwiseXor(array, i, '\u4567'); 1293 assertEquals(o, '\u0123', "getAndBitwiseXor char"); 1294 char x = (char) vh.get(array, i); 1295 assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value"); 1296 } 1297 1298 { 1299 vh.set(array, i, '\u0123'); 1300 1301 char o = (char) vh.getAndBitwiseXorAcquire(array, i, '\u4567'); 1302 assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char"); 1303 char x = (char) vh.get(array, i); 1304 assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value"); 1305 } 1306 1307 { 1308 vh.set(array, i, '\u0123'); 1309 1310 char o = (char) vh.getAndBitwiseXorRelease(array, i, '\u4567'); 1311 assertEquals(o, '\u0123', "getAndBitwiseXorRelease char"); 1312 char x = (char) vh.get(array, i); 1313 assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value"); 1314 } 1315 } 1316 } 1317 1318 static void testArrayUnsupported(VarHandle vh) { 1319 char[] array = new char[10]; 1320 1321 int i = 0; 1322 1323 1324 } 1325 1326 static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable { 1327 char[] array = new char[10]; 1328 1329 for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) { 1330 final int ci = i; 1331 1332 checkAIOOBE(() -> { 1333 char x = (char) vh.get(array, ci); 1334 }); 1335 1336 checkAIOOBE(() -> { 1337 vh.set(array, ci, '\u0123'); 1338 }); 1339 1340 checkAIOOBE(() -> { 1341 char x = (char) vh.getVolatile(array, ci); 1342 }); 1343 1344 checkAIOOBE(() -> { 1345 vh.setVolatile(array, ci, '\u0123'); 1346 }); 1347 1348 checkAIOOBE(() -> { 1349 char x = (char) vh.getAcquire(array, ci); 1350 }); 1351 1352 checkAIOOBE(() -> { 1353 vh.setRelease(array, ci, '\u0123'); 1354 }); 1355 1356 checkAIOOBE(() -> { 1357 char x = (char) vh.getOpaque(array, ci); 1358 }); 1359 1360 checkAIOOBE(() -> { 1361 vh.setOpaque(array, ci, '\u0123'); 1362 }); 1363 1364 checkAIOOBE(() -> { 1365 boolean r = vh.compareAndSet(array, ci, '\u0123', '\u4567'); 1366 }); 1367 1368 checkAIOOBE(() -> { 1369 char r = (char) vh.compareAndExchange(array, ci, '\u4567', '\u0123'); 1370 }); 1371 1372 checkAIOOBE(() -> { 1373 char r = (char) vh.compareAndExchangeAcquire(array, ci, '\u4567', '\u0123'); 1374 }); 1375 1376 checkAIOOBE(() -> { 1377 char r = (char) vh.compareAndExchangeRelease(array, ci, '\u4567', '\u0123'); 1378 }); 1379 1380 checkAIOOBE(() -> { 1381 boolean r = vh.weakCompareAndSetPlain(array, ci, '\u0123', '\u4567'); 1382 }); 1383 1384 checkAIOOBE(() -> { 1385 boolean r = vh.weakCompareAndSet(array, ci, '\u0123', '\u4567'); 1386 }); 1387 1388 checkAIOOBE(() -> { 1389 boolean r = vh.weakCompareAndSetAcquire(array, ci, '\u0123', '\u4567'); 1390 }); 1391 1392 checkAIOOBE(() -> { 1393 boolean r = vh.weakCompareAndSetRelease(array, ci, '\u0123', '\u4567'); 1394 }); 1395 1396 checkAIOOBE(() -> { 1397 char o = (char) vh.getAndSet(array, ci, '\u0123'); 1398 }); 1399 1400 checkAIOOBE(() -> { 1401 char o = (char) vh.getAndSetAcquire(array, ci, '\u0123'); 1402 }); 1403 1404 checkAIOOBE(() -> { 1405 char o = (char) vh.getAndSetRelease(array, ci, '\u0123'); 1406 }); 1407 1408 checkAIOOBE(() -> { 1409 char o = (char) vh.getAndAdd(array, ci, '\u0123'); 1410 }); 1411 1412 checkAIOOBE(() -> { 1413 char o = (char) vh.getAndAddAcquire(array, ci, '\u0123'); 1414 }); 1415 1416 checkAIOOBE(() -> { 1417 char o = (char) vh.getAndAddRelease(array, ci, '\u0123'); 1418 }); 1419 1420 checkAIOOBE(() -> { 1421 char o = (char) vh.getAndBitwiseOr(array, ci, '\u0123'); 1422 }); 1423 1424 checkAIOOBE(() -> { 1425 char o = (char) vh.getAndBitwiseOrAcquire(array, ci, '\u0123'); 1426 }); 1427 1428 checkAIOOBE(() -> { 1429 char o = (char) vh.getAndBitwiseOrRelease(array, ci, '\u0123'); 1430 }); 1431 1432 checkAIOOBE(() -> { 1433 char o = (char) vh.getAndBitwiseAnd(array, ci, '\u0123'); 1434 }); 1435 1436 checkAIOOBE(() -> { 1437 char o = (char) vh.getAndBitwiseAndAcquire(array, ci, '\u0123'); 1438 }); 1439 1440 checkAIOOBE(() -> { 1441 char o = (char) vh.getAndBitwiseAndRelease(array, ci, '\u0123'); 1442 }); 1443 1444 checkAIOOBE(() -> { 1445 char o = (char) vh.getAndBitwiseXor(array, ci, '\u0123'); 1446 }); 1447 1448 checkAIOOBE(() -> { 1449 char o = (char) vh.getAndBitwiseXorAcquire(array, ci, '\u0123'); 1450 }); 1451 1452 checkAIOOBE(() -> { 1453 char o = (char) vh.getAndBitwiseXorRelease(array, ci, '\u0123'); 1454 }); 1455 } 1456 } 1457 1458 } 1459