1 /*
  2  * Copyright (c) 2015, 2021, 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 // -- This file was mechanically generated: Do not edit! -- //
 25 
 26 /*
 27  * @test
 28  * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessFloat
 29  */
 30 
 31 import org.testng.annotations.BeforeClass;
 32 import org.testng.annotations.DataProvider;
 33 import org.testng.annotations.Test;
 34 
 35 import java.lang.invoke.MethodHandles;
 36 import java.lang.invoke.VarHandle;
 37 import java.util.ArrayList;
 38 import java.util.Arrays;
 39 import java.util.List;
 40 
 41 import static org.testng.Assert.*;
 42 
 43 public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
 44     static final Class<?> type = float.class;
 45 
 46     static final float static_final_v = 1.0f;
 47 
 48     static float static_v;
 49 
 50     final float final_v = 1.0f;
 51 
 52     float v;
 53 
 54     VarHandle vhFinalField;
 55 
 56     VarHandle vhField;
 57 
 58     VarHandle vhStaticField;
 59 
 60     VarHandle vhStaticFinalField;
 61 
 62     VarHandle vhArray;
 63 
 64     VarHandle vhValueTypeField;
 65 
 66     @BeforeClass
 67     public void setup() throws Exception {
 68         vhFinalField = MethodHandles.lookup().findVarHandle(
 69                 VarHandleTestMethodHandleAccessFloat.class, "final_v", type);
 70 
 71         vhField = MethodHandles.lookup().findVarHandle(
 72                 VarHandleTestMethodHandleAccessFloat.class, "v", type);
 73 
 74         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
 75             VarHandleTestMethodHandleAccessFloat.class, "static_final_v", type);
 76 
 77         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
 78             VarHandleTestMethodHandleAccessFloat.class, "static_v", type);
 79 
 80         vhArray = MethodHandles.arrayElementVarHandle(float[].class);
 81 
 82         vhValueTypeField = MethodHandles.lookup().findVarHandle(
 83                     Value.class, "float_v", type);
 84     }
 85 
 86 
 87     @DataProvider
 88     public Object[][] accessTestCaseProvider() throws Exception {
 89         List<AccessTestCase<?>> cases = new ArrayList<>();
 90 
 91         for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
 92             cases.add(new MethodHandleAccessTestCase("Instance field",
 93                                                      vhField, f, hs -> testInstanceField(this, hs)));
 94             cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
 95                                                      vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
 96                                                      false));
 97 
 98             cases.add(new MethodHandleAccessTestCase("Static field",
 99                                                      vhStaticField, f, VarHandleTestMethodHandleAccessFloat::testStaticField));
