blob: 4fa6b41fd3cad949069f3e8ab9e7ee9f08246669 [file] [log] [blame]
Paul Sandoz9fb30a32016-03-24 11:21:21 +01001/*
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessFloat
27 * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessFloat
28 * @run testng/othervm -Diters=20000 VarHandleTestAccessFloat
29 * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestAccessFloat
30 */
31
32import org.testng.annotations.BeforeClass;
33import org.testng.annotations.DataProvider;
34import org.testng.annotations.Test;
35
36import java.lang.invoke.MethodHandles;
37import java.lang.invoke.VarHandle;
38import java.util.ArrayList;
39import java.util.Arrays;
40import java.util.List;
41
42import static org.testng.Assert.*;
43
44public class VarHandleTestAccessFloat extends VarHandleBaseTest {
45 static final float static_final_v = 1.0f;
46
47 static float static_v;
48
49 final float final_v = 1.0f;
50
51 float 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 VarHandleTestAccessFloat.class, "final_v", float.class);
67
68 vhField = MethodHandles.lookup().findVarHandle(
69 VarHandleTestAccessFloat.class, "v", float.class);
70
71 vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
72 VarHandleTestAccessFloat.class, "static_final_v", float.class);
73
74 vhStaticField = MethodHandles.lookup().findStaticVarHandle(
75 VarHandleTestAccessFloat.class, "static_v", float.class);
76
77 vhArray = MethodHandles.arrayElementVarHandle(float[].class);
78 }
79
80
81 @DataProvider
82 public Object[][] varHandlesProvider() throws Exception {
83 List<VarHandle> vhs = new ArrayList<>();
84 vhs.add(vhField);
85 vhs.add(vhStaticField);
86 vhs.add(vhArray);
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) {
Paul Sandoza7aff442016-04-13 15:05:48 +020093 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));
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100101
Paul Sandoz734dbe42016-06-20 17:57:19 +0200102 assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
Paul Sandoz3f0273a2016-06-23 13:46:48 +0200103 assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
Paul Sandoz734dbe42016-06-20 17:57:19 +0200104 assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
105 assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700106 assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
Paul Sandoz734dbe42016-06-20 17:57:19 +0200107 assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
Paul Sandoz734dbe42016-06-20 17:57:19 +0200108 assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
109 assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
110 assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
Paul Sandoz82d48912016-09-01 10:16:57 -0700111 assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
112 assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100113
Paul Sandoz734dbe42016-06-20 17:57:19 +0200114 assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
Paul Sandoz82d48912016-09-01 10:16:57 -0700115 assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
116 assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
Paul Sandoz82d48912016-09-01 10:16:57 -0700117
118 assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
119 assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
120 assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
121 assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
122 assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
123 assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
124 assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
125 assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
126 assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100127 }
128
129
130 @DataProvider
131 public Object[][] typesProvider() throws Exception {
132 List<Object[]> types = new ArrayList<>();
133 types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessFloat.class)});
134 types.add(new Object[] {vhStaticField, Arrays.asList()});
135 types.add(new Object[] {vhArray, Arrays.asList(float[].class, int.class)});
136
137 return types.stream().toArray(Object[][]::new);
138 }
139
140 @Test(dataProvider = "typesProvider")
141 public void testTypes(VarHandle vh, List<Class<?>> pts) {
142 assertEquals(vh.varType(), float.class);
143
144 assertEquals(vh.coordinateTypes(), pts);
145
146 testTypes(vh);
147 }
148
149
150 @Test
151 public void testLookupInstanceToStatic() {
152 checkIAE("Lookup of static final field to instance final field", () -> {
153 MethodHandles.lookup().findStaticVarHandle(
154 VarHandleTestAccessFloat.class, "final_v", float.class);
155 });
156
157 checkIAE("Lookup of static field to instance field", () -> {
158 MethodHandles.lookup().findStaticVarHandle(
159 VarHandleTestAccessFloat.class, "v", float.class);
160 });
161 }
162
163 @Test
164 public void testLookupStaticToInstance() {
165 checkIAE("Lookup of instance final field to static final field", () -> {
166 MethodHandles.lookup().findVarHandle(
167 VarHandleTestAccessFloat.class, "static_final_v", float.class);
168 });
169
170 checkIAE("Lookup of instance field to static field", () -> {
171 vhStaticField = MethodHandles.lookup().findVarHandle(
172 VarHandleTestAccessFloat.class, "static_v", float.class);
173 });
174 }
175
176
177 @DataProvider
178 public Object[][] accessTestCaseProvider() throws Exception {
179 List<AccessTestCase<?>> cases = new ArrayList<>();
180
181 cases.add(new VarHandleAccessTestCase("Instance final field",
182 vhFinalField, vh -> testInstanceFinalField(this, vh)));
183 cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
184 vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
185 false));
186
187 cases.add(new VarHandleAccessTestCase("Static final field",
188 vhStaticFinalField, VarHandleTestAccessFloat::testStaticFinalField));
189 cases.add(new VarHandleAccessTestCase("Static final field unsupported",
190 vhStaticFinalField, VarHandleTestAccessFloat::testStaticFinalFieldUnsupported,
191 false));
192
193 cases.add(new VarHandleAccessTestCase("Instance field",
194 vhField, vh -> testInstanceField(this, vh)));
195 cases.add(new VarHandleAccessTestCase("Instance field unsupported",
196 vhField, vh -> testInstanceFieldUnsupported(this, vh),
197 false));
198
199 cases.add(new VarHandleAccessTestCase("Static field",
200 vhStaticField, VarHandleTestAccessFloat::testStaticField));
201 cases.add(new VarHandleAccessTestCase("Static field unsupported",
202 vhStaticField, VarHandleTestAccessFloat::testStaticFieldUnsupported,
203 false));
204
205 cases.add(new VarHandleAccessTestCase("Array",
206 vhArray, VarHandleTestAccessFloat::testArray));
207 cases.add(new VarHandleAccessTestCase("Array unsupported",
208 vhArray, VarHandleTestAccessFloat::testArrayUnsupported,
209 false));
210 cases.add(new VarHandleAccessTestCase("Array index out of bounds",
211 vhArray, VarHandleTestAccessFloat::testArrayIndexOutOfBounds,
212 false));
213
214 // Work around issue with jtreg summary reporting which truncates
215 // the String result of Object.toString to 30 characters, hence
216 // the first dummy argument
217 return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
218 }
219
220 @Test(dataProvider = "accessTestCaseProvider")
221 public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
222 T t = atc.get();
223 int iters = atc.requiresLoop() ? ITERS : 1;
224 for (int c = 0; c < iters; c++) {
225 atc.testAccess(t);
226 }
227 }
228
229
230
231
232 static void testInstanceFinalField(VarHandleTestAccessFloat recv, VarHandle vh) {
233 // Plain
234 {
235 float x = (float) vh.get(recv);
236 assertEquals(x, 1.0f, "get float value");
237 }
238
239
240 // Volatile
241 {
242 float x = (float) vh.getVolatile(recv);
243 assertEquals(x, 1.0f, "getVolatile float value");
244 }
245
246 // Lazy
247 {
248 float x = (float) vh.getAcquire(recv);
249 assertEquals(x, 1.0f, "getRelease float value");
250 }
251
252 // Opaque
253 {
254 float x = (float) vh.getOpaque(recv);
255 assertEquals(x, 1.0f, "getOpaque float value");
256 }
257 }
258
259 static void testInstanceFinalFieldUnsupported(VarHandleTestAccessFloat recv, VarHandle vh) {
260 checkUOE(() -> {
261 vh.set(recv, 2.0f);
262 });
263
264 checkUOE(() -> {
265 vh.setVolatile(recv, 2.0f);
266 });
267
268 checkUOE(() -> {
269 vh.setRelease(recv, 2.0f);
270 });
271
272 checkUOE(() -> {
273 vh.setOpaque(recv, 2.0f);
274 });
275
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100276
Paul Sandoz82d48912016-09-01 10:16:57 -0700277
278 checkUOE(() -> {
279 float o = (float) vh.getAndBitwiseOr(recv, 1.0f);
280 });
281
282 checkUOE(() -> {
283 float o = (float) vh.getAndBitwiseOrAcquire(recv, 1.0f);
284 });
285
286 checkUOE(() -> {
287 float o = (float) vh.getAndBitwiseOrRelease(recv, 1.0f);
288 });
289
290 checkUOE(() -> {
291 float o = (float) vh.getAndBitwiseAnd(recv, 1.0f);
292 });
293
294 checkUOE(() -> {
295 float o = (float) vh.getAndBitwiseAndAcquire(recv, 1.0f);
296 });
297
298 checkUOE(() -> {
299 float o = (float) vh.getAndBitwiseAndRelease(recv, 1.0f);
300 });
301
302 checkUOE(() -> {
303 float o = (float) vh.getAndBitwiseXor(recv, 1.0f);
304 });
305
306 checkUOE(() -> {
307 float o = (float) vh.getAndBitwiseXorAcquire(recv, 1.0f);
308 });
309
310 checkUOE(() -> {
311 float o = (float) vh.getAndBitwiseXorRelease(recv, 1.0f);
312 });
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100313 }
314
315
316 static void testStaticFinalField(VarHandle vh) {
317 // Plain
318 {
319 float x = (float) vh.get();
320 assertEquals(x, 1.0f, "get float value");
321 }
322
323
324 // Volatile
325 {
326 float x = (float) vh.getVolatile();
327 assertEquals(x, 1.0f, "getVolatile float value");
328 }
329
330 // Lazy
331 {
332 float x = (float) vh.getAcquire();
333 assertEquals(x, 1.0f, "getRelease float value");
334 }
335
336 // Opaque
337 {
338 float x = (float) vh.getOpaque();
339 assertEquals(x, 1.0f, "getOpaque float value");
340 }
341 }
342
343 static void testStaticFinalFieldUnsupported(VarHandle vh) {
344 checkUOE(() -> {
345 vh.set(2.0f);
346 });
347
348 checkUOE(() -> {
349 vh.setVolatile(2.0f);
350 });
351
352 checkUOE(() -> {
353 vh.setRelease(2.0f);
354 });
355
356 checkUOE(() -> {
357 vh.setOpaque(2.0f);
358 });
359
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100360
Paul Sandoz82d48912016-09-01 10:16:57 -0700361
362 checkUOE(() -> {
363 float o = (float) vh.getAndBitwiseOr(1.0f);
364 });
365
366 checkUOE(() -> {
367 float o = (float) vh.getAndBitwiseOrAcquire(1.0f);
368 });
369
370 checkUOE(() -> {
371 float o = (float) vh.getAndBitwiseOrRelease(1.0f);
372 });
373
374 checkUOE(() -> {
375 float o = (float) vh.getAndBitwiseAnd(1.0f);
376 });
377
378 checkUOE(() -> {
379 float o = (float) vh.getAndBitwiseAndAcquire(1.0f);
380 });
381
382 checkUOE(() -> {
383 float o = (float) vh.getAndBitwiseAndRelease(1.0f);
384 });
385
386 checkUOE(() -> {
387 float o = (float) vh.getAndBitwiseXor(1.0f);
388 });
389
390 checkUOE(() -> {
391 float o = (float) vh.getAndBitwiseXorAcquire(1.0f);
392 });
393
394 checkUOE(() -> {
395 float o = (float) vh.getAndBitwiseXorRelease(1.0f);
396 });
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100397 }
398
399
400 static void testInstanceField(VarHandleTestAccessFloat recv, VarHandle vh) {
401 // Plain
402 {
403 vh.set(recv, 1.0f);
404 float x = (float) vh.get(recv);
405 assertEquals(x, 1.0f, "set float value");
406 }
407
408
409 // Volatile
410 {
411 vh.setVolatile(recv, 2.0f);
412 float x = (float) vh.getVolatile(recv);
413 assertEquals(x, 2.0f, "setVolatile float value");
414 }
415
416 // Lazy
417 {
418 vh.setRelease(recv, 1.0f);
419 float x = (float) vh.getAcquire(recv);
420 assertEquals(x, 1.0f, "setRelease float value");
421 }
422
423 // Opaque
424 {
425 vh.setOpaque(recv, 2.0f);
426 float x = (float) vh.getOpaque(recv);
427 assertEquals(x, 2.0f, "setOpaque float value");
428 }
429
Paul Sandoz734dbe42016-06-20 17:57:19 +0200430 vh.set(recv, 1.0f);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100431
Paul Sandoz734dbe42016-06-20 17:57:19 +0200432 // Compare
433 {
434 boolean r = vh.compareAndSet(recv, 1.0f, 2.0f);
435 assertEquals(r, true, "success compareAndSet float");
436 float x = (float) vh.get(recv);
437 assertEquals(x, 2.0f, "success compareAndSet float value");
438 }
439
440 {
441 boolean r = vh.compareAndSet(recv, 1.0f, 3.0f);
442 assertEquals(r, false, "failing compareAndSet float");
443 float x = (float) vh.get(recv);
444 assertEquals(x, 2.0f, "failing compareAndSet float value");
445 }
446
447 {
Paul Sandoz3f0273a2016-06-23 13:46:48 +0200448 float r = (float) vh.compareAndExchange(recv, 2.0f, 1.0f);
449 assertEquals(r, 2.0f, "success compareAndExchange float");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200450 float x = (float) vh.get(recv);
Paul Sandoz3f0273a2016-06-23 13:46:48 +0200451 assertEquals(x, 1.0f, "success compareAndExchange float value");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200452 }
453
454 {
Paul Sandoz3f0273a2016-06-23 13:46:48 +0200455 float r = (float) vh.compareAndExchange(recv, 2.0f, 3.0f);
456 assertEquals(r, 1.0f, "failing compareAndExchange float");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200457 float x = (float) vh.get(recv);
Paul Sandoz3f0273a2016-06-23 13:46:48 +0200458 assertEquals(x, 1.0f, "failing compareAndExchange float value");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200459 }
460
461 {
462 float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 2.0f);
463 assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
464 float x = (float) vh.get(recv);
465 assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
466 }
467
468 {
469 float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 3.0f);
470 assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
471 float x = (float) vh.get(recv);
472 assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
473 }
474
475 {
476 float r = (float) vh.compareAndExchangeRelease(recv, 2.0f, 1.0f);
477 assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
478 float x = (float) vh.get(recv);
479 assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
480 }
481
482 {
483 float r = (float) vh.compareAndExchangeRelease(recv, 2.0f, 3.0f);
484 assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
485 float x = (float) vh.get(recv);
486 assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
487 }
488
489 {
490 boolean success = false;
491 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700492 success = vh.weakCompareAndSetPlain(recv, 1.0f, 2.0f);
Paul Sandoz734dbe42016-06-20 17:57:19 +0200493 }
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700494 assertEquals(success, true, "weakCompareAndSetPlain float");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200495 float x = (float) vh.get(recv);
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700496 assertEquals(x, 2.0f, "weakCompareAndSetPlain float value");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200497 }
498
499 {
500 boolean success = false;
501 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
502 success = vh.weakCompareAndSetAcquire(recv, 2.0f, 1.0f);
503 }
504 assertEquals(success, true, "weakCompareAndSetAcquire float");
505 float x = (float) vh.get(recv);
506 assertEquals(x, 1.0f, "weakCompareAndSetAcquire float");
507 }
508
509 {
510 boolean success = false;
511 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
512 success = vh.weakCompareAndSetRelease(recv, 1.0f, 2.0f);
513 }
514 assertEquals(success, true, "weakCompareAndSetRelease float");
515 float x = (float) vh.get(recv);
516 assertEquals(x, 2.0f, "weakCompareAndSetRelease float");
517 }
518
519 {
520 boolean success = false;
521 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700522 success = vh.weakCompareAndSet(recv, 2.0f, 1.0f);
Paul Sandoz734dbe42016-06-20 17:57:19 +0200523 }
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700524 assertEquals(success, true, "weakCompareAndSet float");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200525 float x = (float) vh.get(recv);
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700526 assertEquals(x, 1.0f, "weakCompareAndSet float value");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200527 }
528
529 // Compare set and get
530 {
Paul Sandoz82d48912016-09-01 10:16:57 -0700531 vh.set(recv, 1.0f);
532
Paul Sandoz734dbe42016-06-20 17:57:19 +0200533 float o = (float) vh.getAndSet(recv, 2.0f);
534 assertEquals(o, 1.0f, "getAndSet float");
535 float x = (float) vh.get(recv);
536 assertEquals(x, 2.0f, "getAndSet float value");
537 }
538
Paul Sandoz82d48912016-09-01 10:16:57 -0700539 {
540 vh.set(recv, 1.0f);
541
542 float o = (float) vh.getAndSetAcquire(recv, 2.0f);
543 assertEquals(o, 1.0f, "getAndSetAcquire float");
544 float x = (float) vh.get(recv);
545 assertEquals(x, 2.0f, "getAndSetAcquire float value");
546 }
547
548 {
549 vh.set(recv, 1.0f);
550
551 float o = (float) vh.getAndSetRelease(recv, 2.0f);
552 assertEquals(o, 1.0f, "getAndSetRelease float");
553 float x = (float) vh.get(recv);
554 assertEquals(x, 2.0f, "getAndSetRelease float value");
555 }
Paul Sandoz734dbe42016-06-20 17:57:19 +0200556
557 // get and add, add and get
558 {
Paul Sandoz82d48912016-09-01 10:16:57 -0700559 vh.set(recv, 1.0f);
560
Paul Sandozc073edc2016-09-01 10:17:01 -0700561 float o = (float) vh.getAndAdd(recv, 2.0f);
Paul Sandoz734dbe42016-06-20 17:57:19 +0200562 assertEquals(o, 1.0f, "getAndAdd float");
Paul Sandozc073edc2016-09-01 10:17:01 -0700563 float x = (float) vh.get(recv);
564 assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200565 }
Paul Sandoz82d48912016-09-01 10:16:57 -0700566
567 {
568 vh.set(recv, 1.0f);
569
570 float o = (float) vh.getAndAddAcquire(recv, 2.0f);
571 assertEquals(o, 1.0f, "getAndAddAcquire float");
572 float x = (float) vh.get(recv);
573 assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
574 }
575
576 {
577 vh.set(recv, 1.0f);
578
579 float o = (float) vh.getAndAddRelease(recv, 2.0f);
580 assertEquals(o, 1.0f, "getAndAddReleasefloat");
581 float x = (float) vh.get(recv);
582 assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
583 }
584
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100585 }
586
587 static void testInstanceFieldUnsupported(VarHandleTestAccessFloat recv, VarHandle vh) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100588
Paul Sandoz82d48912016-09-01 10:16:57 -0700589
590 checkUOE(() -> {
591 float o = (float) vh.getAndBitwiseOr(recv, 1.0f);
592 });
593
594 checkUOE(() -> {
595 float o = (float) vh.getAndBitwiseOrAcquire(recv, 1.0f);
596 });
597
598 checkUOE(() -> {
599 float o = (float) vh.getAndBitwiseOrRelease(recv, 1.0f);
600 });
601
602 checkUOE(() -> {
603 float o = (float) vh.getAndBitwiseAnd(recv, 1.0f);
604 });
605
606 checkUOE(() -> {
607 float o = (float) vh.getAndBitwiseAndAcquire(recv, 1.0f);
608 });
609
610 checkUOE(() -> {
611 float o = (float) vh.getAndBitwiseAndRelease(recv, 1.0f);
612 });
613
614 checkUOE(() -> {
615 float o = (float) vh.getAndBitwiseXor(recv, 1.0f);
616 });
617
618 checkUOE(() -> {
619 float o = (float) vh.getAndBitwiseXorAcquire(recv, 1.0f);
620 });
621
622 checkUOE(() -> {
623 float o = (float) vh.getAndBitwiseXorRelease(recv, 1.0f);
624 });
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100625 }
626
627
628 static void testStaticField(VarHandle vh) {
629 // Plain
630 {
631 vh.set(1.0f);
632 float x = (float) vh.get();
633 assertEquals(x, 1.0f, "set float value");
634 }
635
636
637 // Volatile
638 {
639 vh.setVolatile(2.0f);
640 float x = (float) vh.getVolatile();
641 assertEquals(x, 2.0f, "setVolatile float value");
642 }
643
644 // Lazy
645 {
646 vh.setRelease(1.0f);
647 float x = (float) vh.getAcquire();
648 assertEquals(x, 1.0f, "setRelease float value");
649 }
650
651 // Opaque
652 {
653 vh.setOpaque(2.0f);
654 float x = (float) vh.getOpaque();
655 assertEquals(x, 2.0f, "setOpaque float value");
656 }
657
Paul Sandoz734dbe42016-06-20 17:57:19 +0200658 vh.set(1.0f);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100659
Paul Sandoz734dbe42016-06-20 17:57:19 +0200660 // Compare
661 {
662 boolean r = vh.compareAndSet(1.0f, 2.0f);
663 assertEquals(r, true, "success compareAndSet float");
664 float x = (float) vh.get();
665 assertEquals(x, 2.0f, "success compareAndSet float value");
666 }
667
668 {
669 boolean r = vh.compareAndSet(1.0f, 3.0f);
670 assertEquals(r, false, "failing compareAndSet float");
671 float x = (float) vh.get();
672 assertEquals(x, 2.0f, "failing compareAndSet float value");
673 }
674
675 {
Paul Sandoz3f0273a2016-06-23 13:46:48 +0200676 float r = (float) vh.compareAndExchange(2.0f, 1.0f);
677 assertEquals(r, 2.0f, "success compareAndExchange float");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200678 float x = (float) vh.get();
Paul Sandoz3f0273a2016-06-23 13:46:48 +0200679 assertEquals(x, 1.0f, "success compareAndExchange float value");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200680 }
681
682 {
Paul Sandoz3f0273a2016-06-23 13:46:48 +0200683 float r = (float) vh.compareAndExchange(2.0f, 3.0f);
684 assertEquals(r, 1.0f, "failing compareAndExchange float");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200685 float x = (float) vh.get();
Paul Sandoz3f0273a2016-06-23 13:46:48 +0200686 assertEquals(x, 1.0f, "failing compareAndExchange float value");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200687 }
688
689 {
690 float r = (float) vh.compareAndExchangeAcquire(1.0f, 2.0f);
691 assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
692 float x = (float) vh.get();
693 assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
694 }
695
696 {
697 float r = (float) vh.compareAndExchangeAcquire(1.0f, 3.0f);
698 assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
699 float x = (float) vh.get();
700 assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
701 }
702
703 {
704 float r = (float) vh.compareAndExchangeRelease(2.0f, 1.0f);
705 assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
706 float x = (float) vh.get();
707 assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
708 }
709
710 {
711 float r = (float) vh.compareAndExchangeRelease(2.0f, 3.0f);
712 assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
713 float x = (float) vh.get();
714 assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
715 }
716
717 {
718 boolean success = false;
719 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700720 success = vh.weakCompareAndSetPlain(1.0f, 2.0f);
Paul Sandoz734dbe42016-06-20 17:57:19 +0200721 }
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700722 assertEquals(success, true, "weakCompareAndSetPlain float");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200723 float x = (float) vh.get();
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700724 assertEquals(x, 2.0f, "weakCompareAndSetPlain float value");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200725 }
726
727 {
728 boolean success = false;
729 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
730 success = vh.weakCompareAndSetAcquire(2.0f, 1.0f);
731 }
732 assertEquals(success, true, "weakCompareAndSetAcquire float");
733 float x = (float) vh.get();
734 assertEquals(x, 1.0f, "weakCompareAndSetAcquire float");
735 }
736
737 {
738 boolean success = false;
739 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
740 success = vh.weakCompareAndSetRelease(1.0f, 2.0f);
741 }
742 assertEquals(success, true, "weakCompareAndSetRelease float");
743 float x = (float) vh.get();
744 assertEquals(x, 2.0f, "weakCompareAndSetRelease float");
745 }
746
747 {
748 boolean success = false;
749 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700750 success = vh.weakCompareAndSet(2.0f, 1.0f);
Paul Sandoz734dbe42016-06-20 17:57:19 +0200751 }
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700752 assertEquals(success, true, "weakCompareAndSet float");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200753 float x = (float) vh.get();
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700754 assertEquals(x, 1.0f, "weakCompareAndSet float");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200755 }
756
757 // Compare set and get
758 {
Paul Sandoz82d48912016-09-01 10:16:57 -0700759 vh.set(1.0f);
760
Paul Sandoz734dbe42016-06-20 17:57:19 +0200761 float o = (float) vh.getAndSet(2.0f);
762 assertEquals(o, 1.0f, "getAndSet float");
763 float x = (float) vh.get();
764 assertEquals(x, 2.0f, "getAndSet float value");
765 }
766
Paul Sandoz82d48912016-09-01 10:16:57 -0700767 {
768 vh.set(1.0f);
769
770 float o = (float) vh.getAndSetAcquire(2.0f);
771 assertEquals(o, 1.0f, "getAndSetAcquire float");
772 float x = (float) vh.get();
773 assertEquals(x, 2.0f, "getAndSetAcquire float value");
774 }
775
776 {
777 vh.set(1.0f);
778
779 float o = (float) vh.getAndSetRelease(2.0f);
780 assertEquals(o, 1.0f, "getAndSetRelease float");
781 float x = (float) vh.get();
782 assertEquals(x, 2.0f, "getAndSetRelease float value");
783 }
Paul Sandoz734dbe42016-06-20 17:57:19 +0200784
785 // get and add, add and get
786 {
Paul Sandoz82d48912016-09-01 10:16:57 -0700787 vh.set(1.0f);
788
Paul Sandozc073edc2016-09-01 10:17:01 -0700789 float o = (float) vh.getAndAdd(2.0f);
Paul Sandoz734dbe42016-06-20 17:57:19 +0200790 assertEquals(o, 1.0f, "getAndAdd float");
Paul Sandozc073edc2016-09-01 10:17:01 -0700791 float x = (float) vh.get();
792 assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200793 }
Paul Sandoz82d48912016-09-01 10:16:57 -0700794
795 {
796 vh.set(1.0f);
797
798 float o = (float) vh.getAndAddAcquire(2.0f);
799 assertEquals(o, 1.0f, "getAndAddAcquire float");
800 float x = (float) vh.get();
801 assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
802 }
803
804 {
805 vh.set(1.0f);
806
807 float o = (float) vh.getAndAddRelease(2.0f);
808 assertEquals(o, 1.0f, "getAndAddReleasefloat");
809 float x = (float) vh.get();
810 assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
811 }
812
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100813 }
814
815 static void testStaticFieldUnsupported(VarHandle vh) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100816
Paul Sandoz82d48912016-09-01 10:16:57 -0700817
818 checkUOE(() -> {
819 float o = (float) vh.getAndBitwiseOr(1.0f);
820 });
821
822 checkUOE(() -> {
823 float o = (float) vh.getAndBitwiseOrAcquire(1.0f);
824 });
825
826 checkUOE(() -> {
827 float o = (float) vh.getAndBitwiseOrRelease(1.0f);
828 });
829
830 checkUOE(() -> {
831 float o = (float) vh.getAndBitwiseAnd(1.0f);
832 });
833
834 checkUOE(() -> {
835 float o = (float) vh.getAndBitwiseAndAcquire(1.0f);
836 });
837
838 checkUOE(() -> {
839 float o = (float) vh.getAndBitwiseAndRelease(1.0f);
840 });
841
842 checkUOE(() -> {
843 float o = (float) vh.getAndBitwiseXor(1.0f);
844 });
845
846 checkUOE(() -> {
847 float o = (float) vh.getAndBitwiseXorAcquire(1.0f);
848 });
849
850 checkUOE(() -> {
851 float o = (float) vh.getAndBitwiseXorRelease(1.0f);
852 });
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100853 }
854
855
856 static void testArray(VarHandle vh) {
857 float[] array = new float[10];
858
859 for (int i = 0; i < array.length; i++) {
860 // Plain
861 {
862 vh.set(array, i, 1.0f);
863 float x = (float) vh.get(array, i);
864 assertEquals(x, 1.0f, "get float value");
865 }
866
867
868 // Volatile
869 {
870 vh.setVolatile(array, i, 2.0f);
871 float x = (float) vh.getVolatile(array, i);
872 assertEquals(x, 2.0f, "setVolatile float value");
873 }
874
875 // Lazy
876 {
877 vh.setRelease(array, i, 1.0f);
878 float x = (float) vh.getAcquire(array, i);
879 assertEquals(x, 1.0f, "setRelease float value");
880 }
881
882 // Opaque
883 {
884 vh.setOpaque(array, i, 2.0f);
885 float x = (float) vh.getOpaque(array, i);
886 assertEquals(x, 2.0f, "setOpaque float value");
887 }
888
Paul Sandoz734dbe42016-06-20 17:57:19 +0200889 vh.set(array, i, 1.0f);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100890
Paul Sandoz734dbe42016-06-20 17:57:19 +0200891 // Compare
892 {
893 boolean r = vh.compareAndSet(array, i, 1.0f, 2.0f);
894 assertEquals(r, true, "success compareAndSet float");
895 float x = (float) vh.get(array, i);
896 assertEquals(x, 2.0f, "success compareAndSet float value");
897 }
898
899 {
900 boolean r = vh.compareAndSet(array, i, 1.0f, 3.0f);
901 assertEquals(r, false, "failing compareAndSet float");
902 float x = (float) vh.get(array, i);
903 assertEquals(x, 2.0f, "failing compareAndSet float value");
904 }
905
906 {
Paul Sandoz3f0273a2016-06-23 13:46:48 +0200907 float r = (float) vh.compareAndExchange(array, i, 2.0f, 1.0f);
908 assertEquals(r, 2.0f, "success compareAndExchange float");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200909 float x = (float) vh.get(array, i);
Paul Sandoz3f0273a2016-06-23 13:46:48 +0200910 assertEquals(x, 1.0f, "success compareAndExchange float value");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200911 }
912
913 {
Paul Sandoz3f0273a2016-06-23 13:46:48 +0200914 float r = (float) vh.compareAndExchange(array, i, 2.0f, 3.0f);
915 assertEquals(r, 1.0f, "failing compareAndExchange float");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200916 float x = (float) vh.get(array, i);
Paul Sandoz3f0273a2016-06-23 13:46:48 +0200917 assertEquals(x, 1.0f, "failing compareAndExchange float value");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200918 }
919
920 {
921 float r = (float) vh.compareAndExchangeAcquire(array, i, 1.0f, 2.0f);
922 assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
923 float x = (float) vh.get(array, i);
924 assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
925 }
926
927 {
928 float r = (float) vh.compareAndExchangeAcquire(array, i, 1.0f, 3.0f);
929 assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
930 float x = (float) vh.get(array, i);
931 assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
932 }
933
934 {
935 float r = (float) vh.compareAndExchangeRelease(array, i, 2.0f, 1.0f);
936 assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
937 float x = (float) vh.get(array, i);
938 assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
939 }
940
941 {
942 float r = (float) vh.compareAndExchangeRelease(array, i, 2.0f, 3.0f);
943 assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
944 float x = (float) vh.get(array, i);
945 assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
946 }
947
948 {
949 boolean success = false;
950 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700951 success = vh.weakCompareAndSetPlain(array, i, 1.0f, 2.0f);
Paul Sandoz734dbe42016-06-20 17:57:19 +0200952 }
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700953 assertEquals(success, true, "weakCompareAndSetPlain float");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200954 float x = (float) vh.get(array, i);
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700955 assertEquals(x, 2.0f, "weakCompareAndSetPlain float value");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200956 }
957
958 {
959 boolean success = false;
960 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
961 success = vh.weakCompareAndSetAcquire(array, i, 2.0f, 1.0f);
962 }
963 assertEquals(success, true, "weakCompareAndSetAcquire float");
964 float x = (float) vh.get(array, i);
965 assertEquals(x, 1.0f, "weakCompareAndSetAcquire float");
966 }
967
968 {
969 boolean success = false;
970 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
971 success = vh.weakCompareAndSetRelease(array, i, 1.0f, 2.0f);
972 }
973 assertEquals(success, true, "weakCompareAndSetRelease float");
974 float x = (float) vh.get(array, i);
975 assertEquals(x, 2.0f, "weakCompareAndSetRelease float");
976 }
977
978 {
979 boolean success = false;
980 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700981 success = vh.weakCompareAndSet(array, i, 2.0f, 1.0f);
Paul Sandoz734dbe42016-06-20 17:57:19 +0200982 }
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700983 assertEquals(success, true, "weakCompareAndSet float");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200984 float x = (float) vh.get(array, i);
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -0700985 assertEquals(x, 1.0f, "weakCompareAndSet float");
Paul Sandoz734dbe42016-06-20 17:57:19 +0200986 }
987
988 // Compare set and get
989 {
Paul Sandoz82d48912016-09-01 10:16:57 -0700990 vh.set(array, i, 1.0f);
991
Paul Sandoz734dbe42016-06-20 17:57:19 +0200992 float o = (float) vh.getAndSet(array, i, 2.0f);
993 assertEquals(o, 1.0f, "getAndSet float");
994 float x = (float) vh.get(array, i);
995 assertEquals(x, 2.0f, "getAndSet float value");
996 }
997
Paul Sandoz82d48912016-09-01 10:16:57 -0700998 {
999 vh.set(array, i, 1.0f);
1000
1001 float o = (float) vh.getAndSetAcquire(array, i, 2.0f);
1002 assertEquals(o, 1.0f, "getAndSetAcquire float");
1003 float x = (float) vh.get(array, i);
1004 assertEquals(x, 2.0f, "getAndSetAcquire float value");
1005 }
1006
1007 {
1008 vh.set(array, i, 1.0f);
1009
1010 float o = (float) vh.getAndSetRelease(array, i, 2.0f);
1011 assertEquals(o, 1.0f, "getAndSetRelease float");
1012 float x = (float) vh.get(array, i);
1013 assertEquals(x, 2.0f, "getAndSetRelease float value");
1014 }
Paul Sandoz734dbe42016-06-20 17:57:19 +02001015
1016 // get and add, add and get
1017 {
Paul Sandoz82d48912016-09-01 10:16:57 -07001018 vh.set(array, i, 1.0f);
1019
Paul Sandozc073edc2016-09-01 10:17:01 -07001020 float o = (float) vh.getAndAdd(array, i, 2.0f);
Paul Sandoz734dbe42016-06-20 17:57:19 +02001021 assertEquals(o, 1.0f, "getAndAdd float");
Paul Sandozc073edc2016-09-01 10:17:01 -07001022 float x = (float) vh.get(array, i);
1023 assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
Paul Sandoz734dbe42016-06-20 17:57:19 +02001024 }
Paul Sandoz82d48912016-09-01 10:16:57 -07001025
1026 {
1027 vh.set(array, i, 1.0f);
1028
1029 float o = (float) vh.getAndAddAcquire(array, i, 2.0f);
1030 assertEquals(o, 1.0f, "getAndAddAcquire float");
1031 float x = (float) vh.get(array, i);
1032 assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
1033 }
1034
1035 {
1036 vh.set(array, i, 1.0f);
1037
1038 float o = (float) vh.getAndAddRelease(array, i, 2.0f);
1039 assertEquals(o, 1.0f, "getAndAddReleasefloat");
1040 float x = (float) vh.get(array, i);
1041 assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
1042 }
1043
Paul Sandoz9fb30a32016-03-24 11:21:21 +01001044 }
1045 }
1046
1047 static void testArrayUnsupported(VarHandle vh) {
1048 float[] array = new float[10];
1049
1050 int i = 0;
Paul Sandoz9fb30a32016-03-24 11:21:21 +01001051
Paul Sandoz82d48912016-09-01 10:16:57 -07001052
1053 checkUOE(() -> {
1054 float o = (float) vh.getAndBitwiseOr(array, i, 1.0f);
1055 });
1056
1057 checkUOE(() -> {
1058 float o = (float) vh.getAndBitwiseOrAcquire(array, i, 1.0f);
1059 });
1060
1061 checkUOE(() -> {
1062 float o = (float) vh.getAndBitwiseOrRelease(array, i, 1.0f);
1063 });
1064
1065 checkUOE(() -> {
1066 float o = (float) vh.getAndBitwiseAnd(array, i, 1.0f);
1067 });
1068
1069 checkUOE(() -> {
1070 float o = (float) vh.getAndBitwiseAndAcquire(array, i, 1.0f);
1071 });
1072
1073 checkUOE(() -> {
1074 float o = (float) vh.getAndBitwiseAndRelease(array, i, 1.0f);
1075 });
1076
1077 checkUOE(() -> {
1078 float o = (float) vh.getAndBitwiseXor(array, i, 1.0f);
1079 });
1080
1081 checkUOE(() -> {
1082 float o = (float) vh.getAndBitwiseXorAcquire(array, i, 1.0f);
1083 });
1084
1085 checkUOE(() -> {
1086 float o = (float) vh.getAndBitwiseXorRelease(array, i, 1.0f);
1087 });
Paul Sandoz9fb30a32016-03-24 11:21:21 +01001088 }
1089
1090 static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
1091 float[] array = new float[10];
1092
1093 for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
1094 final int ci = i;
1095
1096 checkIOOBE(() -> {
1097 float x = (float) vh.get(array, ci);
1098 });
1099
1100 checkIOOBE(() -> {
1101 vh.set(array, ci, 1.0f);
1102 });
1103
1104 checkIOOBE(() -> {
1105 float x = (float) vh.getVolatile(array, ci);
1106 });
1107
1108 checkIOOBE(() -> {
1109 vh.setVolatile(array, ci, 1.0f);
1110 });
1111
1112 checkIOOBE(() -> {
1113 float x = (float) vh.getAcquire(array, ci);
1114 });
1115
1116 checkIOOBE(() -> {
1117 vh.setRelease(array, ci, 1.0f);
1118 });
1119
1120 checkIOOBE(() -> {
1121 float x = (float) vh.getOpaque(array, ci);
1122 });
1123
1124 checkIOOBE(() -> {
1125 vh.setOpaque(array, ci, 1.0f);
1126 });
1127
Paul Sandoz734dbe42016-06-20 17:57:19 +02001128 checkIOOBE(() -> {
1129 boolean r = vh.compareAndSet(array, ci, 1.0f, 2.0f);
1130 });
Paul Sandoz9fb30a32016-03-24 11:21:21 +01001131
Paul Sandoz734dbe42016-06-20 17:57:19 +02001132 checkIOOBE(() -> {
Paul Sandoz3f0273a2016-06-23 13:46:48 +02001133 float r = (float) vh.compareAndExchange(array, ci, 2.0f, 1.0f);
Paul Sandoz734dbe42016-06-20 17:57:19 +02001134 });
1135
1136 checkIOOBE(() -> {
1137 float r = (float) vh.compareAndExchangeAcquire(array, ci, 2.0f, 1.0f);
1138 });
1139
1140 checkIOOBE(() -> {
1141 float r = (float) vh.compareAndExchangeRelease(array, ci, 2.0f, 1.0f);
1142 });
1143
1144 checkIOOBE(() -> {
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -07001145 boolean r = vh.weakCompareAndSetPlain(array, ci, 1.0f, 2.0f);
Paul Sandoz734dbe42016-06-20 17:57:19 +02001146 });
1147
1148 checkIOOBE(() -> {
Paul Sandoz3bd5ebe2016-09-01 13:56:13 -07001149 boolean r = vh.weakCompareAndSet(array, ci, 1.0f, 2.0f);
Paul Sandoz734dbe42016-06-20 17:57:19 +02001150 });
1151
1152 checkIOOBE(() -> {
1153 boolean r = vh.weakCompareAndSetAcquire(array, ci, 1.0f, 2.0f);
1154 });
1155
1156 checkIOOBE(() -> {
1157 boolean r = vh.weakCompareAndSetRelease(array, ci, 1.0f, 2.0f);
1158 });
1159
1160 checkIOOBE(() -> {
1161 float o = (float) vh.getAndSet(array, ci, 1.0f);
1162 });
1163
1164 checkIOOBE(() -> {
Paul Sandoz82d48912016-09-01 10:16:57 -07001165 float o = (float) vh.getAndSetAcquire(array, ci, 1.0f);
Paul Sandoz734dbe42016-06-20 17:57:19 +02001166 });
1167
1168 checkIOOBE(() -> {
Paul Sandoz82d48912016-09-01 10:16:57 -07001169 float o = (float) vh.getAndSetRelease(array, ci, 1.0f);
Paul Sandoz734dbe42016-06-20 17:57:19 +02001170 });
Paul Sandoz82d48912016-09-01 10:16:57 -07001171
1172 checkIOOBE(() -> {
1173 float o = (float) vh.getAndAdd(array, ci, 1.0f);
1174 });
1175
1176 checkIOOBE(() -> {
1177 float o = (float) vh.getAndAddAcquire(array, ci, 1.0f);
1178 });
1179
1180 checkIOOBE(() -> {
1181 float o = (float) vh.getAndAddRelease(array, ci, 1.0f);
1182 });
1183
Paul Sandoz9fb30a32016-03-24 11:21:21 +01001184 }
1185 }
1186}
1187