1 /*
2  * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /*
25  * @test
26  * @run testng/othervm -Diters=10    -Xint                   VarHandleTestAccessChar
27  * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessChar
28  * @run testng/othervm -Diters=20000                         VarHandleTestAccessChar
29  * @run testng/othervm -Diters=20000 -XX:-TieredCompilation  VarHandleTestAccessChar
30  */
31 
32 import org.testng.annotations.BeforeClass;
33 import org.testng.annotations.DataProvider;
34 import org.testng.annotations.Test;
35 
36 import java.lang.invoke.MethodHandles;
37 import java.lang.invoke.VarHandle;
38 import java.util.ArrayList;
39 import java.util.Arrays;
40 import java.util.List;
41 
42 import static org.testng.Assert.*;
43 
44 public class VarHandleTestAccessChar extends VarHandleBaseTest {
45     static final char static_final_v = '\u0123';
46 
47     static char static_v;
48 
49     final char final_v = '\u0123';
50 
51     char v;
52 
53     static final char static_final_v2 = '\u0123';
54 
55     static char static_v2;
56 
57     final char final_v2 = '\u0123';
58 
59     char v2;
60 
61     VarHandle vhFinalField;
62 
63     VarHandle vhField;
64 
65     VarHandle vhStaticField;
66 
67     VarHandle vhStaticFinalField;
68 
69     VarHandle vhArray;
70 
71 
allocate(boolean same)72     VarHandle[] allocate(boolean same) {
73         List<VarHandle> vhs = new ArrayList<>();
74 
75         String postfix = same ? "" : "2";
76         VarHandle vh;
77         try {
78             vh = MethodHandles.lookup().findVarHandle(
79                     VarHandleTestAccessChar.class, "final_v" + postfix, char.class);
80             vhs.add(vh);
81 
82             vh = MethodHandles.lookup().findVarHandle(
83                     VarHandleTestAccessChar.class, "v" + postfix, char.class);
84             vhs.add(vh);
85 
86             vh = MethodHandles.lookup().findStaticVarHandle(
87                 VarHandleTestAccessChar.class, "static_final_v" + postfix, char.class);
88             vhs.add(vh);
89 
90             vh = MethodHandles.lookup().findStaticVarHandle(
91                 VarHandleTestAccessChar.class, "static_v" + postfix, char.class);
92             vhs.add(vh);
93 
94             if (same) {
95                 vh = MethodHandles.arrayElementVarHandle(char[].class);
96             }
97             else {
98                 vh = MethodHandles.arrayElementVarHandle(String[].class);
99             }
100             vhs.add(vh);
101         } catch (Exception e) {
102             throw new InternalError(e);
103         }
104         return vhs.toArray(new VarHandle[0]);
105     }
106 
107     @BeforeClass
setup()108     public void setup() throws Exception {
109         vhFinalField = MethodHandles.lookup().findVarHandle(
110                 VarHandleTestAccessChar.class, "final_v", char.class);
111 
112         vhField = MethodHandles.lookup().findVarHandle(
113                 VarHandleTestAccessChar.class, "v", char.class);
114 
115         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
116             VarHandleTestAccessChar.class, "static_final_v", char.class);
117 
118         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
119             VarHandleTestAccessChar.class, "static_v", char.class);
120 
121         vhArray = MethodHandles.arrayElementVarHandle(char[].class);
122     }
123 
124 
125     @DataProvider
varHandlesProvider()126     public Object[][] varHandlesProvider() throws Exception {
127         List<VarHandle> vhs = new ArrayList<>();
128         vhs.add(vhField);
129         vhs.add(vhStaticField);
130         vhs.add(vhArray);
131 
132         return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
133     }
134 
135     @Test
testEquals()136     public void testEquals() {
137         VarHandle[] vhs1 = allocate(true);
138         VarHandle[] vhs2 = allocate(true);
139 
140         for (int i = 0; i < vhs1.length; i++) {
141             for (int j = 0; j < vhs1.length; j++) {
142                 if (i != j) {
143                     assertNotEquals(vhs1[i], vhs1[j]);
144                     assertNotEquals(vhs1[i], vhs2[j]);
145                 }
146             }
147         }
148 
149         VarHandle[] vhs3 = allocate(false);
150         for (int i = 0; i < vhs1.length; i++) {
151             assertNotEquals(vhs1[i], vhs3[i]);
152         }
153     }
154 
155     @Test(dataProvider = "varHandlesProvider")
testIsAccessModeSupported(VarHandle vh)156     public void testIsAccessModeSupported(VarHandle vh) {
157         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
158         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
159         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
160         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
161         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
162         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
163         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
164         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
165 
166         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
167         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
168         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
169         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
170         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
171         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
172         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
173         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
174         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
175         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
176         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
177 
178         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
179         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
180         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
181 
182         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
183         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
184         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
185         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
186         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
187         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
188         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
189         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
190         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
191     }
192 
193 
194     @DataProvider
typesProvider()195     public Object[][] typesProvider() throws Exception {
196         List<Object[]> types = new ArrayList<>();
197         types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessChar.class)});
198         types.add(new Object[] {vhStaticField, Arrays.asList()});
199         types.add(new Object[] {vhArray, Arrays.asList(char[].class, int.class)});
200 
201         return types.stream().toArray(Object[][]::new);
202     }
203 
204     @Test(dataProvider = "typesProvider")
testTypes(VarHandle vh, List<Class<?>> pts)205     public void testTypes(VarHandle vh, List<Class<?>> pts) {
206         assertEquals(vh.varType(), char.class);
207 
208         assertEquals(vh.coordinateTypes(), pts);
209 
210         testTypes(vh);
211     }
212 
213 
214     @Test
testLookupInstanceToStatic()215     public void testLookupInstanceToStatic() {
216         checkIAE("Lookup of static final field to instance final field", () -> {
217             MethodHandles.lookup().findStaticVarHandle(
218                     VarHandleTestAccessChar.class, "final_v", char.class);
219         });
220 
221         checkIAE("Lookup of static field to instance field", () -> {
222             MethodHandles.lookup().findStaticVarHandle(
223                     VarHandleTestAccessChar.class, "v", char.class);
224         });
225     }
226 
227     @Test
testLookupStaticToInstance()228     public void testLookupStaticToInstance() {
229         checkIAE("Lookup of instance final field to static final field", () -> {
230             MethodHandles.lookup().findVarHandle(
231                 VarHandleTestAccessChar.class, "static_final_v", char.class);
232         });
233 
234         checkIAE("Lookup of instance field to static field", () -> {
235             vhStaticField = MethodHandles.lookup().findVarHandle(
236                 VarHandleTestAccessChar.class, "static_v", char.class);
237         });
238     }
239 
240 
241     @DataProvider
accessTestCaseProvider()242     public Object[][] accessTestCaseProvider() throws Exception {
243         List<AccessTestCase<?>> cases = new ArrayList<>();
244 
245         cases.add(new VarHandleAccessTestCase("Instance final field",
246                                               vhFinalField, vh -> testInstanceFinalField(this, vh)));
247         cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
248                                               vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
249                                               false));
250 
251         cases.add(new VarHandleAccessTestCase("Static final field",
252                                               vhStaticFinalField, VarHandleTestAccessChar::testStaticFinalField));
253         cases.add(new VarHandleAccessTestCase("Static final field unsupported",
254                                               vhStaticFinalField, VarHandleTestAccessChar::testStaticFinalFieldUnsupported,
255                                               false));
256 
257         cases.add(new VarHandleAccessTestCase("Instance field",
258                                               vhField, vh -> testInstanceField(this, vh)));
259         cases.add(new VarHandleAccessTestCase("Instance field unsupported",
260                                               vhField, vh -> testInstanceFieldUnsupported(this, vh),
261                                               false));
262 
263         cases.add(new VarHandleAccessTestCase("Static field",
264                                               vhStaticField, VarHandleTestAccessChar::testStaticField));
265         cases.add(new VarHandleAccessTestCase("Static field unsupported",
266                                               vhStaticField, VarHandleTestAccessChar::testStaticFieldUnsupported,
267                                               false));
268 
269         cases.add(new VarHandleAccessTestCase("Array",
270                                               vhArray, VarHandleTestAccessChar::testArray));
271         cases.add(new VarHandleAccessTestCase("Array unsupported",
272                                               vhArray, VarHandleTestAccessChar::testArrayUnsupported,
273                                               false));
274         cases.add(new VarHandleAccessTestCase("Array index out of bounds",
275                                               vhArray, VarHandleTestAccessChar::testArrayIndexOutOfBounds,
276                                               false));
277         // Work around issue with jtreg summary reporting which truncates
278         // the String result of Object.toString to 30 characters, hence
279         // the first dummy argument
280         return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
281     }
282 
283     @Test(dataProvider = "accessTestCaseProvider")
testAccess(String desc, AccessTestCase<T> atc)284     public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
285         T t = atc.get();
286         int iters = atc.requiresLoop() ? ITERS : 1;
287         for (int c = 0; c < iters; c++) {
288             atc.testAccess(t);
289         }
290     }
291 
292 
293 
294 
testInstanceFinalField(VarHandleTestAccessChar recv, VarHandle vh)295     static void testInstanceFinalField(VarHandleTestAccessChar recv, VarHandle vh) {
296         // Plain
297         {
298             char x = (char) vh.get(recv);
299             assertEquals(x, '\u0123', "get char value");
300         }
301 
302 
303         // Volatile
304         {
305             char x = (char) vh.getVolatile(recv);
306             assertEquals(x, '\u0123', "getVolatile char value");
307         }
308 
309         // Lazy
310         {
311             char x = (char) vh.getAcquire(recv);
312             assertEquals(x, '\u0123', "getRelease char value");
313         }
314 
315         // Opaque
316         {
317             char x = (char) vh.getOpaque(recv);
318             assertEquals(x, '\u0123', "getOpaque char value");
319         }
320     }
321 
testInstanceFinalFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh)322     static void testInstanceFinalFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh) {
323         checkUOE(() -> {
324             vh.set(recv, '\u4567');
325         });
326 
327         checkUOE(() -> {
328             vh.setVolatile(recv, '\u4567');
329         });
330 
331         checkUOE(() -> {
332             vh.setRelease(recv, '\u4567');
333         });
334 
335         checkUOE(() -> {
336             vh.setOpaque(recv, '\u4567');
337         });
338 
339 
340 
341     }
342 
343 
testStaticFinalField(VarHandle vh)344     static void testStaticFinalField(VarHandle vh) {
345         // Plain
346         {
347             char x = (char) vh.get();
348             assertEquals(x, '\u0123', "get char value");
349         }
350 
351 
352         // Volatile
353         {
354             char x = (char) vh.getVolatile();
355             assertEquals(x, '\u0123', "getVolatile char value");
356         }
357 
358         // Lazy
359         {
360             char x = (char) vh.getAcquire();
361             assertEquals(x, '\u0123', "getRelease char value");
362         }
363 
364         // Opaque
365         {
366             char x = (char) vh.getOpaque();
367             assertEquals(x, '\u0123', "getOpaque char value");
368         }
369     }
370 
testStaticFinalFieldUnsupported(VarHandle vh)371     static void testStaticFinalFieldUnsupported(VarHandle vh) {
372         checkUOE(() -> {
373             vh.set('\u4567');
374         });
375 
376         checkUOE(() -> {
377             vh.setVolatile('\u4567');
378         });
379 
380         checkUOE(() -> {
381             vh.setRelease('\u4567');
382         });
383 
384         checkUOE(() -> {
385             vh.setOpaque('\u4567');
386         });
387 
388 
389 
390     }
391 
392 
testInstanceField(VarHandleTestAccessChar recv, VarHandle vh)393     static void testInstanceField(VarHandleTestAccessChar recv, VarHandle vh) {
394         // Plain
395         {
396             vh.set(recv, '\u0123');
397             char x = (char) vh.get(recv);
398             assertEquals(x, '\u0123', "set char value");
399         }
400 
401 
402         // Volatile
403         {
404             vh.setVolatile(recv, '\u4567');
405             char x = (char) vh.getVolatile(recv);
406             assertEquals(x, '\u4567', "setVolatile char value");
407         }
408 
409         // Lazy
410         {
411             vh.setRelease(recv, '\u0123');
412             char x = (char) vh.getAcquire(recv);
413             assertEquals(x, '\u0123', "setRelease char value");
414         }
415 
416         // Opaque
417         {
418             vh.setOpaque(recv, '\u4567');
419             char x = (char) vh.getOpaque(recv);
420             assertEquals(x, '\u4567', "setOpaque char value");
421         }
422 
423         vh.set(recv, '\u0123');
424 
425         // Compare
426         {
427             boolean r = vh.compareAndSet(recv, '\u0123', '\u4567');
428             assertEquals(r, true, "success compareAndSet char");
429             char x = (char) vh.get(recv);
430             assertEquals(x, '\u4567', "success compareAndSet char value");
431         }
432 
433         {
434             boolean r = vh.compareAndSet(recv, '\u0123', '\u89AB');
435             assertEquals(r, false, "failing compareAndSet char");
436             char x = (char) vh.get(recv);
437             assertEquals(x, '\u4567', "failing compareAndSet char value");
438         }
439 
440         {
441             char r = (char) vh.compareAndExchange(recv, '\u4567', '\u0123');
442             assertEquals(r, '\u4567', "success compareAndExchange char");
443             char x = (char) vh.get(recv);
444             assertEquals(x, '\u0123', "success compareAndExchange char value");
445         }
446 
447         {
448             char r = (char) vh.compareAndExchange(recv, '\u4567', '\u89AB');
449             assertEquals(r, '\u0123', "failing compareAndExchange char");
450             char x = (char) vh.get(recv);
451             assertEquals(x, '\u0123', "failing compareAndExchange char value");
452         }
453 
454         {
455             char r = (char) vh.compareAndExchangeAcquire(recv, '\u0123', '\u4567');
456             assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
457             char x = (char) vh.get(recv);
458             assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
459         }
460 
461         {
462             char r = (char) vh.compareAndExchangeAcquire(recv, '\u0123', '\u89AB');
463             assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
464             char x = (char) vh.get(recv);
465             assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
466         }
467 
468         {
469             char r = (char) vh.compareAndExchangeRelease(recv, '\u4567', '\u0123');
470             assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
471             char x = (char) vh.get(recv);
472             assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
473         }
474 
475         {
476             char r = (char) vh.compareAndExchangeRelease(recv, '\u4567', '\u89AB');
477             assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
478             char x = (char) vh.get(recv);
479             assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
480         }
481 
482         {
483             boolean success = false;
484             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
485                 success = vh.weakCompareAndSetPlain(recv, '\u0123', '\u4567');
486             }
487             assertEquals(success, true, "weakCompareAndSetPlain char");
488             char x = (char) vh.get(recv);
489             assertEquals(x, '\u4567', "weakCompareAndSetPlain char value");
490         }
491 
492         {
493             boolean success = false;
494             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
495                 success = vh.weakCompareAndSetAcquire(recv, '\u4567', '\u0123');
496             }
497             assertEquals(success, true, "weakCompareAndSetAcquire char");
498             char x = (char) vh.get(recv);
499             assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
500         }
501 
502         {
503             boolean success = false;
504             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
505                 success = vh.weakCompareAndSetRelease(recv, '\u0123', '\u4567');
506             }
507             assertEquals(success, true, "weakCompareAndSetRelease char");
508             char x = (char) vh.get(recv);
509             assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
510         }
511 
512         {
513             boolean success = false;
514             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
515                 success = vh.weakCompareAndSet(recv, '\u4567', '\u0123');
516             }
517             assertEquals(success, true, "weakCompareAndSet char");
518             char x = (char) vh.get(recv);
519             assertEquals(x, '\u0123', "weakCompareAndSet char value");
520         }
521 
522         // Compare set and get
523         {
524             vh.set(recv, '\u0123');
525 
526             char o = (char) vh.getAndSet(recv, '\u4567');
527             assertEquals(o, '\u0123', "getAndSet char");
528             char x = (char) vh.get(recv);
529             assertEquals(x, '\u4567', "getAndSet char value");
530         }
531 
532         {
533             vh.set(recv, '\u0123');
534 
535             char o = (char) vh.getAndSetAcquire(recv, '\u4567');
536             assertEquals(o, '\u0123', "getAndSetAcquire char");
537             char x = (char) vh.get(recv);
538             assertEquals(x, '\u4567', "getAndSetAcquire char value");
539         }
540 
541         {
542             vh.set(recv, '\u0123');
543 
544             char o = (char) vh.getAndSetRelease(recv, '\u4567');
545             assertEquals(o, '\u0123', "getAndSetRelease char");
546             char x = (char) vh.get(recv);
547             assertEquals(x, '\u4567', "getAndSetRelease char value");
548         }
549 
550         // get and add, add and get
551         {
552             vh.set(recv, '\u0123');
553 
554             char o = (char) vh.getAndAdd(recv, '\u4567');
555             assertEquals(o, '\u0123', "getAndAdd char");
556             char x = (char) vh.get(recv);
557             assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value");
558         }
559 
560         {
561             vh.set(recv, '\u0123');
562 
563             char o = (char) vh.getAndAddAcquire(recv, '\u4567');
564             assertEquals(o, '\u0123', "getAndAddAcquire char");
565             char x = (char) vh.get(recv);
566             assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value");
567         }
568 
569         {
570             vh.set(recv, '\u0123');
571 
572             char o = (char) vh.getAndAddRelease(recv, '\u4567');
573             assertEquals(o, '\u0123', "getAndAddReleasechar");
574             char x = (char) vh.get(recv);
575             assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value");
576         }
577 
578         // get and bitwise or
579         {
580             vh.set(recv, '\u0123');
581 
582             char o = (char) vh.getAndBitwiseOr(recv, '\u4567');
583             assertEquals(o, '\u0123', "getAndBitwiseOr char");
584             char x = (char) vh.get(recv);
585             assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value");
586         }
587 
588         {
589             vh.set(recv, '\u0123');
590 
591             char o = (char) vh.getAndBitwiseOrAcquire(recv, '\u4567');
592             assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char");
593             char x = (char) vh.get(recv);
594             assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value");
595         }
596 
597         {
598             vh.set(recv, '\u0123');
599 
600             char o = (char) vh.getAndBitwiseOrRelease(recv, '\u4567');
601             assertEquals(o, '\u0123', "getAndBitwiseOrRelease char");
602             char x = (char) vh.get(recv);
603             assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value");
604         }
605 
606         // get and bitwise and
607         {
608             vh.set(recv, '\u0123');
609 
610             char o = (char) vh.getAndBitwiseAnd(recv, '\u4567');
611             assertEquals(o, '\u0123', "getAndBitwiseAnd char");
612             char x = (char) vh.get(recv);
613             assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value");
614         }
615 
616         {
617             vh.set(recv, '\u0123');
618 
619             char o = (char) vh.getAndBitwiseAndAcquire(recv, '\u4567');
620             assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char");
621             char x = (char) vh.get(recv);
622             assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value");
623         }
624 
625         {
626             vh.set(recv, '\u0123');
627 
628             char o = (char) vh.getAndBitwiseAndRelease(recv, '\u4567');
629             assertEquals(o, '\u0123', "getAndBitwiseAndRelease char");
630             char x = (char) vh.get(recv);
631             assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value");
632         }
633 
634         // get and bitwise xor
635         {
636             vh.set(recv, '\u0123');
637 
638             char o = (char) vh.getAndBitwiseXor(recv, '\u4567');
639             assertEquals(o, '\u0123', "getAndBitwiseXor char");
640             char x = (char) vh.get(recv);
641             assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value");
642         }
643 
644         {
645             vh.set(recv, '\u0123');
646 
647             char o = (char) vh.getAndBitwiseXorAcquire(recv, '\u4567');
648             assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char");
649             char x = (char) vh.get(recv);
650             assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value");
651         }
652 
653         {
654             vh.set(recv, '\u0123');
655 
656             char o = (char) vh.getAndBitwiseXorRelease(recv, '\u4567');
657             assertEquals(o, '\u0123', "getAndBitwiseXorRelease char");
658             char x = (char) vh.get(recv);
659             assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value");
660         }
661     }
662 
testInstanceFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh)663     static void testInstanceFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh) {
664 
665 
666     }
667 
668 
testStaticField(VarHandle vh)669     static void testStaticField(VarHandle vh) {
670         // Plain
671         {
672             vh.set('\u0123');
673             char x = (char) vh.get();
674             assertEquals(x, '\u0123', "set char value");
675         }
676 
677 
678         // Volatile
679         {
680             vh.setVolatile('\u4567');
681             char x = (char) vh.getVolatile();
682             assertEquals(x, '\u4567', "setVolatile char value");
683         }
684 
685         // Lazy
686         {
687             vh.setRelease('\u0123');
688             char x = (char) vh.getAcquire();
689             assertEquals(x, '\u0123', "setRelease char value");
690         }
691 
692         // Opaque
693         {
694             vh.setOpaque('\u4567');
695             char x = (char) vh.getOpaque();
696             assertEquals(x, '\u4567', "setOpaque char value");
697         }
698 
699         vh.set('\u0123');
700 
701         // Compare
702         {
703             boolean r = vh.compareAndSet('\u0123', '\u4567');
704             assertEquals(r, true, "success compareAndSet char");
705             char x = (char) vh.get();
706             assertEquals(x, '\u4567', "success compareAndSet char value");
707         }
708 
709         {
710             boolean r = vh.compareAndSet('\u0123', '\u89AB');
711             assertEquals(r, false, "failing compareAndSet char");
712             char x = (char) vh.get();
713             assertEquals(x, '\u4567', "failing compareAndSet char value");
714         }
715 
716         {
717             char r = (char) vh.compareAndExchange('\u4567', '\u0123');
718             assertEquals(r, '\u4567', "success compareAndExchange char");
719             char x = (char) vh.get();
720             assertEquals(x, '\u0123', "success compareAndExchange char value");
721         }
722 
723         {
724             char r = (char) vh.compareAndExchange('\u4567', '\u89AB');
725             assertEquals(r, '\u0123', "failing compareAndExchange char");
726             char x = (char) vh.get();
727             assertEquals(x, '\u0123', "failing compareAndExchange char value");
728         }
729 
730         {
731             char r = (char) vh.compareAndExchangeAcquire('\u0123', '\u4567');
732             assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
733             char x = (char) vh.get();
734             assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
735         }
736 
737         {
738             char r = (char) vh.compareAndExchangeAcquire('\u0123', '\u89AB');
739             assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
740             char x = (char) vh.get();
741             assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
742         }
743 
744         {
745             char r = (char) vh.compareAndExchangeRelease('\u4567', '\u0123');
746             assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
747             char x = (char) vh.get();
748             assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
749         }
750 
751         {
752             char r = (char) vh.compareAndExchangeRelease('\u4567', '\u89AB');
753             assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
754             char x = (char) vh.get();
755             assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
756         }
757 
758         {
759             boolean success = false;
760             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
761                 success = vh.weakCompareAndSetPlain('\u0123', '\u4567');
762             }
763             assertEquals(success, true, "weakCompareAndSetPlain char");
764             char x = (char) vh.get();
765             assertEquals(x, '\u4567', "weakCompareAndSetPlain char value");
766         }
767 
768         {
769             boolean success = false;
770             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
771                 success = vh.weakCompareAndSetAcquire('\u4567', '\u0123');
772             }
773             assertEquals(success, true, "weakCompareAndSetAcquire char");
774             char x = (char) vh.get();
775             assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
776         }
777 
778         {
779             boolean success = false;
780             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
781                 success = vh.weakCompareAndSetRelease('\u0123', '\u4567');
782             }
783             assertEquals(success, true, "weakCompareAndSetRelease char");
784             char x = (char) vh.get();
785             assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
786         }
787 
788         {
789             boolean success = false;
790             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
791                 success = vh.weakCompareAndSet('\u4567', '\u0123');
792             }
793             assertEquals(success, true, "weakCompareAndSet char");
794             char x = (char) vh.get();
795             assertEquals(x, '\u0123', "weakCompareAndSet char");
796         }
797 
798         // Compare set and get
799         {
800             vh.set('\u0123');
801 
802             char o = (char) vh.getAndSet('\u4567');
803             assertEquals(o, '\u0123', "getAndSet char");
804             char x = (char) vh.get();
805             assertEquals(x, '\u4567', "getAndSet char value");
806         }
807 
808         {
809             vh.set('\u0123');
810 
811             char o = (char) vh.getAndSetAcquire('\u4567');
812             assertEquals(o, '\u0123', "getAndSetAcquire char");
813             char x = (char) vh.get();
814             assertEquals(x, '\u4567', "getAndSetAcquire char value");
815         }
816 
817         {
818             vh.set('\u0123');
819 
820             char o = (char) vh.getAndSetRelease('\u4567');
821             assertEquals(o, '\u0123', "getAndSetRelease char");
822             char x = (char) vh.get();
823             assertEquals(x, '\u4567', "getAndSetRelease char value");
824         }
825 
826         // get and add, add and get
827         {
828             vh.set('\u0123');
829 
830             char o = (char) vh.getAndAdd('\u4567');
831             assertEquals(o, '\u0123', "getAndAdd char");
832             char x = (char) vh.get();
833             assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value");
834         }
835 
836         {
837             vh.set('\u0123');
838 
839             char o = (char) vh.getAndAddAcquire('\u4567');
840             assertEquals(o, '\u0123', "getAndAddAcquire char");
841             char x = (char) vh.get();
842             assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value");
843         }
844 
845         {
846             vh.set('\u0123');
847 
848             char o = (char) vh.getAndAddRelease('\u4567');
849             assertEquals(o, '\u0123', "getAndAddReleasechar");
850             char x = (char) vh.get();
851             assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value");
852         }
853 
854         // get and bitwise or
855         {
856             vh.set('\u0123');
857 
858             char o = (char) vh.getAndBitwiseOr('\u4567');
859             assertEquals(o, '\u0123', "getAndBitwiseOr char");
860             char x = (char) vh.get();
861             assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value");
862         }
863 
864         {
865             vh.set('\u0123');
866 
867             char o = (char) vh.getAndBitwiseOrAcquire('\u4567');
868             assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char");
869             char x = (char) vh.get();
870             assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value");
871         }
872 
873         {
874             vh.set('\u0123');
875 
876             char o = (char) vh.getAndBitwiseOrRelease('\u4567');
877             assertEquals(o, '\u0123', "getAndBitwiseOrRelease char");
878             char x = (char) vh.get();
879             assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value");
880         }
881 
882         // get and bitwise and
883         {
884             vh.set('\u0123');
885 
886             char o = (char) vh.getAndBitwiseAnd('\u4567');
887             assertEquals(o, '\u0123', "getAndBitwiseAnd char");
888             char x = (char) vh.get();
889             assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value");
890         }
891 
892         {
893             vh.set('\u0123');
894 
895             char o = (char) vh.getAndBitwiseAndAcquire('\u4567');
896             assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char");
897             char x = (char) vh.get();
898             assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value");
899         }
900 
901         {
902             vh.set('\u0123');
903 
904             char o = (char) vh.getAndBitwiseAndRelease('\u4567');
905             assertEquals(o, '\u0123', "getAndBitwiseAndRelease char");
906             char x = (char) vh.get();
907             assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value");
908         }
909 
910         // get and bitwise xor
911         {
912             vh.set('\u0123');
913 
914             char o = (char) vh.getAndBitwiseXor('\u4567');
915             assertEquals(o, '\u0123', "getAndBitwiseXor char");
916             char x = (char) vh.get();
917             assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value");
918         }
919 
920         {
921             vh.set('\u0123');
922 
923             char o = (char) vh.getAndBitwiseXorAcquire('\u4567');
924             assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char");
925             char x = (char) vh.get();
926             assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value");
927         }
928 
929         {
930             vh.set('\u0123');
931 
932             char o = (char) vh.getAndBitwiseXorRelease('\u4567');
933             assertEquals(o, '\u0123', "getAndBitwiseXorRelease char");
934             char x = (char) vh.get();
935             assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value");
936         }
937     }
938 
testStaticFieldUnsupported(VarHandle vh)939     static void testStaticFieldUnsupported(VarHandle vh) {
940 
941 
942     }
943 
944 
testArray(VarHandle vh)945     static void testArray(VarHandle vh) {
946         char[] array = new char[10];
947 
948         for (int i = 0; i < array.length; i++) {
949             // Plain
950             {
951                 vh.set(array, i, '\u0123');
952                 char x = (char) vh.get(array, i);
953                 assertEquals(x, '\u0123', "get char value");
954             }
955 
956 
957             // Volatile
958             {
959                 vh.setVolatile(array, i, '\u4567');
960                 char x = (char) vh.getVolatile(array, i);
961                 assertEquals(x, '\u4567', "setVolatile char value");
962             }
963 
964             // Lazy
965             {
966                 vh.setRelease(array, i, '\u0123');
967                 char x = (char) vh.getAcquire(array, i);
968                 assertEquals(x, '\u0123', "setRelease char value");
969             }
970 
971             // Opaque
972             {
973                 vh.setOpaque(array, i, '\u4567');
974                 char x = (char) vh.getOpaque(array, i);
975                 assertEquals(x, '\u4567', "setOpaque char value");
976             }
977 
978             vh.set(array, i, '\u0123');
979 
980             // Compare
981             {
982                 boolean r = vh.compareAndSet(array, i, '\u0123', '\u4567');
983                 assertEquals(r, true, "success compareAndSet char");
984                 char x = (char) vh.get(array, i);
985                 assertEquals(x, '\u4567', "success compareAndSet char value");
986             }
987 
988             {
989                 boolean r = vh.compareAndSet(array, i, '\u0123', '\u89AB');
990                 assertEquals(r, false, "failing compareAndSet char");
991                 char x = (char) vh.get(array, i);
992                 assertEquals(x, '\u4567', "failing compareAndSet char value");
993             }
994 
995             {
996                 char r = (char) vh.compareAndExchange(array, i, '\u4567', '\u0123');
997                 assertEquals(r, '\u4567', "success compareAndExchange char");
998                 char x = (char) vh.get(array, i);
999                 assertEquals(x, '\u0123', "success compareAndExchange char value");
1000             }
1001 
1002             {
1003                 char r = (char) vh.compareAndExchange(array, i, '\u4567', '\u89AB');
1004                 assertEquals(r, '\u0123', "failing compareAndExchange char");
1005                 char x = (char) vh.get(array, i);
1006                 assertEquals(x, '\u0123', "failing compareAndExchange char value");
1007             }
1008 
1009             {
1010                 char r = (char) vh.compareAndExchangeAcquire(array, i, '\u0123', '\u4567');
1011                 assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
1012                 char x = (char) vh.get(array, i);
1013                 assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
1014             }
1015 
1016             {
1017                 char r = (char) vh.compareAndExchangeAcquire(array, i, '\u0123', '\u89AB');
1018                 assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
1019                 char x = (char) vh.get(array, i);
1020                 assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
1021             }
1022 
1023             {
1024                 char r = (char) vh.compareAndExchangeRelease(array, i, '\u4567', '\u0123');
1025                 assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
1026                 char x = (char) vh.get(array, i);
1027                 assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
1028             }
1029 
1030             {
1031                 char r = (char) vh.compareAndExchangeRelease(array, i, '\u4567', '\u89AB');
1032                 assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
1033                 char x = (char) vh.get(array, i);
1034                 assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
1035             }
1036 
1037             {
1038                 boolean success = false;
1039                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1040                     success = vh.weakCompareAndSetPlain(array, i, '\u0123', '\u4567');
1041                 }
1042                 assertEquals(success, true, "weakCompareAndSetPlain char");
1043                 char x = (char) vh.get(array, i);
1044                 assertEquals(x, '\u4567', "weakCompareAndSetPlain char value");
1045             }
1046 
1047             {
1048                 boolean success = false;
1049                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1050                     success = vh.weakCompareAndSetAcquire(array, i, '\u4567', '\u0123');
1051                 }
1052                 assertEquals(success, true, "weakCompareAndSetAcquire char");
1053                 char x = (char) vh.get(array, i);
1054                 assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
1055             }
1056 
1057             {
1058                 boolean success = false;
1059                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1060                     success = vh.weakCompareAndSetRelease(array, i, '\u0123', '\u4567');
1061                 }
1062                 assertEquals(success, true, "weakCompareAndSetRelease char");
1063                 char x = (char) vh.get(array, i);
1064                 assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
1065             }
1066 
1067             {
1068                 boolean success = false;
1069                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1070                     success = vh.weakCompareAndSet(array, i, '\u4567', '\u0123');
1071                 }
1072                 assertEquals(success, true, "weakCompareAndSet char");
1073                 char x = (char) vh.get(array, i);
1074                 assertEquals(x, '\u0123', "weakCompareAndSet char");
1075             }
1076 
1077             // Compare set and get
1078             {
1079                 vh.set(array, i, '\u0123');
1080 
1081                 char o = (char) vh.getAndSet(array, i, '\u4567');
1082                 assertEquals(o, '\u0123', "getAndSet char");
1083                 char x = (char) vh.get(array, i);
1084                 assertEquals(x, '\u4567', "getAndSet char value");
1085             }
1086 
1087             {
1088                 vh.set(array, i, '\u0123');
1089 
1090                 char o = (char) vh.getAndSetAcquire(array, i, '\u4567');
1091                 assertEquals(o, '\u0123', "getAndSetAcquire char");
1092                 char x = (char) vh.get(array, i);
1093                 assertEquals(x, '\u4567', "getAndSetAcquire char value");
1094             }
1095 
1096             {
1097                 vh.set(array, i, '\u0123');
1098 
1099                 char o = (char) vh.getAndSetRelease(array, i, '\u4567');
1100                 assertEquals(o, '\u0123', "getAndSetRelease char");
1101                 char x = (char) vh.get(array, i);
1102                 assertEquals(x, '\u4567', "getAndSetRelease char value");
1103             }
1104 
1105             // get and add, add and get
1106             {
1107                 vh.set(array, i, '\u0123');
1108 
1109                 char o = (char) vh.getAndAdd(array, i, '\u4567');
1110                 assertEquals(o, '\u0123', "getAndAdd char");
1111                 char x = (char) vh.get(array, i);
1112                 assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value");
1113             }
1114 
1115             {
1116                 vh.set(array, i, '\u0123');
1117 
1118                 char o = (char) vh.getAndAddAcquire(array, i, '\u4567');
1119                 assertEquals(o, '\u0123', "getAndAddAcquire char");
1120                 char x = (char) vh.get(array, i);
1121                 assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value");
1122             }
1123 
1124             {
1125                 vh.set(array, i, '\u0123');
1126 
1127                 char o = (char) vh.getAndAddRelease(array, i, '\u4567');
1128                 assertEquals(o, '\u0123', "getAndAddReleasechar");
1129                 char x = (char) vh.get(array, i);
1130                 assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value");
1131             }
1132 
1133             // get and bitwise or
1134             {
1135                 vh.set(array, i, '\u0123');
1136 
1137                 char o = (char) vh.getAndBitwiseOr(array, i, '\u4567');
1138                 assertEquals(o, '\u0123', "getAndBitwiseOr char");
1139                 char x = (char) vh.get(array, i);
1140                 assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value");
1141             }
1142 
1143             {
1144                 vh.set(array, i, '\u0123');
1145 
1146                 char o = (char) vh.getAndBitwiseOrAcquire(array, i, '\u4567');
1147                 assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char");
1148                 char x = (char) vh.get(array, i);
1149                 assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value");
1150             }
1151 
1152             {
1153                 vh.set(array, i, '\u0123');
1154 
1155                 char o = (char) vh.getAndBitwiseOrRelease(array, i, '\u4567');
1156                 assertEquals(o, '\u0123', "getAndBitwiseOrRelease char");
1157                 char x = (char) vh.get(array, i);
1158                 assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value");
1159             }
1160 
1161             // get and bitwise and
1162             {
1163                 vh.set(array, i, '\u0123');
1164 
1165                 char o = (char) vh.getAndBitwiseAnd(array, i, '\u4567');
1166                 assertEquals(o, '\u0123', "getAndBitwiseAnd char");
1167                 char x = (char) vh.get(array, i);
1168                 assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value");
1169             }
1170 
1171             {
1172                 vh.set(array, i, '\u0123');
1173 
1174                 char o = (char) vh.getAndBitwiseAndAcquire(array, i, '\u4567');
1175                 assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char");
1176                 char x = (char) vh.get(array, i);
1177                 assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value");
1178             }
1179 
1180             {
1181                 vh.set(array, i, '\u0123');
1182 
1183                 char o = (char) vh.getAndBitwiseAndRelease(array, i, '\u4567');
1184                 assertEquals(o, '\u0123', "getAndBitwiseAndRelease char");
1185                 char x = (char) vh.get(array, i);
1186                 assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value");
1187             }
1188 
1189             // get and bitwise xor
1190             {
1191                 vh.set(array, i, '\u0123');
1192 
1193                 char o = (char) vh.getAndBitwiseXor(array, i, '\u4567');
1194                 assertEquals(o, '\u0123', "getAndBitwiseXor char");
1195                 char x = (char) vh.get(array, i);
1196                 assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value");
1197             }
1198 
1199             {
1200                 vh.set(array, i, '\u0123');
1201 
1202                 char o = (char) vh.getAndBitwiseXorAcquire(array, i, '\u4567');
1203                 assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char");
1204                 char x = (char) vh.get(array, i);
1205                 assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value");
1206             }
1207 
1208             {
1209                 vh.set(array, i, '\u0123');
1210 
1211                 char o = (char) vh.getAndBitwiseXorRelease(array, i, '\u4567');
1212                 assertEquals(o, '\u0123', "getAndBitwiseXorRelease char");
1213                 char x = (char) vh.get(array, i);
1214                 assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value");
1215             }
1216         }
1217     }
1218 
testArrayUnsupported(VarHandle vh)1219     static void testArrayUnsupported(VarHandle vh) {
1220         char[] array = new char[10];
1221 
1222         int i = 0;
1223 
1224 
1225     }
1226 
testArrayIndexOutOfBounds(VarHandle vh)1227     static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
1228         char[] array = new char[10];
1229 
1230         for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
1231             final int ci = i;
1232 
1233             checkIOOBE(() -> {
1234                 char x = (char) vh.get(array, ci);
1235             });
1236 
1237             checkIOOBE(() -> {
1238                 vh.set(array, ci, '\u0123');
1239             });
1240 
1241             checkIOOBE(() -> {
1242                 char x = (char) vh.getVolatile(array, ci);
1243             });
1244 
1245             checkIOOBE(() -> {
1246                 vh.setVolatile(array, ci, '\u0123');
1247             });
1248 
1249             checkIOOBE(() -> {
1250                 char x = (char) vh.getAcquire(array, ci);
1251             });
1252 
1253             checkIOOBE(() -> {
1254                 vh.setRelease(array, ci, '\u0123');
1255             });
1256 
1257             checkIOOBE(() -> {
1258                 char x = (char) vh.getOpaque(array, ci);
1259             });
1260 
1261             checkIOOBE(() -> {
1262                 vh.setOpaque(array, ci, '\u0123');
1263             });
1264 
1265             checkIOOBE(() -> {
1266                 boolean r = vh.compareAndSet(array, ci, '\u0123', '\u4567');
1267             });
1268 
1269             checkIOOBE(() -> {
1270                 char r = (char) vh.compareAndExchange(array, ci, '\u4567', '\u0123');
1271             });
1272 
1273             checkIOOBE(() -> {
1274                 char r = (char) vh.compareAndExchangeAcquire(array, ci, '\u4567', '\u0123');
1275             });
1276 
1277             checkIOOBE(() -> {
1278                 char r = (char) vh.compareAndExchangeRelease(array, ci, '\u4567', '\u0123');
1279             });
1280 
1281             checkIOOBE(() -> {
1282                 boolean r = vh.weakCompareAndSetPlain(array, ci, '\u0123', '\u4567');
1283             });
1284 
1285             checkIOOBE(() -> {
1286                 boolean r = vh.weakCompareAndSet(array, ci, '\u0123', '\u4567');
1287             });
1288 
1289             checkIOOBE(() -> {
1290                 boolean r = vh.weakCompareAndSetAcquire(array, ci, '\u0123', '\u4567');
1291             });
1292 
1293             checkIOOBE(() -> {
1294                 boolean r = vh.weakCompareAndSetRelease(array, ci, '\u0123', '\u4567');
1295             });
1296 
1297             checkIOOBE(() -> {
1298                 char o = (char) vh.getAndSet(array, ci, '\u0123');
1299             });
1300 
1301             checkIOOBE(() -> {
1302                 char o = (char) vh.getAndSetAcquire(array, ci, '\u0123');
1303             });
1304 
1305             checkIOOBE(() -> {
1306                 char o = (char) vh.getAndSetRelease(array, ci, '\u0123');
1307             });
1308 
1309             checkIOOBE(() -> {
1310                 char o = (char) vh.getAndAdd(array, ci, '\u0123');
1311             });
1312 
1313             checkIOOBE(() -> {
1314                 char o = (char) vh.getAndAddAcquire(array, ci, '\u0123');
1315             });
1316 
1317             checkIOOBE(() -> {
1318                 char o = (char) vh.getAndAddRelease(array, ci, '\u0123');
1319             });
1320 
1321             checkIOOBE(() -> {
1322                 char o = (char) vh.getAndBitwiseOr(array, ci, '\u0123');
1323             });
1324 
1325             checkIOOBE(() -> {
1326                 char o = (char) vh.getAndBitwiseOrAcquire(array, ci, '\u0123');
1327             });
1328 
1329             checkIOOBE(() -> {
1330                 char o = (char) vh.getAndBitwiseOrRelease(array, ci, '\u0123');
1331             });
1332 
1333             checkIOOBE(() -> {
1334                 char o = (char) vh.getAndBitwiseAnd(array, ci, '\u0123');
1335             });
1336 
1337             checkIOOBE(() -> {
1338                 char o = (char) vh.getAndBitwiseAndAcquire(array, ci, '\u0123');
1339             });
1340 
1341             checkIOOBE(() -> {
1342                 char o = (char) vh.getAndBitwiseAndRelease(array, ci, '\u0123');
1343             });
1344 
1345             checkIOOBE(() -> {
1346                 char o = (char) vh.getAndBitwiseXor(array, ci, '\u0123');
1347             });
1348 
1349             checkIOOBE(() -> {
1350                 char o = (char) vh.getAndBitwiseXorAcquire(array, ci, '\u0123');
1351             });
1352 
1353             checkIOOBE(() -> {
1354                 char o = (char) vh.getAndBitwiseXorRelease(array, ci, '\u0123');
1355             });
1356         }
1357     }
1358 
1359 }
1360 
1361