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