1 /*
2  * Copyright (c) 2015, 2016, 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=20000 VarHandleTestMethodHandleAccessShort
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 VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest {
45     static final short static_final_v = (short)0x0123;
46 
47     static short static_v;
48 
49     final short final_v = (short)0x0123;
50 
51     short v;
52 
53     VarHandle vhFinalField;
54 
55     VarHandle vhField;
56 
57     VarHandle vhStaticField;
58 
59     VarHandle vhStaticFinalField;
60 
61     VarHandle vhArray;
62 
63     @BeforeClass
setup()64     public void setup() throws Exception {
65         vhFinalField = MethodHandles.lookup().findVarHandle(
66                 VarHandleTestMethodHandleAccessShort.class, "final_v", short.class);
67 
68         vhField = MethodHandles.lookup().findVarHandle(
69                 VarHandleTestMethodHandleAccessShort.class, "v", short.class);
70 
71         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
72             VarHandleTestMethodHandleAccessShort.class, "static_final_v", short.class);
73 
74         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
75             VarHandleTestMethodHandleAccessShort.class, "static_v", short.class);
76 
77         vhArray = MethodHandles.arrayElementVarHandle(short[].class);
78     }
79 
80 
81     @DataProvider
accessTestCaseProvider()82     public Object[][] accessTestCaseProvider() throws Exception {
83         List<AccessTestCase<?>> cases = new ArrayList<>();
84 
85         for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
86             cases.add(new MethodHandleAccessTestCase("Instance field",
87                                                      vhField, f, hs -> testInstanceField(this, hs)));
88             cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
89                                                      vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
90                                                      false));
91 
92             cases.add(new MethodHandleAccessTestCase("Static field",
93                                                      vhStaticField, f, VarHandleTestMethodHandleAccessShort::testStaticField));
94             cases.add(new MethodHandleAccessTestCase("Static field unsupported",
95                                                      vhStaticField, f, VarHandleTestMethodHandleAccessShort::testStaticFieldUnsupported,
96                                                      false));
97 
98             cases.add(new MethodHandleAccessTestCase("Array",
99                                                      vhArray, f, VarHandleTestMethodHandleAccessShort::testArray));
100             cases.add(new MethodHandleAccessTestCase("Array unsupported",
101                                                      vhArray, f, VarHandleTestMethodHandleAccessShort::testArrayUnsupported,
102                                                      false));
103             cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
104                                                      vhArray, f, VarHandleTestMethodHandleAccessShort::testArrayIndexOutOfBounds,
105                                                      false));
106         }
107 
108         // Work around issue with jtreg summary reporting which truncates
109         // the String result of Object.toString to 30 characters, hence
110         // the first dummy argument
111         return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
112     }
113 
114     @Test(dataProvider = "accessTestCaseProvider")
testAccess(String desc, AccessTestCase<T> atc)115     public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
116         T t = atc.get();
117         int iters = atc.requiresLoop() ? ITERS : 1;
118         for (int c = 0; c < iters; c++) {
119             atc.testAccess(t);
120         }
121     }
122 
123 
testInstanceField(VarHandleTestMethodHandleAccessShort recv, Handles hs)124     static void testInstanceField(VarHandleTestMethodHandleAccessShort recv, Handles hs) throws Throwable {
125         // Plain
126         {
127             hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
128             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
129             assertEquals(x, (short)0x0123, "set short value");
130         }
131 
132 
133         // Volatile
134         {
135             hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, (short)0x4567);
136             short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
137             assertEquals(x, (short)0x4567, "setVolatile short value");
138         }
139 
140         // Lazy
141         {
142             hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, (short)0x0123);
143             short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
144             assertEquals(x, (short)0x0123, "setRelease short value");
145         }
146 
147         // Opaque
148         {
149             hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, (short)0x4567);
150             short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
151             assertEquals(x, (short)0x4567, "setOpaque short value");
152         }
153 
154         hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
155 
156         // Compare
157         {
158             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (short)0x0123, (short)0x4567);
159             assertEquals(r, true, "success compareAndSet short");
160             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
161             assertEquals(x, (short)0x4567, "success compareAndSet short value");
162         }
163 
164         {
165             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (short)0x0123, (short)0x89AB);
166             assertEquals(r, false, "failing compareAndSet short");
167             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
168             assertEquals(x, (short)0x4567, "failing compareAndSet short value");
169         }
170 
171         {
172             short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (short)0x4567, (short)0x0123);
173             assertEquals(r, (short)0x4567, "success compareAndExchange short");
174             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
175             assertEquals(x, (short)0x0123, "success compareAndExchange short value");
176         }
177 
178         {
179             short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (short)0x4567, (short)0x89AB);
180             assertEquals(r, (short)0x0123, "failing compareAndExchange short");
181             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
182             assertEquals(x, (short)0x0123, "failing compareAndExchange short value");
183         }
184 
185         {
186             short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (short)0x0123, (short)0x4567);
187             assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short");
188             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
189             assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value");
190         }
191 
192         {
193             short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (short)0x0123, (short)0x89AB);
194             assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short");
195             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
196             assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value");
197         }
198 
199         {
200             short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (short)0x4567, (short)0x0123);
201             assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short");
202             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
203             assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value");
204         }
205 
206         {
207             short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (short)0x4567, (short)0x89AB);
208             assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short");
209             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
210             assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value");
211         }
212 
213         {
214             boolean success = false;
215             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
216                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, (short)0x0123, (short)0x4567);
217             }
218             assertEquals(success, true, "weakCompareAndSetPlain short");
219             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
220             assertEquals(x, (short)0x4567, "weakCompareAndSetPlain short value");
221         }
222 
223         {
224             boolean success = false;
225             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
226                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, (short)0x4567, (short)0x0123);
227             }
228             assertEquals(success, true, "weakCompareAndSetAcquire short");
229             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
230             assertEquals(x, (short)0x0123, "weakCompareAndSetAcquire short");
231         }
232 
233         {
234             boolean success = false;
235             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
236                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, (short)0x0123, (short)0x4567);
237             }
238             assertEquals(success, true, "weakCompareAndSetRelease short");
239             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
240             assertEquals(x, (short)0x4567, "weakCompareAndSetRelease short");
241         }
242 
243         {
244             boolean success = false;
245             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
246                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, (short)0x4567, (short)0x0123);
247             }
248             assertEquals(success, true, "weakCompareAndSet short");
249             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
250             assertEquals(x, (short)0x0123, "weakCompareAndSet short");
251         }
252 
253         // Compare set and get
254         {
255             short o = (short) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, (short)0x4567);
256             assertEquals(o, (short)0x0123, "getAndSet short");
257             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
258             assertEquals(x, (short)0x4567, "getAndSet short value");
259         }
260 
261         // get and add, add and get
262         {
263             hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
264 
265             short o = (short) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, (short)0x4567);
266             assertEquals(o, (short)0x0123, "getAndAdd short");
267             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
268             assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value");
269         }
270 
271         {
272             hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
273 
274             short o = (short) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, (short)0x4567);
275             assertEquals(o, (short)0x0123, "getAndAddAcquire short");
276             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
277             assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value");
278         }
279 
280         {
281             hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
282 
283             short o = (short) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, (short)0x4567);
284             assertEquals(o, (short)0x0123, "getAndAddRelease short");
285             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
286             assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value");
287         }
288 
289         // get and bitwise or
290         {
291             hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
292 
293             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, (short)0x4567);
294             assertEquals(o, (short)0x0123, "getAndBitwiseOr short");
295             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
296             assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value");
297         }
298 
299         {
300             hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
301 
302             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, (short)0x4567);
303             assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short");
304             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
305             assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value");
306         }
307 
308         {
309             hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
310 
311             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, (short)0x4567);
312             assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short");
313             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
314             assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value");
315         }
316 
317         // get and bitwise and
318         {
319             hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
320 
321             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, (short)0x4567);
322             assertEquals(o, (short)0x0123, "getAndBitwiseAnd short");
323             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
324             assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value");
325         }
326 
327         {
328             hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
329 
330             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, (short)0x4567);
331             assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short");
332             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
333             assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value");
334         }
335 
336         {
337             hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
338 
339             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, (short)0x4567);
340             assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short");
341             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
342             assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value");
343         }
344 
345         // get and bitwise xor
346         {
347             hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
348 
349             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, (short)0x4567);
350             assertEquals(o, (short)0x0123, "getAndBitwiseXor short");
351             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
352             assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value");
353         }
354 
355         {
356             hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
357 
358             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, (short)0x4567);
359             assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short");
360             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
361             assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value");
362         }
363 
364         {
365             hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123);
366 
367             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, (short)0x4567);
368             assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short");
369             short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv);
370             assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short value");
371         }
372     }
373 
testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessShort recv, Handles hs)374     static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessShort recv, Handles hs) throws Throwable {
375 
376 
377     }
378 
379 
testStaticField(Handles hs)380     static void testStaticField(Handles hs) throws Throwable {
381         // Plain
382         {
383             hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
384             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
385             assertEquals(x, (short)0x0123, "set short value");
386         }
387 
388 
389         // Volatile
390         {
391             hs.get(TestAccessMode.SET_VOLATILE).invokeExact((short)0x4567);
392             short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
393             assertEquals(x, (short)0x4567, "setVolatile short value");
394         }
395 
396         // Lazy
397         {
398             hs.get(TestAccessMode.SET_RELEASE).invokeExact((short)0x0123);
399             short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
400             assertEquals(x, (short)0x0123, "setRelease short value");
401         }
402 
403         // Opaque
404         {
405             hs.get(TestAccessMode.SET_OPAQUE).invokeExact((short)0x4567);
406             short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
407             assertEquals(x, (short)0x4567, "setOpaque short value");
408         }
409 
410         hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
411 
412         // Compare
413         {
414             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((short)0x0123, (short)0x4567);
415             assertEquals(r, true, "success compareAndSet short");
416             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
417             assertEquals(x, (short)0x4567, "success compareAndSet short value");
418         }
419 
420         {
421             boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((short)0x0123, (short)0x89AB);
422             assertEquals(r, false, "failing compareAndSet short");
423             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
424             assertEquals(x, (short)0x4567, "failing compareAndSet short value");
425         }
426 
427         {
428             short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((short)0x4567, (short)0x0123);
429             assertEquals(r, (short)0x4567, "success compareAndExchange short");
430             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
431             assertEquals(x, (short)0x0123, "success compareAndExchange short value");
432         }
433 
434         {
435             short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((short)0x4567, (short)0x89AB);
436             assertEquals(r, (short)0x0123, "failing compareAndExchange short");
437             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
438             assertEquals(x, (short)0x0123, "failing compareAndExchange short value");
439         }
440 
441         {
442             short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((short)0x0123, (short)0x4567);
443             assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short");
444             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
445             assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value");
446         }
447 
448         {
449             short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((short)0x0123, (short)0x89AB);
450             assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short");
451             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
452             assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value");
453         }
454 
455         {
456             short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((short)0x4567, (short)0x0123);
457             assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short");
458             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
459             assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value");
460         }
461 
462         {
463             short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((short)0x4567, (short)0x89AB);
464             assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short");
465             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
466             assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value");
467         }
468 
469         {
470             boolean success = false;
471             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
472                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact((short)0x0123, (short)0x4567);
473             }
474             assertEquals(success, true, "weakCompareAndSetPlain short");
475             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
476             assertEquals(x, (short)0x4567, "weakCompareAndSetPlain short value");
477         }
478 
479         {
480             boolean success = false;
481             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
482                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact((short)0x4567, (short)0x0123);
483             }
484             assertEquals(success, true, "weakCompareAndSetAcquire short");
485             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
486             assertEquals(x, (short)0x0123, "weakCompareAndSetAcquire short");
487         }
488 
489         {
490             boolean success = false;
491             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
492                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact((short)0x0123, (short)0x4567);
493             }
494             assertEquals(success, true, "weakCompareAndSetRelease short");
495             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
496             assertEquals(x, (short)0x4567, "weakCompareAndSetRelease short");
497         }
498 
499         {
500             boolean success = false;
501             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
502                 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact((short)0x4567, (short)0x0123);
503             }
504             assertEquals(success, true, "weakCompareAndSet short");
505             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
506             assertEquals(x, (short)0x0123, "weakCompareAndSet short");
507         }
508 
509         // Compare set and get
510         {
511             hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
512 
513             short o = (short) hs.get(TestAccessMode.GET_AND_SET).invokeExact((short)0x4567);
514             assertEquals(o, (short)0x0123, "getAndSet short");
515             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
516             assertEquals(x, (short)0x4567, "getAndSet short value");
517         }
518 
519         // Compare set and get
520         {
521             hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
522 
523             short o = (short) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact((short)0x4567);
524             assertEquals(o, (short)0x0123, "getAndSetAcquire short");
525             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
526             assertEquals(x, (short)0x4567, "getAndSetAcquire short value");
527         }
528 
529         // Compare set and get
530         {
531             hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
532 
533             short o = (short) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact((short)0x4567);
534             assertEquals(o, (short)0x0123, "getAndSetRelease short");
535             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
536             assertEquals(x, (short)0x4567, "getAndSetRelease short value");
537         }
538 
539         // get and add, add and get
540         {
541             hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
542 
543             short o = (short) hs.get(TestAccessMode.GET_AND_ADD).invokeExact((short)0x4567);
544             assertEquals(o, (short)0x0123, "getAndAdd short");
545             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
546             assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value");
547         }
548 
549         {
550             hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
551 
552             short o = (short) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact((short)0x4567);
553             assertEquals(o, (short)0x0123, "getAndAddAcquire short");
554             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
555             assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value");
556         }
557 
558         {
559             hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
560 
561             short o = (short) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact((short)0x4567);
562             assertEquals(o, (short)0x0123, "getAndAddRelease short");
563             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
564             assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value");
565         }
566 
567         // get and bitwise or
568         {
569             hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
570 
571             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact((short)0x4567);
572             assertEquals(o, (short)0x0123, "getAndBitwiseOr short");
573             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
574             assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value");
575         }
576 
577         {
578             hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
579 
580             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact((short)0x4567);
581             assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short");
582             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
583             assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value");
584         }
585 
586         {
587             hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
588 
589             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact((short)0x4567);
590             assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short");
591             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
592             assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value");
593         }
594 
595         // get and bitwise and
596         {
597             hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
598 
599             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact((short)0x4567);
600             assertEquals(o, (short)0x0123, "getAndBitwiseAnd short");
601             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
602             assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value");
603         }
604 
605         {
606             hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
607 
608             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact((short)0x4567);
609             assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short");
610             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
611             assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value");
612         }
613 
614         {
615             hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
616 
617             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact((short)0x4567);
618             assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short");
619             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
620             assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value");
621         }
622 
623         // get and bitwise xor
624         {
625             hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
626 
627             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact((short)0x4567);
628             assertEquals(o, (short)0x0123, "getAndBitwiseXor short");
629             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
630             assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value");
631         }
632 
633         {
634             hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
635 
636             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact((short)0x4567);
637             assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short");
638             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
639             assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value");
640         }
641 
642         {
643             hs.get(TestAccessMode.SET).invokeExact((short)0x0123);
644 
645             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact((short)0x4567);
646             assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short");
647             short x = (short) hs.get(TestAccessMode.GET).invokeExact();
648             assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short value");
649         }
650     }
651 
testStaticFieldUnsupported(Handles hs)652     static void testStaticFieldUnsupported(Handles hs) throws Throwable {
653 
654 
655     }
656 
657 
testArray(Handles hs)658     static void testArray(Handles hs) throws Throwable {
659         short[] array = new short[10];
660 
661         for (int i = 0; i < array.length; i++) {
662             // Plain
663             {
664                 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
665                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
666                 assertEquals(x, (short)0x0123, "get short value");
667             }
668 
669 
670             // Volatile
671             {
672                 hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, (short)0x4567);
673                 short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
674                 assertEquals(x, (short)0x4567, "setVolatile short value");
675             }
676 
677             // Lazy
678             {
679                 hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, (short)0x0123);
680                 short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
681                 assertEquals(x, (short)0x0123, "setRelease short value");
682             }
683 
684             // Opaque
685             {
686                 hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, (short)0x4567);
687                 short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
688                 assertEquals(x, (short)0x4567, "setOpaque short value");
689             }
690 
691             hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
692 
693             // Compare
694             {
695                 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (short)0x0123, (short)0x4567);
696                 assertEquals(r, true, "success compareAndSet short");
697                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
698                 assertEquals(x, (short)0x4567, "success compareAndSet short value");
699             }
700 
701             {
702                 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (short)0x0123, (short)0x89AB);
703                 assertEquals(r, false, "failing compareAndSet short");
704                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
705                 assertEquals(x, (short)0x4567, "failing compareAndSet short value");
706             }
707 
708             {
709                 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (short)0x4567, (short)0x0123);
710                 assertEquals(r, (short)0x4567, "success compareAndExchange short");
711                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
712                 assertEquals(x, (short)0x0123, "success compareAndExchange short value");
713             }
714 
715             {
716                 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (short)0x4567, (short)0x89AB);
717                 assertEquals(r, (short)0x0123, "failing compareAndExchange short");
718                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
719                 assertEquals(x, (short)0x0123, "failing compareAndExchange short value");
720             }
721 
722             {
723                 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (short)0x0123, (short)0x4567);
724                 assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short");
725                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
726                 assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value");
727             }
728 
729             {
730                 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (short)0x0123, (short)0x89AB);
731                 assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short");
732                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
733                 assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value");
734             }
735 
736             {
737                 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (short)0x4567, (short)0x0123);
738                 assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short");
739                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
740                 assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value");
741             }
742 
743             {
744                 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (short)0x4567, (short)0x89AB);
745                 assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short");
746                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
747                 assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value");
748             }
749 
750             {
751                 boolean success = false;
752                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
753                     success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, (short)0x0123, (short)0x4567);
754                 }
755                 assertEquals(success, true, "weakCompareAndSetPlain short");
756                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
757                 assertEquals(x, (short)0x4567, "weakCompareAndSetPlain short value");
758             }
759 
760             {
761                 boolean success = false;
762                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
763                     success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, (short)0x4567, (short)0x0123);
764                 }
765                 assertEquals(success, true, "weakCompareAndSetAcquire short");
766                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
767                 assertEquals(x, (short)0x0123, "weakCompareAndSetAcquire short");
768             }
769 
770             {
771                 boolean success = false;
772                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
773                     success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, (short)0x0123, (short)0x4567);
774                 }
775                 assertEquals(success, true, "weakCompareAndSetRelease short");
776                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
777                 assertEquals(x, (short)0x4567, "weakCompareAndSetRelease short");
778             }
779 
780             {
781                 boolean success = false;
782                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
783                     success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, (short)0x4567, (short)0x0123);
784                 }
785                 assertEquals(success, true, "weakCompareAndSet short");
786                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
787                 assertEquals(x, (short)0x0123, "weakCompareAndSet short");
788             }
789 
790             // Compare set and get
791             {
792                 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
793 
794                 short o = (short) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, (short)0x4567);
795                 assertEquals(o, (short)0x0123, "getAndSet short");
796                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
797                 assertEquals(x, (short)0x4567, "getAndSet short value");
798             }
799 
800             {
801                 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
802 
803                 short o = (short) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, (short)0x4567);
804                 assertEquals(o, (short)0x0123, "getAndSetAcquire short");
805                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
806                 assertEquals(x, (short)0x4567, "getAndSetAcquire short value");
807             }
808 
809             {
810                 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
811 
812                 short o = (short) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, (short)0x4567);
813                 assertEquals(o, (short)0x0123, "getAndSetRelease short");
814                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
815                 assertEquals(x, (short)0x4567, "getAndSetRelease short value");
816             }
817 
818             // get and add, add and get
819             {
820                 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
821 
822                 short o = (short) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, (short)0x4567);
823                 assertEquals(o, (short)0x0123, "getAndAdd short");
824                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
825                 assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value");
826             }
827 
828             {
829                 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
830 
831                 short o = (short) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, (short)0x4567);
832                 assertEquals(o, (short)0x0123, "getAndAddAcquire short");
833                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
834                 assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value");
835             }
836 
837             {
838                 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
839 
840                 short o = (short) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, (short)0x4567);
841                 assertEquals(o, (short)0x0123, "getAndAddRelease short");
842                 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
843                 assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value");
844             }
845 
846         // get and bitwise or
847         {
848             hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
849 
850             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, (short)0x4567);
851             assertEquals(o, (short)0x0123, "getAndBitwiseOr short");
852             short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
853             assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value");
854         }
855 
856         {
857             hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
858 
859             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, (short)0x4567);
860             assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short");
861             short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
862             assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value");
863         }
864 
865         {
866             hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
867 
868             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, (short)0x4567);
869             assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short");
870             short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
871             assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value");
872         }
873 
874         // get and bitwise and
875         {
876             hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
877 
878             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, (short)0x4567);
879             assertEquals(o, (short)0x0123, "getAndBitwiseAnd short");
880             short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
881             assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value");
882         }
883 
884         {
885             hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
886 
887             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, (short)0x4567);
888             assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short");
889             short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
890             assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value");
891         }
892 
893         {
894             hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
895 
896             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, (short)0x4567);
897             assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short");
898             short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
899             assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value");
900         }
901 
902         // get and bitwise xor
903         {
904             hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
905 
906             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, (short)0x4567);
907             assertEquals(o, (short)0x0123, "getAndBitwiseXor short");
908             short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
909             assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value");
910         }
911 
912         {
913             hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
914 
915             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, (short)0x4567);
916             assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short");
917             short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
918             assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value");
919         }
920 
921         {
922             hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123);
923 
924             short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, (short)0x4567);
925             assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short");
926             short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i);
927             assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short value");
928         }
929         }
930     }
931 
testArrayUnsupported(Handles hs)932     static void testArrayUnsupported(Handles hs) throws Throwable {
933         short[] array = new short[10];
934 
935         final int i = 0;
936 
937 
938     }
939 
testArrayIndexOutOfBounds(Handles hs)940     static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
941         short[] array = new short[10];
942 
943         for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
944             final int ci = i;
945 
946             for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
947                 checkIOOBE(am, () -> {
948                     short x = (short) hs.get(am).invokeExact(array, ci);
949                 });
950             }
951 
952             for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
953                 checkIOOBE(am, () -> {
954                     hs.get(am).invokeExact(array, ci, (short)0x0123);
955                 });
956             }
957 
958             for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
959                 checkIOOBE(am, () -> {
960                     boolean r = (boolean) hs.get(am).invokeExact(array, ci, (short)0x0123, (short)0x4567);
961                 });
962             }
963 
964             for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
965                 checkIOOBE(am, () -> {
966                     short r = (short) hs.get(am).invokeExact(array, ci, (short)0x4567, (short)0x0123);
967                 });
968             }
969 
970             for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
971                 checkIOOBE(am, () -> {
972                     short o = (short) hs.get(am).invokeExact(array, ci, (short)0x0123);
973                 });
974             }
975 
976             for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
977                 checkIOOBE(am, () -> {
978                     short o = (short) hs.get(am).invokeExact(array, ci, (short)0x89AB);
979                 });
980             }
981 
982             for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
983                 checkIOOBE(am, () -> {
984                     short o = (short) hs.get(am).invokeExact(array, ci, (short)0x89AB);
985                 });
986             }
987         }
988     }
989 }
990 
991