100             cases.add(new MethodHandleAccessTestCase("Static field unsupported",
101                                                      vhStaticField, f, VarHandleTestMethodHandleAccessFloat::testStaticFieldUnsupported,
102                                                      false));
103 
104             cases.add(new MethodHandleAccessTestCase("Array",
105                                                      vhArray, f, VarHandleTestMethodHandleAccessFloat::testArray));
106             cases.add(new MethodHandleAccessTestCase("Array unsupported",
107                                                      vhArray, f, VarHandleTestMethodHandleAccessFloat::testArrayUnsupported,
108                                                      false));
109             cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
110                                                      vhArray, f, VarHandleTestMethodHandleAccessFloat::testArrayIndexOutOfBounds,
111                                                      false));
112         cases.add(new MethodHandleAccessTestCase("Value type field",
113                                                  vhValueTypeField, f, hs -> testValueTypeField(Value.getInstance(), hs)));
114         cases.add(new MethodHandleAccessTestCase("Value type field unsupported",
115                                                  vhValueTypeField, f, hs -> testValueTypeFieldUnsupported(Value.getInstance(), hs),
116                                                  false));
117         }
118 
119         // Work around issue with jtreg summary reporting which truncates
120         // the String result of Object.toString to 30 characters, hence
121         // the first dummy argument
122         return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
123     }
124 
125     @Test(dataProvider = "accessTestCaseProvider")
126     public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
127         T t = atc.get();
128         int iters = atc.requiresLoop() ? ITERS : 1;
129         for (int c = 0; c < iters; c++) {
130             atc.testAccess(t);
131         }
132     }
133 
134 
135     static void testInstanceField(VarHandleTestMethodHandleAccessFloat recv, Handles hs) throws Throwable {
136         // Plain
137         {
138             hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f);
139             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
140             assertEquals(x, 1.0f, "set float value");
141         }
142 
143 
144         // Volatile
145         {
146             hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 2.0f);
147             float x = (float) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
148             assertEquals(x, 2.0f, "setVolatile float value");
149         }
150 
151         // Lazy
152         {
153             hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 1.0f);
154             float x = (float) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
155             assertEquals(x, 1.0f, "setRelease float value");
156         }
157 
158         // Opaque
159         {
160             hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 2.0f);
161             float x = (float) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
162             assertEquals(x, 2.0f, "setOpaque float value");
163         }
164 
165         hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f);
166 
167         // Compare
168         {
169             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0f, 2.0f);
170             assertEquals(r, true, "success compareAndSet float");
171             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
172             assertEquals(x, 2.0f, "success compareAndSet float value");
173         }
174 
175         {
176             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0f, 3.0f);
177             assertEquals(r, false, "failing compareAndSet float");
178             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
179             assertEquals(x, 2.0f, "failing compareAndSet float value");
180         }
181 
182         {
183             float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0f, 1.0f);
184             assertEquals(r, 2.0f, "success compareAndExchange float");
185             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
186             assertEquals(x, 1.0f, "success compareAndExchange float value");
187         }
188 
189         {
190             float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0f, 3.0f);
191             assertEquals(r, 1.0f, "failing compareAndExchange float");
192             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
193             assertEquals(x, 1.0f, "failing compareAndExchange float value");
194         }
195 
196         {
197             float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0f, 2.0f);
198             assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
199             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
200             assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
201         }
202 
203         {
204             float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0f, 3.0f);
205             assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
206             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
207             assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
208         }
209 
210         {
211             float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0f, 1.0f);
212             assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
213             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
214             assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
215         }
216 
217         {
218             float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0f, 3.0f);
219             assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
220             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
221             assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
222         }
223 
224         {
225             boolean success = false;
226             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
227                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, 1.0f, 2.0f);
228             }
229             assertEquals(success, true, "weakCompareAndSetPlain float");
230             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
231             assertEquals(x, 2.0f, "weakCompareAndSetPlain float value");
232         }
233 
234         {
235             boolean success = false;
236             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
237                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 2.0f, 1.0f);
238             }
239             assertEquals(success, true, "weakCompareAndSetAcquire float");
240             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
241             assertEquals(x, 1.0f, "weakCompareAndSetAcquire float");
242         }
243 
244         {
245             boolean success = false;
246             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
247                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 1.0f, 2.0f);
248             }
249             assertEquals(success, true, "weakCompareAndSetRelease float");
250             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
251             assertEquals(x, 2.0f, "weakCompareAndSetRelease float");
252         }
253 
254         {
255             boolean success = false;
256             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
257                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 2.0f, 1.0f);
258             }
259             assertEquals(success, true, "weakCompareAndSet float");
260             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
261             assertEquals(x, 1.0f, "weakCompareAndSet float");
262         }
263 
264         // Compare set and get
265         {
266             float o = (float) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 2.0f);
267             assertEquals(o, 1.0f, "getAndSet float");
268             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
269             assertEquals(x, 2.0f, "getAndSet float value");
270         }
271 
272         // get and add, add and get
273         {
274             hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f);
275 
276             float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 2.0f);
277             assertEquals(o, 1.0f, "getAndAdd float");
278             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
279             assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
280         }
281 
282         {
283             hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f);
284 
285             float o = (float) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, 2.0f);
286             assertEquals(o, 1.0f, "getAndAddAcquire float");
287             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
288             assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
289         }
290 
291         {
292             hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f);
293 
294             float o = (float) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, 2.0f);
295             assertEquals(o, 1.0f, "getAndAddRelease float");
296             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
297             assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
298         }
299 
300     }
301 
302     static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessFloat recv, Handles hs) throws Throwable {
303 
304 
305         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
306             checkUOE(am, () -> {
307                 float r = (float) hs.get(am).invokeExact(recv, 1.0f);
308             });
309         }
310     }
311 
312     static void testValueTypeField(Value recv, Handles hs) throws Throwable {
313         // Plain
314         {
315             float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
316             assertEquals(x, 1.0f, "get float value");
317         }
318     }
319 
320     static void testValueTypeFieldUnsupported(Value recv, Handles hs) throws Throwable {
321         // Plain
322         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
323             checkUOE(am, () -> {
324                 hs.get(am).invokeExact(recv, 1.0f);
325             });
326         }
327 
328 
329         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
330             checkUOE(am, () -> {
331                 float r = (float) hs.get(am).invokeExact(recv, 1.0f);
332             });
333         }
334     }
335 
336     static void testStaticField(Handles hs) throws Throwable {
337         // Plain
338         {
339             hs.get(TestAccessMode.SET).invokeExact(1.0f);
340             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
341             assertEquals(x, 1.0f, "set float value");
342         }
343 
344 
345         // Volatile
346         {
347             hs.get(TestAccessMode.SET_VOLATILE).invokeExact(2.0f);
348             float x = (float) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
349             assertEquals(x, 2.0f, "setVolatile float value");
350         }
351 
352         // Lazy
353         {
354             hs.get(TestAccessMode.SET_RELEASE).invokeExact(1.0f);
355             float x = (float) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
356             assertEquals(x, 1.0f, "setRelease float value");
357         }
358 
359         // Opaque
360         {
361             hs.get(TestAccessMode.SET_OPAQUE).invokeExact(2.0f);
362             float x = (float) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
363             assertEquals(x, 2.0f, "setOpaque float value");
364         }
365 
366         hs.get(TestAccessMode.SET).invokeExact(1.0f);
367 
368         // Compare
369         {
370             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0f, 2.0f);
371             assertEquals(r, true, "success compareAndSet float");
372             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
373             assertEquals(x, 2.0f, "success compareAndSet float value");
374         }
375 
376         {
377             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0f, 3.0f);
378             assertEquals(r, false, "failing compareAndSet float");
379             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
380             assertEquals(x, 2.0f, "failing compareAndSet float value");
381         }
382 
383         {
384             float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0f, 1.0f);
385             assertEquals(r, 2.0f, "success compareAndExchange float");
386             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
387             assertEquals(x, 1.0f, "success compareAndExchange float value");
388         }
389 
390         {
391             float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0f, 3.0f);
392             assertEquals(r, 1.0f, "failing compareAndExchange float");
393             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
394             assertEquals(x, 1.0f, "failing compareAndExchange float value");
395         }
396 
397         {
398             float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0f, 2.0f);
399             assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
400             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
401             assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
402         }
403 
404         {
405             float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0f, 3.0f);
406             assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
407             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
408             assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
409         }
410 
411         {
412             float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0f, 1.0f);
413             assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
414             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
415             assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
416         }
417 
418         {
419             float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0f, 3.0f);
420             assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
421             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
422             assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
423         }
424 
425         {
426             boolean success = false;
427             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
428                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(1.0f, 2.0f);
429             }
430             assertEquals(success, true, "weakCompareAndSetPlain float");
431             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
432             assertEquals(x, 2.0f, "weakCompareAndSetPlain float value");
433         }
434 
435         {
436             boolean success = false;
437             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
438                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(2.0f, 1.0f);
439             }
440             assertEquals(success, true, "weakCompareAndSetAcquire float");
441             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
442             assertEquals(x, 1.0f, "weakCompareAndSetAcquire float");
443         }
444 
445         {
446             boolean success = false;
447             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
448                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(1.0f, 2.0f);
449             }
450             assertEquals(success, true, "weakCompareAndSetRelease float");
451             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
452             assertEquals(x, 2.0f, "weakCompareAndSetRelease float");
453         }
454 
455         {
456             boolean success = false;
457             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
458                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(2.0f, 1.0f);
459             }
460             assertEquals(success, true, "weakCompareAndSet float");
461             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
462             assertEquals(x, 1.0f, "weakCompareAndSet float");
463         }
464 
465         // Compare set and get
466         {
467             hs.get(TestAccessMode.SET).invokeExact(1.0f);
468 
469             float o = (float) hs.get(TestAccessMode.GET_AND_SET).invokeExact(2.0f);
470             assertEquals(o, 1.0f, "getAndSet float");
471             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
472             assertEquals(x, 2.0f, "getAndSet float value");
473         }
474 
475         // Compare set and get
476         {
477             hs.get(TestAccessMode.SET).invokeExact(1.0f);
478 
479             float o = (float) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(2.0f);
480             assertEquals(o, 1.0f, "getAndSetAcquire float");
481             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
482             assertEquals(x, 2.0f, "getAndSetAcquire float value");
483         }
484 
485         // Compare set and get
486         {
487             hs.get(TestAccessMode.SET).invokeExact(1.0f);
488 
489             float o = (float) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(2.0f);
490             assertEquals(o, 1.0f, "getAndSetRelease float");
491             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
492             assertEquals(x, 2.0f, "getAndSetRelease float value");
493         }
494 
495         // get and add, add and get
496         {
497             hs.get(TestAccessMode.SET).invokeExact(1.0f);
498 
499             float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(2.0f);
500             assertEquals(o, 1.0f, "getAndAdd float");
501             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
502             assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
503         }
504 
505         {
506             hs.get(TestAccessMode.SET).invokeExact(1.0f);
507 
508             float o = (float) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(2.0f);
509             assertEquals(o, 1.0f, "getAndAddAcquire float");
510             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
511             assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
512         }
513 
514         {
515             hs.get(TestAccessMode.SET).invokeExact(1.0f);
516 
517             float o = (float) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(2.0f);
518             assertEquals(o, 1.0f, "getAndAddRelease float");
519             float x = (float) hs.get(TestAccessMode.GET).invokeExact();
520             assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
521         }
522 
523     }
524 
525     static void testStaticFieldUnsupported(Handles hs) throws Throwable {
526 
527 
528         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
529             checkUOE(am, () -> {
530                 float r = (float) hs.get(am).invokeExact(1.0f);
531             });
532         }
533     }
534 
535 
536     static void testArray(Handles hs) throws Throwable {
537         float[] array = new float[10];
538 
539         for (int i = 0; i < array.length; i++) {
540             // Plain
541             {
542                 hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
543                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
544                 assertEquals(x, 1.0f, "get float value");
545             }
546 
547 
548             // Volatile
549             {
550                 hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 2.0f);
551                 float x = (float) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
552                 assertEquals(x, 2.0f, "setVolatile float value");
553             }
554 
555             // Lazy
556             {
557                 hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 1.0f);
558                 float x = (float) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
559                 assertEquals(x, 1.0f, "setRelease float value");
560             }
561 
562             // Opaque
563             {
564                 hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 2.0f);
565                 float x = (float) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
566                 assertEquals(x, 2.0f, "setOpaque float value");
567             }
568 
569             hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
570 
571             // Compare
572             {
573                 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0f, 2.0f);
574                 assertEquals(r, true, "success compareAndSet float");
575                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
576                 assertEquals(x, 2.0f, "success compareAndSet float value");
577             }
578 
579             {
580                 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0f, 3.0f);
581                 assertEquals(r, false, "failing compareAndSet float");
582                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
583                 assertEquals(x, 2.0f, "failing compareAndSet float value");
584             }
585 
586             {
587                 float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0f, 1.0f);
588                 assertEquals(r, 2.0f, "success compareAndExchange float");
589                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
590                 assertEquals(x, 1.0f, "success compareAndExchange float value");
591             }
592 
593             {
594                 float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0f, 3.0f);
595                 assertEquals(r, 1.0f, "failing compareAndExchange float");
596                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
597                 assertEquals(x, 1.0f, "failing compareAndExchange float value");
598             }
599 
600             {
601                 float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0f, 2.0f);
602                 assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
603                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
604                 assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
605             }
606 
607             {
608                 float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0f, 3.0f);
609                 assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
610                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
611                 assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
612             }
613 
614             {
615                 float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0f, 1.0f);
616                 assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
617                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
618                 assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
619             }
620 
621             {
622                 float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0f, 3.0f);
623                 assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
624                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
625                 assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
626             }
627 
628             {
629                 boolean success = false;
630                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
631                     success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, 1.0f, 2.0f);
632                 }
633                 assertEquals(success, true, "weakCompareAndSetPlain float");
634                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
635                 assertEquals(x, 2.0f, "weakCompareAndSetPlain float value");
636             }
637 
638             {
639                 boolean success = false;
640                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
641                     success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 2.0f, 1.0f);
642                 }
643                 assertEquals(success, true, "weakCompareAndSetAcquire float");
644                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
645                 assertEquals(x, 1.0f, "weakCompareAndSetAcquire float");
646             }
647 
648             {
649                 boolean success = false;
650                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
651                     success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, 1.0f, 2.0f);
652                 }
653                 assertEquals(success, true, "weakCompareAndSetRelease float");
654                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
655                 assertEquals(x, 2.0f, "weakCompareAndSetRelease float");
656             }
657 
658             {
659                 boolean success = false;
660                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
661                     success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 2.0f, 1.0f);
662                 }
663                 assertEquals(success, true, "weakCompareAndSet float");
664                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
665                 assertEquals(x, 1.0f, "weakCompareAndSet float");
666             }
667 
668             // Compare set and get
669             {
670                 hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
671 
672                 float o = (float) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 2.0f);
673                 assertEquals(o, 1.0f, "getAndSet float");
674                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
675                 assertEquals(x, 2.0f, "getAndSet float value");
676             }
677 
678             {
679                 hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
680 
681                 float o = (float) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, 2.0f);
682                 assertEquals(o, 1.0f, "getAndSetAcquire float");
683                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
684                 assertEquals(x, 2.0f, "getAndSetAcquire float value");
685             }
686 
687             {
688                 hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
689 
690                 float o = (float) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, 2.0f);
691                 assertEquals(o, 1.0f, "getAndSetRelease float");
692                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
693                 assertEquals(x, 2.0f, "getAndSetRelease float value");
694             }
695 
696             // get and add, add and get
697             {
698                 hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
699 
700                 float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 2.0f);
701                 assertEquals(o, 1.0f, "getAndAdd float");
702                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
703                 assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
704             }
705 
706             {
707                 hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
708 
709                 float o = (float) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, 2.0f);
710                 assertEquals(o, 1.0f, "getAndAddAcquire float");
711                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
712                 assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
713             }
714 
715             {
716                 hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
717 
718                 float o = (float) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, 2.0f);
719                 assertEquals(o, 1.0f, "getAndAddRelease float");
720                 float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
721                 assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
722             }
723 
724         }
725     }
726 
727     static void testArrayUnsupported(Handles hs) throws Throwable {
728         float[] array = new float[10];
729 
730         final int i = 0;
731 
732 
733         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
734             checkUOE(am, () -> {
735                 float o = (float) hs.get(am).invokeExact(array, i, 1.0f);
736             });
737         }
738     }
739 
740     static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
741         float[] array = new float[10];
742 
743         for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
744             final int ci = i;
745 
746             for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
747                 checkAIOOBE(am, () -> {
748                     float x = (float) hs.get(am).invokeExact(array, ci);
749                 });
750             }
751 
752             for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
753                 checkAIOOBE(am, () -> {
754                     hs.get(am).invokeExact(array, ci, 1.0f);
755                 });
756             }
757 
758             for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
759                 checkAIOOBE(am, () -> {
760                     boolean r = (boolean) hs.get(am).invokeExact(array, ci, 1.0f, 2.0f);
761                 });
762             }
763 
764             for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
765                 checkAIOOBE(am, () -> {
766                     float r = (float) hs.get(am).invokeExact(array, ci, 2.0f, 1.0f);
767                 });
768             }
769 
770             for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
771                 checkAIOOBE(am, () -> {
772                     float o = (float) hs.get(am).invokeExact(array, ci, 1.0f);
773                 });
774             }
775 
776             for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
777                 checkAIOOBE(am, () -> {
778                     float o = (float) hs.get(am).invokeExact(array, ci, 3.0f);
779                 });
780             }
781 
782         }
783     }
784 }
785