< prev index next >

test/java/lang/invoke/VarHandles/VarHandleTestAccessInt.java

Print this page




  25  * @test
  26  * @run testng/othervm -Diters=10    -Xint                   VarHandleTestAccessInt
  27  * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessInt
  28  * @run testng/othervm -Diters=20000                         VarHandleTestAccessInt
  29  * @run testng/othervm -Diters=20000 -XX:-TieredCompilation  VarHandleTestAccessInt
  30  */
  31 
  32 import org.testng.annotations.BeforeClass;
  33 import org.testng.annotations.DataProvider;
  34 import org.testng.annotations.Test;
  35 
  36 import java.lang.invoke.MethodHandles;
  37 import java.lang.invoke.VarHandle;
  38 import java.util.ArrayList;
  39 import java.util.Arrays;
  40 import java.util.List;
  41 
  42 import static org.testng.Assert.*;
  43 
  44 public class VarHandleTestAccessInt extends VarHandleBaseTest {
  45     static final int static_final_v = 1;
  46 
  47     static int static_v;
  48 
  49     final int final_v = 1;
  50 
  51     int v;
  52 
  53     VarHandle vhFinalField;
  54 
  55     VarHandle vhField;
  56 
  57     VarHandle vhStaticField;
  58 
  59     VarHandle vhStaticFinalField;
  60 
  61     VarHandle vhArray;
  62 
  63     @BeforeClass
  64     public void setup() throws Exception {
  65         vhFinalField = MethodHandles.lookup().findVarHandle(
  66                 VarHandleTestAccessInt.class, "final_v", int.class);
  67 
  68         vhField = MethodHandles.lookup().findVarHandle(
  69                 VarHandleTestAccessInt.class, "v", int.class);


 202         // the first dummy argument
 203         return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
 204     }
 205 
 206     @Test(dataProvider = "accessTestCaseProvider")
 207     public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
 208         T t = atc.get();
 209         int iters = atc.requiresLoop() ? ITERS : 1;
 210         for (int c = 0; c < iters; c++) {
 211             atc.testAccess(t);
 212         }
 213     }
 214 
 215 
 216 
 217 
 218     static void testInstanceFinalField(VarHandleTestAccessInt recv, VarHandle vh) {
 219         // Plain
 220         {
 221             int x = (int) vh.get(recv);
 222             assertEquals(x, 1, "get int value");
 223         }
 224 
 225 
 226         // Volatile
 227         {
 228             int x = (int) vh.getVolatile(recv);
 229             assertEquals(x, 1, "getVolatile int value");
 230         }
 231 
 232         // Lazy
 233         {
 234             int x = (int) vh.getAcquire(recv);
 235             assertEquals(x, 1, "getRelease int value");
 236         }
 237 
 238         // Opaque
 239         {
 240             int x = (int) vh.getOpaque(recv);
 241             assertEquals(x, 1, "getOpaque int value");
 242         }
 243     }
 244 
 245     static void testInstanceFinalFieldUnsupported(VarHandleTestAccessInt recv, VarHandle vh) {
 246         checkUOE(() -> {
 247             vh.set(recv, 2);
 248         });
 249 
 250         checkUOE(() -> {
 251             vh.setVolatile(recv, 2);
 252         });
 253 
 254         checkUOE(() -> {
 255             vh.setRelease(recv, 2);
 256         });
 257 
 258         checkUOE(() -> {
 259             vh.setOpaque(recv, 2);
 260         });
 261 
 262 
 263     }
 264 
 265 
 266     static void testStaticFinalField(VarHandle vh) {
 267         // Plain
 268         {
 269             int x = (int) vh.get();
 270             assertEquals(x, 1, "get int value");
 271         }
 272 
 273 
 274         // Volatile
 275         {
 276             int x = (int) vh.getVolatile();
 277             assertEquals(x, 1, "getVolatile int value");
 278         }
 279 
 280         // Lazy
 281         {
 282             int x = (int) vh.getAcquire();
 283             assertEquals(x, 1, "getRelease int value");
 284         }
 285 
 286         // Opaque
 287         {
 288             int x = (int) vh.getOpaque();
 289             assertEquals(x, 1, "getOpaque int value");
 290         }
 291     }
 292 
 293     static void testStaticFinalFieldUnsupported(VarHandle vh) {
 294         checkUOE(() -> {
 295             vh.set(2);
 296         });
 297 
 298         checkUOE(() -> {
 299             vh.setVolatile(2);
 300         });
 301 
 302         checkUOE(() -> {
 303             vh.setRelease(2);
 304         });
 305 
 306         checkUOE(() -> {
 307             vh.setOpaque(2);
 308         });
 309 
 310 
 311     }
 312 
 313 
 314     static void testInstanceField(VarHandleTestAccessInt recv, VarHandle vh) {
 315         // Plain
 316         {
 317             vh.set(recv, 1);
 318             int x = (int) vh.get(recv);
 319             assertEquals(x, 1, "set int value");
 320         }
 321 
 322 
 323         // Volatile
 324         {
 325             vh.setVolatile(recv, 2);
 326             int x = (int) vh.getVolatile(recv);
 327             assertEquals(x, 2, "setVolatile int value");
 328         }
 329 
 330         // Lazy
 331         {
 332             vh.setRelease(recv, 1);
 333             int x = (int) vh.getAcquire(recv);
 334             assertEquals(x, 1, "setRelease int value");
 335         }
 336 
 337         // Opaque
 338         {
 339             vh.setOpaque(recv, 2);
 340             int x = (int) vh.getOpaque(recv);
 341             assertEquals(x, 2, "setOpaque int value");
 342         }
 343 
 344         vh.set(recv, 1);
 345 
 346         // Compare
 347         {
 348             boolean r = vh.compareAndSet(recv, 1, 2);
 349             assertEquals(r, true, "success compareAndSet int");
 350             int x = (int) vh.get(recv);
 351             assertEquals(x, 2, "success compareAndSet int value");
 352         }
 353 
 354         {
 355             boolean r = vh.compareAndSet(recv, 1, 3);
 356             assertEquals(r, false, "failing compareAndSet int");
 357             int x = (int) vh.get(recv);
 358             assertEquals(x, 2, "failing compareAndSet int value");
 359         }
 360 
 361         {
 362             int r = (int) vh.compareAndExchangeVolatile(recv, 2, 1);
 363             assertEquals(r, 2, "success compareAndExchangeVolatile int");
 364             int x = (int) vh.get(recv);
 365             assertEquals(x, 1, "success compareAndExchangeVolatile int value");
 366         }
 367 
 368         {
 369             int r = (int) vh.compareAndExchangeVolatile(recv, 2, 3);
 370             assertEquals(r, 1, "failing compareAndExchangeVolatile int");
 371             int x = (int) vh.get(recv);
 372             assertEquals(x, 1, "failing compareAndExchangeVolatile int value");
 373         }
 374 
 375         {
 376             int r = (int) vh.compareAndExchangeAcquire(recv, 1, 2);
 377             assertEquals(r, 1, "success compareAndExchangeAcquire int");
 378             int x = (int) vh.get(recv);
 379             assertEquals(x, 2, "success compareAndExchangeAcquire int value");
 380         }
 381 
 382         {
 383             int r = (int) vh.compareAndExchangeAcquire(recv, 1, 3);
 384             assertEquals(r, 2, "failing compareAndExchangeAcquire int");
 385             int x = (int) vh.get(recv);
 386             assertEquals(x, 2, "failing compareAndExchangeAcquire int value");
 387         }
 388 
 389         {
 390             int r = (int) vh.compareAndExchangeRelease(recv, 2, 1);
 391             assertEquals(r, 2, "success compareAndExchangeRelease int");
 392             int x = (int) vh.get(recv);
 393             assertEquals(x, 1, "success compareAndExchangeRelease int value");
 394         }
 395 
 396         {
 397             int r = (int) vh.compareAndExchangeRelease(recv, 2, 3);
 398             assertEquals(r, 1, "failing compareAndExchangeRelease int");
 399             int x = (int) vh.get(recv);
 400             assertEquals(x, 1, "failing compareAndExchangeRelease int value");
 401         }
 402 
 403         {
 404             boolean success = false;
 405             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 406                 success = vh.weakCompareAndSet(recv, 1, 2);
 407             }
 408             assertEquals(success, true, "weakCompareAndSet int");
 409             int x = (int) vh.get(recv);
 410             assertEquals(x, 2, "weakCompareAndSet int value");
 411         }
 412 
 413         {
 414             boolean success = false;
 415             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 416                 success = vh.weakCompareAndSetAcquire(recv, 2, 1);
 417             }
 418             assertEquals(success, true, "weakCompareAndSetAcquire int");
 419             int x = (int) vh.get(recv);
 420             assertEquals(x, 1, "weakCompareAndSetAcquire int");
 421         }
 422 
 423         {
 424             boolean success = false;
 425             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 426                 success = vh.weakCompareAndSetRelease(recv, 1, 2);
 427             }
 428             assertEquals(success, true, "weakCompareAndSetRelease int");
 429             int x = (int) vh.get(recv);
 430             assertEquals(x, 2, "weakCompareAndSetRelease int");
 431         }
 432 
 433         // Compare set and get
 434         {
 435             int o = (int) vh.getAndSet(recv, 1);
 436             assertEquals(o, 2, "getAndSet int");
 437             int x = (int) vh.get(recv);
 438             assertEquals(x, 1, "getAndSet int value");
 439         }
 440 
 441         vh.set(recv, 1);
 442 
 443         // get and add, add and get
 444         {
 445             int o = (int) vh.getAndAdd(recv, 3);
 446             assertEquals(o, 1, "getAndAdd int");
 447             int c = (int) vh.addAndGet(recv, 3);
 448             assertEquals(c, 1 + 3 + 3, "getAndAdd int value");
 449         }
 450     }
 451 
 452     static void testInstanceFieldUnsupported(VarHandleTestAccessInt recv, VarHandle vh) {
 453 
 454     }
 455 
 456 
 457     static void testStaticField(VarHandle vh) {
 458         // Plain
 459         {
 460             vh.set(1);
 461             int x = (int) vh.get();
 462             assertEquals(x, 1, "set int value");
 463         }
 464 
 465 
 466         // Volatile
 467         {
 468             vh.setVolatile(2);
 469             int x = (int) vh.getVolatile();
 470             assertEquals(x, 2, "setVolatile int value");
 471         }
 472 
 473         // Lazy
 474         {
 475             vh.setRelease(1);
 476             int x = (int) vh.getAcquire();
 477             assertEquals(x, 1, "setRelease int value");
 478         }
 479 
 480         // Opaque
 481         {
 482             vh.setOpaque(2);
 483             int x = (int) vh.getOpaque();
 484             assertEquals(x, 2, "setOpaque int value");
 485         }
 486 
 487         vh.set(1);
 488 
 489         // Compare
 490         {
 491             boolean r = vh.compareAndSet(1, 2);
 492             assertEquals(r, true, "success compareAndSet int");
 493             int x = (int) vh.get();
 494             assertEquals(x, 2, "success compareAndSet int value");
 495         }
 496 
 497         {
 498             boolean r = vh.compareAndSet(1, 3);
 499             assertEquals(r, false, "failing compareAndSet int");
 500             int x = (int) vh.get();
 501             assertEquals(x, 2, "failing compareAndSet int value");
 502         }
 503 
 504         {
 505             int r = (int) vh.compareAndExchangeVolatile(2, 1);
 506             assertEquals(r, 2, "success compareAndExchangeVolatile int");
 507             int x = (int) vh.get();
 508             assertEquals(x, 1, "success compareAndExchangeVolatile int value");
 509         }
 510 
 511         {
 512             int r = (int) vh.compareAndExchangeVolatile(2, 3);
 513             assertEquals(r, 1, "failing compareAndExchangeVolatile int");
 514             int x = (int) vh.get();
 515             assertEquals(x, 1, "failing compareAndExchangeVolatile int value");
 516         }
 517 
 518         {
 519             int r = (int) vh.compareAndExchangeAcquire(1, 2);
 520             assertEquals(r, 1, "success compareAndExchangeAcquire int");
 521             int x = (int) vh.get();
 522             assertEquals(x, 2, "success compareAndExchangeAcquire int value");
 523         }
 524 
 525         {
 526             int r = (int) vh.compareAndExchangeAcquire(1, 3);
 527             assertEquals(r, 2, "failing compareAndExchangeAcquire int");
 528             int x = (int) vh.get();
 529             assertEquals(x, 2, "failing compareAndExchangeAcquire int value");
 530         }
 531 
 532         {
 533             int r = (int) vh.compareAndExchangeRelease(2, 1);
 534             assertEquals(r, 2, "success compareAndExchangeRelease int");
 535             int x = (int) vh.get();
 536             assertEquals(x, 1, "success compareAndExchangeRelease int value");
 537         }
 538 
 539         {
 540             int r = (int) vh.compareAndExchangeRelease(2, 3);
 541             assertEquals(r, 1, "failing compareAndExchangeRelease int");
 542             int x = (int) vh.get();
 543             assertEquals(x, 1, "failing compareAndExchangeRelease int value");
 544         }
 545 
 546         {
 547             boolean success = false;
 548             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 549                 success = vh.weakCompareAndSet(1, 2);
 550             }
 551             assertEquals(success, true, "weakCompareAndSet int");
 552             int x = (int) vh.get();
 553             assertEquals(x, 2, "weakCompareAndSet int value");
 554         }
 555 
 556         {
 557             boolean success = false;
 558             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 559                 success = vh.weakCompareAndSetAcquire(2, 1);
 560             }
 561             assertEquals(success, true, "weakCompareAndSetAcquire int");
 562             int x = (int) vh.get();
 563             assertEquals(x, 1, "weakCompareAndSetAcquire int");
 564         }
 565 
 566         {
 567             boolean success = false;
 568             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 569                 success = vh.weakCompareAndSetRelease(1, 2);
 570             }
 571             assertEquals(success, true, "weakCompareAndSetRelease int");
 572             int x = (int) vh.get();
 573             assertEquals(x, 2, "weakCompareAndSetRelease int");
 574         }
 575 
 576         // Compare set and get
 577         {
 578             int o = (int) vh.getAndSet( 1);
 579             assertEquals(o, 2, "getAndSet int");
 580             int x = (int) vh.get();
 581             assertEquals(x, 1, "getAndSet int value");
 582         }
 583 
 584         vh.set(1);
 585 
 586         // get and add, add and get
 587         {
 588             int o = (int) vh.getAndAdd( 3);
 589             assertEquals(o, 1, "getAndAdd int");
 590             int c = (int) vh.addAndGet(3);
 591             assertEquals(c, 1 + 3 + 3, "getAndAdd int value");
 592         }
 593     }
 594 
 595     static void testStaticFieldUnsupported(VarHandle vh) {
 596 
 597     }
 598 
 599 
 600     static void testArray(VarHandle vh) {
 601         int[] array = new int[10];
 602 
 603         for (int i = 0; i < array.length; i++) {
 604             // Plain
 605             {
 606                 vh.set(array, i, 1);
 607                 int x = (int) vh.get(array, i);
 608                 assertEquals(x, 1, "get int value");
 609             }
 610 
 611 
 612             // Volatile
 613             {
 614                 vh.setVolatile(array, i, 2);
 615                 int x = (int) vh.getVolatile(array, i);
 616                 assertEquals(x, 2, "setVolatile int value");
 617             }
 618 
 619             // Lazy
 620             {
 621                 vh.setRelease(array, i, 1);
 622                 int x = (int) vh.getAcquire(array, i);
 623                 assertEquals(x, 1, "setRelease int value");
 624             }
 625 
 626             // Opaque
 627             {
 628                 vh.setOpaque(array, i, 2);
 629                 int x = (int) vh.getOpaque(array, i);
 630                 assertEquals(x, 2, "setOpaque int value");
 631             }
 632 
 633             vh.set(array, i, 1);
 634 
 635             // Compare
 636             {
 637                 boolean r = vh.compareAndSet(array, i, 1, 2);
 638                 assertEquals(r, true, "success compareAndSet int");
 639                 int x = (int) vh.get(array, i);
 640                 assertEquals(x, 2, "success compareAndSet int value");
 641             }
 642 
 643             {
 644                 boolean r = vh.compareAndSet(array, i, 1, 3);
 645                 assertEquals(r, false, "failing compareAndSet int");
 646                 int x = (int) vh.get(array, i);
 647                 assertEquals(x, 2, "failing compareAndSet int value");
 648             }
 649 
 650             {
 651                 int r = (int) vh.compareAndExchangeVolatile(array, i, 2, 1);
 652                 assertEquals(r, 2, "success compareAndExchangeVolatile int");
 653                 int x = (int) vh.get(array, i);
 654                 assertEquals(x, 1, "success compareAndExchangeVolatile int value");
 655             }
 656 
 657             {
 658                 int r = (int) vh.compareAndExchangeVolatile(array, i, 2, 3);
 659                 assertEquals(r, 1, "failing compareAndExchangeVolatile int");
 660                 int x = (int) vh.get(array, i);
 661                 assertEquals(x, 1, "failing compareAndExchangeVolatile int value");
 662             }
 663 
 664             {
 665                 int r = (int) vh.compareAndExchangeAcquire(array, i, 1, 2);
 666                 assertEquals(r, 1, "success compareAndExchangeAcquire int");
 667                 int x = (int) vh.get(array, i);
 668                 assertEquals(x, 2, "success compareAndExchangeAcquire int value");
 669             }
 670 
 671             {
 672                 int r = (int) vh.compareAndExchangeAcquire(array, i, 1, 3);
 673                 assertEquals(r, 2, "failing compareAndExchangeAcquire int");
 674                 int x = (int) vh.get(array, i);
 675                 assertEquals(x, 2, "failing compareAndExchangeAcquire int value");
 676             }
 677 
 678             {
 679                 int r = (int) vh.compareAndExchangeRelease(array, i, 2, 1);
 680                 assertEquals(r, 2, "success compareAndExchangeRelease int");
 681                 int x = (int) vh.get(array, i);
 682                 assertEquals(x, 1, "success compareAndExchangeRelease int value");
 683             }
 684 
 685             {
 686                 int r = (int) vh.compareAndExchangeRelease(array, i, 2, 3);
 687                 assertEquals(r, 1, "failing compareAndExchangeRelease int");
 688                 int x = (int) vh.get(array, i);
 689                 assertEquals(x, 1, "failing compareAndExchangeRelease int value");
 690             }
 691 
 692             {
 693                 boolean success = false;
 694                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 695                     success = vh.weakCompareAndSet(array, i, 1, 2);
 696                 }
 697                 assertEquals(success, true, "weakCompareAndSet int");
 698                 int x = (int) vh.get(array, i);
 699                 assertEquals(x, 2, "weakCompareAndSet int value");
 700             }
 701 
 702             {
 703                 boolean success = false;
 704                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 705                     success = vh.weakCompareAndSetAcquire(array, i, 2, 1);
 706                 }
 707                 assertEquals(success, true, "weakCompareAndSetAcquire int");
 708                 int x = (int) vh.get(array, i);
 709                 assertEquals(x, 1, "weakCompareAndSetAcquire int");
 710             }
 711 
 712             {
 713                 boolean success = false;
 714                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 715                     success = vh.weakCompareAndSetRelease(array, i, 1, 2);
 716                 }
 717                 assertEquals(success, true, "weakCompareAndSetRelease int");
 718                 int x = (int) vh.get(array, i);
 719                 assertEquals(x, 2, "weakCompareAndSetRelease int");
 720             }
 721 
 722             // Compare set and get
 723             {
 724                 int o = (int) vh.getAndSet(array, i, 1);
 725                 assertEquals(o, 2, "getAndSet int");
 726                 int x = (int) vh.get(array, i);
 727                 assertEquals(x, 1, "getAndSet int value");
 728             }
 729 
 730             vh.set(array, i, 1);
 731 
 732             // get and add, add and get
 733             {
 734                 int o = (int) vh.getAndAdd(array, i, 3);
 735                 assertEquals(o, 1, "getAndAdd int");
 736                 int c = (int) vh.addAndGet(array, i, 3);
 737                 assertEquals(c, 1 + 3 + 3, "getAndAdd int value");
 738             }
 739         }
 740     }
 741 
 742     static void testArrayUnsupported(VarHandle vh) {
 743         int[] array = new int[10];
 744 
 745         int i = 0;
 746 
 747     }
 748 
 749     static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
 750         int[] array = new int[10];
 751 
 752         for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
 753             final int ci = i;
 754 
 755             checkIOOBE(() -> {
 756                 int x = (int) vh.get(array, ci);
 757             });
 758 
 759             checkIOOBE(() -> {
 760                 vh.set(array, ci, 1);
 761             });
 762 
 763             checkIOOBE(() -> {
 764                 int x = (int) vh.getVolatile(array, ci);
 765             });
 766 
 767             checkIOOBE(() -> {
 768                 vh.setVolatile(array, ci, 1);
 769             });
 770 
 771             checkIOOBE(() -> {
 772                 int x = (int) vh.getAcquire(array, ci);
 773             });
 774 
 775             checkIOOBE(() -> {
 776                 vh.setRelease(array, ci, 1);
 777             });
 778 
 779             checkIOOBE(() -> {
 780                 int x = (int) vh.getOpaque(array, ci);
 781             });
 782 
 783             checkIOOBE(() -> {
 784                 vh.setOpaque(array, ci, 1);
 785             });
 786 
 787             checkIOOBE(() -> {
 788                 boolean r = vh.compareAndSet(array, ci, 1, 2);
 789             });
 790 
 791             checkIOOBE(() -> {
 792                 int r = (int) vh.compareAndExchangeVolatile(array, ci, 2, 1);
 793             });
 794 
 795             checkIOOBE(() -> {
 796                 int r = (int) vh.compareAndExchangeAcquire(array, ci, 2, 1);
 797             });
 798 
 799             checkIOOBE(() -> {
 800                 int r = (int) vh.compareAndExchangeRelease(array, ci, 2, 1);
 801             });
 802 
 803             checkIOOBE(() -> {
 804                 boolean r = vh.weakCompareAndSet(array, ci, 1, 2);
 805             });
 806 
 807             checkIOOBE(() -> {
 808                 boolean r = vh.weakCompareAndSetAcquire(array, ci, 1, 2);
 809             });
 810 
 811             checkIOOBE(() -> {
 812                 boolean r = vh.weakCompareAndSetRelease(array, ci, 1, 2);
 813             });
 814 
 815             checkIOOBE(() -> {
 816                 int o = (int) vh.getAndSet(array, ci, 1);
 817             });
 818 
 819             checkIOOBE(() -> {
 820                 int o = (int) vh.getAndAdd(array, ci, 3);
 821             });
 822 
 823             checkIOOBE(() -> {
 824                 int o = (int) vh.addAndGet(array, ci, 3);
 825             });
 826         }
 827     }
 828 }
 829 


  25  * @test
  26  * @run testng/othervm -Diters=10    -Xint                   VarHandleTestAccessInt
  27  * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessInt
  28  * @run testng/othervm -Diters=20000                         VarHandleTestAccessInt
  29  * @run testng/othervm -Diters=20000 -XX:-TieredCompilation  VarHandleTestAccessInt
  30  */
  31 
  32 import org.testng.annotations.BeforeClass;
  33 import org.testng.annotations.DataProvider;
  34 import org.testng.annotations.Test;
  35 
  36 import java.lang.invoke.MethodHandles;
  37 import java.lang.invoke.VarHandle;
  38 import java.util.ArrayList;
  39 import java.util.Arrays;
  40 import java.util.List;
  41 
  42 import static org.testng.Assert.*;
  43 
  44 public class VarHandleTestAccessInt extends VarHandleBaseTest {
  45     static final int static_final_v = 0x01234567;
  46 
  47     static int static_v;
  48 
  49     final int final_v = 0x01234567;
  50 
  51     int v;
  52 
  53     VarHandle vhFinalField;
  54 
  55     VarHandle vhField;
  56 
  57     VarHandle vhStaticField;
  58 
  59     VarHandle vhStaticFinalField;
  60 
  61     VarHandle vhArray;
  62 
  63     @BeforeClass
  64     public void setup() throws Exception {
  65         vhFinalField = MethodHandles.lookup().findVarHandle(
  66                 VarHandleTestAccessInt.class, "final_v", int.class);
  67 
  68         vhField = MethodHandles.lookup().findVarHandle(
  69                 VarHandleTestAccessInt.class, "v", int.class);


 202         // the first dummy argument
 203         return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
 204     }
 205 
 206     @Test(dataProvider = "accessTestCaseProvider")
 207     public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
 208         T t = atc.get();
 209         int iters = atc.requiresLoop() ? ITERS : 1;
 210         for (int c = 0; c < iters; c++) {
 211             atc.testAccess(t);
 212         }
 213     }
 214 
 215 
 216 
 217 
 218     static void testInstanceFinalField(VarHandleTestAccessInt recv, VarHandle vh) {
 219         // Plain
 220         {
 221             int x = (int) vh.get(recv);
 222             assertEquals(x, 0x01234567, "get int value");
 223         }
 224 
 225 
 226         // Volatile
 227         {
 228             int x = (int) vh.getVolatile(recv);
 229             assertEquals(x, 0x01234567, "getVolatile int value");
 230         }
 231 
 232         // Lazy
 233         {
 234             int x = (int) vh.getAcquire(recv);
 235             assertEquals(x, 0x01234567, "getRelease int value");
 236         }
 237 
 238         // Opaque
 239         {
 240             int x = (int) vh.getOpaque(recv);
 241             assertEquals(x, 0x01234567, "getOpaque int value");
 242         }
 243     }
 244 
 245     static void testInstanceFinalFieldUnsupported(VarHandleTestAccessInt recv, VarHandle vh) {
 246         checkUOE(() -> {
 247             vh.set(recv, 0x89ABCDEF);
 248         });
 249 
 250         checkUOE(() -> {
 251             vh.setVolatile(recv, 0x89ABCDEF);
 252         });
 253 
 254         checkUOE(() -> {
 255             vh.setRelease(recv, 0x89ABCDEF);
 256         });
 257 
 258         checkUOE(() -> {
 259             vh.setOpaque(recv, 0x89ABCDEF);
 260         });
 261 
 262 
 263     }
 264 
 265 
 266     static void testStaticFinalField(VarHandle vh) {
 267         // Plain
 268         {
 269             int x = (int) vh.get();
 270             assertEquals(x, 0x01234567, "get int value");
 271         }
 272 
 273 
 274         // Volatile
 275         {
 276             int x = (int) vh.getVolatile();
 277             assertEquals(x, 0x01234567, "getVolatile int value");
 278         }
 279 
 280         // Lazy
 281         {
 282             int x = (int) vh.getAcquire();
 283             assertEquals(x, 0x01234567, "getRelease int value");
 284         }
 285 
 286         // Opaque
 287         {
 288             int x = (int) vh.getOpaque();
 289             assertEquals(x, 0x01234567, "getOpaque int value");
 290         }
 291     }
 292 
 293     static void testStaticFinalFieldUnsupported(VarHandle vh) {
 294         checkUOE(() -> {
 295             vh.set(0x89ABCDEF);
 296         });
 297 
 298         checkUOE(() -> {
 299             vh.setVolatile(0x89ABCDEF);
 300         });
 301 
 302         checkUOE(() -> {
 303             vh.setRelease(0x89ABCDEF);
 304         });
 305 
 306         checkUOE(() -> {
 307             vh.setOpaque(0x89ABCDEF);
 308         });
 309 
 310 
 311     }
 312 
 313 
 314     static void testInstanceField(VarHandleTestAccessInt recv, VarHandle vh) {
 315         // Plain
 316         {
 317             vh.set(recv, 0x01234567);
 318             int x = (int) vh.get(recv);
 319             assertEquals(x, 0x01234567, "set int value");
 320         }
 321 
 322 
 323         // Volatile
 324         {
 325             vh.setVolatile(recv, 0x89ABCDEF);
 326             int x = (int) vh.getVolatile(recv);
 327             assertEquals(x, 0x89ABCDEF, "setVolatile int value");
 328         }
 329 
 330         // Lazy
 331         {
 332             vh.setRelease(recv, 0x01234567);
 333             int x = (int) vh.getAcquire(recv);
 334             assertEquals(x, 0x01234567, "setRelease int value");
 335         }
 336 
 337         // Opaque
 338         {
 339             vh.setOpaque(recv, 0x89ABCDEF);
 340             int x = (int) vh.getOpaque(recv);
 341             assertEquals(x, 0x89ABCDEF, "setOpaque int value");
 342         }
 343 
 344         vh.set(recv, 0x01234567);
 345 
 346         // Compare
 347         {
 348             boolean r = vh.compareAndSet(recv, 0x01234567, 0x89ABCDEF);
 349             assertEquals(r, true, "success compareAndSet int");
 350             int x = (int) vh.get(recv);
 351             assertEquals(x, 0x89ABCDEF, "success compareAndSet int value");
 352         }
 353 
 354         {
 355             boolean r = vh.compareAndSet(recv, 0x01234567, 0xCAFEBABE);
 356             assertEquals(r, false, "failing compareAndSet int");
 357             int x = (int) vh.get(recv);
 358             assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value");
 359         }
 360 
 361         {
 362             int r = (int) vh.compareAndExchangeVolatile(recv, 0x89ABCDEF, 0x01234567);
 363             assertEquals(r, 0x89ABCDEF, "success compareAndExchangeVolatile int");
 364             int x = (int) vh.get(recv);
 365             assertEquals(x, 0x01234567, "success compareAndExchangeVolatile int value");
 366         }
 367 
 368         {
 369             int r = (int) vh.compareAndExchangeVolatile(recv, 0x89ABCDEF, 0xCAFEBABE);
 370             assertEquals(r, 0x01234567, "failing compareAndExchangeVolatile int");
 371             int x = (int) vh.get(recv);
 372             assertEquals(x, 0x01234567, "failing compareAndExchangeVolatile int value");
 373         }
 374 
 375         {
 376             int r = (int) vh.compareAndExchangeAcquire(recv, 0x01234567, 0x89ABCDEF);
 377             assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int");
 378             int x = (int) vh.get(recv);
 379             assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value");
 380         }
 381 
 382         {
 383             int r = (int) vh.compareAndExchangeAcquire(recv, 0x01234567, 0xCAFEBABE);
 384             assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int");
 385             int x = (int) vh.get(recv);
 386             assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value");
 387         }
 388 
 389         {
 390             int r = (int) vh.compareAndExchangeRelease(recv, 0x89ABCDEF, 0x01234567);
 391             assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int");
 392             int x = (int) vh.get(recv);
 393             assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value");
 394         }
 395 
 396         {
 397             int r = (int) vh.compareAndExchangeRelease(recv, 0x89ABCDEF, 0xCAFEBABE);
 398             assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int");
 399             int x = (int) vh.get(recv);
 400             assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value");
 401         }
 402 
 403         {
 404             boolean success = false;
 405             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 406                 success = vh.weakCompareAndSet(recv, 0x01234567, 0x89ABCDEF);
 407             }
 408             assertEquals(success, true, "weakCompareAndSet int");
 409             int x = (int) vh.get(recv);
 410             assertEquals(x, 0x89ABCDEF, "weakCompareAndSet int value");
 411         }
 412 
 413         {
 414             boolean success = false;
 415             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 416                 success = vh.weakCompareAndSetAcquire(recv, 0x89ABCDEF, 0x01234567);
 417             }
 418             assertEquals(success, true, "weakCompareAndSetAcquire int");
 419             int x = (int) vh.get(recv);
 420             assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int");
 421         }
 422 
 423         {
 424             boolean success = false;
 425             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 426                 success = vh.weakCompareAndSetRelease(recv, 0x01234567, 0x89ABCDEF);
 427             }
 428             assertEquals(success, true, "weakCompareAndSetRelease int");
 429             int x = (int) vh.get(recv);
 430             assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int");
 431         }
 432 
 433         // Compare set and get
 434         {
 435             int o = (int) vh.getAndSet(recv, 0x01234567);
 436             assertEquals(o, 0x89ABCDEF, "getAndSet int");
 437             int x = (int) vh.get(recv);
 438             assertEquals(x, 0x01234567, "getAndSet int value");
 439         }
 440 
 441         vh.set(recv, 0x01234567);
 442 
 443         // get and add, add and get
 444         {
 445             int o = (int) vh.getAndAdd(recv, 0xCAFEBABE);
 446             assertEquals(o, 0x01234567, "getAndAdd int");
 447             int c = (int) vh.addAndGet(recv, 0xCAFEBABE);
 448             assertEquals(c, (int)(0x01234567 + 0xCAFEBABE + 0xCAFEBABE), "getAndAdd int value");
 449         }
 450     }
 451 
 452     static void testInstanceFieldUnsupported(VarHandleTestAccessInt recv, VarHandle vh) {
 453 
 454     }
 455 
 456 
 457     static void testStaticField(VarHandle vh) {
 458         // Plain
 459         {
 460             vh.set(0x01234567);
 461             int x = (int) vh.get();
 462             assertEquals(x, 0x01234567, "set int value");
 463         }
 464 
 465 
 466         // Volatile
 467         {
 468             vh.setVolatile(0x89ABCDEF);
 469             int x = (int) vh.getVolatile();
 470             assertEquals(x, 0x89ABCDEF, "setVolatile int value");
 471         }
 472 
 473         // Lazy
 474         {
 475             vh.setRelease(0x01234567);
 476             int x = (int) vh.getAcquire();
 477             assertEquals(x, 0x01234567, "setRelease int value");
 478         }
 479 
 480         // Opaque
 481         {
 482             vh.setOpaque(0x89ABCDEF);
 483             int x = (int) vh.getOpaque();
 484             assertEquals(x, 0x89ABCDEF, "setOpaque int value");
 485         }
 486 
 487         vh.set(0x01234567);
 488 
 489         // Compare
 490         {
 491             boolean r = vh.compareAndSet(0x01234567, 0x89ABCDEF);
 492             assertEquals(r, true, "success compareAndSet int");
 493             int x = (int) vh.get();
 494             assertEquals(x, 0x89ABCDEF, "success compareAndSet int value");
 495         }
 496 
 497         {
 498             boolean r = vh.compareAndSet(0x01234567, 0xCAFEBABE);
 499             assertEquals(r, false, "failing compareAndSet int");
 500             int x = (int) vh.get();
 501             assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value");
 502         }
 503 
 504         {
 505             int r = (int) vh.compareAndExchangeVolatile(0x89ABCDEF, 0x01234567);
 506             assertEquals(r, 0x89ABCDEF, "success compareAndExchangeVolatile int");
 507             int x = (int) vh.get();
 508             assertEquals(x, 0x01234567, "success compareAndExchangeVolatile int value");
 509         }
 510 
 511         {
 512             int r = (int) vh.compareAndExchangeVolatile(0x89ABCDEF, 0xCAFEBABE);
 513             assertEquals(r, 0x01234567, "failing compareAndExchangeVolatile int");
 514             int x = (int) vh.get();
 515             assertEquals(x, 0x01234567, "failing compareAndExchangeVolatile int value");
 516         }
 517 
 518         {
 519             int r = (int) vh.compareAndExchangeAcquire(0x01234567, 0x89ABCDEF);
 520             assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int");
 521             int x = (int) vh.get();
 522             assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value");
 523         }
 524 
 525         {
 526             int r = (int) vh.compareAndExchangeAcquire(0x01234567, 0xCAFEBABE);
 527             assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int");
 528             int x = (int) vh.get();
 529             assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value");
 530         }
 531 
 532         {
 533             int r = (int) vh.compareAndExchangeRelease(0x89ABCDEF, 0x01234567);
 534             assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int");
 535             int x = (int) vh.get();
 536             assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value");
 537         }
 538 
 539         {
 540             int r = (int) vh.compareAndExchangeRelease(0x89ABCDEF, 0xCAFEBABE);
 541             assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int");
 542             int x = (int) vh.get();
 543             assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value");
 544         }
 545 
 546         {
 547             boolean success = false;
 548             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 549                 success = vh.weakCompareAndSet(0x01234567, 0x89ABCDEF);
 550             }
 551             assertEquals(success, true, "weakCompareAndSet int");
 552             int x = (int) vh.get();
 553             assertEquals(x, 0x89ABCDEF, "weakCompareAndSet int value");
 554         }
 555 
 556         {
 557             boolean success = false;
 558             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 559                 success = vh.weakCompareAndSetAcquire(0x89ABCDEF, 0x01234567);
 560             }
 561             assertEquals(success, true, "weakCompareAndSetAcquire int");
 562             int x = (int) vh.get();
 563             assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int");
 564         }
 565 
 566         {
 567             boolean success = false;
 568             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 569                 success = vh.weakCompareAndSetRelease(0x01234567, 0x89ABCDEF);
 570             }
 571             assertEquals(success, true, "weakCompareAndSetRelease int");
 572             int x = (int) vh.get();
 573             assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int");
 574         }
 575 
 576         // Compare set and get
 577         {
 578             int o = (int) vh.getAndSet( 0x01234567);
 579             assertEquals(o, 0x89ABCDEF, "getAndSet int");
 580             int x = (int) vh.get();
 581             assertEquals(x, 0x01234567, "getAndSet int value");
 582         }
 583 
 584         vh.set(0x01234567);
 585 
 586         // get and add, add and get
 587         {
 588             int o = (int) vh.getAndAdd( 0xCAFEBABE);
 589             assertEquals(o, 0x01234567, "getAndAdd int");
 590             int c = (int) vh.addAndGet(0xCAFEBABE);
 591             assertEquals(c, (int)(0x01234567 + 0xCAFEBABE + 0xCAFEBABE), "getAndAdd int value");
 592         }
 593     }
 594 
 595     static void testStaticFieldUnsupported(VarHandle vh) {
 596 
 597     }
 598 
 599 
 600     static void testArray(VarHandle vh) {
 601         int[] array = new int[10];
 602 
 603         for (int i = 0; i < array.length; i++) {
 604             // Plain
 605             {
 606                 vh.set(array, i, 0x01234567);
 607                 int x = (int) vh.get(array, i);
 608                 assertEquals(x, 0x01234567, "get int value");
 609             }
 610 
 611 
 612             // Volatile
 613             {
 614                 vh.setVolatile(array, i, 0x89ABCDEF);
 615                 int x = (int) vh.getVolatile(array, i);
 616                 assertEquals(x, 0x89ABCDEF, "setVolatile int value");
 617             }
 618 
 619             // Lazy
 620             {
 621                 vh.setRelease(array, i, 0x01234567);
 622                 int x = (int) vh.getAcquire(array, i);
 623                 assertEquals(x, 0x01234567, "setRelease int value");
 624             }
 625 
 626             // Opaque
 627             {
 628                 vh.setOpaque(array, i, 0x89ABCDEF);
 629                 int x = (int) vh.getOpaque(array, i);
 630                 assertEquals(x, 0x89ABCDEF, "setOpaque int value");
 631             }
 632 
 633             vh.set(array, i, 0x01234567);
 634 
 635             // Compare
 636             {
 637                 boolean r = vh.compareAndSet(array, i, 0x01234567, 0x89ABCDEF);
 638                 assertEquals(r, true, "success compareAndSet int");
 639                 int x = (int) vh.get(array, i);
 640                 assertEquals(x, 0x89ABCDEF, "success compareAndSet int value");
 641             }
 642 
 643             {
 644                 boolean r = vh.compareAndSet(array, i, 0x01234567, 0xCAFEBABE);
 645                 assertEquals(r, false, "failing compareAndSet int");
 646                 int x = (int) vh.get(array, i);
 647                 assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value");
 648             }
 649 
 650             {
 651                 int r = (int) vh.compareAndExchangeVolatile(array, i, 0x89ABCDEF, 0x01234567);
 652                 assertEquals(r, 0x89ABCDEF, "success compareAndExchangeVolatile int");
 653                 int x = (int) vh.get(array, i);
 654                 assertEquals(x, 0x01234567, "success compareAndExchangeVolatile int value");
 655             }
 656 
 657             {
 658                 int r = (int) vh.compareAndExchangeVolatile(array, i, 0x89ABCDEF, 0xCAFEBABE);
 659                 assertEquals(r, 0x01234567, "failing compareAndExchangeVolatile int");
 660                 int x = (int) vh.get(array, i);
 661                 assertEquals(x, 0x01234567, "failing compareAndExchangeVolatile int value");
 662             }
 663 
 664             {
 665                 int r = (int) vh.compareAndExchangeAcquire(array, i, 0x01234567, 0x89ABCDEF);
 666                 assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int");
 667                 int x = (int) vh.get(array, i);
 668                 assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value");
 669             }
 670 
 671             {
 672                 int r = (int) vh.compareAndExchangeAcquire(array, i, 0x01234567, 0xCAFEBABE);
 673                 assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int");
 674                 int x = (int) vh.get(array, i);
 675                 assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value");
 676             }
 677 
 678             {
 679                 int r = (int) vh.compareAndExchangeRelease(array, i, 0x89ABCDEF, 0x01234567);
 680                 assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int");
 681                 int x = (int) vh.get(array, i);
 682                 assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value");
 683             }
 684 
 685             {
 686                 int r = (int) vh.compareAndExchangeRelease(array, i, 0x89ABCDEF, 0xCAFEBABE);
 687                 assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int");
 688                 int x = (int) vh.get(array, i);
 689                 assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value");
 690             }
 691 
 692             {
 693                 boolean success = false;
 694                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 695                     success = vh.weakCompareAndSet(array, i, 0x01234567, 0x89ABCDEF);
 696                 }
 697                 assertEquals(success, true, "weakCompareAndSet int");
 698                 int x = (int) vh.get(array, i);
 699                 assertEquals(x, 0x89ABCDEF, "weakCompareAndSet int value");
 700             }
 701 
 702             {
 703                 boolean success = false;
 704                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 705                     success = vh.weakCompareAndSetAcquire(array, i, 0x89ABCDEF, 0x01234567);
 706                 }
 707                 assertEquals(success, true, "weakCompareAndSetAcquire int");
 708                 int x = (int) vh.get(array, i);
 709                 assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int");
 710             }
 711 
 712             {
 713                 boolean success = false;
 714                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 715                     success = vh.weakCompareAndSetRelease(array, i, 0x01234567, 0x89ABCDEF);
 716                 }
 717                 assertEquals(success, true, "weakCompareAndSetRelease int");
 718                 int x = (int) vh.get(array, i);
 719                 assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int");
 720             }
 721 
 722             // Compare set and get
 723             {
 724                 int o = (int) vh.getAndSet(array, i, 0x01234567);
 725                 assertEquals(o, 0x89ABCDEF, "getAndSet int");
 726                 int x = (int) vh.get(array, i);
 727                 assertEquals(x, 0x01234567, "getAndSet int value");
 728             }
 729 
 730             vh.set(array, i, 0x01234567);
 731 
 732             // get and add, add and get
 733             {
 734                 int o = (int) vh.getAndAdd(array, i, 0xCAFEBABE);
 735                 assertEquals(o, 0x01234567, "getAndAdd int");
 736                 int c = (int) vh.addAndGet(array, i, 0xCAFEBABE);
 737                 assertEquals(c, (int)(0x01234567 + 0xCAFEBABE + 0xCAFEBABE), "getAndAdd int value");
 738             }
 739         }
 740     }
 741 
 742     static void testArrayUnsupported(VarHandle vh) {
 743         int[] array = new int[10];
 744 
 745         int i = 0;
 746 
 747     }
 748 
 749     static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
 750         int[] array = new int[10];
 751 
 752         for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
 753             final int ci = i;
 754 
 755             checkIOOBE(() -> {
 756                 int x = (int) vh.get(array, ci);
 757             });
 758 
 759             checkIOOBE(() -> {
 760                 vh.set(array, ci, 0x01234567);
 761             });
 762 
 763             checkIOOBE(() -> {
 764                 int x = (int) vh.getVolatile(array, ci);
 765             });
 766 
 767             checkIOOBE(() -> {
 768                 vh.setVolatile(array, ci, 0x01234567);
 769             });
 770 
 771             checkIOOBE(() -> {
 772                 int x = (int) vh.getAcquire(array, ci);
 773             });
 774 
 775             checkIOOBE(() -> {
 776                 vh.setRelease(array, ci, 0x01234567);
 777             });
 778 
 779             checkIOOBE(() -> {
 780                 int x = (int) vh.getOpaque(array, ci);
 781             });
 782 
 783             checkIOOBE(() -> {
 784                 vh.setOpaque(array, ci, 0x01234567);
 785             });
 786 
 787             checkIOOBE(() -> {
 788                 boolean r = vh.compareAndSet(array, ci, 0x01234567, 0x89ABCDEF);
 789             });
 790 
 791             checkIOOBE(() -> {
 792                 int r = (int) vh.compareAndExchangeVolatile(array, ci, 0x89ABCDEF, 0x01234567);
 793             });
 794 
 795             checkIOOBE(() -> {
 796                 int r = (int) vh.compareAndExchangeAcquire(array, ci, 0x89ABCDEF, 0x01234567);
 797             });
 798 
 799             checkIOOBE(() -> {
 800                 int r = (int) vh.compareAndExchangeRelease(array, ci, 0x89ABCDEF, 0x01234567);
 801             });
 802 
 803             checkIOOBE(() -> {
 804                 boolean r = vh.weakCompareAndSet(array, ci, 0x01234567, 0x89ABCDEF);
 805             });
 806 
 807             checkIOOBE(() -> {
 808                 boolean r = vh.weakCompareAndSetAcquire(array, ci, 0x01234567, 0x89ABCDEF);
 809             });
 810 
 811             checkIOOBE(() -> {
 812                 boolean r = vh.weakCompareAndSetRelease(array, ci, 0x01234567, 0x89ABCDEF);
 813             });
 814 
 815             checkIOOBE(() -> {
 816                 int o = (int) vh.getAndSet(array, ci, 0x01234567);
 817             });
 818 
 819             checkIOOBE(() -> {
 820                 int o = (int) vh.getAndAdd(array, ci, 0xCAFEBABE);
 821             });
 822 
 823             checkIOOBE(() -> {
 824                 int o = (int) vh.addAndGet(array, ci, 0xCAFEBABE);
 825             });
 826         }
 827     }
 828 }
 829 
< prev index next >