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(VarHandleTestAccessFloat.class)});
121 types.add(new Object[] {vhStaticField, Arrays.asList()});
122 types.add(new Object[] {vhArray, Arrays.asList(float[].class, int.class)});
123
124 return types.stream().toArray(Object[][]::new);
125 }
126
127 @Test(dataProvider = "typesProvider")
264 boolean r = vh.compareAndSet(recv, 1.0f, 2.0f);
265 });
266
267 checkUOE(() -> {
268 float r = (float) vh.compareAndExchangeVolatile(recv, 1.0f, 2.0f);
269 });
270
271 checkUOE(() -> {
272 float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 2.0f);
273 });
274
275 checkUOE(() -> {
276 float r = (float) vh.compareAndExchangeRelease(recv, 1.0f, 2.0f);
277 });
278
279 checkUOE(() -> {
280 boolean r = vh.weakCompareAndSet(recv, 1.0f, 2.0f);
281 });
282
283 checkUOE(() -> {
284 boolean r = vh.weakCompareAndSetVolatile(recv, 1.0f, 2.0f);
285 });
286
287 checkUOE(() -> {
288 boolean r = vh.weakCompareAndSetAcquire(recv, 1.0f, 2.0f);
289 });
290
291 checkUOE(() -> {
292 boolean r = vh.weakCompareAndSetRelease(recv, 1.0f, 2.0f);
293 });
294
295 checkUOE(() -> {
296 float o = (float) vh.getAndAdd(recv, 1.0f);
297 });
298
299 checkUOE(() -> {
300 float o = (float) vh.addAndGet(recv, 1.0f);
301 });
302 }
303
304
305 static void testStaticFinalField(VarHandle vh) {
306 // Plain
307 {
350 boolean r = vh.compareAndSet(1.0f, 2.0f);
351 });
352
353 checkUOE(() -> {
354 float r = (float) vh.compareAndExchangeVolatile(1.0f, 2.0f);
355 });
356
357 checkUOE(() -> {
358 float r = (float) vh.compareAndExchangeAcquire(1.0f, 2.0f);
359 });
360
361 checkUOE(() -> {
362 float r = (float) vh.compareAndExchangeRelease(1.0f, 2.0f);
363 });
364
365 checkUOE(() -> {
366 boolean r = vh.weakCompareAndSet(1.0f, 2.0f);
367 });
368
369 checkUOE(() -> {
370 boolean r = vh.weakCompareAndSetVolatile(1.0f, 2.0f);
371 });
372
373 checkUOE(() -> {
374 boolean r = vh.weakCompareAndSetAcquire(1.0f, 2.0f);
375 });
376
377 checkUOE(() -> {
378 boolean r = vh.weakCompareAndSetRelease(1.0f, 2.0f);
379 });
380
381 checkUOE(() -> {
382 float o = (float) vh.getAndAdd(1.0f);
383 });
384
385 checkUOE(() -> {
386 float o = (float) vh.addAndGet(1.0f);
387 });
388 }
389
390
391 static void testInstanceField(VarHandleTestAccessFloat recv, VarHandle vh) {
392 // Plain
393 {
426 boolean r = vh.compareAndSet(recv, 1.0f, 2.0f);
427 });
428
429 checkUOE(() -> {
430 float r = (float) vh.compareAndExchangeVolatile(recv, 1.0f, 2.0f);
431 });
432
433 checkUOE(() -> {
434 float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 2.0f);
435 });
436
437 checkUOE(() -> {
438 float r = (float) vh.compareAndExchangeRelease(recv, 1.0f, 2.0f);
439 });
440
441 checkUOE(() -> {
442 boolean r = vh.weakCompareAndSet(recv, 1.0f, 2.0f);
443 });
444
445 checkUOE(() -> {
446 boolean r = vh.weakCompareAndSetVolatile(recv, 1.0f, 2.0f);
447 });
448
449 checkUOE(() -> {
450 boolean r = vh.weakCompareAndSetAcquire(recv, 1.0f, 2.0f);
451 });
452
453 checkUOE(() -> {
454 boolean r = vh.weakCompareAndSetRelease(recv, 1.0f, 2.0f);
455 });
456
457 checkUOE(() -> {
458 float o = (float) vh.getAndAdd(recv, 1.0f);
459 });
460
461 checkUOE(() -> {
462 float o = (float) vh.addAndGet(recv, 1.0f);
463 });
464 }
465
466
467 static void testStaticField(VarHandle vh) {
468 // Plain
469 {
502 boolean r = vh.compareAndSet(1.0f, 2.0f);
503 });
504
505 checkUOE(() -> {
506 float r = (float) vh.compareAndExchangeVolatile(1.0f, 2.0f);
507 });
508
509 checkUOE(() -> {
510 float r = (float) vh.compareAndExchangeAcquire(1.0f, 2.0f);
511 });
512
513 checkUOE(() -> {
514 float r = (float) vh.compareAndExchangeRelease(1.0f, 2.0f);
515 });
516
517 checkUOE(() -> {
518 boolean r = vh.weakCompareAndSet(1.0f, 2.0f);
519 });
520
521 checkUOE(() -> {
522 boolean r = vh.weakCompareAndSetVolatile(1.0f, 2.0f);
523 });
524
525 checkUOE(() -> {
526 boolean r = vh.weakCompareAndSetAcquire(1.0f, 2.0f);
527 });
528
529 checkUOE(() -> {
530 boolean r = vh.weakCompareAndSetRelease(1.0f, 2.0f);
531 });
532
533 checkUOE(() -> {
534 float o = (float) vh.getAndAdd(1.0f);
535 });
536
537 checkUOE(() -> {
538 float o = (float) vh.addAndGet(1.0f);
539 });
540 }
541
542
543 static void testArray(VarHandle vh) {
544 float[] array = new float[10];
545
582
583 int i = 0;
584 checkUOE(() -> {
585 boolean r = vh.compareAndSet(array, i, 1.0f, 2.0f);
586 });
587
588 checkUOE(() -> {
589 float r = (float) vh.compareAndExchangeVolatile(array, i, 1.0f, 2.0f);
590 });
591
592 checkUOE(() -> {
593 float r = (float) vh.compareAndExchangeAcquire(array, i, 1.0f, 2.0f);
594 });
595
596 checkUOE(() -> {
597 float r = (float) vh.compareAndExchangeRelease(array, i, 1.0f, 2.0f);
598 });
599
600 checkUOE(() -> {
601 boolean r = vh.weakCompareAndSet(array, i, 1.0f, 2.0f);
602 });
603
604 checkUOE(() -> {
605 boolean r = vh.weakCompareAndSetVolatile(array, i, 1.0f, 2.0f);
606 });
607
608 checkUOE(() -> {
609 boolean r = vh.weakCompareAndSetAcquire(array, i, 1.0f, 2.0f);
610 });
611
612 checkUOE(() -> {
613 boolean r = vh.weakCompareAndSetRelease(array, i, 1.0f, 2.0f);
614 });
615
616 checkUOE(() -> {
617 float o = (float) vh.getAndAdd(array, i, 1.0f);
618 });
619
620 checkUOE(() -> {
621 float o = (float) vh.addAndGet(array, i, 1.0f);
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(VarHandleTestAccessFloat.class)});
120 types.add(new Object[] {vhStaticField, Arrays.asList()});
121 types.add(new Object[] {vhArray, Arrays.asList(float[].class, int.class)});
122
123 return types.stream().toArray(Object[][]::new);
124 }
125
126 @Test(dataProvider = "typesProvider")
263 boolean r = vh.compareAndSet(recv, 1.0f, 2.0f);
264 });
265
266 checkUOE(() -> {
267 float r = (float) vh.compareAndExchangeVolatile(recv, 1.0f, 2.0f);
268 });
269
270 checkUOE(() -> {
271 float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 2.0f);
272 });
273
274 checkUOE(() -> {
275 float r = (float) vh.compareAndExchangeRelease(recv, 1.0f, 2.0f);
276 });
277
278 checkUOE(() -> {
279 boolean r = vh.weakCompareAndSet(recv, 1.0f, 2.0f);
280 });
281
282 checkUOE(() -> {
283 boolean r = vh.weakCompareAndSetAcquire(recv, 1.0f, 2.0f);
284 });
285
286 checkUOE(() -> {
287 boolean r = vh.weakCompareAndSetRelease(recv, 1.0f, 2.0f);
288 });
289
290 checkUOE(() -> {
291 float o = (float) vh.getAndAdd(recv, 1.0f);
292 });
293
294 checkUOE(() -> {
295 float o = (float) vh.addAndGet(recv, 1.0f);
296 });
297 }
298
299
300 static void testStaticFinalField(VarHandle vh) {
301 // Plain
302 {
345 boolean r = vh.compareAndSet(1.0f, 2.0f);
346 });
347
348 checkUOE(() -> {
349 float r = (float) vh.compareAndExchangeVolatile(1.0f, 2.0f);
350 });
351
352 checkUOE(() -> {
353 float r = (float) vh.compareAndExchangeAcquire(1.0f, 2.0f);
354 });
355
356 checkUOE(() -> {
357 float r = (float) vh.compareAndExchangeRelease(1.0f, 2.0f);
358 });
359
360 checkUOE(() -> {
361 boolean r = vh.weakCompareAndSet(1.0f, 2.0f);
362 });
363
364 checkUOE(() -> {
365 boolean r = vh.weakCompareAndSetAcquire(1.0f, 2.0f);
366 });
367
368 checkUOE(() -> {
369 boolean r = vh.weakCompareAndSetRelease(1.0f, 2.0f);
370 });
371
372 checkUOE(() -> {
373 float o = (float) vh.getAndAdd(1.0f);
374 });
375
376 checkUOE(() -> {
377 float o = (float) vh.addAndGet(1.0f);
378 });
379 }
380
381
382 static void testInstanceField(VarHandleTestAccessFloat recv, VarHandle vh) {
383 // Plain
384 {
417 boolean r = vh.compareAndSet(recv, 1.0f, 2.0f);
418 });
419
420 checkUOE(() -> {
421 float r = (float) vh.compareAndExchangeVolatile(recv, 1.0f, 2.0f);
422 });
423
424 checkUOE(() -> {
425 float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 2.0f);
426 });
427
428 checkUOE(() -> {
429 float r = (float) vh.compareAndExchangeRelease(recv, 1.0f, 2.0f);
430 });
431
432 checkUOE(() -> {
433 boolean r = vh.weakCompareAndSet(recv, 1.0f, 2.0f);
434 });
435
436 checkUOE(() -> {
437 boolean r = vh.weakCompareAndSetAcquire(recv, 1.0f, 2.0f);
438 });
439
440 checkUOE(() -> {
441 boolean r = vh.weakCompareAndSetRelease(recv, 1.0f, 2.0f);
442 });
443
444 checkUOE(() -> {
445 float o = (float) vh.getAndAdd(recv, 1.0f);
446 });
447
448 checkUOE(() -> {
449 float o = (float) vh.addAndGet(recv, 1.0f);
450 });
451 }
452
453
454 static void testStaticField(VarHandle vh) {
455 // Plain
456 {
489 boolean r = vh.compareAndSet(1.0f, 2.0f);
490 });
491
492 checkUOE(() -> {
493 float r = (float) vh.compareAndExchangeVolatile(1.0f, 2.0f);
494 });
495
496 checkUOE(() -> {
497 float r = (float) vh.compareAndExchangeAcquire(1.0f, 2.0f);
498 });
499
500 checkUOE(() -> {
501 float r = (float) vh.compareAndExchangeRelease(1.0f, 2.0f);
502 });
503
504 checkUOE(() -> {
505 boolean r = vh.weakCompareAndSet(1.0f, 2.0f);
506 });
507
508 checkUOE(() -> {
509 boolean r = vh.weakCompareAndSetAcquire(1.0f, 2.0f);
510 });
511
512 checkUOE(() -> {
513 boolean r = vh.weakCompareAndSetRelease(1.0f, 2.0f);
514 });
515
516 checkUOE(() -> {
517 float o = (float) vh.getAndAdd(1.0f);
518 });
519
520 checkUOE(() -> {
521 float o = (float) vh.addAndGet(1.0f);
522 });
523 }
524
525
526 static void testArray(VarHandle vh) {
527 float[] array = new float[10];
528
565
566 int i = 0;
567 checkUOE(() -> {
568 boolean r = vh.compareAndSet(array, i, 1.0f, 2.0f);
569 });
570
571 checkUOE(() -> {
572 float r = (float) vh.compareAndExchangeVolatile(array, i, 1.0f, 2.0f);
573 });
574
575 checkUOE(() -> {
576 float r = (float) vh.compareAndExchangeAcquire(array, i, 1.0f, 2.0f);
577 });
578
579 checkUOE(() -> {
580 float r = (float) vh.compareAndExchangeRelease(array, i, 1.0f, 2.0f);
581 });
582
583 checkUOE(() -> {
584 boolean r = vh.weakCompareAndSet(array, i, 1.0f, 2.0f);
585 });
586
587 checkUOE(() -> {
588 boolean r = vh.weakCompareAndSetAcquire(array, i, 1.0f, 2.0f);
589 });
590
591 checkUOE(() -> {
592 boolean r = vh.weakCompareAndSetRelease(array, i, 1.0f, 2.0f);
593 });
594
595 checkUOE(() -> {
596 float o = (float) vh.getAndAdd(array, i, 1.0f);
597 });
598
599 checkUOE(() -> {
600 float o = (float) vh.addAndGet(array, i, 1.0f);
601 });
602 }
603
604 static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
|