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