< prev index next >

test/java/lang/invoke/VarHandles/X-VarHandleTestAccess.java.template

Print this page




 523             assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
 524         }
 525 
 526         // Compare set and get
 527         {
 528             $type$ o = ($type$) vh.getAndSet(recv, $value1$);
 529             assertEquals(o, $value2$, "getAndSet $type$");
 530             $type$ x = ($type$) vh.get(recv);
 531             assertEquals(x, $value1$, "getAndSet $type$ value");
 532         }
 533 #end[CAS]
 534 
 535 #if[AtomicAdd]
 536         vh.set(recv, $value1$);
 537 
 538         // get and add, add and get
 539         {
 540             $type$ o = ($type$) vh.getAndAdd(recv, $value3$);
 541             assertEquals(o, $value1$, "getAndAdd $type$");
 542             $type$ c = ($type$) vh.addAndGet(recv, $value3$);
 543             assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
 544         }
 545 #end[AtomicAdd]
 546     }
 547 
 548     static void testInstanceFieldUnsupported(VarHandleTestAccess$Type$ recv, VarHandle vh) {
 549 #if[!CAS]
 550         checkUOE(() -> {
 551             boolean r = vh.compareAndSet(recv, $value1$, $value2$);
 552         });
 553 
 554         checkUOE(() -> {
 555             $type$ r = ($type$) vh.compareAndExchangeVolatile(recv, $value1$, $value2$);
 556         });
 557 
 558         checkUOE(() -> {
 559             $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value2$);
 560         });
 561 
 562         checkUOE(() -> {
 563             $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value1$, $value2$);


 708             assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
 709         }
 710 
 711         // Compare set and get
 712         {
 713             $type$ o = ($type$) vh.getAndSet( $value1$);
 714             assertEquals(o, $value2$, "getAndSet $type$");
 715             $type$ x = ($type$) vh.get();
 716             assertEquals(x, $value1$, "getAndSet $type$ value");
 717         }
 718 #end[CAS]
 719 
 720 #if[AtomicAdd]
 721         vh.set($value1$);
 722 
 723         // get and add, add and get
 724         {
 725             $type$ o = ($type$) vh.getAndAdd( $value3$);
 726             assertEquals(o, $value1$, "getAndAdd $type$");
 727             $type$ c = ($type$) vh.addAndGet($value3$);
 728             assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
 729         }
 730 #end[AtomicAdd]
 731     }
 732 
 733     static void testStaticFieldUnsupported(VarHandle vh) {
 734 #if[!CAS]
 735         checkUOE(() -> {
 736             boolean r = vh.compareAndSet($value1$, $value2$);
 737         });
 738 
 739         checkUOE(() -> {
 740             $type$ r = ($type$) vh.compareAndExchangeVolatile($value1$, $value2$);
 741         });
 742 
 743         checkUOE(() -> {
 744             $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value2$);
 745         });
 746 
 747         checkUOE(() -> {
 748             $type$ r = ($type$) vh.compareAndExchangeRelease($value1$, $value2$);


 896                 assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
 897             }
 898 
 899             // Compare set and get
 900             {
 901                 $type$ o = ($type$) vh.getAndSet(array, i, $value1$);
 902                 assertEquals(o, $value2$, "getAndSet $type$");
 903                 $type$ x = ($type$) vh.get(array, i);
 904                 assertEquals(x, $value1$, "getAndSet $type$ value");
 905             }
 906 #end[CAS]
 907 
 908 #if[AtomicAdd]
 909             vh.set(array, i, $value1$);
 910 
 911             // get and add, add and get
 912             {
 913                 $type$ o = ($type$) vh.getAndAdd(array, i, $value3$);
 914                 assertEquals(o, $value1$, "getAndAdd $type$");
 915                 $type$ c = ($type$) vh.addAndGet(array, i, $value3$);
 916                 assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
 917             }
 918 #end[AtomicAdd]
 919         }
 920     }
 921 
 922     static void testArrayUnsupported(VarHandle vh) {
 923         $type$[] array = new $type$[10];
 924 
 925         int i = 0;
 926 #if[!CAS]
 927         checkUOE(() -> {
 928             boolean r = vh.compareAndSet(array, i, $value1$, $value2$);
 929         });
 930 
 931         checkUOE(() -> {
 932             $type$ r = ($type$) vh.compareAndExchangeVolatile(array, i, $value1$, $value2$);
 933         });
 934 
 935         checkUOE(() -> {
 936             $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, $value1$, $value2$);




 523             assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
 524         }
 525 
 526         // Compare set and get
 527         {
 528             $type$ o = ($type$) vh.getAndSet(recv, $value1$);
 529             assertEquals(o, $value2$, "getAndSet $type$");
 530             $type$ x = ($type$) vh.get(recv);
 531             assertEquals(x, $value1$, "getAndSet $type$ value");
 532         }
 533 #end[CAS]
 534 
 535 #if[AtomicAdd]
 536         vh.set(recv, $value1$);
 537 
 538         // get and add, add and get
 539         {
 540             $type$ o = ($type$) vh.getAndAdd(recv, $value3$);
 541             assertEquals(o, $value1$, "getAndAdd $type$");
 542             $type$ c = ($type$) vh.addAndGet(recv, $value3$);
 543             assertEquals(c, ($type$)($value1$ + $value3$ + $value3$), "getAndAdd $type$ value");
 544         }
 545 #end[AtomicAdd]
 546     }
 547 
 548     static void testInstanceFieldUnsupported(VarHandleTestAccess$Type$ recv, VarHandle vh) {
 549 #if[!CAS]
 550         checkUOE(() -> {
 551             boolean r = vh.compareAndSet(recv, $value1$, $value2$);
 552         });
 553 
 554         checkUOE(() -> {
 555             $type$ r = ($type$) vh.compareAndExchangeVolatile(recv, $value1$, $value2$);
 556         });
 557 
 558         checkUOE(() -> {
 559             $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value2$);
 560         });
 561 
 562         checkUOE(() -> {
 563             $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value1$, $value2$);


 708             assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
 709         }
 710 
 711         // Compare set and get
 712         {
 713             $type$ o = ($type$) vh.getAndSet( $value1$);
 714             assertEquals(o, $value2$, "getAndSet $type$");
 715             $type$ x = ($type$) vh.get();
 716             assertEquals(x, $value1$, "getAndSet $type$ value");
 717         }
 718 #end[CAS]
 719 
 720 #if[AtomicAdd]
 721         vh.set($value1$);
 722 
 723         // get and add, add and get
 724         {
 725             $type$ o = ($type$) vh.getAndAdd( $value3$);
 726             assertEquals(o, $value1$, "getAndAdd $type$");
 727             $type$ c = ($type$) vh.addAndGet($value3$);
 728             assertEquals(c, ($type$)($value1$ + $value3$ + $value3$), "getAndAdd $type$ value");
 729         }
 730 #end[AtomicAdd]
 731     }
 732 
 733     static void testStaticFieldUnsupported(VarHandle vh) {
 734 #if[!CAS]
 735         checkUOE(() -> {
 736             boolean r = vh.compareAndSet($value1$, $value2$);
 737         });
 738 
 739         checkUOE(() -> {
 740             $type$ r = ($type$) vh.compareAndExchangeVolatile($value1$, $value2$);
 741         });
 742 
 743         checkUOE(() -> {
 744             $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value2$);
 745         });
 746 
 747         checkUOE(() -> {
 748             $type$ r = ($type$) vh.compareAndExchangeRelease($value1$, $value2$);


 896                 assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
 897             }
 898 
 899             // Compare set and get
 900             {
 901                 $type$ o = ($type$) vh.getAndSet(array, i, $value1$);
 902                 assertEquals(o, $value2$, "getAndSet $type$");
 903                 $type$ x = ($type$) vh.get(array, i);
 904                 assertEquals(x, $value1$, "getAndSet $type$ value");
 905             }
 906 #end[CAS]
 907 
 908 #if[AtomicAdd]
 909             vh.set(array, i, $value1$);
 910 
 911             // get and add, add and get
 912             {
 913                 $type$ o = ($type$) vh.getAndAdd(array, i, $value3$);
 914                 assertEquals(o, $value1$, "getAndAdd $type$");
 915                 $type$ c = ($type$) vh.addAndGet(array, i, $value3$);
 916                 assertEquals(c, ($type$)($value1$ + $value3$ + $value3$), "getAndAdd $type$ value");
 917             }
 918 #end[AtomicAdd]
 919         }
 920     }
 921 
 922     static void testArrayUnsupported(VarHandle vh) {
 923         $type$[] array = new $type$[10];
 924 
 925         int i = 0;
 926 #if[!CAS]
 927         checkUOE(() -> {
 928             boolean r = vh.compareAndSet(array, i, $value1$, $value2$);
 929         });
 930 
 931         checkUOE(() -> {
 932             $type$ r = ($type$) vh.compareAndExchangeVolatile(array, i, $value1$, $value2$);
 933         });
 934 
 935         checkUOE(() -> {
 936             $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, $value1$, $value2$);


< prev index next >