< prev index next >

test/java/lang/invoke/VarHandles/VarHandleTestAccessDouble.java

Print this page




  87 
  88         return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
  89     }
  90 
  91     @Test(dataProvider = "varHandlesProvider")
  92     public void testIsAccessModeSupported(VarHandle vh) {
  93         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
  94         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
  95         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
  96         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
  97         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
  98         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
  99         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
 100         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
 101 
 102         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
 103         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE));
 104         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
 105         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
 106         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
 107         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE));
 108         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
 109         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
 110         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
 111 
 112         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
 113         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET));
 114     }
 115 
 116 
 117     @DataProvider
 118     public Object[][] typesProvider() throws Exception {
 119         List<Object[]> types = new ArrayList<>();
 120         types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessDouble.class)});
 121         types.add(new Object[] {vhStaticField, Arrays.asList()});
 122         types.add(new Object[] {vhArray, Arrays.asList(double[].class, int.class)});
 123 
 124         return types.stream().toArray(Object[][]::new);
 125     }
 126 
 127     @Test(dataProvider = "typesProvider")


 264             boolean r = vh.compareAndSet(recv, 1.0d, 2.0d);
 265         });
 266 
 267         checkUOE(() -> {
 268             double r = (double) vh.compareAndExchangeVolatile(recv, 1.0d, 2.0d);
 269         });
 270 
 271         checkUOE(() -> {
 272             double r = (double) vh.compareAndExchangeAcquire(recv, 1.0d, 2.0d);
 273         });
 274 
 275         checkUOE(() -> {
 276             double r = (double) vh.compareAndExchangeRelease(recv, 1.0d, 2.0d);
 277         });
 278 
 279         checkUOE(() -> {
 280             boolean r = vh.weakCompareAndSet(recv, 1.0d, 2.0d);
 281         });
 282 
 283         checkUOE(() -> {
 284             boolean r = vh.weakCompareAndSetVolatile(recv, 1.0d, 2.0d);
 285         });
 286 
 287         checkUOE(() -> {
 288             boolean r = vh.weakCompareAndSetAcquire(recv, 1.0d, 2.0d);
 289         });
 290 
 291         checkUOE(() -> {
 292             boolean r = vh.weakCompareAndSetRelease(recv, 1.0d, 2.0d);
 293         });
 294 
 295         checkUOE(() -> {
 296             double o = (double) vh.getAndAdd(recv, 1.0d);
 297         });
 298 
 299         checkUOE(() -> {
 300             double o = (double) vh.addAndGet(recv, 1.0d);
 301         });
 302     }
 303 
 304 
 305     static void testStaticFinalField(VarHandle vh) {
 306         // Plain
 307         {


 350             boolean r = vh.compareAndSet(1.0d, 2.0d);
 351         });
 352 
 353         checkUOE(() -> {
 354             double r = (double) vh.compareAndExchangeVolatile(1.0d, 2.0d);
 355         });
 356 
 357         checkUOE(() -> {
 358             double r = (double) vh.compareAndExchangeAcquire(1.0d, 2.0d);
 359         });
 360 
 361         checkUOE(() -> {
 362             double r = (double) vh.compareAndExchangeRelease(1.0d, 2.0d);
 363         });
 364 
 365         checkUOE(() -> {
 366             boolean r = vh.weakCompareAndSet(1.0d, 2.0d);
 367         });
 368 
 369         checkUOE(() -> {
 370             boolean r = vh.weakCompareAndSetVolatile(1.0d, 2.0d);
 371         });
 372 
 373         checkUOE(() -> {
 374             boolean r = vh.weakCompareAndSetAcquire(1.0d, 2.0d);
 375         });
 376 
 377         checkUOE(() -> {
 378             boolean r = vh.weakCompareAndSetRelease(1.0d, 2.0d);
 379         });
 380 
 381         checkUOE(() -> {
 382             double o = (double) vh.getAndAdd(1.0d);
 383         });
 384 
 385         checkUOE(() -> {
 386             double o = (double) vh.addAndGet(1.0d);
 387         });
 388     }
 389 
 390 
 391     static void testInstanceField(VarHandleTestAccessDouble recv, VarHandle vh) {
 392         // Plain
 393         {


 426             boolean r = vh.compareAndSet(recv, 1.0d, 2.0d);
 427         });
 428 
 429         checkUOE(() -> {
 430             double r = (double) vh.compareAndExchangeVolatile(recv, 1.0d, 2.0d);
 431         });
 432 
 433         checkUOE(() -> {
 434             double r = (double) vh.compareAndExchangeAcquire(recv, 1.0d, 2.0d);
 435         });
 436 
 437         checkUOE(() -> {
 438             double r = (double) vh.compareAndExchangeRelease(recv, 1.0d, 2.0d);
 439         });
 440 
 441         checkUOE(() -> {
 442             boolean r = vh.weakCompareAndSet(recv, 1.0d, 2.0d);
 443         });
 444 
 445         checkUOE(() -> {
 446             boolean r = vh.weakCompareAndSetVolatile(recv, 1.0d, 2.0d);
 447         });
 448 
 449         checkUOE(() -> {
 450             boolean r = vh.weakCompareAndSetAcquire(recv, 1.0d, 2.0d);
 451         });
 452 
 453         checkUOE(() -> {
 454             boolean r = vh.weakCompareAndSetRelease(recv, 1.0d, 2.0d);
 455         });
 456 
 457         checkUOE(() -> {
 458             double o = (double) vh.getAndAdd(recv, 1.0d);
 459         });
 460 
 461         checkUOE(() -> {
 462             double o = (double) vh.addAndGet(recv, 1.0d);
 463         });
 464     }
 465 
 466 
 467     static void testStaticField(VarHandle vh) {
 468         // Plain
 469         {


 502             boolean r = vh.compareAndSet(1.0d, 2.0d);
 503         });
 504 
 505         checkUOE(() -> {
 506             double r = (double) vh.compareAndExchangeVolatile(1.0d, 2.0d);
 507         });
 508 
 509         checkUOE(() -> {
 510             double r = (double) vh.compareAndExchangeAcquire(1.0d, 2.0d);
 511         });
 512 
 513         checkUOE(() -> {
 514             double r = (double) vh.compareAndExchangeRelease(1.0d, 2.0d);
 515         });
 516 
 517         checkUOE(() -> {
 518             boolean r = vh.weakCompareAndSet(1.0d, 2.0d);
 519         });
 520 
 521         checkUOE(() -> {
 522             boolean r = vh.weakCompareAndSetVolatile(1.0d, 2.0d);
 523         });
 524 
 525         checkUOE(() -> {
 526             boolean r = vh.weakCompareAndSetAcquire(1.0d, 2.0d);
 527         });
 528 
 529         checkUOE(() -> {
 530             boolean r = vh.weakCompareAndSetRelease(1.0d, 2.0d);
 531         });
 532 
 533         checkUOE(() -> {
 534             double o = (double) vh.getAndAdd(1.0d);
 535         });
 536 
 537         checkUOE(() -> {
 538             double o = (double) vh.addAndGet(1.0d);
 539         });
 540     }
 541 
 542 
 543     static void testArray(VarHandle vh) {
 544         double[] array = new double[10];
 545 


 582 
 583         int i = 0;
 584         checkUOE(() -> {
 585             boolean r = vh.compareAndSet(array, i, 1.0d, 2.0d);
 586         });
 587 
 588         checkUOE(() -> {
 589             double r = (double) vh.compareAndExchangeVolatile(array, i, 1.0d, 2.0d);
 590         });
 591 
 592         checkUOE(() -> {
 593             double r = (double) vh.compareAndExchangeAcquire(array, i, 1.0d, 2.0d);
 594         });
 595 
 596         checkUOE(() -> {
 597             double r = (double) vh.compareAndExchangeRelease(array, i, 1.0d, 2.0d);
 598         });
 599 
 600         checkUOE(() -> {
 601             boolean r = vh.weakCompareAndSet(array, i, 1.0d, 2.0d);
 602         });
 603 
 604         checkUOE(() -> {
 605             boolean r = vh.weakCompareAndSetVolatile(array, i, 1.0d, 2.0d);
 606         });
 607 
 608         checkUOE(() -> {
 609             boolean r = vh.weakCompareAndSetAcquire(array, i, 1.0d, 2.0d);
 610         });
 611 
 612         checkUOE(() -> {
 613             boolean r = vh.weakCompareAndSetRelease(array, i, 1.0d, 2.0d);
 614         });
 615 
 616         checkUOE(() -> {
 617             double o = (double) vh.getAndAdd(array, i, 1.0d);
 618         });
 619 
 620         checkUOE(() -> {
 621             double o = (double) vh.addAndGet(array, i, 1.0d);
 622         });
 623     }
 624 
 625     static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {




  87 
  88         return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
  89     }
  90 
  91     @Test(dataProvider = "varHandlesProvider")
  92     public void testIsAccessModeSupported(VarHandle vh) {
  93         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
  94         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
  95         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
  96         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
  97         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
  98         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
  99         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
 100         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
 101 
 102         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
 103         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE));
 104         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
 105         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
 106         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));

 107         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
 108         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
 109         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
 110 
 111         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
 112         assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET));
 113     }
 114 
 115 
 116     @DataProvider
 117     public Object[][] typesProvider() throws Exception {
 118         List<Object[]> types = new ArrayList<>();
 119         types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessDouble.class)});
 120         types.add(new Object[] {vhStaticField, Arrays.asList()});
 121         types.add(new Object[] {vhArray, Arrays.asList(double[].class, int.class)});
 122 
 123         return types.stream().toArray(Object[][]::new);
 124     }
 125 
 126     @Test(dataProvider = "typesProvider")


 263             boolean r = vh.compareAndSet(recv, 1.0d, 2.0d);
 264         });
 265 
 266         checkUOE(() -> {
 267             double r = (double) vh.compareAndExchangeVolatile(recv, 1.0d, 2.0d);
 268         });
 269 
 270         checkUOE(() -> {
 271             double r = (double) vh.compareAndExchangeAcquire(recv, 1.0d, 2.0d);
 272         });
 273 
 274         checkUOE(() -> {
 275             double r = (double) vh.compareAndExchangeRelease(recv, 1.0d, 2.0d);
 276         });
 277 
 278         checkUOE(() -> {
 279             boolean r = vh.weakCompareAndSet(recv, 1.0d, 2.0d);
 280         });
 281 
 282         checkUOE(() -> {




 283             boolean r = vh.weakCompareAndSetAcquire(recv, 1.0d, 2.0d);
 284         });
 285 
 286         checkUOE(() -> {
 287             boolean r = vh.weakCompareAndSetRelease(recv, 1.0d, 2.0d);
 288         });
 289 
 290         checkUOE(() -> {
 291             double o = (double) vh.getAndAdd(recv, 1.0d);
 292         });
 293 
 294         checkUOE(() -> {
 295             double o = (double) vh.addAndGet(recv, 1.0d);
 296         });
 297     }
 298 
 299 
 300     static void testStaticFinalField(VarHandle vh) {
 301         // Plain
 302         {


 345             boolean r = vh.compareAndSet(1.0d, 2.0d);
 346         });
 347 
 348         checkUOE(() -> {
 349             double r = (double) vh.compareAndExchangeVolatile(1.0d, 2.0d);
 350         });
 351 
 352         checkUOE(() -> {
 353             double r = (double) vh.compareAndExchangeAcquire(1.0d, 2.0d);
 354         });
 355 
 356         checkUOE(() -> {
 357             double r = (double) vh.compareAndExchangeRelease(1.0d, 2.0d);
 358         });
 359 
 360         checkUOE(() -> {
 361             boolean r = vh.weakCompareAndSet(1.0d, 2.0d);
 362         });
 363 
 364         checkUOE(() -> {




 365             boolean r = vh.weakCompareAndSetAcquire(1.0d, 2.0d);
 366         });
 367 
 368         checkUOE(() -> {
 369             boolean r = vh.weakCompareAndSetRelease(1.0d, 2.0d);
 370         });
 371 
 372         checkUOE(() -> {
 373             double o = (double) vh.getAndAdd(1.0d);
 374         });
 375 
 376         checkUOE(() -> {
 377             double o = (double) vh.addAndGet(1.0d);
 378         });
 379     }
 380 
 381 
 382     static void testInstanceField(VarHandleTestAccessDouble recv, VarHandle vh) {
 383         // Plain
 384         {


 417             boolean r = vh.compareAndSet(recv, 1.0d, 2.0d);
 418         });
 419 
 420         checkUOE(() -> {
 421             double r = (double) vh.compareAndExchangeVolatile(recv, 1.0d, 2.0d);
 422         });
 423 
 424         checkUOE(() -> {
 425             double r = (double) vh.compareAndExchangeAcquire(recv, 1.0d, 2.0d);
 426         });
 427 
 428         checkUOE(() -> {
 429             double r = (double) vh.compareAndExchangeRelease(recv, 1.0d, 2.0d);
 430         });
 431 
 432         checkUOE(() -> {
 433             boolean r = vh.weakCompareAndSet(recv, 1.0d, 2.0d);
 434         });
 435 
 436         checkUOE(() -> {




 437             boolean r = vh.weakCompareAndSetAcquire(recv, 1.0d, 2.0d);
 438         });
 439 
 440         checkUOE(() -> {
 441             boolean r = vh.weakCompareAndSetRelease(recv, 1.0d, 2.0d);
 442         });
 443 
 444         checkUOE(() -> {
 445             double o = (double) vh.getAndAdd(recv, 1.0d);
 446         });
 447 
 448         checkUOE(() -> {
 449             double o = (double) vh.addAndGet(recv, 1.0d);
 450         });
 451     }
 452 
 453 
 454     static void testStaticField(VarHandle vh) {
 455         // Plain
 456         {


 489             boolean r = vh.compareAndSet(1.0d, 2.0d);
 490         });
 491 
 492         checkUOE(() -> {
 493             double r = (double) vh.compareAndExchangeVolatile(1.0d, 2.0d);
 494         });
 495 
 496         checkUOE(() -> {
 497             double r = (double) vh.compareAndExchangeAcquire(1.0d, 2.0d);
 498         });
 499 
 500         checkUOE(() -> {
 501             double r = (double) vh.compareAndExchangeRelease(1.0d, 2.0d);
 502         });
 503 
 504         checkUOE(() -> {
 505             boolean r = vh.weakCompareAndSet(1.0d, 2.0d);
 506         });
 507 
 508         checkUOE(() -> {




 509             boolean r = vh.weakCompareAndSetAcquire(1.0d, 2.0d);
 510         });
 511 
 512         checkUOE(() -> {
 513             boolean r = vh.weakCompareAndSetRelease(1.0d, 2.0d);
 514         });
 515 
 516         checkUOE(() -> {
 517             double o = (double) vh.getAndAdd(1.0d);
 518         });
 519 
 520         checkUOE(() -> {
 521             double o = (double) vh.addAndGet(1.0d);
 522         });
 523     }
 524 
 525 
 526     static void testArray(VarHandle vh) {
 527         double[] array = new double[10];
 528 


 565 
 566         int i = 0;
 567         checkUOE(() -> {
 568             boolean r = vh.compareAndSet(array, i, 1.0d, 2.0d);
 569         });
 570 
 571         checkUOE(() -> {
 572             double r = (double) vh.compareAndExchangeVolatile(array, i, 1.0d, 2.0d);
 573         });
 574 
 575         checkUOE(() -> {
 576             double r = (double) vh.compareAndExchangeAcquire(array, i, 1.0d, 2.0d);
 577         });
 578 
 579         checkUOE(() -> {
 580             double r = (double) vh.compareAndExchangeRelease(array, i, 1.0d, 2.0d);
 581         });
 582 
 583         checkUOE(() -> {
 584             boolean r = vh.weakCompareAndSet(array, i, 1.0d, 2.0d);




 585         });
 586 
 587         checkUOE(() -> {
 588             boolean r = vh.weakCompareAndSetAcquire(array, i, 1.0d, 2.0d);
 589         });
 590 
 591         checkUOE(() -> {
 592             boolean r = vh.weakCompareAndSetRelease(array, i, 1.0d, 2.0d);
 593         });
 594 
 595         checkUOE(() -> {
 596             double o = (double) vh.getAndAdd(array, i, 1.0d);
 597         });
 598 
 599         checkUOE(() -> {
 600             double o = (double) vh.addAndGet(array, i, 1.0d);
 601         });
 602     }
 603 
 604     static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {


< prev index next >