< prev index next >

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

Print this page




 238             assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
 239         }
 240 
 241         // Compare set and get
 242         {
 243             $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, $value1$);
 244             assertEquals(o, $value2$, "getAndSet $type$");
 245             $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
 246             assertEquals(x, $value1$, "getAndSet $type$ value");
 247         }
 248 #end[CAS]
 249 
 250 #if[AtomicAdd]
 251         hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
 252 
 253         // get and add, add and get
 254         {
 255             $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, $value3$);
 256             assertEquals(o, $value1$, "getAndAdd $type$");
 257             $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, $value3$);
 258             assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
 259         }
 260 #end[AtomicAdd]
 261     }
 262 
 263     static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccess$Type$ recv, Handles hs) throws Throwable {
 264 #if[!CAS]
 265         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
 266             checkUOE(am, () -> {
 267                 boolean r = (boolean) hs.get(am).invokeExact(recv, $value1$, $value2$);
 268             });
 269         }
 270 
 271         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
 272             checkUOE(am, () -> {
 273                 $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$, $value2$);
 274             });
 275         }
 276 
 277         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
 278             checkUOE(am, () -> {


 411             assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
 412         }
 413 
 414         // Compare set and get
 415         {
 416             $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact( $value1$);
 417             assertEquals(o, $value2$, "getAndSet $type$");
 418             $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
 419             assertEquals(x, $value1$, "getAndSet $type$ value");
 420         }
 421 #end[CAS]
 422 
 423 #if[AtomicAdd]
 424         hs.get(TestAccessMode.SET).invokeExact($value1$);
 425 
 426         // get and add, add and get
 427         {
 428             $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( $value3$);
 429             assertEquals(o, $value1$, "getAndAdd $type$");
 430             $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact($value3$);
 431             assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
 432         }
 433 #end[AtomicAdd]
 434     }
 435 
 436     static void testStaticFieldUnsupported(Handles hs) throws Throwable {
 437 #if[!CAS]
 438         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
 439             checkUOE(am, () -> {
 440                 boolean r = (boolean) hs.get(am).invokeExact($value1$, $value2$);
 441             });
 442         }
 443 
 444         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
 445             checkUOE(am, () -> {
 446                 $type$ r = ($type$) hs.get(am).invokeExact($value1$, $value2$);
 447             });
 448         }
 449 
 450         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
 451             checkUOE(am, () -> {


 587                 assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
 588             }
 589 
 590             // Compare set and get
 591             {
 592                 $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, $value1$);
 593                 assertEquals(o, $value2$, "getAndSet $type$");
 594                 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
 595                 assertEquals(x, $value1$, "getAndSet $type$ value");
 596             }
 597 #end[CAS]
 598 
 599 #if[AtomicAdd]
 600             hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
 601 
 602             // get and add, add and get
 603             {
 604                 $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, $value3$);
 605                 assertEquals(o, $value1$, "getAndAdd $type$");
 606                 $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, $value3$);
 607                 assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
 608             }
 609 #end[AtomicAdd]
 610         }
 611     }
 612 
 613     static void testArrayUnsupported(Handles hs) throws Throwable {
 614         $type$[] array = new $type$[10];
 615 
 616         final int i = 0;
 617 #if[!CAS]
 618         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
 619             checkUOE(am, () -> {
 620                 boolean r = (boolean) hs.get(am).invokeExact(array, i, $value1$, $value2$);
 621             });
 622         }
 623 
 624         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
 625             checkUOE(am, () -> {
 626                 $type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$, $value2$);
 627             });




 238             assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
 239         }
 240 
 241         // Compare set and get
 242         {
 243             $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, $value1$);
 244             assertEquals(o, $value2$, "getAndSet $type$");
 245             $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
 246             assertEquals(x, $value1$, "getAndSet $type$ value");
 247         }
 248 #end[CAS]
 249 
 250 #if[AtomicAdd]
 251         hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
 252 
 253         // get and add, add and get
 254         {
 255             $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, $value3$);
 256             assertEquals(o, $value1$, "getAndAdd $type$");
 257             $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, $value3$);
 258             assertEquals(c, ($type$)($value1$ + $value3$ + $value3$), "getAndAdd $type$ value");
 259         }
 260 #end[AtomicAdd]
 261     }
 262 
 263     static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccess$Type$ recv, Handles hs) throws Throwable {
 264 #if[!CAS]
 265         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
 266             checkUOE(am, () -> {
 267                 boolean r = (boolean) hs.get(am).invokeExact(recv, $value1$, $value2$);
 268             });
 269         }
 270 
 271         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
 272             checkUOE(am, () -> {
 273                 $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$, $value2$);
 274             });
 275         }
 276 
 277         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
 278             checkUOE(am, () -> {


 411             assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
 412         }
 413 
 414         // Compare set and get
 415         {
 416             $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact( $value1$);
 417             assertEquals(o, $value2$, "getAndSet $type$");
 418             $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
 419             assertEquals(x, $value1$, "getAndSet $type$ value");
 420         }
 421 #end[CAS]
 422 
 423 #if[AtomicAdd]
 424         hs.get(TestAccessMode.SET).invokeExact($value1$);
 425 
 426         // get and add, add and get
 427         {
 428             $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( $value3$);
 429             assertEquals(o, $value1$, "getAndAdd $type$");
 430             $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact($value3$);
 431             assertEquals(c, ($type$)($value1$ + $value3$ + $value3$), "getAndAdd $type$ value");
 432         }
 433 #end[AtomicAdd]
 434     }
 435 
 436     static void testStaticFieldUnsupported(Handles hs) throws Throwable {
 437 #if[!CAS]
 438         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
 439             checkUOE(am, () -> {
 440                 boolean r = (boolean) hs.get(am).invokeExact($value1$, $value2$);
 441             });
 442         }
 443 
 444         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
 445             checkUOE(am, () -> {
 446                 $type$ r = ($type$) hs.get(am).invokeExact($value1$, $value2$);
 447             });
 448         }
 449 
 450         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
 451             checkUOE(am, () -> {


 587                 assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
 588             }
 589 
 590             // Compare set and get
 591             {
 592                 $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, $value1$);
 593                 assertEquals(o, $value2$, "getAndSet $type$");
 594                 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
 595                 assertEquals(x, $value1$, "getAndSet $type$ value");
 596             }
 597 #end[CAS]
 598 
 599 #if[AtomicAdd]
 600             hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
 601 
 602             // get and add, add and get
 603             {
 604                 $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, $value3$);
 605                 assertEquals(o, $value1$, "getAndAdd $type$");
 606                 $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, $value3$);
 607                 assertEquals(c, ($type$)($value1$ + $value3$ + $value3$), "getAndAdd $type$ value");
 608             }
 609 #end[AtomicAdd]
 610         }
 611     }
 612 
 613     static void testArrayUnsupported(Handles hs) throws Throwable {
 614         $type$[] array = new $type$[10];
 615 
 616         final int i = 0;
 617 #if[!CAS]
 618         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
 619             checkUOE(am, () -> {
 620                 boolean r = (boolean) hs.get(am).invokeExact(array, i, $value1$, $value2$);
 621             });
 622         }
 623 
 624         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
 625             checkUOE(am, () -> {
 626                 $type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$, $value2$);
 627             });


< prev index next >