1/*
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// Android-added: package for test.
25package test.java.lang.invoke.VarHandles;
26
27/*
28 * @test
29 * @run testng/othervm -Diters=10    -Xint                   VarHandleTestAccess$Type$
30 * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccess$Type$
31 * @run testng/othervm -Diters=20000                         VarHandleTestAccess$Type$
32 * @run testng/othervm -Diters=20000 -XX:-TieredCompilation  VarHandleTestAccess$Type$
33 */
34
35import org.testng.annotations.BeforeClass;
36import org.testng.annotations.DataProvider;
37import org.testng.annotations.Test;
38
39import java.lang.invoke.MethodHandles;
40import java.lang.invoke.VarHandle;
41import java.util.ArrayList;
42import java.util.Arrays;
43import java.util.List;
44
45import static org.testng.Assert.*;
46
47public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
48    static final $type$ static_final_v = $value1$;
49
50    static $type$ static_v;
51
52    final $type$ final_v = $value1$;
53
54    $type$ v;
55
56    VarHandle vhFinalField;
57
58    VarHandle vhField;
59
60    VarHandle vhStaticField;
61
62    VarHandle vhStaticFinalField;
63
64    VarHandle vhArray;
65
66#if[String]
67    VarHandle vhArrayObject;
68#end[String]
69
70    @BeforeClass
71    public void setup() throws Exception {
72        vhFinalField = MethodHandles.lookup().findVarHandle(
73                VarHandleTestAccess$Type$.class, "final_v", $type$.class);
74
75        vhField = MethodHandles.lookup().findVarHandle(
76                VarHandleTestAccess$Type$.class, "v", $type$.class);
77
78        vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
79            VarHandleTestAccess$Type$.class, "static_final_v", $type$.class);
80
81        vhStaticField = MethodHandles.lookup().findStaticVarHandle(
82            VarHandleTestAccess$Type$.class, "static_v", $type$.class);
83
84        vhArray = MethodHandles.arrayElementVarHandle($type$[].class);
85#if[String]
86        vhArrayObject = MethodHandles.arrayElementVarHandle(Object[].class);
87#end[String]
88    }
89
90
91    @DataProvider
92    public Object[][] varHandlesProvider() throws Exception {
93        List<VarHandle> vhs = new ArrayList<>();
94        vhs.add(vhField);
95        vhs.add(vhStaticField);
96        vhs.add(vhArray);
97
98        return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
99    }
100
101    @Test(dataProvider = "varHandlesProvider")
102    public void testIsAccessModeSupported(VarHandle vh) {
103        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
104        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
105        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
106        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
107        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
108        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
109        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
110        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
111
112#if[CAS]
113        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
114        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
115        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
116        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
117        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
118        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
119        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
120        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
121        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
122        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
123        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
124#else[CAS]
125        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
126        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
127        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
128        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
129        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
130        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
131        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
132        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
133        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
134        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
135        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
136#end[CAS]
137
138#if[AtomicAdd]
139        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
140        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
141        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
142#else[AtomicAdd]
143        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
144        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
145        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
146#end[AtomicAdd]
147
148#if[Bitwise]
149        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
150        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
151        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
152        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
153        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
154        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
155        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
156        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
157        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
158#else[Bitwise]
159        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
160        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
161        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
162        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
163        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
164        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
165        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
166        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
167        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
168#end[Bitwise]
169    }
170
171
172    @DataProvider
173    public Object[][] typesProvider() throws Exception {
174        List<Object[]> types = new ArrayList<>();
175        types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccess$Type$.class)});
176        types.add(new Object[] {vhStaticField, Arrays.asList()});
177        types.add(new Object[] {vhArray, Arrays.asList($type$[].class, int.class)});
178
179        return types.stream().toArray(Object[][]::new);
180    }
181
182    @Test(dataProvider = "typesProvider")
183    public void testTypes(VarHandle vh, List<Class<?>> pts) {
184        assertEquals(vh.varType(), $type$.class);
185
186        assertEquals(vh.coordinateTypes(), pts);
187
188        testTypes(vh);
189    }
190
191
192    @Test
193    public void testLookupInstanceToStatic() {
194        checkIAE("Lookup of static final field to instance final field", () -> {
195            MethodHandles.lookup().findStaticVarHandle(
196                    VarHandleTestAccess$Type$.class, "final_v", $type$.class);
197        });
198
199        checkIAE("Lookup of static field to instance field", () -> {
200            MethodHandles.lookup().findStaticVarHandle(
201                    VarHandleTestAccess$Type$.class, "v", $type$.class);
202        });
203    }
204
205    @Test
206    public void testLookupStaticToInstance() {
207        checkIAE("Lookup of instance final field to static final field", () -> {
208            MethodHandles.lookup().findVarHandle(
209                VarHandleTestAccess$Type$.class, "static_final_v", $type$.class);
210        });
211
212        checkIAE("Lookup of instance field to static field", () -> {
213            vhStaticField = MethodHandles.lookup().findVarHandle(
214                VarHandleTestAccess$Type$.class, "static_v", $type$.class);
215        });
216    }
217
218
219    @DataProvider
220    public Object[][] accessTestCaseProvider() throws Exception {
221        List<AccessTestCase<?>> cases = new ArrayList<>();
222
223        cases.add(new VarHandleAccessTestCase("Instance final field",
224                                              vhFinalField, vh -> testInstanceFinalField(this, vh)));
225        cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
226                                              vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
227                                              false));
228
229        cases.add(new VarHandleAccessTestCase("Static final field",
230                                              vhStaticFinalField, VarHandleTestAccess$Type$::testStaticFinalField));
231        cases.add(new VarHandleAccessTestCase("Static final field unsupported",
232                                              vhStaticFinalField, VarHandleTestAccess$Type$::testStaticFinalFieldUnsupported,
233                                              false));
234
235        cases.add(new VarHandleAccessTestCase("Instance field",
236                                              vhField, vh -> testInstanceField(this, vh)));
237        cases.add(new VarHandleAccessTestCase("Instance field unsupported",
238                                              vhField, vh -> testInstanceFieldUnsupported(this, vh),
239                                              false));
240
241        cases.add(new VarHandleAccessTestCase("Static field",
242                                              vhStaticField, VarHandleTestAccess$Type$::testStaticField));
243        cases.add(new VarHandleAccessTestCase("Static field unsupported",
244                                              vhStaticField, VarHandleTestAccess$Type$::testStaticFieldUnsupported,
245                                              false));
246
247        cases.add(new VarHandleAccessTestCase("Array",
248                                              vhArray, VarHandleTestAccess$Type$::testArray));
249#if[String]
250        cases.add(new VarHandleAccessTestCase("Array Object[]",
251                                              vhArrayObject, VarHandleTestAccess$Type$::testArray));
252#end[String]
253        cases.add(new VarHandleAccessTestCase("Array unsupported",
254                                              vhArray, VarHandleTestAccess$Type$::testArrayUnsupported,
255                                              false));
256        cases.add(new VarHandleAccessTestCase("Array index out of bounds",
257                                              vhArray, VarHandleTestAccess$Type$::testArrayIndexOutOfBounds,
258                                              false));
259#if[String]
260        cases.add(new VarHandleAccessTestCase("Array store exception",
261                                              vhArrayObject, VarHandleTestAccess$Type$::testArrayStoreException,
262                                              false));
263#end[String]
264        // Work around issue with jtreg summary reporting which truncates
265        // the String result of Object.toString to 30 characters, hence
266        // the first dummy argument
267        return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
268    }
269
270    @Test(dataProvider = "accessTestCaseProvider")
271    public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
272        T t = atc.get();
273        int iters = atc.requiresLoop() ? ITERS : 1;
274        for (int c = 0; c < iters; c++) {
275            atc.testAccess(t);
276        }
277    }
278
279
280
281
282    static void testInstanceFinalField(VarHandleTestAccess$Type$ recv, VarHandle vh) {
283        // Plain
284        {
285            $type$ x = ($type$) vh.get(recv);
286            assertEquals(x, $value1$, "get $type$ value");
287        }
288
289
290        // Volatile
291        {
292            $type$ x = ($type$) vh.getVolatile(recv);
293            assertEquals(x, $value1$, "getVolatile $type$ value");
294        }
295
296        // Lazy
297        {
298            $type$ x = ($type$) vh.getAcquire(recv);
299            assertEquals(x, $value1$, "getRelease $type$ value");
300        }
301
302        // Opaque
303        {
304            $type$ x = ($type$) vh.getOpaque(recv);
305            assertEquals(x, $value1$, "getOpaque $type$ value");
306        }
307    }
308
309    static void testInstanceFinalFieldUnsupported(VarHandleTestAccess$Type$ recv, VarHandle vh) {
310        checkUOE(() -> {
311            vh.set(recv, $value2$);
312        });
313
314        checkUOE(() -> {
315            vh.setVolatile(recv, $value2$);
316        });
317
318        checkUOE(() -> {
319            vh.setRelease(recv, $value2$);
320        });
321
322        checkUOE(() -> {
323            vh.setOpaque(recv, $value2$);
324        });
325
326#if[!CAS]
327        checkUOE(() -> {
328            boolean r = vh.compareAndSet(recv, $value1$, $value2$);
329        });
330
331        checkUOE(() -> {
332            $type$ r = ($type$) vh.compareAndExchange(recv, $value1$, $value2$);
333        });
334
335        checkUOE(() -> {
336            $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value2$);
337        });
338
339        checkUOE(() -> {
340            $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value1$, $value2$);
341        });
342
343        checkUOE(() -> {
344            boolean r = vh.weakCompareAndSetPlain(recv, $value1$, $value2$);
345        });
346
347        checkUOE(() -> {
348            boolean r = vh.weakCompareAndSet(recv, $value1$, $value2$);
349        });
350
351        checkUOE(() -> {
352            boolean r = vh.weakCompareAndSetAcquire(recv, $value1$, $value2$);
353        });
354
355        checkUOE(() -> {
356            boolean r = vh.weakCompareAndSetRelease(recv, $value1$, $value2$);
357        });
358
359        checkUOE(() -> {
360            $type$ r = ($type$) vh.getAndSet(recv, $value1$);
361        });
362
363        checkUOE(() -> {
364            $type$ r = ($type$) vh.getAndSetAcquire(recv, $value1$);
365        });
366
367        checkUOE(() -> {
368            $type$ r = ($type$) vh.getAndSetRelease(recv, $value1$);
369        });
370#end[CAS]
371
372#if[!AtomicAdd]
373        checkUOE(() -> {
374            $type$ o = ($type$) vh.getAndAdd(recv, $value1$);
375        });
376
377        checkUOE(() -> {
378            $type$ o = ($type$) vh.getAndAddAcquire(recv, $value1$);
379        });
380
381        checkUOE(() -> {
382            $type$ o = ($type$) vh.getAndAddRelease(recv, $value1$);
383        });
384#end[AtomicAdd]
385
386#if[!Bitwise]
387        checkUOE(() -> {
388            $type$ o = ($type$) vh.getAndBitwiseOr(recv, $value1$);
389        });
390
391        checkUOE(() -> {
392            $type$ o = ($type$) vh.getAndBitwiseOrAcquire(recv, $value1$);
393        });
394
395        checkUOE(() -> {
396            $type$ o = ($type$) vh.getAndBitwiseOrRelease(recv, $value1$);
397        });
398
399        checkUOE(() -> {
400            $type$ o = ($type$) vh.getAndBitwiseAnd(recv, $value1$);
401        });
402
403        checkUOE(() -> {
404            $type$ o = ($type$) vh.getAndBitwiseAndAcquire(recv, $value1$);
405        });
406
407        checkUOE(() -> {
408            $type$ o = ($type$) vh.getAndBitwiseAndRelease(recv, $value1$);
409        });
410
411        checkUOE(() -> {
412            $type$ o = ($type$) vh.getAndBitwiseXor(recv, $value1$);
413        });
414
415        checkUOE(() -> {
416            $type$ o = ($type$) vh.getAndBitwiseXorAcquire(recv, $value1$);
417        });
418
419        checkUOE(() -> {
420            $type$ o = ($type$) vh.getAndBitwiseXorRelease(recv, $value1$);
421        });
422#end[Bitwise]
423    }
424
425
426    static void testStaticFinalField(VarHandle vh) {
427        // Plain
428        {
429            $type$ x = ($type$) vh.get();
430            assertEquals(x, $value1$, "get $type$ value");
431        }
432
433
434        // Volatile
435        {
436            $type$ x = ($type$) vh.getVolatile();
437            assertEquals(x, $value1$, "getVolatile $type$ value");
438        }
439
440        // Lazy
441        {
442            $type$ x = ($type$) vh.getAcquire();
443            assertEquals(x, $value1$, "getRelease $type$ value");
444        }
445
446        // Opaque
447        {
448            $type$ x = ($type$) vh.getOpaque();
449            assertEquals(x, $value1$, "getOpaque $type$ value");
450        }
451    }
452
453    static void testStaticFinalFieldUnsupported(VarHandle vh) {
454        checkUOE(() -> {
455            vh.set($value2$);
456        });
457
458        checkUOE(() -> {
459            vh.setVolatile($value2$);
460        });
461
462        checkUOE(() -> {
463            vh.setRelease($value2$);
464        });
465
466        checkUOE(() -> {
467            vh.setOpaque($value2$);
468        });
469
470#if[!CAS]
471        checkUOE(() -> {
472            boolean r = vh.compareAndSet($value1$, $value2$);
473        });
474
475        checkUOE(() -> {
476            $type$ r = ($type$) vh.compareAndExchange($value1$, $value2$);
477        });
478
479        checkUOE(() -> {
480            $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value2$);
481        });
482
483        checkUOE(() -> {
484            $type$ r = ($type$) vh.compareAndExchangeRelease($value1$, $value2$);
485        });
486
487        checkUOE(() -> {
488            boolean r = vh.weakCompareAndSetPlain($value1$, $value2$);
489        });
490
491        checkUOE(() -> {
492            boolean r = vh.weakCompareAndSet($value1$, $value2$);
493        });
494
495        checkUOE(() -> {
496            boolean r = vh.weakCompareAndSetAcquire($value1$, $value2$);
497        });
498
499        checkUOE(() -> {
500            boolean r = vh.weakCompareAndSetRelease($value1$, $value2$);
501        });
502
503        checkUOE(() -> {
504            $type$ r = ($type$) vh.getAndSet($value1$);
505        });
506
507        checkUOE(() -> {
508            $type$ r = ($type$) vh.getAndSetAcquire($value1$);
509        });
510
511        checkUOE(() -> {
512            $type$ r = ($type$) vh.getAndSetRelease($value1$);
513        });
514#end[CAS]
515
516#if[!AtomicAdd]
517        checkUOE(() -> {
518            $type$ o = ($type$) vh.getAndAdd($value1$);
519        });
520
521        checkUOE(() -> {
522            $type$ o = ($type$) vh.getAndAddAcquire($value1$);
523        });
524
525        checkUOE(() -> {
526            $type$ o = ($type$) vh.getAndAddRelease($value1$);
527        });
528#end[AtomicAdd]
529
530#if[!Bitwise]
531        checkUOE(() -> {
532            $type$ o = ($type$) vh.getAndBitwiseOr($value1$);
533        });
534
535        checkUOE(() -> {
536            $type$ o = ($type$) vh.getAndBitwiseOrAcquire($value1$);
537        });
538
539        checkUOE(() -> {
540            $type$ o = ($type$) vh.getAndBitwiseOrRelease($value1$);
541        });
542
543        checkUOE(() -> {
544            $type$ o = ($type$) vh.getAndBitwiseAnd($value1$);
545        });
546
547        checkUOE(() -> {
548            $type$ o = ($type$) vh.getAndBitwiseAndAcquire($value1$);
549        });
550
551        checkUOE(() -> {
552            $type$ o = ($type$) vh.getAndBitwiseAndRelease($value1$);
553        });
554
555        checkUOE(() -> {
556            $type$ o = ($type$) vh.getAndBitwiseXor($value1$);
557        });
558
559        checkUOE(() -> {
560            $type$ o = ($type$) vh.getAndBitwiseXorAcquire($value1$);
561        });
562
563        checkUOE(() -> {
564            $type$ o = ($type$) vh.getAndBitwiseXorRelease($value1$);
565        });
566#end[Bitwise]
567    }
568
569
570    static void testInstanceField(VarHandleTestAccess$Type$ recv, VarHandle vh) {
571        // Plain
572        {
573            vh.set(recv, $value1$);
574            $type$ x = ($type$) vh.get(recv);
575            assertEquals(x, $value1$, "set $type$ value");
576        }
577
578
579        // Volatile
580        {
581            vh.setVolatile(recv, $value2$);
582            $type$ x = ($type$) vh.getVolatile(recv);
583            assertEquals(x, $value2$, "setVolatile $type$ value");
584        }
585
586        // Lazy
587        {
588            vh.setRelease(recv, $value1$);
589            $type$ x = ($type$) vh.getAcquire(recv);
590            assertEquals(x, $value1$, "setRelease $type$ value");
591        }
592
593        // Opaque
594        {
595            vh.setOpaque(recv, $value2$);
596            $type$ x = ($type$) vh.getOpaque(recv);
597            assertEquals(x, $value2$, "setOpaque $type$ value");
598        }
599
600#if[CAS]
601        vh.set(recv, $value1$);
602
603        // Compare
604        {
605            boolean r = vh.compareAndSet(recv, $value1$, $value2$);
606            assertEquals(r, true, "success compareAndSet $type$");
607            $type$ x = ($type$) vh.get(recv);
608            assertEquals(x, $value2$, "success compareAndSet $type$ value");
609        }
610
611        {
612            boolean r = vh.compareAndSet(recv, $value1$, $value3$);
613            assertEquals(r, false, "failing compareAndSet $type$");
614            $type$ x = ($type$) vh.get(recv);
615            assertEquals(x, $value2$, "failing compareAndSet $type$ value");
616        }
617
618        {
619            $type$ r = ($type$) vh.compareAndExchange(recv, $value2$, $value1$);
620            assertEquals(r, $value2$, "success compareAndExchange $type$");
621            $type$ x = ($type$) vh.get(recv);
622            assertEquals(x, $value1$, "success compareAndExchange $type$ value");
623        }
624
625        {
626            $type$ r = ($type$) vh.compareAndExchange(recv, $value2$, $value3$);
627            assertEquals(r, $value1$, "failing compareAndExchange $type$");
628            $type$ x = ($type$) vh.get(recv);
629            assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
630        }
631
632        {
633            $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value2$);
634            assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
635            $type$ x = ($type$) vh.get(recv);
636            assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
637        }
638
639        {
640            $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value3$);
641            assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
642            $type$ x = ($type$) vh.get(recv);
643            assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
644        }
645
646        {
647            $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value2$, $value1$);
648            assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
649            $type$ x = ($type$) vh.get(recv);
650            assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
651        }
652
653        {
654            $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value2$, $value3$);
655            assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
656            $type$ x = ($type$) vh.get(recv);
657            assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
658        }
659
660        {
661            boolean success = false;
662            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
663                success = vh.weakCompareAndSetPlain(recv, $value1$, $value2$);
664            }
665            assertEquals(success, true, "weakCompareAndSetPlain $type$");
666            $type$ x = ($type$) vh.get(recv);
667            assertEquals(x, $value2$, "weakCompareAndSetPlain $type$ value");
668        }
669
670        {
671            boolean success = false;
672            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
673                success = vh.weakCompareAndSetAcquire(recv, $value2$, $value1$);
674            }
675            assertEquals(success, true, "weakCompareAndSetAcquire $type$");
676            $type$ x = ($type$) vh.get(recv);
677            assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
678        }
679
680        {
681            boolean success = false;
682            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
683                success = vh.weakCompareAndSetRelease(recv, $value1$, $value2$);
684            }
685            assertEquals(success, true, "weakCompareAndSetRelease $type$");
686            $type$ x = ($type$) vh.get(recv);
687            assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
688        }
689
690        {
691            boolean success = false;
692            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
693                success = vh.weakCompareAndSet(recv, $value2$, $value1$);
694            }
695            assertEquals(success, true, "weakCompareAndSet $type$");
696            $type$ x = ($type$) vh.get(recv);
697            assertEquals(x, $value1$, "weakCompareAndSet $type$ value");
698        }
699
700        // Compare set and get
701        {
702            vh.set(recv, $value1$);
703
704            $type$ o = ($type$) vh.getAndSet(recv, $value2$);
705            assertEquals(o, $value1$, "getAndSet $type$");
706            $type$ x = ($type$) vh.get(recv);
707            assertEquals(x, $value2$, "getAndSet $type$ value");
708        }
709
710        {
711            vh.set(recv, $value1$);
712
713            $type$ o = ($type$) vh.getAndSetAcquire(recv, $value2$);
714            assertEquals(o, $value1$, "getAndSetAcquire $type$");
715            $type$ x = ($type$) vh.get(recv);
716            assertEquals(x, $value2$, "getAndSetAcquire $type$ value");
717        }
718
719        {
720            vh.set(recv, $value1$);
721
722            $type$ o = ($type$) vh.getAndSetRelease(recv, $value2$);
723            assertEquals(o, $value1$, "getAndSetRelease $type$");
724            $type$ x = ($type$) vh.get(recv);
725            assertEquals(x, $value2$, "getAndSetRelease $type$ value");
726        }
727#end[CAS]
728
729#if[AtomicAdd]
730        // get and add, add and get
731        {
732            vh.set(recv, $value1$);
733
734            $type$ o = ($type$) vh.getAndAdd(recv, $value2$);
735            assertEquals(o, $value1$, "getAndAdd $type$");
736            $type$ x = ($type$) vh.get(recv);
737            assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value");
738        }
739
740        {
741            vh.set(recv, $value1$);
742
743            $type$ o = ($type$) vh.getAndAddAcquire(recv, $value2$);
744            assertEquals(o, $value1$, "getAndAddAcquire $type$");
745            $type$ x = ($type$) vh.get(recv);
746            assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value");
747        }
748
749        {
750            vh.set(recv, $value1$);
751
752            $type$ o = ($type$) vh.getAndAddRelease(recv, $value2$);
753            assertEquals(o, $value1$, "getAndAddRelease$type$");
754            $type$ x = ($type$) vh.get(recv);
755            assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value");
756        }
757#end[AtomicAdd]
758
759#if[Bitwise]
760        // get and bitwise or
761        {
762            vh.set(recv, $value1$);
763
764            $type$ o = ($type$) vh.getAndBitwiseOr(recv, $value2$);
765            assertEquals(o, $value1$, "getAndBitwiseOr $type$");
766            $type$ x = ($type$) vh.get(recv);
767            assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value");
768        }
769
770        {
771            vh.set(recv, $value1$);
772
773            $type$ o = ($type$) vh.getAndBitwiseOrAcquire(recv, $value2$);
774            assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$");
775            $type$ x = ($type$) vh.get(recv);
776            assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value");
777        }
778
779        {
780            vh.set(recv, $value1$);
781
782            $type$ o = ($type$) vh.getAndBitwiseOrRelease(recv, $value2$);
783            assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$");
784            $type$ x = ($type$) vh.get(recv);
785            assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value");
786        }
787
788        // get and bitwise and
789        {
790            vh.set(recv, $value1$);
791
792            $type$ o = ($type$) vh.getAndBitwiseAnd(recv, $value2$);
793            assertEquals(o, $value1$, "getAndBitwiseAnd $type$");
794            $type$ x = ($type$) vh.get(recv);
795            assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value");
796        }
797
798        {
799            vh.set(recv, $value1$);
800
801            $type$ o = ($type$) vh.getAndBitwiseAndAcquire(recv, $value2$);
802            assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$");
803            $type$ x = ($type$) vh.get(recv);
804            assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value");
805        }
806
807        {
808            vh.set(recv, $value1$);
809
810            $type$ o = ($type$) vh.getAndBitwiseAndRelease(recv, $value2$);
811            assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$");
812            $type$ x = ($type$) vh.get(recv);
813            assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value");
814        }
815
816        // get and bitwise xor
817        {
818            vh.set(recv, $value1$);
819
820            $type$ o = ($type$) vh.getAndBitwiseXor(recv, $value2$);
821            assertEquals(o, $value1$, "getAndBitwiseXor $type$");
822            $type$ x = ($type$) vh.get(recv);
823            assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value");
824        }
825
826        {
827            vh.set(recv, $value1$);
828
829            $type$ o = ($type$) vh.getAndBitwiseXorAcquire(recv, $value2$);
830            assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$");
831            $type$ x = ($type$) vh.get(recv);
832            assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value");
833        }
834
835        {
836            vh.set(recv, $value1$);
837
838            $type$ o = ($type$) vh.getAndBitwiseXorRelease(recv, $value2$);
839            assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$");
840            $type$ x = ($type$) vh.get(recv);
841            assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value");
842        }
843#end[Bitwise]
844    }
845
846    static void testInstanceFieldUnsupported(VarHandleTestAccess$Type$ recv, VarHandle vh) {
847#if[!CAS]
848        checkUOE(() -> {
849            boolean r = vh.compareAndSet(recv, $value1$, $value2$);
850        });
851
852        checkUOE(() -> {
853            $type$ r = ($type$) vh.compareAndExchange(recv, $value1$, $value2$);
854        });
855
856        checkUOE(() -> {
857            $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value2$);
858        });
859
860        checkUOE(() -> {
861            $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value1$, $value2$);
862        });
863
864        checkUOE(() -> {
865            boolean r = vh.weakCompareAndSetPlain(recv, $value1$, $value2$);
866        });
867
868        checkUOE(() -> {
869            boolean r = vh.weakCompareAndSet(recv, $value1$, $value2$);
870        });
871
872        checkUOE(() -> {
873            boolean r = vh.weakCompareAndSetAcquire(recv, $value1$, $value2$);
874        });
875
876        checkUOE(() -> {
877            boolean r = vh.weakCompareAndSetRelease(recv, $value1$, $value2$);
878        });
879
880        checkUOE(() -> {
881            $type$ r = ($type$) vh.getAndSet(recv, $value1$);
882        });
883
884        checkUOE(() -> {
885            $type$ r = ($type$) vh.getAndSetAcquire(recv, $value1$);
886        });
887
888        checkUOE(() -> {
889            $type$ r = ($type$) vh.getAndSetRelease(recv, $value1$);
890        });
891#end[CAS]
892
893#if[!AtomicAdd]
894        checkUOE(() -> {
895            $type$ o = ($type$) vh.getAndAdd(recv, $value1$);
896        });
897
898        checkUOE(() -> {
899            $type$ o = ($type$) vh.getAndAddAcquire(recv, $value1$);
900        });
901
902        checkUOE(() -> {
903            $type$ o = ($type$) vh.getAndAddRelease(recv, $value1$);
904        });
905#end[AtomicAdd]
906
907#if[!Bitwise]
908        checkUOE(() -> {
909            $type$ o = ($type$) vh.getAndBitwiseOr(recv, $value1$);
910        });
911
912        checkUOE(() -> {
913            $type$ o = ($type$) vh.getAndBitwiseOrAcquire(recv, $value1$);
914        });
915
916        checkUOE(() -> {
917            $type$ o = ($type$) vh.getAndBitwiseOrRelease(recv, $value1$);
918        });
919
920        checkUOE(() -> {
921            $type$ o = ($type$) vh.getAndBitwiseAnd(recv, $value1$);
922        });
923
924        checkUOE(() -> {
925            $type$ o = ($type$) vh.getAndBitwiseAndAcquire(recv, $value1$);
926        });
927
928        checkUOE(() -> {
929            $type$ o = ($type$) vh.getAndBitwiseAndRelease(recv, $value1$);
930        });
931
932        checkUOE(() -> {
933            $type$ o = ($type$) vh.getAndBitwiseXor(recv, $value1$);
934        });
935
936        checkUOE(() -> {
937            $type$ o = ($type$) vh.getAndBitwiseXorAcquire(recv, $value1$);
938        });
939
940        checkUOE(() -> {
941            $type$ o = ($type$) vh.getAndBitwiseXorRelease(recv, $value1$);
942        });
943#end[Bitwise]
944    }
945
946
947    static void testStaticField(VarHandle vh) {
948        // Plain
949        {
950            vh.set($value1$);
951            $type$ x = ($type$) vh.get();
952            assertEquals(x, $value1$, "set $type$ value");
953        }
954
955
956        // Volatile
957        {
958            vh.setVolatile($value2$);
959            $type$ x = ($type$) vh.getVolatile();
960            assertEquals(x, $value2$, "setVolatile $type$ value");
961        }
962
963        // Lazy
964        {
965            vh.setRelease($value1$);
966            $type$ x = ($type$) vh.getAcquire();
967            assertEquals(x, $value1$, "setRelease $type$ value");
968        }
969
970        // Opaque
971        {
972            vh.setOpaque($value2$);
973            $type$ x = ($type$) vh.getOpaque();
974            assertEquals(x, $value2$, "setOpaque $type$ value");
975        }
976
977#if[CAS]
978        vh.set($value1$);
979
980        // Compare
981        {
982            boolean r = vh.compareAndSet($value1$, $value2$);
983            assertEquals(r, true, "success compareAndSet $type$");
984            $type$ x = ($type$) vh.get();
985            assertEquals(x, $value2$, "success compareAndSet $type$ value");
986        }
987
988        {
989            boolean r = vh.compareAndSet($value1$, $value3$);
990            assertEquals(r, false, "failing compareAndSet $type$");
991            $type$ x = ($type$) vh.get();
992            assertEquals(x, $value2$, "failing compareAndSet $type$ value");
993        }
994
995        {
996            $type$ r = ($type$) vh.compareAndExchange($value2$, $value1$);
997            assertEquals(r, $value2$, "success compareAndExchange $type$");
998            $type$ x = ($type$) vh.get();
999            assertEquals(x, $value1$, "success compareAndExchange $type$ value");
1000        }
1001
1002        {
1003            $type$ r = ($type$) vh.compareAndExchange($value2$, $value3$);
1004            assertEquals(r, $value1$, "failing compareAndExchange $type$");
1005            $type$ x = ($type$) vh.get();
1006            assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
1007        }
1008
1009        {
1010            $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value2$);
1011            assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
1012            $type$ x = ($type$) vh.get();
1013            assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
1014        }
1015
1016        {
1017            $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value3$);
1018            assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
1019            $type$ x = ($type$) vh.get();
1020            assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
1021        }
1022
1023        {
1024            $type$ r = ($type$) vh.compareAndExchangeRelease($value2$, $value1$);
1025            assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
1026            $type$ x = ($type$) vh.get();
1027            assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
1028        }
1029
1030        {
1031            $type$ r = ($type$) vh.compareAndExchangeRelease($value2$, $value3$);
1032            assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
1033            $type$ x = ($type$) vh.get();
1034            assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
1035        }
1036
1037        {
1038            boolean success = false;
1039            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1040                success = vh.weakCompareAndSetPlain($value1$, $value2$);
1041            }
1042            assertEquals(success, true, "weakCompareAndSetPlain $type$");
1043            $type$ x = ($type$) vh.get();
1044            assertEquals(x, $value2$, "weakCompareAndSetPlain $type$ value");
1045        }
1046
1047        {
1048            boolean success = false;
1049            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1050                success = vh.weakCompareAndSetAcquire($value2$, $value1$);
1051            }
1052            assertEquals(success, true, "weakCompareAndSetAcquire $type$");
1053            $type$ x = ($type$) vh.get();
1054            assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
1055        }
1056
1057        {
1058            boolean success = false;
1059            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1060                success = vh.weakCompareAndSetRelease($value1$, $value2$);
1061            }
1062            assertEquals(success, true, "weakCompareAndSetRelease $type$");
1063            $type$ x = ($type$) vh.get();
1064            assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
1065        }
1066
1067        {
1068            boolean success = false;
1069            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1070                success = vh.weakCompareAndSet($value2$, $value1$);
1071            }
1072            assertEquals(success, true, "weakCompareAndSet $type$");
1073            $type$ x = ($type$) vh.get();
1074            assertEquals(x, $value1$, "weakCompareAndSet $type$");
1075        }
1076
1077        // Compare set and get
1078        {
1079            vh.set($value1$);
1080
1081            $type$ o = ($type$) vh.getAndSet($value2$);
1082            assertEquals(o, $value1$, "getAndSet $type$");
1083            $type$ x = ($type$) vh.get();
1084            assertEquals(x, $value2$, "getAndSet $type$ value");
1085        }
1086
1087        {
1088            vh.set($value1$);
1089
1090            $type$ o = ($type$) vh.getAndSetAcquire($value2$);
1091            assertEquals(o, $value1$, "getAndSetAcquire $type$");
1092            $type$ x = ($type$) vh.get();
1093            assertEquals(x, $value2$, "getAndSetAcquire $type$ value");
1094        }
1095
1096        {
1097            vh.set($value1$);
1098
1099            $type$ o = ($type$) vh.getAndSetRelease($value2$);
1100            assertEquals(o, $value1$, "getAndSetRelease $type$");
1101            $type$ x = ($type$) vh.get();
1102            assertEquals(x, $value2$, "getAndSetRelease $type$ value");
1103        }
1104#end[CAS]
1105
1106#if[AtomicAdd]
1107        // get and add, add and get
1108        {
1109            vh.set($value1$);
1110
1111            $type$ o = ($type$) vh.getAndAdd($value2$);
1112            assertEquals(o, $value1$, "getAndAdd $type$");
1113            $type$ x = ($type$) vh.get();
1114            assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value");
1115        }
1116
1117        {
1118            vh.set($value1$);
1119
1120            $type$ o = ($type$) vh.getAndAddAcquire($value2$);
1121            assertEquals(o, $value1$, "getAndAddAcquire $type$");
1122            $type$ x = ($type$) vh.get();
1123            assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value");
1124        }
1125
1126        {
1127            vh.set($value1$);
1128
1129            $type$ o = ($type$) vh.getAndAddRelease($value2$);
1130            assertEquals(o, $value1$, "getAndAddRelease$type$");
1131            $type$ x = ($type$) vh.get();
1132            assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value");
1133        }
1134#end[AtomicAdd]
1135
1136#if[Bitwise]
1137        // get and bitwise or
1138        {
1139            vh.set($value1$);
1140
1141            $type$ o = ($type$) vh.getAndBitwiseOr($value2$);
1142            assertEquals(o, $value1$, "getAndBitwiseOr $type$");
1143            $type$ x = ($type$) vh.get();
1144            assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value");
1145        }
1146
1147        {
1148            vh.set($value1$);
1149
1150            $type$ o = ($type$) vh.getAndBitwiseOrAcquire($value2$);
1151            assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$");
1152            $type$ x = ($type$) vh.get();
1153            assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value");
1154        }
1155
1156        {
1157            vh.set($value1$);
1158
1159            $type$ o = ($type$) vh.getAndBitwiseOrRelease($value2$);
1160            assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$");
1161            $type$ x = ($type$) vh.get();
1162            assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value");
1163        }
1164
1165        // get and bitwise and
1166        {
1167            vh.set($value1$);
1168
1169            $type$ o = ($type$) vh.getAndBitwiseAnd($value2$);
1170            assertEquals(o, $value1$, "getAndBitwiseAnd $type$");
1171            $type$ x = ($type$) vh.get();
1172            assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value");
1173        }
1174
1175        {
1176            vh.set($value1$);
1177
1178            $type$ o = ($type$) vh.getAndBitwiseAndAcquire($value2$);
1179            assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$");
1180            $type$ x = ($type$) vh.get();
1181            assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value");
1182        }
1183
1184        {
1185            vh.set($value1$);
1186
1187            $type$ o = ($type$) vh.getAndBitwiseAndRelease($value2$);
1188            assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$");
1189            $type$ x = ($type$) vh.get();
1190            assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value");
1191        }
1192
1193        // get and bitwise xor
1194        {
1195            vh.set($value1$);
1196
1197            $type$ o = ($type$) vh.getAndBitwiseXor($value2$);
1198            assertEquals(o, $value1$, "getAndBitwiseXor $type$");
1199            $type$ x = ($type$) vh.get();
1200            assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value");
1201        }
1202
1203        {
1204            vh.set($value1$);
1205
1206            $type$ o = ($type$) vh.getAndBitwiseXorAcquire($value2$);
1207            assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$");
1208            $type$ x = ($type$) vh.get();
1209            assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value");
1210        }
1211
1212        {
1213            vh.set($value1$);
1214
1215            $type$ o = ($type$) vh.getAndBitwiseXorRelease($value2$);
1216            assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$");
1217            $type$ x = ($type$) vh.get();
1218            assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value");
1219        }
1220#end[Bitwise]
1221    }
1222
1223    static void testStaticFieldUnsupported(VarHandle vh) {
1224#if[!CAS]
1225        checkUOE(() -> {
1226            boolean r = vh.compareAndSet($value1$, $value2$);
1227        });
1228
1229        checkUOE(() -> {
1230            $type$ r = ($type$) vh.compareAndExchange($value1$, $value2$);
1231        });
1232
1233        checkUOE(() -> {
1234            $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value2$);
1235        });
1236
1237        checkUOE(() -> {
1238            $type$ r = ($type$) vh.compareAndExchangeRelease($value1$, $value2$);
1239        });
1240
1241        checkUOE(() -> {
1242            boolean r = vh.weakCompareAndSetPlain($value1$, $value2$);
1243        });
1244
1245        checkUOE(() -> {
1246            boolean r = vh.weakCompareAndSet($value1$, $value2$);
1247        });
1248
1249        checkUOE(() -> {
1250            boolean r = vh.weakCompareAndSetAcquire($value1$, $value2$);
1251        });
1252
1253        checkUOE(() -> {
1254            boolean r = vh.weakCompareAndSetRelease($value1$, $value2$);
1255        });
1256
1257        checkUOE(() -> {
1258            $type$ r = ($type$) vh.getAndSet($value1$);
1259        });
1260
1261        checkUOE(() -> {
1262            $type$ r = ($type$) vh.getAndSetAcquire($value1$);
1263        });
1264
1265        checkUOE(() -> {
1266            $type$ r = ($type$) vh.getAndSetRelease($value1$);
1267        });
1268#end[CAS]
1269
1270#if[!AtomicAdd]
1271        checkUOE(() -> {
1272            $type$ o = ($type$) vh.getAndAdd($value1$);
1273        });
1274
1275        checkUOE(() -> {
1276            $type$ o = ($type$) vh.getAndAddAcquire($value1$);
1277        });
1278
1279        checkUOE(() -> {
1280            $type$ o = ($type$) vh.getAndAddRelease($value1$);
1281        });
1282#end[AtomicAdd]
1283
1284#if[!Bitwise]
1285        checkUOE(() -> {
1286            $type$ o = ($type$) vh.getAndBitwiseOr($value1$);
1287        });
1288
1289        checkUOE(() -> {
1290            $type$ o = ($type$) vh.getAndBitwiseOrAcquire($value1$);
1291        });
1292
1293        checkUOE(() -> {
1294            $type$ o = ($type$) vh.getAndBitwiseOrRelease($value1$);
1295        });
1296
1297        checkUOE(() -> {
1298            $type$ o = ($type$) vh.getAndBitwiseAnd($value1$);
1299        });
1300
1301        checkUOE(() -> {
1302            $type$ o = ($type$) vh.getAndBitwiseAndAcquire($value1$);
1303        });
1304
1305        checkUOE(() -> {
1306            $type$ o = ($type$) vh.getAndBitwiseAndRelease($value1$);
1307        });
1308
1309        checkUOE(() -> {
1310            $type$ o = ($type$) vh.getAndBitwiseXor($value1$);
1311        });
1312
1313        checkUOE(() -> {
1314            $type$ o = ($type$) vh.getAndBitwiseXorAcquire($value1$);
1315        });
1316
1317        checkUOE(() -> {
1318            $type$ o = ($type$) vh.getAndBitwiseXorRelease($value1$);
1319        });
1320#end[Bitwise]
1321    }
1322
1323
1324    static void testArray(VarHandle vh) {
1325        $type$[] array = new $type$[10];
1326
1327        for (int i = 0; i < array.length; i++) {
1328            // Plain
1329            {
1330                vh.set(array, i, $value1$);
1331                $type$ x = ($type$) vh.get(array, i);
1332                assertEquals(x, $value1$, "get $type$ value");
1333            }
1334
1335
1336            // Volatile
1337            {
1338                vh.setVolatile(array, i, $value2$);
1339                $type$ x = ($type$) vh.getVolatile(array, i);
1340                assertEquals(x, $value2$, "setVolatile $type$ value");
1341            }
1342
1343            // Lazy
1344            {
1345                vh.setRelease(array, i, $value1$);
1346                $type$ x = ($type$) vh.getAcquire(array, i);
1347                assertEquals(x, $value1$, "setRelease $type$ value");
1348            }
1349
1350            // Opaque
1351            {
1352                vh.setOpaque(array, i, $value2$);
1353                $type$ x = ($type$) vh.getOpaque(array, i);
1354                assertEquals(x, $value2$, "setOpaque $type$ value");
1355            }
1356
1357#if[CAS]
1358            vh.set(array, i, $value1$);
1359
1360            // Compare
1361            {
1362                boolean r = vh.compareAndSet(array, i, $value1$, $value2$);
1363                assertEquals(r, true, "success compareAndSet $type$");
1364                $type$ x = ($type$) vh.get(array, i);
1365                assertEquals(x, $value2$, "success compareAndSet $type$ value");
1366            }
1367
1368            {
1369                boolean r = vh.compareAndSet(array, i, $value1$, $value3$);
1370                assertEquals(r, false, "failing compareAndSet $type$");
1371                $type$ x = ($type$) vh.get(array, i);
1372                assertEquals(x, $value2$, "failing compareAndSet $type$ value");
1373            }
1374
1375            {
1376                $type$ r = ($type$) vh.compareAndExchange(array, i, $value2$, $value1$);
1377                assertEquals(r, $value2$, "success compareAndExchange $type$");
1378                $type$ x = ($type$) vh.get(array, i);
1379                assertEquals(x, $value1$, "success compareAndExchange $type$ value");
1380            }
1381
1382            {
1383                $type$ r = ($type$) vh.compareAndExchange(array, i, $value2$, $value3$);
1384                assertEquals(r, $value1$, "failing compareAndExchange $type$");
1385                $type$ x = ($type$) vh.get(array, i);
1386                assertEquals(x, $value1$, "failing compareAndExchange $type$ value");
1387            }
1388
1389            {
1390                $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, $value1$, $value2$);
1391                assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
1392                $type$ x = ($type$) vh.get(array, i);
1393                assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
1394            }
1395
1396            {
1397                $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, $value1$, $value3$);
1398                assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
1399                $type$ x = ($type$) vh.get(array, i);
1400                assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
1401            }
1402
1403            {
1404                $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, $value2$, $value1$);
1405                assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
1406                $type$ x = ($type$) vh.get(array, i);
1407                assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
1408            }
1409
1410            {
1411                $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, $value2$, $value3$);
1412                assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
1413                $type$ x = ($type$) vh.get(array, i);
1414                assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
1415            }
1416
1417            {
1418                boolean success = false;
1419                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1420                    success = vh.weakCompareAndSetPlain(array, i, $value1$, $value2$);
1421                }
1422                assertEquals(success, true, "weakCompareAndSetPlain $type$");
1423                $type$ x = ($type$) vh.get(array, i);
1424                assertEquals(x, $value2$, "weakCompareAndSetPlain $type$ value");
1425            }
1426
1427            {
1428                boolean success = false;
1429                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1430                    success = vh.weakCompareAndSetAcquire(array, i, $value2$, $value1$);
1431                }
1432                assertEquals(success, true, "weakCompareAndSetAcquire $type$");
1433                $type$ x = ($type$) vh.get(array, i);
1434                assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
1435            }
1436
1437            {
1438                boolean success = false;
1439                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1440                    success = vh.weakCompareAndSetRelease(array, i, $value1$, $value2$);
1441                }
1442                assertEquals(success, true, "weakCompareAndSetRelease $type$");
1443                $type$ x = ($type$) vh.get(array, i);
1444                assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
1445            }
1446
1447            {
1448                boolean success = false;
1449                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1450                    success = vh.weakCompareAndSet(array, i, $value2$, $value1$);
1451                }
1452                assertEquals(success, true, "weakCompareAndSet $type$");
1453                $type$ x = ($type$) vh.get(array, i);
1454                assertEquals(x, $value1$, "weakCompareAndSet $type$");
1455            }
1456
1457            // Compare set and get
1458            {
1459                vh.set(array, i, $value1$);
1460
1461                $type$ o = ($type$) vh.getAndSet(array, i, $value2$);
1462                assertEquals(o, $value1$, "getAndSet $type$");
1463                $type$ x = ($type$) vh.get(array, i);
1464                assertEquals(x, $value2$, "getAndSet $type$ value");
1465            }
1466
1467            {
1468                vh.set(array, i, $value1$);
1469
1470                $type$ o = ($type$) vh.getAndSetAcquire(array, i, $value2$);
1471                assertEquals(o, $value1$, "getAndSetAcquire $type$");
1472                $type$ x = ($type$) vh.get(array, i);
1473                assertEquals(x, $value2$, "getAndSetAcquire $type$ value");
1474            }
1475
1476            {
1477                vh.set(array, i, $value1$);
1478
1479                $type$ o = ($type$) vh.getAndSetRelease(array, i, $value2$);
1480                assertEquals(o, $value1$, "getAndSetRelease $type$");
1481                $type$ x = ($type$) vh.get(array, i);
1482                assertEquals(x, $value2$, "getAndSetRelease $type$ value");
1483            }
1484#end[CAS]
1485
1486#if[AtomicAdd]
1487            // get and add, add and get
1488            {
1489                vh.set(array, i, $value1$);
1490
1491                $type$ o = ($type$) vh.getAndAdd(array, i, $value2$);
1492                assertEquals(o, $value1$, "getAndAdd $type$");
1493                $type$ x = ($type$) vh.get(array, i);
1494                assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value");
1495            }
1496
1497            {
1498                vh.set(array, i, $value1$);
1499
1500                $type$ o = ($type$) vh.getAndAddAcquire(array, i, $value2$);
1501                assertEquals(o, $value1$, "getAndAddAcquire $type$");
1502                $type$ x = ($type$) vh.get(array, i);
1503                assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value");
1504            }
1505
1506            {
1507                vh.set(array, i, $value1$);
1508
1509                $type$ o = ($type$) vh.getAndAddRelease(array, i, $value2$);
1510                assertEquals(o, $value1$, "getAndAddRelease$type$");
1511                $type$ x = ($type$) vh.get(array, i);
1512                assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value");
1513            }
1514#end[AtomicAdd]
1515
1516#if[Bitwise]
1517            // get and bitwise or
1518            {
1519                vh.set(array, i, $value1$);
1520
1521                $type$ o = ($type$) vh.getAndBitwiseOr(array, i, $value2$);
1522                assertEquals(o, $value1$, "getAndBitwiseOr $type$");
1523                $type$ x = ($type$) vh.get(array, i);
1524                assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value");
1525            }
1526
1527            {
1528                vh.set(array, i, $value1$);
1529
1530                $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, i, $value2$);
1531                assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$");
1532                $type$ x = ($type$) vh.get(array, i);
1533                assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value");
1534            }
1535
1536            {
1537                vh.set(array, i, $value1$);
1538
1539                $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, i, $value2$);
1540                assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$");
1541                $type$ x = ($type$) vh.get(array, i);
1542                assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value");
1543            }
1544
1545            // get and bitwise and
1546            {
1547                vh.set(array, i, $value1$);
1548
1549                $type$ o = ($type$) vh.getAndBitwiseAnd(array, i, $value2$);
1550                assertEquals(o, $value1$, "getAndBitwiseAnd $type$");
1551                $type$ x = ($type$) vh.get(array, i);
1552                assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value");
1553            }
1554
1555            {
1556                vh.set(array, i, $value1$);
1557
1558                $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, i, $value2$);
1559                assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$");
1560                $type$ x = ($type$) vh.get(array, i);
1561                assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value");
1562            }
1563
1564            {
1565                vh.set(array, i, $value1$);
1566
1567                $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, i, $value2$);
1568                assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$");
1569                $type$ x = ($type$) vh.get(array, i);
1570                assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value");
1571            }
1572
1573            // get and bitwise xor
1574            {
1575                vh.set(array, i, $value1$);
1576
1577                $type$ o = ($type$) vh.getAndBitwiseXor(array, i, $value2$);
1578                assertEquals(o, $value1$, "getAndBitwiseXor $type$");
1579                $type$ x = ($type$) vh.get(array, i);
1580                assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value");
1581            }
1582
1583            {
1584                vh.set(array, i, $value1$);
1585
1586                $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, i, $value2$);
1587                assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$");
1588                $type$ x = ($type$) vh.get(array, i);
1589                assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value");
1590            }
1591
1592            {
1593                vh.set(array, i, $value1$);
1594
1595                $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, i, $value2$);
1596                assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$");
1597                $type$ x = ($type$) vh.get(array, i);
1598                assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value");
1599            }
1600#end[Bitwise]
1601        }
1602    }
1603
1604    static void testArrayUnsupported(VarHandle vh) {
1605        $type$[] array = new $type$[10];
1606
1607        int i = 0;
1608#if[!CAS]
1609        checkUOE(() -> {
1610            boolean r = vh.compareAndSet(array, i, $value1$, $value2$);
1611        });
1612
1613        checkUOE(() -> {
1614            $type$ r = ($type$) vh.compareAndExchange(array, i, $value1$, $value2$);
1615        });
1616
1617        checkUOE(() -> {
1618            $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, $value1$, $value2$);
1619        });
1620
1621        checkUOE(() -> {
1622            $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, $value1$, $value2$);
1623        });
1624
1625        checkUOE(() -> {
1626            boolean r = vh.weakCompareAndSetPlain(array, i, $value1$, $value2$);
1627        });
1628
1629        checkUOE(() -> {
1630            boolean r = vh.weakCompareAndSet(array, i, $value1$, $value2$);
1631        });
1632
1633        checkUOE(() -> {
1634            boolean r = vh.weakCompareAndSetAcquire(array, i, $value1$, $value2$);
1635        });
1636
1637        checkUOE(() -> {
1638            boolean r = vh.weakCompareAndSetRelease(array, i, $value1$, $value2$);
1639        });
1640
1641        checkUOE(() -> {
1642            $type$ r = ($type$) vh.getAndSet(array, i, $value1$);
1643        });
1644
1645        checkUOE(() -> {
1646            $type$ r = ($type$) vh.getAndSetAcquire(array, i, $value1$);
1647        });
1648
1649        checkUOE(() -> {
1650            $type$ r = ($type$) vh.getAndSetRelease(array, i, $value1$);
1651        });
1652#end[CAS]
1653
1654#if[!AtomicAdd]
1655        checkUOE(() -> {
1656            $type$ o = ($type$) vh.getAndAdd(array, i, $value1$);
1657        });
1658
1659        checkUOE(() -> {
1660            $type$ o = ($type$) vh.getAndAddAcquire(array, i, $value1$);
1661        });
1662
1663        checkUOE(() -> {
1664            $type$ o = ($type$) vh.getAndAddRelease(array, i, $value1$);
1665        });
1666#end[AtomicAdd]
1667
1668#if[!Bitwise]
1669        checkUOE(() -> {
1670            $type$ o = ($type$) vh.getAndBitwiseOr(array, i, $value1$);
1671        });
1672
1673        checkUOE(() -> {
1674            $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, i, $value1$);
1675        });
1676
1677        checkUOE(() -> {
1678            $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, i, $value1$);
1679        });
1680
1681        checkUOE(() -> {
1682            $type$ o = ($type$) vh.getAndBitwiseAnd(array, i, $value1$);
1683        });
1684
1685        checkUOE(() -> {
1686            $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, i, $value1$);
1687        });
1688
1689        checkUOE(() -> {
1690            $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, i, $value1$);
1691        });
1692
1693        checkUOE(() -> {
1694            $type$ o = ($type$) vh.getAndBitwiseXor(array, i, $value1$);
1695        });
1696
1697        checkUOE(() -> {
1698            $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, i, $value1$);
1699        });
1700
1701        checkUOE(() -> {
1702            $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, i, $value1$);
1703        });
1704#end[Bitwise]
1705    }
1706
1707    static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
1708        $type$[] array = new $type$[10];
1709
1710        for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
1711            final int ci = i;
1712
1713            checkIOOBE(() -> {
1714                $type$ x = ($type$) vh.get(array, ci);
1715            });
1716
1717            checkIOOBE(() -> {
1718                vh.set(array, ci, $value1$);
1719            });
1720
1721            checkIOOBE(() -> {
1722                $type$ x = ($type$) vh.getVolatile(array, ci);
1723            });
1724
1725            checkIOOBE(() -> {
1726                vh.setVolatile(array, ci, $value1$);
1727            });
1728
1729            checkIOOBE(() -> {
1730                $type$ x = ($type$) vh.getAcquire(array, ci);
1731            });
1732
1733            checkIOOBE(() -> {
1734                vh.setRelease(array, ci, $value1$);
1735            });
1736
1737            checkIOOBE(() -> {
1738                $type$ x = ($type$) vh.getOpaque(array, ci);
1739            });
1740
1741            checkIOOBE(() -> {
1742                vh.setOpaque(array, ci, $value1$);
1743            });
1744
1745#if[CAS]
1746            checkIOOBE(() -> {
1747                boolean r = vh.compareAndSet(array, ci, $value1$, $value2$);
1748            });
1749
1750            checkIOOBE(() -> {
1751                $type$ r = ($type$) vh.compareAndExchange(array, ci, $value2$, $value1$);
1752            });
1753
1754            checkIOOBE(() -> {
1755                $type$ r = ($type$) vh.compareAndExchangeAcquire(array, ci, $value2$, $value1$);
1756            });
1757
1758            checkIOOBE(() -> {
1759                $type$ r = ($type$) vh.compareAndExchangeRelease(array, ci, $value2$, $value1$);
1760            });
1761
1762            checkIOOBE(() -> {
1763                boolean r = vh.weakCompareAndSetPlain(array, ci, $value1$, $value2$);
1764            });
1765
1766            checkIOOBE(() -> {
1767                boolean r = vh.weakCompareAndSet(array, ci, $value1$, $value2$);
1768            });
1769
1770            checkIOOBE(() -> {
1771                boolean r = vh.weakCompareAndSetAcquire(array, ci, $value1$, $value2$);
1772            });
1773
1774            checkIOOBE(() -> {
1775                boolean r = vh.weakCompareAndSetRelease(array, ci, $value1$, $value2$);
1776            });
1777
1778            checkIOOBE(() -> {
1779                $type$ o = ($type$) vh.getAndSet(array, ci, $value1$);
1780            });
1781
1782            checkIOOBE(() -> {
1783                $type$ o = ($type$) vh.getAndSetAcquire(array, ci, $value1$);
1784            });
1785
1786            checkIOOBE(() -> {
1787                $type$ o = ($type$) vh.getAndSetRelease(array, ci, $value1$);
1788            });
1789#end[CAS]
1790
1791#if[AtomicAdd]
1792            checkIOOBE(() -> {
1793                $type$ o = ($type$) vh.getAndAdd(array, ci, $value1$);
1794            });
1795
1796            checkIOOBE(() -> {
1797                $type$ o = ($type$) vh.getAndAddAcquire(array, ci, $value1$);
1798            });
1799
1800            checkIOOBE(() -> {
1801                $type$ o = ($type$) vh.getAndAddRelease(array, ci, $value1$);
1802            });
1803#end[AtomicAdd]
1804
1805#if[Bitwise]
1806            checkIOOBE(() -> {
1807                $type$ o = ($type$) vh.getAndBitwiseOr(array, ci, $value1$);
1808            });
1809
1810            checkIOOBE(() -> {
1811                $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, ci, $value1$);
1812            });
1813
1814            checkIOOBE(() -> {
1815                $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, ci, $value1$);
1816            });
1817
1818            checkIOOBE(() -> {
1819                $type$ o = ($type$) vh.getAndBitwiseAnd(array, ci, $value1$);
1820            });
1821
1822            checkIOOBE(() -> {
1823                $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, ci, $value1$);
1824            });
1825
1826            checkIOOBE(() -> {
1827                $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, ci, $value1$);
1828            });
1829
1830            checkIOOBE(() -> {
1831                $type$ o = ($type$) vh.getAndBitwiseXor(array, ci, $value1$);
1832            });
1833
1834            checkIOOBE(() -> {
1835                $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, ci, $value1$);
1836            });
1837
1838            checkIOOBE(() -> {
1839                $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, ci, $value1$);
1840            });
1841#end[Bitwise]
1842        }
1843    }
1844
1845#if[String]
1846    static void testArrayStoreException(VarHandle vh) throws Throwable {
1847        Object[] array = new $type$[10];
1848        Arrays.fill(array, $value1$);
1849        Object value = new Object();
1850
1851        // Set
1852        checkASE(() -> {
1853            vh.set(array, 0, value);
1854        });
1855
1856        // SetVolatile
1857        checkASE(() -> {
1858            vh.setVolatile(array, 0, value);
1859        });
1860
1861        // SetOpaque
1862        checkASE(() -> {
1863            vh.setOpaque(array, 0, value);
1864        });
1865
1866        // SetRelease
1867        checkASE(() -> {
1868            vh.setRelease(array, 0, value);
1869        });
1870
1871        // CompareAndSet
1872        checkASE(() -> { // receiver reference class
1873            boolean r = vh.compareAndSet(array, 0, $value1$, value);
1874        });
1875
1876        // WeakCompareAndSet
1877        checkASE(() -> { // receiver reference class
1878            boolean r = vh.weakCompareAndSetPlain(array, 0, $value1$, value);
1879        });
1880
1881        // WeakCompareAndSetVolatile
1882        checkASE(() -> { // receiver reference class
1883            boolean r = vh.weakCompareAndSet(array, 0, $value1$, value);
1884        });
1885
1886        // WeakCompareAndSetAcquire
1887        checkASE(() -> { // receiver reference class
1888            boolean r = vh.weakCompareAndSetAcquire(array, 0, $value1$, value);
1889        });
1890
1891        // WeakCompareAndSetRelease
1892        checkASE(() -> { // receiver reference class
1893            boolean r = vh.weakCompareAndSetRelease(array, 0, $value1$, value);
1894        });
1895
1896        // CompareAndExchange
1897        checkASE(() -> { // receiver reference class
1898            $type$ x = ($type$) vh.compareAndExchange(array, 0, $value1$, value);
1899        });
1900
1901        // CompareAndExchangeAcquire
1902        checkASE(() -> { // receiver reference class
1903            $type$ x = ($type$) vh.compareAndExchangeAcquire(array, 0, $value1$, value);
1904        });
1905
1906        // CompareAndExchangeRelease
1907        checkASE(() -> { // receiver reference class
1908            $type$ x = ($type$) vh.compareAndExchangeRelease(array, 0, $value1$, value);
1909        });
1910
1911        // GetAndSet
1912        checkASE(() -> { // receiver reference class
1913            $type$ x = ($type$) vh.getAndSet(array, 0, value);
1914        });
1915
1916        // GetAndSetAcquire
1917        checkASE(() -> { // receiver reference class
1918            $type$ x = ($type$) vh.getAndSetAcquire(array, 0, value);
1919        });
1920
1921        // GetAndSetRelease
1922        checkASE(() -> { // receiver reference class
1923            $type$ x = ($type$) vh.getAndSetRelease(array, 0, value);
1924        });
1925    }
1926#end[String]
1927}
1928
1929