X-VarHandleTestMethodType.java.template revision 14347:6929d396c267
12351Smartin/*
22351Smartin * Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved.
32351Smartin * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
42351Smartin *
52351Smartin * This code is free software; you can redistribute it and/or modify it
62351Smartin * under the terms of the GNU General Public License version 2 only, as
72351Smartin * published by the Free Software Foundation.
82351Smartin *
92351Smartin * This code is distributed in the hope that it will be useful, but WITHOUT
102351Smartin * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
112351Smartin * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
122351Smartin * version 2 for more details (a copy is included in the LICENSE file that
132351Smartin * accompanied this code).
142351Smartin *
152351Smartin * You should have received a copy of the GNU General Public License version
162351Smartin * 2 along with this work; if not, write to the Free Software Foundation,
172351Smartin * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
182362Sohair *
192362Sohair * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202362Sohair * or visit www.oracle.com if you need additional information or have any
212351Smartin * questions.
222351Smartin */
232351Smartin
242351Smartin/*
252351Smartin * @test
262351Smartin * @run testng/othervm VarHandleTestMethodType$Type$
272351Smartin * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestMethodType$Type$
282351Smartin */
292351Smartin
302351Smartinimport org.testng.annotations.BeforeClass;
313984Sdlimport org.testng.annotations.DataProvider;
322351Smartinimport org.testng.annotations.Test;
332351Smartin
342351Smartinimport java.lang.invoke.MethodHandles;
352351Smartinimport java.lang.invoke.VarHandle;
362351Smartinimport java.util.ArrayList;
372351Smartinimport java.util.Arrays;
382351Smartinimport java.util.List;
392351Smartin
402351Smartinimport static org.testng.Assert.*;
412351Smartin
422351Smartinimport static java.lang.invoke.MethodType.*;
432351Smartin
442351Smartinpublic class VarHandleTestMethodType$Type$ extends VarHandleBaseTest {
452351Smartin    static final $type$ static_final_v = $value1$;
462351Smartin
472351Smartin    static $type$ static_v = $value1$;
482351Smartin
492351Smartin    final $type$ final_v = $value1$;
502351Smartin
512351Smartin    $type$ v = $value1$;
522351Smartin
532351Smartin    VarHandle vhFinalField;
5416622Sdl
552351Smartin    VarHandle vhField;
562351Smartin
572351Smartin    VarHandle vhStaticField;
582351Smartin
592351Smartin    VarHandle vhStaticFinalField;
602351Smartin
612351Smartin    VarHandle vhArray;
622351Smartin
632351Smartin    @BeforeClass
642351Smartin    public void setup() throws Exception {
652351Smartin        vhFinalField = MethodHandles.lookup().findVarHandle(
6616622Sdl                VarHandleTestMethodType$Type$.class, "final_v", $type$.class);
672351Smartin
682351Smartin        vhField = MethodHandles.lookup().findVarHandle(
692351Smartin                VarHandleTestMethodType$Type$.class, "v", $type$.class);
702351Smartin
712351Smartin        vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
722351Smartin            VarHandleTestMethodType$Type$.class, "static_final_v", $type$.class);
732351Smartin
742351Smartin        vhStaticField = MethodHandles.lookup().findStaticVarHandle(
752351Smartin            VarHandleTestMethodType$Type$.class, "static_v", $type$.class);
762351Smartin
772351Smartin        vhArray = MethodHandles.arrayElementVarHandle($type$[].class);
782351Smartin    }
792351Smartin
802351Smartin    @DataProvider
812351Smartin    public Object[][] accessTestCaseProvider() throws Exception {
822351Smartin        List<AccessTestCase<?>> cases = new ArrayList<>();
832351Smartin
842351Smartin        cases.add(new VarHandleAccessTestCase("Instance field wrong method type",
852351Smartin                                              vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
862351Smartin                                              false));
872351Smartin
882351Smartin        cases.add(new VarHandleAccessTestCase("Static field wrong method type",
892351Smartin                                              vhStaticField, VarHandleTestMethodType$Type$::testStaticFieldWrongMethodType,
902351Smartin                                              false));
912351Smartin
922351Smartin        cases.add(new VarHandleAccessTestCase("Array wrong method type",
932351Smartin                                              vhArray, VarHandleTestMethodType$Type$::testArrayWrongMethodType,
942351Smartin                                              false));
952351Smartin        for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
962351Smartin            cases.add(new MethodHandleAccessTestCase("Instance field wrong method type",
972351Smartin                                                     vhField, f, hs -> testInstanceFieldWrongMethodType(this, hs),
982351Smartin                                                     false));
992351Smartin
1002351Smartin            cases.add(new MethodHandleAccessTestCase("Static field wrong method type",
1012351Smartin                                                     vhStaticField, f, VarHandleTestMethodType$Type$::testStaticFieldWrongMethodType,
1022351Smartin                                                     false));
1032351Smartin
1042351Smartin            cases.add(new MethodHandleAccessTestCase("Array wrong method type",
1052351Smartin                                                     vhArray, f, VarHandleTestMethodType$Type$::testArrayWrongMethodType,
1062351Smartin                                                     false));
1072351Smartin        }
1082351Smartin        // Work around issue with jtreg summary reporting which truncates
1092351Smartin        // the String result of Object.toString to 30 characters, hence
1102351Smartin        // the first dummy argument
1112351Smartin        return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
1122351Smartin    }
1132351Smartin
1142351Smartin    @Test(dataProvider = "accessTestCaseProvider")
1152351Smartin    public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
1162351Smartin        T t = atc.get();
1172351Smartin        int iters = atc.requiresLoop() ? ITERS : 1;
1182351Smartin        for (int c = 0; c < iters; c++) {
1192351Smartin            atc.testAccess(t);
1202351Smartin        }
1212351Smartin    }
1222351Smartin
1232351Smartin
1242351Smartin    static void testInstanceFieldWrongMethodType(VarHandleTestMethodType$Type$ recv, VarHandle vh) throws Throwable {
1252351Smartin        // Get
1262351Smartin        // Incorrect argument types
1272351Smartin        checkNPE(() -> { // null receiver
1282351Smartin            $type$ x = ($type$) vh.get(null);
1292351Smartin        });
1302351Smartin        checkCCE(() -> { // receiver reference class
1312351Smartin            $type$ x = ($type$) vh.get(Void.class);
1322351Smartin        });
1332351Smartin        checkWMTE(() -> { // receiver primitive class
1342351Smartin            $type$ x = ($type$) vh.get(0);
1352351Smartin        });
1362351Smartin        // Incorrect return type
1372351Smartin        check{#if[String]?CCE:WMTE}(() -> { // reference class
1382351Smartin            Void x = (Void) vh.get(recv);
1392351Smartin        });
1402351Smartin        checkWMTE(() -> { // primitive class
1412351Smartin            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.get(recv);
1422351Smartin        });
1432351Smartin        // Incorrect arity
1442351Smartin        checkWMTE(() -> { // 0
1452351Smartin            $type$ x = ($type$) vh.get();
1462351Smartin        });
1472351Smartin        checkWMTE(() -> { // >
1482351Smartin            $type$ x = ($type$) vh.get(recv, Void.class);
1492351Smartin        });
1502351Smartin
1512351Smartin
1522351Smartin        // Set
1532351Smartin        // Incorrect argument types
1542351Smartin        checkNPE(() -> { // null receiver
1552351Smartin            vh.set(null, $value1$);
1562351Smartin        });
1572351Smartin        checkCCE(() -> { // receiver reference class
1582351Smartin            vh.set(Void.class, $value1$);
1592351Smartin        });
1602351Smartin        check{#if[String]?CCE:WMTE}(() -> { // value reference class
1612351Smartin            vh.set(recv, Void.class);
1622351Smartin        });
1632351Smartin        checkWMTE(() -> { // receiver primitive class
1642351Smartin            vh.set(0, $value1$);
1652351Smartin        });
1662351Smartin        // Incorrect arity
1672351Smartin        checkWMTE(() -> { // 0
1682351Smartin            vh.set();
1692351Smartin        });
1702351Smartin        checkWMTE(() -> { // >
1712351Smartin            vh.set(recv, $value1$, Void.class);
1722351Smartin        });
1732351Smartin
1742351Smartin
1752351Smartin        // GetVolatile
1762351Smartin        // Incorrect argument types
1772351Smartin        checkNPE(() -> { // null receiver
1782351Smartin            $type$ x = ($type$) vh.getVolatile(null);
1792351Smartin        });
1802351Smartin        checkCCE(() -> { // receiver reference class
1812351Smartin            $type$ x = ($type$) vh.getVolatile(Void.class);
1822351Smartin        });
1832351Smartin        checkWMTE(() -> { // receiver primitive class
1842351Smartin            $type$ x = ($type$) vh.getVolatile(0);
1852351Smartin        });
1862351Smartin        // Incorrect return type
1872351Smartin        check{#if[String]?CCE:WMTE}(() -> { // reference class
1882351Smartin            Void x = (Void) vh.getVolatile(recv);
1892351Smartin        });
1902351Smartin        checkWMTE(() -> { // primitive class
1912351Smartin            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getVolatile(recv);
1922351Smartin        });
1932351Smartin        // Incorrect arity
1942351Smartin        checkWMTE(() -> { // 0
1952351Smartin            $type$ x = ($type$) vh.getVolatile();
1962351Smartin        });
1972351Smartin        checkWMTE(() -> { // >
1982351Smartin            $type$ x = ($type$) vh.getVolatile(recv, Void.class);
1992351Smartin        });
2002351Smartin
2012351Smartin
2022351Smartin        // SetVolatile
203        // Incorrect argument types
204        checkNPE(() -> { // null receiver
205            vh.setVolatile(null, $value1$);
206        });
207        checkCCE(() -> { // receiver reference class
208            vh.setVolatile(Void.class, $value1$);
209        });
210        check{#if[String]?CCE:WMTE}(() -> { // value reference class
211            vh.setVolatile(recv, Void.class);
212        });
213        checkWMTE(() -> { // receiver primitive class
214            vh.setVolatile(0, $value1$);
215        });
216        // Incorrect arity
217        checkWMTE(() -> { // 0
218            vh.setVolatile();
219        });
220        checkWMTE(() -> { // >
221            vh.setVolatile(recv, $value1$, Void.class);
222        });
223
224
225        // GetOpaque
226        // Incorrect argument types
227        checkNPE(() -> { // null receiver
228            $type$ x = ($type$) vh.getOpaque(null);
229        });
230        checkCCE(() -> { // receiver reference class
231            $type$ x = ($type$) vh.getOpaque(Void.class);
232        });
233        checkWMTE(() -> { // receiver primitive class
234            $type$ x = ($type$) vh.getOpaque(0);
235        });
236        // Incorrect return type
237        check{#if[String]?CCE:WMTE}(() -> { // reference class
238            Void x = (Void) vh.getOpaque(recv);
239        });
240        checkWMTE(() -> { // primitive class
241            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getOpaque(recv);
242        });
243        // Incorrect arity
244        checkWMTE(() -> { // 0
245            $type$ x = ($type$) vh.getOpaque();
246        });
247        checkWMTE(() -> { // >
248            $type$ x = ($type$) vh.getOpaque(recv, Void.class);
249        });
250
251
252        // SetOpaque
253        // Incorrect argument types
254        checkNPE(() -> { // null receiver
255            vh.setOpaque(null, $value1$);
256        });
257        checkCCE(() -> { // receiver reference class
258            vh.setOpaque(Void.class, $value1$);
259        });
260        check{#if[String]?CCE:WMTE}(() -> { // value reference class
261            vh.setOpaque(recv, Void.class);
262        });
263        checkWMTE(() -> { // receiver primitive class
264            vh.setOpaque(0, $value1$);
265        });
266        // Incorrect arity
267        checkWMTE(() -> { // 0
268            vh.setOpaque();
269        });
270        checkWMTE(() -> { // >
271            vh.setOpaque(recv, $value1$, Void.class);
272        });
273
274
275        // GetAcquire
276        // Incorrect argument types
277        checkNPE(() -> { // null receiver
278            $type$ x = ($type$) vh.getAcquire(null);
279        });
280        checkCCE(() -> { // receiver reference class
281            $type$ x = ($type$) vh.getAcquire(Void.class);
282        });
283        checkWMTE(() -> { // receiver primitive class
284            $type$ x = ($type$) vh.getAcquire(0);
285        });
286        // Incorrect return type
287        check{#if[String]?CCE:WMTE}(() -> { // reference class
288            Void x = (Void) vh.getAcquire(recv);
289        });
290        checkWMTE(() -> { // primitive class
291            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAcquire(recv);
292        });
293        // Incorrect arity
294        checkWMTE(() -> { // 0
295            $type$ x = ($type$) vh.getAcquire();
296        });
297        checkWMTE(() -> { // >
298            $type$ x = ($type$) vh.getAcquire(recv, Void.class);
299        });
300
301
302        // SetRelease
303        // Incorrect argument types
304        checkNPE(() -> { // null receiver
305            vh.setRelease(null, $value1$);
306        });
307        checkCCE(() -> { // receiver reference class
308            vh.setRelease(Void.class, $value1$);
309        });
310        check{#if[String]?CCE:WMTE}(() -> { // value reference class
311            vh.setRelease(recv, Void.class);
312        });
313        checkWMTE(() -> { // receiver primitive class
314            vh.setRelease(0, $value1$);
315        });
316        // Incorrect arity
317        checkWMTE(() -> { // 0
318            vh.setRelease();
319        });
320        checkWMTE(() -> { // >
321            vh.setRelease(recv, $value1$, Void.class);
322        });
323
324
325#if[CAS]
326        // CompareAndSet
327        // Incorrect argument types
328        checkNPE(() -> { // null receiver
329            boolean r = vh.compareAndSet(null, $value1$, $value1$);
330        });
331        checkCCE(() -> { // receiver reference class
332            boolean r = vh.compareAndSet(Void.class, $value1$, $value1$);
333        });
334        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
335            boolean r = vh.compareAndSet(recv, Void.class, $value1$);
336        });
337        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
338            boolean r = vh.compareAndSet(recv, $value1$, Void.class);
339        });
340        checkWMTE(() -> { // receiver primitive class
341            boolean r = vh.compareAndSet(0, $value1$, $value1$);
342        });
343        // Incorrect arity
344        checkWMTE(() -> { // 0
345            boolean r = vh.compareAndSet();
346        });
347        checkWMTE(() -> { // >
348            boolean r = vh.compareAndSet(recv, $value1$, $value1$, Void.class);
349        });
350
351
352        // WeakCompareAndSet
353        // Incorrect argument types
354        checkNPE(() -> { // null receiver
355            boolean r = vh.weakCompareAndSet(null, $value1$, $value1$);
356        });
357        checkCCE(() -> { // receiver reference class
358            boolean r = vh.weakCompareAndSet(Void.class, $value1$, $value1$);
359        });
360        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
361            boolean r = vh.weakCompareAndSet(recv, Void.class, $value1$);
362        });
363        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
364            boolean r = vh.weakCompareAndSet(recv, $value1$, Void.class);
365        });
366        checkWMTE(() -> { // receiver primitive class
367            boolean r = vh.weakCompareAndSet(0, $value1$, $value1$);
368        });
369        // Incorrect arity
370        checkWMTE(() -> { // 0
371            boolean r = vh.weakCompareAndSet();
372        });
373        checkWMTE(() -> { // >
374            boolean r = vh.weakCompareAndSet(recv, $value1$, $value1$, Void.class);
375        });
376
377
378        // WeakCompareAndSetVolatile
379        // Incorrect argument types
380        checkNPE(() -> { // null receiver
381            boolean r = vh.weakCompareAndSetVolatile(null, $value1$, $value1$);
382        });
383        checkCCE(() -> { // receiver reference class
384            boolean r = vh.weakCompareAndSetVolatile(Void.class, $value1$, $value1$);
385        });
386        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
387            boolean r = vh.weakCompareAndSetVolatile(recv, Void.class, $value1$);
388        });
389        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
390            boolean r = vh.weakCompareAndSetVolatile(recv, $value1$, Void.class);
391        });
392        checkWMTE(() -> { // receiver primitive class
393            boolean r = vh.weakCompareAndSetVolatile(0, $value1$, $value1$);
394        });
395        // Incorrect arity
396        checkWMTE(() -> { // 0
397            boolean r = vh.weakCompareAndSetVolatile();
398        });
399        checkWMTE(() -> { // >
400            boolean r = vh.weakCompareAndSetVolatile(recv, $value1$, $value1$, Void.class);
401        });
402
403
404        // WeakCompareAndSetAcquire
405        // Incorrect argument types
406        checkNPE(() -> { // null receiver
407            boolean r = vh.weakCompareAndSetAcquire(null, $value1$, $value1$);
408        });
409        checkCCE(() -> { // receiver reference class
410            boolean r = vh.weakCompareAndSetAcquire(Void.class, $value1$, $value1$);
411        });
412        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
413            boolean r = vh.weakCompareAndSetAcquire(recv, Void.class, $value1$);
414        });
415        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
416            boolean r = vh.weakCompareAndSetAcquire(recv, $value1$, Void.class);
417        });
418        checkWMTE(() -> { // receiver primitive class
419            boolean r = vh.weakCompareAndSetAcquire(0, $value1$, $value1$);
420        });
421        // Incorrect arity
422        checkWMTE(() -> { // 0
423            boolean r = vh.weakCompareAndSetAcquire();
424        });
425        checkWMTE(() -> { // >
426            boolean r = vh.weakCompareAndSetAcquire(recv, $value1$, $value1$, Void.class);
427        });
428
429
430        // WeakCompareAndSetRelease
431        // Incorrect argument types
432        checkNPE(() -> { // null receiver
433            boolean r = vh.weakCompareAndSetRelease(null, $value1$, $value1$);
434        });
435        checkCCE(() -> { // receiver reference class
436            boolean r = vh.weakCompareAndSetRelease(Void.class, $value1$, $value1$);
437        });
438        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
439            boolean r = vh.weakCompareAndSetRelease(recv, Void.class, $value1$);
440        });
441        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
442            boolean r = vh.weakCompareAndSetRelease(recv, $value1$, Void.class);
443        });
444        checkWMTE(() -> { // receiver primitive class
445            boolean r = vh.weakCompareAndSetRelease(0, $value1$, $value1$);
446        });
447        // Incorrect arity
448        checkWMTE(() -> { // 0
449            boolean r = vh.weakCompareAndSetRelease();
450        });
451        checkWMTE(() -> { // >
452            boolean r = vh.weakCompareAndSetRelease(recv, $value1$, $value1$, Void.class);
453        });
454
455
456        // CompareAndExchangeVolatile
457        // Incorrect argument types
458        checkNPE(() -> { // null receiver
459            $type$ x = ($type$) vh.compareAndExchangeVolatile(null, $value1$, $value1$);
460        });
461        checkCCE(() -> { // receiver reference class
462            $type$ x = ($type$) vh.compareAndExchangeVolatile(Void.class, $value1$, $value1$);
463        });
464        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
465            $type$ x = ($type$) vh.compareAndExchangeVolatile(recv, Void.class, $value1$);
466        });
467        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
468            $type$ x = ($type$) vh.compareAndExchangeVolatile(recv, $value1$, Void.class);
469        });
470        checkWMTE(() -> { // reciever primitive class
471            $type$ x = ($type$) vh.compareAndExchangeVolatile(0, $value1$, $value1$);
472        });
473        // Incorrect return type
474        check{#if[String]?CCE:WMTE}(() -> { // reference class
475            Void r = (Void) vh.compareAndExchangeVolatile(recv, $value1$, $value1$);
476        });
477        checkWMTE(() -> { // primitive class
478            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeVolatile(recv, $value1$, $value1$);
479        });
480        // Incorrect arity
481        checkWMTE(() -> { // 0
482            $type$ x = ($type$) vh.compareAndExchangeVolatile();
483        });
484        checkWMTE(() -> { // >
485            $type$ x = ($type$) vh.compareAndExchangeVolatile(recv, $value1$, $value1$, Void.class);
486        });
487
488
489        // CompareAndExchangeVolatileAcquire
490        // Incorrect argument types
491        checkNPE(() -> { // null receiver
492            $type$ x = ($type$) vh.compareAndExchangeAcquire(null, $value1$, $value1$);
493        });
494        checkCCE(() -> { // receiver reference class
495            $type$ x = ($type$) vh.compareAndExchangeAcquire(Void.class, $value1$, $value1$);
496        });
497        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
498            $type$ x = ($type$) vh.compareAndExchangeAcquire(recv, Void.class, $value1$);
499        });
500        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
501            $type$ x = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, Void.class);
502        });
503        checkWMTE(() -> { // reciever primitive class
504            $type$ x = ($type$) vh.compareAndExchangeAcquire(0, $value1$, $value1$);
505        });
506        // Incorrect return type
507        check{#if[String]?CCE:WMTE}(() -> { // reference class
508            Void r = (Void) vh.compareAndExchangeAcquire(recv, $value1$, $value1$);
509        });
510        checkWMTE(() -> { // primitive class
511            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeAcquire(recv, $value1$, $value1$);
512        });
513        // Incorrect arity
514        checkWMTE(() -> { // 0
515            $type$ x = ($type$) vh.compareAndExchangeAcquire();
516        });
517        checkWMTE(() -> { // >
518            $type$ x = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value1$, Void.class);
519        });
520
521
522        // CompareAndExchangeRelease
523        // Incorrect argument types
524        checkNPE(() -> { // null receiver
525            $type$ x = ($type$) vh.compareAndExchangeRelease(null, $value1$, $value1$);
526        });
527        checkCCE(() -> { // receiver reference class
528            $type$ x = ($type$) vh.compareAndExchangeRelease(Void.class, $value1$, $value1$);
529        });
530        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
531            $type$ x = ($type$) vh.compareAndExchangeRelease(recv, Void.class, $value1$);
532        });
533        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
534            $type$ x = ($type$) vh.compareAndExchangeRelease(recv, $value1$, Void.class);
535        });
536        checkWMTE(() -> { // reciever primitive class
537            $type$ x = ($type$) vh.compareAndExchangeRelease(0, $value1$, $value1$);
538        });
539        // Incorrect return type
540        check{#if[String]?CCE:WMTE}(() -> { // reference class
541            Void r = (Void) vh.compareAndExchangeRelease(recv, $value1$, $value1$);
542        });
543        checkWMTE(() -> { // primitive class
544            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeRelease(recv, $value1$, $value1$);
545        });
546        // Incorrect arity
547        checkWMTE(() -> { // 0
548            $type$ x = ($type$) vh.compareAndExchangeRelease();
549        });
550        checkWMTE(() -> { // >
551            $type$ x = ($type$) vh.compareAndExchangeRelease(recv, $value1$, $value1$, Void.class);
552        });
553
554
555        // GetAndSet
556        // Incorrect argument types
557        checkNPE(() -> { // null receiver
558            $type$ x = ($type$) vh.getAndSet(null, $value1$);
559        });
560        checkCCE(() -> { // receiver reference class
561            $type$ x = ($type$) vh.getAndSet(Void.class, $value1$);
562        });
563        check{#if[String]?CCE:WMTE}(() -> { // value reference class
564            $type$ x = ($type$) vh.getAndSet(recv, Void.class);
565        });
566        checkWMTE(() -> { // reciever primitive class
567            $type$ x = ($type$) vh.getAndSet(0, $value1$);
568        });
569        // Incorrect return type
570        check{#if[String]?CCE:WMTE}(() -> { // reference class
571            Void r = (Void) vh.getAndSet(recv, $value1$);
572        });
573        checkWMTE(() -> { // primitive class
574            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndSet(recv, $value1$);
575        });
576        // Incorrect arity
577        checkWMTE(() -> { // 0
578            $type$ x = ($type$) vh.getAndSet();
579        });
580        checkWMTE(() -> { // >
581            $type$ x = ($type$) vh.getAndSet(recv, $value1$, Void.class);
582        });
583#end[CAS]
584
585#if[AtomicAdd]
586        // GetAndAdd
587        // Incorrect argument types
588        checkNPE(() -> { // null receiver
589            $type$ x = ($type$) vh.getAndAdd(null, $value1$);
590        });
591        checkCCE(() -> { // receiver reference class
592            $type$ x = ($type$) vh.getAndAdd(Void.class, $value1$);
593        });
594        check{#if[String]?CCE:WMTE}(() -> { // value reference class
595            $type$ x = ($type$) vh.getAndAdd(recv, Void.class);
596        });
597        checkWMTE(() -> { // reciever primitive class
598            $type$ x = ($type$) vh.getAndAdd(0, $value1$);
599        });
600        // Incorrect return type
601        check{#if[String]?CCE:WMTE}(() -> { // reference class
602            Void r = (Void) vh.getAndAdd(recv, $value1$);
603        });
604        checkWMTE(() -> { // primitive class
605            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndAdd(recv, $value1$);
606        });
607        // Incorrect arity
608        checkWMTE(() -> { // 0
609            $type$ x = ($type$) vh.getAndAdd();
610        });
611        checkWMTE(() -> { // >
612            $type$ x = ($type$) vh.getAndAdd(recv, $value1$, Void.class);
613        });
614
615
616        // AddAndGet
617        // Incorrect argument types
618        checkNPE(() -> { // null receiver
619            $type$ x = ($type$) vh.addAndGet(null, $value1$);
620        });
621        checkCCE(() -> { // receiver reference class
622            $type$ x = ($type$) vh.addAndGet(Void.class, $value1$);
623        });
624        check{#if[String]?CCE:WMTE}(() -> { // value reference class
625            $type$ x = ($type$) vh.addAndGet(recv, Void.class);
626        });
627        checkWMTE(() -> { // reciever primitive class
628            $type$ x = ($type$) vh.addAndGet(0, $value1$);
629        });
630        // Incorrect return type
631        check{#if[String]?CCE:WMTE}(() -> { // reference class
632            Void r = (Void) vh.addAndGet(recv, $value1$);
633        });
634        checkWMTE(() -> { // primitive class
635            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.addAndGet(recv, $value1$);
636        });
637        // Incorrect arity
638        checkWMTE(() -> { // 0
639            $type$ x = ($type$) vh.addAndGet();
640        });
641        checkWMTE(() -> { // >
642            $type$ x = ($type$) vh.addAndGet(recv, $value1$, Void.class);
643        });
644#end[AtomicAdd]
645    }
646
647    static void testInstanceFieldWrongMethodType(VarHandleTestMethodType$Type$ recv, Handles hs) throws Throwable {
648        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
649            // Incorrect argument types
650            checkNPE(() -> { // null receiver
651                $type$ x = ($type$) hs.get(am, methodType($type$.class, Void.class)).
652                    invoke(null);
653            });
654            checkCCE(() -> { // receiver reference class
655                $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class)).
656                    invoke(Void.class);
657            });
658            checkWMTE(() -> { // receiver primitive class
659                $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class)).
660                    invoke(0);
661            });
662            // Incorrect return type
663            check{#if[String]?CCE:WMTE}(() -> { // reference class
664                Void x = (Void) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class)).
665                    invoke(recv);
666            });
667            checkWMTE(() -> { // primitive class
668                $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, VarHandleTestMethodType$Type$.class)).
669                    invoke(recv);
670            });
671            // Incorrect arity
672            checkWMTE(() -> { // 0
673                $type$ x = ($type$) hs.get(am, methodType($type$.class)).
674                    invoke();
675            });
676            checkWMTE(() -> { // >
677                $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, Class.class)).
678                    invoke(recv, Void.class);
679            });
680        }
681
682        for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
683            // Incorrect argument types
684            checkNPE(() -> { // null receiver
685                hs.get(am, methodType(void.class, Void.class, $type$.class)).
686                    invoke(null, $value1$);
687            });
688            checkCCE(() -> { // receiver reference class
689                hs.get(am, methodType(void.class, Class.class, $type$.class)).
690                    invoke(Void.class, $value1$);
691            });
692            check{#if[String]?CCE:WMTE}(() -> { // value reference class
693                hs.get(am, methodType(void.class, VarHandleTestMethodType$Type$.class, Class.class)).
694                    invoke(recv, Void.class);
695            });
696            checkWMTE(() -> { // receiver primitive class
697                hs.get(am, methodType(void.class, int.class, $type$.class)).
698                    invoke(0, $value1$);
699            });
700            // Incorrect arity
701            checkWMTE(() -> { // 0
702                hs.get(am, methodType(void.class)).
703                    invoke();
704            });
705            checkWMTE(() -> { // >
706                hs.get(am, methodType(void.class, VarHandleTestMethodType$Type$.class, $type$.class, Class.class)).
707                    invoke(recv, $value1$, Void.class);
708            });
709        }
710
711#if[CAS]
712        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
713            // Incorrect argument types
714            checkNPE(() -> { // null receiver
715                boolean r = (boolean) hs.get(am, methodType(boolean.class, Void.class, $type$.class, $type$.class)).
716                    invoke(null, $value1$, $value1$);
717            });
718            checkCCE(() -> { // receiver reference class
719                boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, $type$.class, $type$.class)).
720                    invoke(Void.class, $value1$, $value1$);
721            });
722            check{#if[String]?CCE:WMTE}(() -> { // expected reference class
723                boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodType$Type$.class, Class.class, $type$.class)).
724                    invoke(recv, Void.class, $value1$);
725            });
726            check{#if[String]?CCE:WMTE}(() -> { // actual reference class
727                boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodType$Type$.class, $type$.class, Class.class)).
728                    invoke(recv, $value1$, Void.class);
729            });
730            checkWMTE(() -> { // receiver primitive class
731                boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , $type$.class, $type$.class)).
732                    invoke(0, $value1$, $value1$);
733            });
734            // Incorrect arity
735            checkWMTE(() -> { // 0
736                boolean r = (boolean) hs.get(am, methodType(boolean.class)).
737                    invoke();
738            });
739            checkWMTE(() -> { // >
740                boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodType$Type$.class, $type$.class, $type$.class, Class.class)).
741                    invoke(recv, $value1$, $value1$, Void.class);
742            });
743        }
744
745        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
746            checkNPE(() -> { // null receiver
747                $type$ x = ($type$) hs.get(am, methodType($type$.class, Void.class, $type$.class, $type$.class)).
748                    invoke(null, $value1$, $value1$);
749            });
750            checkCCE(() -> { // receiver reference class
751                $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, $type$.class, $type$.class)).
752                    invoke(Void.class, $value1$, $value1$);
753            });
754            check{#if[String]?CCE:WMTE}(() -> { // expected reference class
755                $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, Class.class, $type$.class)).
756                    invoke(recv, Void.class, $value1$);
757            });
758            check{#if[String]?CCE:WMTE}(() -> { // actual reference class
759                $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, $type$.class, Class.class)).
760                    invoke(recv, $value1$, Void.class);
761            });
762            checkWMTE(() -> { // reciever primitive class
763                $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class , $type$.class, $type$.class)).
764                    invoke(0, $value1$, $value1$);
765            });
766            // Incorrect return type
767            check{#if[String]?CCE:WMTE}(() -> { // reference class
768                Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodType$Type$.class , $type$.class, $type$.class)).
769                    invoke(recv, $value1$, $value1$);
770            });
771            checkWMTE(() -> { // primitive class
772                $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, VarHandleTestMethodType$Type$.class , $type$.class, $type$.class)).
773                    invoke(recv, $value1$, $value1$);
774            });
775            // Incorrect arity
776            checkWMTE(() -> { // 0
777                $type$ x = ($type$) hs.get(am, methodType($type$.class)).
778                    invoke();
779            });
780            checkWMTE(() -> { // >
781                $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, $type$.class, $type$.class, Class.class)).
782                    invoke(recv, $value1$, $value1$, Void.class);
783            });
784        }
785
786        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
787            checkNPE(() -> { // null receiver
788                $type$ x = ($type$) hs.get(am, methodType($type$.class, Void.class, $type$.class)).
789                    invoke(null, $value1$);
790            });
791            checkCCE(() -> { // receiver reference class
792                $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, $type$.class)).
793                    invoke(Void.class, $value1$);
794            });
795            check{#if[String]?CCE:WMTE}(() -> { // value reference class
796                $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, Class.class)).
797                    invoke(recv, Void.class);
798            });
799            checkWMTE(() -> { // reciever primitive class
800                $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class, $type$.class)).
801                    invoke(0, $value1$);
802            });
803            // Incorrect return type
804            check{#if[String]?CCE:WMTE}(() -> { // reference class
805                Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodType$Type$.class, $type$.class)).
806                    invoke(recv, $value1$);
807            });
808            checkWMTE(() -> { // primitive class
809                $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, VarHandleTestMethodType$Type$.class, $type$.class)).
810                    invoke(recv, $value1$);
811            });
812            // Incorrect arity
813            checkWMTE(() -> { // 0
814                $type$ x = ($type$) hs.get(am, methodType($type$.class)).
815                    invoke();
816            });
817            checkWMTE(() -> { // >
818                $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, $type$.class)).
819                    invoke(recv, $value1$, Void.class);
820            });
821        }
822#end[CAS]
823
824#if[AtomicAdd]
825        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
826            checkNPE(() -> { // null receiver
827                $type$ x = ($type$) hs.get(am, methodType($type$.class, Void.class, $type$.class)).
828                    invoke(null, $value1$);
829            });
830            checkCCE(() -> { // receiver reference class
831                $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, $type$.class)).
832                    invoke(Void.class, $value1$);
833            });
834            check{#if[String]?CCE:WMTE}(() -> { // value reference class
835                $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, Class.class)).
836                    invoke(recv, Void.class);
837            });
838            checkWMTE(() -> { // reciever primitive class
839                $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class, $type$.class)).
840                    invoke(0, $value1$);
841            });
842            // Incorrect return type
843            check{#if[String]?CCE:WMTE}(() -> { // reference class
844                Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodType$Type$.class, $type$.class)).
845                    invoke(recv, $value1$);
846            });
847            checkWMTE(() -> { // primitive class
848                $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, VarHandleTestMethodType$Type$.class, $type$.class)).
849                    invoke(recv, $value1$);
850            });
851            // Incorrect arity
852            checkWMTE(() -> { // 0
853                $type$ x = ($type$) hs.get(am, methodType($type$.class)).
854                    invoke();
855            });
856            checkWMTE(() -> { // >
857                $type$ x = ($type$) hs.get(am, methodType($type$.class, VarHandleTestMethodType$Type$.class, $type$.class)).
858                    invoke(recv, $value1$, Void.class);
859            });
860        }
861#end[AtomicAdd]
862    }
863
864
865    static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
866        // Get
867        // Incorrect return type
868        check{#if[String]?CCE:WMTE}(() -> { // reference class
869            Void x = (Void) vh.get();
870        });
871        checkWMTE(() -> { // primitive class
872            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.get();
873        });
874        // Incorrect arity
875        checkWMTE(() -> { // >
876            $type$ x = ($type$) vh.get(Void.class);
877        });
878
879
880        // Set
881        // Incorrect argument types
882        check{#if[String]?CCE:WMTE}(() -> { // value reference class
883            vh.set(Void.class);
884        });
885        // Incorrect arity
886        checkWMTE(() -> { // 0
887            vh.set();
888        });
889        checkWMTE(() -> { // >
890            vh.set($value1$, Void.class);
891        });
892
893
894        // GetVolatile
895        // Incorrect return type
896        check{#if[String]?CCE:WMTE}(() -> { // reference class
897            Void x = (Void) vh.getVolatile();
898        });
899        checkWMTE(() -> { // primitive class
900            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getVolatile();
901        });
902        checkWMTE(() -> { // >
903            $type$ x = ($type$) vh.getVolatile(Void.class);
904        });
905
906
907        // SetVolatile
908        // Incorrect argument types
909        check{#if[String]?CCE:WMTE}(() -> { // value reference class
910            vh.setVolatile(Void.class);
911        });
912        // Incorrect arity
913        checkWMTE(() -> { // 0
914            vh.setVolatile();
915        });
916        checkWMTE(() -> { // >
917            vh.setVolatile($value1$, Void.class);
918        });
919
920
921        // GetOpaque
922        // Incorrect return type
923        check{#if[String]?CCE:WMTE}(() -> { // reference class
924            Void x = (Void) vh.getOpaque();
925        });
926        checkWMTE(() -> { // primitive class
927            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getOpaque();
928        });
929        checkWMTE(() -> { // >
930            $type$ x = ($type$) vh.getOpaque(Void.class);
931        });
932
933
934        // SetOpaque
935        // Incorrect argument types
936        check{#if[String]?CCE:WMTE}(() -> { // value reference class
937            vh.setOpaque(Void.class);
938        });
939        // Incorrect arity
940        checkWMTE(() -> { // 0
941            vh.setOpaque();
942        });
943        checkWMTE(() -> { // >
944            vh.setOpaque($value1$, Void.class);
945        });
946
947
948        // GetAcquire
949        // Incorrect return type
950        check{#if[String]?CCE:WMTE}(() -> { // reference class
951            Void x = (Void) vh.getAcquire();
952        });
953        checkWMTE(() -> { // primitive class
954            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAcquire();
955        });
956        checkWMTE(() -> { // >
957            $type$ x = ($type$) vh.getAcquire(Void.class);
958        });
959
960
961        // SetRelease
962        // Incorrect argument types
963        check{#if[String]?CCE:WMTE}(() -> { // value reference class
964            vh.setRelease(Void.class);
965        });
966        // Incorrect arity
967        checkWMTE(() -> { // 0
968            vh.setRelease();
969        });
970        checkWMTE(() -> { // >
971            vh.setRelease($value1$, Void.class);
972        });
973
974
975#if[CAS]
976        // CompareAndSet
977        // Incorrect argument types
978        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
979            boolean r = vh.compareAndSet(Void.class, $value1$);
980        });
981        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
982            boolean r = vh.compareAndSet($value1$, Void.class);
983        });
984        // Incorrect arity
985        checkWMTE(() -> { // 0
986            boolean r = vh.compareAndSet();
987        });
988        checkWMTE(() -> { // >
989            boolean r = vh.compareAndSet($value1$, $value1$, Void.class);
990        });
991
992
993        // WeakCompareAndSet
994        // Incorrect argument types
995        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
996            boolean r = vh.weakCompareAndSet(Void.class, $value1$);
997        });
998        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
999            boolean r = vh.weakCompareAndSet($value1$, Void.class);
1000        });
1001        // Incorrect arity
1002        checkWMTE(() -> { // 0
1003            boolean r = vh.weakCompareAndSet();
1004        });
1005        checkWMTE(() -> { // >
1006            boolean r = vh.weakCompareAndSet($value1$, $value1$, Void.class);
1007        });
1008
1009
1010        // WeakCompareAndSetVolatile
1011        // Incorrect argument types
1012        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
1013            boolean r = vh.weakCompareAndSetVolatile(Void.class, $value1$);
1014        });
1015        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
1016            boolean r = vh.weakCompareAndSetVolatile($value1$, Void.class);
1017        });
1018        // Incorrect arity
1019        checkWMTE(() -> { // 0
1020            boolean r = vh.weakCompareAndSetVolatile();
1021        });
1022        checkWMTE(() -> { // >
1023            boolean r = vh.weakCompareAndSetVolatile($value1$, $value1$, Void.class);
1024        });
1025
1026
1027        // WeakCompareAndSetAcquire
1028        // Incorrect argument types
1029        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
1030            boolean r = vh.weakCompareAndSetAcquire(Void.class, $value1$);
1031        });
1032        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
1033            boolean r = vh.weakCompareAndSetAcquire($value1$, Void.class);
1034        });
1035        // Incorrect arity
1036        checkWMTE(() -> { // 0
1037            boolean r = vh.weakCompareAndSetAcquire();
1038        });
1039        checkWMTE(() -> { // >
1040            boolean r = vh.weakCompareAndSetAcquire($value1$, $value1$, Void.class);
1041        });
1042
1043
1044        // WeakCompareAndSetRelease
1045        // Incorrect argument types
1046        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
1047            boolean r = vh.weakCompareAndSetRelease(Void.class, $value1$);
1048        });
1049        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
1050            boolean r = vh.weakCompareAndSetRelease($value1$, Void.class);
1051        });
1052        // Incorrect arity
1053        checkWMTE(() -> { // 0
1054            boolean r = vh.weakCompareAndSetRelease();
1055        });
1056        checkWMTE(() -> { // >
1057            boolean r = vh.weakCompareAndSetRelease($value1$, $value1$, Void.class);
1058        });
1059
1060
1061        // CompareAndExchangeVolatile
1062        // Incorrect argument types
1063        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
1064            $type$ x = ($type$) vh.compareAndExchangeVolatile(Void.class, $value1$);
1065        });
1066        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
1067            $type$ x = ($type$) vh.compareAndExchangeVolatile($value1$, Void.class);
1068        });
1069        // Incorrect return type
1070        check{#if[String]?CCE:WMTE}(() -> { // reference class
1071            Void r = (Void) vh.compareAndExchangeVolatile($value1$, $value1$);
1072        });
1073        checkWMTE(() -> { // primitive class
1074            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeVolatile($value1$, $value1$);
1075        });
1076        // Incorrect arity
1077        checkWMTE(() -> { // 0
1078            $type$ x = ($type$) vh.compareAndExchangeVolatile();
1079        });
1080        checkWMTE(() -> { // >
1081            $type$ x = ($type$) vh.compareAndExchangeVolatile($value1$, $value1$, Void.class);
1082        });
1083
1084
1085        // CompareAndExchangeAcquire
1086        // Incorrect argument types
1087        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
1088            $type$ x = ($type$) vh.compareAndExchangeAcquire(Void.class, $value1$);
1089        });
1090        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
1091            $type$ x = ($type$) vh.compareAndExchangeAcquire($value1$, Void.class);
1092        });
1093        // Incorrect return type
1094        check{#if[String]?CCE:WMTE}(() -> { // reference class
1095            Void r = (Void) vh.compareAndExchangeAcquire($value1$, $value1$);
1096        });
1097        checkWMTE(() -> { // primitive class
1098            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeAcquire($value1$, $value1$);
1099        });
1100        // Incorrect arity
1101        checkWMTE(() -> { // 0
1102            $type$ x = ($type$) vh.compareAndExchangeAcquire();
1103        });
1104        checkWMTE(() -> { // >
1105            $type$ x = ($type$) vh.compareAndExchangeAcquire($value1$, $value1$, Void.class);
1106        });
1107
1108
1109        // CompareAndExchangeRelease
1110        // Incorrect argument types
1111        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
1112            $type$ x = ($type$) vh.compareAndExchangeRelease(Void.class, $value1$);
1113        });
1114        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
1115            $type$ x = ($type$) vh.compareAndExchangeRelease($value1$, Void.class);
1116        });
1117        // Incorrect return type
1118        check{#if[String]?CCE:WMTE}(() -> { // reference class
1119            Void r = (Void) vh.compareAndExchangeRelease($value1$, $value1$);
1120        });
1121        checkWMTE(() -> { // primitive class
1122            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeRelease($value1$, $value1$);
1123        });
1124        // Incorrect arity
1125        checkWMTE(() -> { // 0
1126            $type$ x = ($type$) vh.compareAndExchangeRelease();
1127        });
1128        checkWMTE(() -> { // >
1129            $type$ x = ($type$) vh.compareAndExchangeRelease($value1$, $value1$, Void.class);
1130        });
1131
1132
1133        // GetAndSet
1134        // Incorrect argument types
1135        check{#if[String]?CCE:WMTE}(() -> { // value reference class
1136            $type$ x = ($type$) vh.getAndSet(Void.class);
1137        });
1138        // Incorrect return type
1139        check{#if[String]?CCE:WMTE}(() -> { // reference class
1140            Void r = (Void) vh.getAndSet($value1$);
1141        });
1142        checkWMTE(() -> { // primitive class
1143            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndSet($value1$);
1144        });
1145        // Incorrect arity
1146        checkWMTE(() -> { // 0
1147            $type$ x = ($type$) vh.getAndSet();
1148        });
1149        checkWMTE(() -> { // >
1150            $type$ x = ($type$) vh.getAndSet($value1$, Void.class);
1151        });
1152#end[CAS]
1153
1154#if[AtomicAdd]
1155        // GetAndAdd
1156        // Incorrect argument types
1157        check{#if[String]?CCE:WMTE}(() -> { // value reference class
1158            $type$ x = ($type$) vh.getAndAdd(Void.class);
1159        });
1160        // Incorrect return type
1161        check{#if[String]?CCE:WMTE}(() -> { // reference class
1162            Void r = (Void) vh.getAndAdd($value1$);
1163        });
1164        checkWMTE(() -> { // primitive class
1165            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndAdd($value1$);
1166        });
1167        // Incorrect arity
1168        checkWMTE(() -> { // 0
1169            $type$ x = ($type$) vh.getAndAdd();
1170        });
1171        checkWMTE(() -> { // >
1172            $type$ x = ($type$) vh.getAndAdd($value1$, Void.class);
1173        });
1174
1175
1176        // AddAndGet
1177        // Incorrect argument types
1178        check{#if[String]?CCE:WMTE}(() -> { // value reference class
1179            $type$ x = ($type$) vh.addAndGet(Void.class);
1180        });
1181        // Incorrect return type
1182        check{#if[String]?CCE:WMTE}(() -> { // reference class
1183            Void r = (Void) vh.addAndGet($value1$);
1184        });
1185        checkWMTE(() -> { // primitive class
1186            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.addAndGet($value1$);
1187        });
1188        // Incorrect arity
1189        checkWMTE(() -> { // 0
1190            $type$ x = ($type$) vh.addAndGet();
1191        });
1192        checkWMTE(() -> { // >
1193            $type$ x = ($type$) vh.addAndGet($value1$, Void.class);
1194        });
1195#end[AtomicAdd]
1196    }
1197
1198    static void testStaticFieldWrongMethodType(Handles hs) throws Throwable {
1199        int i = 0;
1200
1201        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
1202            // Incorrect return type
1203            check{#if[String]?CCE:WMTE}(() -> { // reference class
1204                Void x = (Void) hs.get(am, methodType(Void.class)).
1205                    invoke();
1206            });
1207            checkWMTE(() -> { // primitive class
1208                $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class)).
1209                    invoke();
1210            });
1211            // Incorrect arity
1212            checkWMTE(() -> { // >
1213                $type$ x = ($type$) hs.get(am, methodType(Class.class)).
1214                    invoke(Void.class);
1215            });
1216        }
1217
1218        for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
1219            check{#if[String]?CCE:WMTE}(() -> { // value reference class
1220                hs.get(am, methodType(void.class, Class.class)).
1221                    invoke(Void.class);
1222            });
1223            // Incorrect arity
1224            checkWMTE(() -> { // 0
1225                hs.get(am, methodType(void.class)).
1226                    invoke();
1227            });
1228            checkWMTE(() -> { // >
1229                hs.get(am, methodType(void.class, $type$.class, Class.class)).
1230                    invoke($value1$, Void.class);
1231            });
1232        }
1233#if[CAS]
1234        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
1235            // Incorrect argument types
1236            check{#if[String]?CCE:WMTE}(() -> { // expected reference class
1237                boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, $type$.class)).
1238                    invoke(Void.class, $value1$);
1239            });
1240            check{#if[String]?CCE:WMTE}(() -> { // actual reference class
1241                boolean r = (boolean) hs.get(am, methodType(boolean.class, $type$.class, Class.class)).
1242                    invoke($value1$, Void.class);
1243            });
1244            // Incorrect arity
1245            checkWMTE(() -> { // 0
1246                boolean r = (boolean) hs.get(am, methodType(boolean.class)).
1247                    invoke();
1248            });
1249            checkWMTE(() -> { // >
1250                boolean r = (boolean) hs.get(am, methodType(boolean.class, $type$.class, $type$.class, Class.class)).
1251                    invoke($value1$, $value1$, Void.class);
1252            });
1253        }
1254
1255        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1256            // Incorrect argument types
1257            check{#if[String]?CCE:WMTE}(() -> { // expected reference class
1258                $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, $type$.class)).
1259                    invoke(Void.class, $value1$);
1260            });
1261            check{#if[String]?CCE:WMTE}(() -> { // actual reference class
1262                $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$.class, Class.class)).
1263                    invoke($value1$, Void.class);
1264            });
1265            // Incorrect return type
1266            check{#if[String]?CCE:WMTE}(() -> { // reference class
1267                Void r = (Void) hs.get(am, methodType(Void.class, $type$.class, $type$.class)).
1268                    invoke($value1$, $value1$);
1269            });
1270            checkWMTE(() -> { // primitive class
1271                $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, $type$.class, $type$.class)).
1272                    invoke($value1$, $value1$);
1273            });
1274            // Incorrect arity
1275            checkWMTE(() -> { // 0
1276                $type$ x = ($type$) hs.get(am, methodType($type$.class)).
1277                    invoke();
1278            });
1279            checkWMTE(() -> { // >
1280                $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$.class, $type$.class, Class.class)).
1281                    invoke($value1$, $value1$, Void.class);
1282            });
1283        }
1284
1285        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1286            // Incorrect argument types
1287            check{#if[String]?CCE:WMTE}(() -> { // value reference class
1288                $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class)).
1289                    invoke(Void.class);
1290            });
1291            // Incorrect return type
1292            check{#if[String]?CCE:WMTE}(() -> { // reference class
1293                Void r = (Void) hs.get(am, methodType(Void.class, $type$.class)).
1294                    invoke($value1$);
1295            });
1296            checkWMTE(() -> { // primitive class
1297                $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, $type$.class)).
1298                    invoke($value1$);
1299            });
1300            // Incorrect arity
1301            checkWMTE(() -> { // 0
1302                $type$ x = ($type$) hs.get(am, methodType($type$.class)).
1303                    invoke();
1304            });
1305            checkWMTE(() -> { // >
1306                $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$.class, Class.class)).
1307                    invoke($value1$, Void.class);
1308            });
1309        }
1310#end[CAS]
1311
1312#if[AtomicAdd]
1313        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
1314            // Incorrect argument types
1315            check{#if[String]?CCE:WMTE}(() -> { // value reference class
1316                $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class)).
1317                    invoke(Void.class);
1318            });
1319            // Incorrect return type
1320            check{#if[String]?CCE:WMTE}(() -> { // reference class
1321                Void r = (Void) hs.get(am, methodType(Void.class, $type$.class)).
1322                    invoke($value1$);
1323            });
1324            checkWMTE(() -> { // primitive class
1325                $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, $type$.class)).
1326                    invoke($value1$);
1327            });
1328            // Incorrect arity
1329            checkWMTE(() -> { // 0
1330                $type$ x = ($type$) hs.get(am, methodType($type$.class)).
1331                    invoke();
1332            });
1333            checkWMTE(() -> { // >
1334                $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$.class, Class.class)).
1335                    invoke($value1$, Void.class);
1336            });
1337        }
1338#end[AtomicAdd]
1339    }
1340
1341
1342    static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
1343        $type$[] array = new $type$[10];
1344        Arrays.fill(array, $value1$);
1345
1346        // Get
1347        // Incorrect argument types
1348        checkNPE(() -> { // null array
1349            $type$ x = ($type$) vh.get(null, 0);
1350        });
1351        checkCCE(() -> { // array reference class
1352            $type$ x = ($type$) vh.get(Void.class, 0);
1353        });
1354        checkWMTE(() -> { // array primitive class
1355            $type$ x = ($type$) vh.get(0, 0);
1356        });
1357        checkWMTE(() -> { // index reference class
1358            $type$ x = ($type$) vh.get(array, Void.class);
1359        });
1360        // Incorrect return type
1361        check{#if[String]?CCE:WMTE}(() -> { // reference class
1362            Void x = (Void) vh.get(array, 0);
1363        });
1364        checkWMTE(() -> { // primitive class
1365            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.get(array, 0);
1366        });
1367        // Incorrect arity
1368        checkWMTE(() -> { // 0
1369            $type$ x = ($type$) vh.get();
1370        });
1371        checkWMTE(() -> { // >
1372            $type$ x = ($type$) vh.get(array, 0, Void.class);
1373        });
1374
1375
1376        // Set
1377        // Incorrect argument types
1378        checkNPE(() -> { // null array
1379            vh.set(null, 0, $value1$);
1380        });
1381        checkCCE(() -> { // array reference class
1382            vh.set(Void.class, 0, $value1$);
1383        });
1384        check{#if[String]?CCE:WMTE}(() -> { // value reference class
1385            vh.set(array, 0, Void.class);
1386        });
1387        checkWMTE(() -> { // receiver primitive class
1388            vh.set(0, 0, $value1$);
1389        });
1390        checkWMTE(() -> { // index reference class
1391            vh.set(array, Void.class, $value1$);
1392        });
1393        // Incorrect arity
1394        checkWMTE(() -> { // 0
1395            vh.set();
1396        });
1397        checkWMTE(() -> { // >
1398            vh.set(array, 0, $value1$, Void.class);
1399        });
1400
1401
1402        // GetVolatile
1403        // Incorrect argument types
1404        checkNPE(() -> { // null array
1405            $type$ x = ($type$) vh.getVolatile(null, 0);
1406        });
1407        checkCCE(() -> { // array reference class
1408            $type$ x = ($type$) vh.getVolatile(Void.class, 0);
1409        });
1410        checkWMTE(() -> { // array primitive class
1411            $type$ x = ($type$) vh.getVolatile(0, 0);
1412        });
1413        checkWMTE(() -> { // index reference class
1414            $type$ x = ($type$) vh.getVolatile(array, Void.class);
1415        });
1416        // Incorrect return type
1417        check{#if[String]?CCE:WMTE}(() -> { // reference class
1418            Void x = (Void) vh.getVolatile(array, 0);
1419        });
1420        checkWMTE(() -> { // primitive class
1421            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getVolatile(array, 0);
1422        });
1423        // Incorrect arity
1424        checkWMTE(() -> { // 0
1425            $type$ x = ($type$) vh.getVolatile();
1426        });
1427        checkWMTE(() -> { // >
1428            $type$ x = ($type$) vh.getVolatile(array, 0, Void.class);
1429        });
1430
1431
1432        // SetVolatile
1433        // Incorrect argument types
1434        checkNPE(() -> { // null array
1435            vh.setVolatile(null, 0, $value1$);
1436        });
1437        checkCCE(() -> { // array reference class
1438            vh.setVolatile(Void.class, 0, $value1$);
1439        });
1440        check{#if[String]?CCE:WMTE}(() -> { // value reference class
1441            vh.setVolatile(array, 0, Void.class);
1442        });
1443        checkWMTE(() -> { // receiver primitive class
1444            vh.setVolatile(0, 0, $value1$);
1445        });
1446        checkWMTE(() -> { // index reference class
1447            vh.setVolatile(array, Void.class, $value1$);
1448        });
1449        // Incorrect arity
1450        checkWMTE(() -> { // 0
1451            vh.setVolatile();
1452        });
1453        checkWMTE(() -> { // >
1454            vh.setVolatile(array, 0, $value1$, Void.class);
1455        });
1456
1457
1458        // GetOpaque
1459        // Incorrect argument types
1460        checkNPE(() -> { // null array
1461            $type$ x = ($type$) vh.getOpaque(null, 0);
1462        });
1463        checkCCE(() -> { // array reference class
1464            $type$ x = ($type$) vh.getOpaque(Void.class, 0);
1465        });
1466        checkWMTE(() -> { // array primitive class
1467            $type$ x = ($type$) vh.getOpaque(0, 0);
1468        });
1469        checkWMTE(() -> { // index reference class
1470            $type$ x = ($type$) vh.getOpaque(array, Void.class);
1471        });
1472        // Incorrect return type
1473        check{#if[String]?CCE:WMTE}(() -> { // reference class
1474            Void x = (Void) vh.getOpaque(array, 0);
1475        });
1476        checkWMTE(() -> { // primitive class
1477            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getOpaque(array, 0);
1478        });
1479        // Incorrect arity
1480        checkWMTE(() -> { // 0
1481            $type$ x = ($type$) vh.getOpaque();
1482        });
1483        checkWMTE(() -> { // >
1484            $type$ x = ($type$) vh.getOpaque(array, 0, Void.class);
1485        });
1486
1487
1488        // SetOpaque
1489        // Incorrect argument types
1490        checkNPE(() -> { // null array
1491            vh.setOpaque(null, 0, $value1$);
1492        });
1493        checkCCE(() -> { // array reference class
1494            vh.setOpaque(Void.class, 0, $value1$);
1495        });
1496        check{#if[String]?CCE:WMTE}(() -> { // value reference class
1497            vh.setOpaque(array, 0, Void.class);
1498        });
1499        checkWMTE(() -> { // receiver primitive class
1500            vh.setOpaque(0, 0, $value1$);
1501        });
1502        checkWMTE(() -> { // index reference class
1503            vh.setOpaque(array, Void.class, $value1$);
1504        });
1505        // Incorrect arity
1506        checkWMTE(() -> { // 0
1507            vh.setOpaque();
1508        });
1509        checkWMTE(() -> { // >
1510            vh.setOpaque(array, 0, $value1$, Void.class);
1511        });
1512
1513
1514        // GetAcquire
1515        // Incorrect argument types
1516        checkNPE(() -> { // null array
1517            $type$ x = ($type$) vh.getAcquire(null, 0);
1518        });
1519        checkCCE(() -> { // array reference class
1520            $type$ x = ($type$) vh.getAcquire(Void.class, 0);
1521        });
1522        checkWMTE(() -> { // array primitive class
1523            $type$ x = ($type$) vh.getAcquire(0, 0);
1524        });
1525        checkWMTE(() -> { // index reference class
1526            $type$ x = ($type$) vh.getAcquire(array, Void.class);
1527        });
1528        // Incorrect return type
1529        check{#if[String]?CCE:WMTE}(() -> { // reference class
1530            Void x = (Void) vh.getAcquire(array, 0);
1531        });
1532        checkWMTE(() -> { // primitive class
1533            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAcquire(array, 0);
1534        });
1535        // Incorrect arity
1536        checkWMTE(() -> { // 0
1537            $type$ x = ($type$) vh.getAcquire();
1538        });
1539        checkWMTE(() -> { // >
1540            $type$ x = ($type$) vh.getAcquire(array, 0, Void.class);
1541        });
1542
1543
1544        // SetRelease
1545        // Incorrect argument types
1546        checkNPE(() -> { // null array
1547            vh.setRelease(null, 0, $value1$);
1548        });
1549        checkCCE(() -> { // array reference class
1550            vh.setRelease(Void.class, 0, $value1$);
1551        });
1552        check{#if[String]?CCE:WMTE}(() -> { // value reference class
1553            vh.setRelease(array, 0, Void.class);
1554        });
1555        checkWMTE(() -> { // receiver primitive class
1556            vh.setRelease(0, 0, $value1$);
1557        });
1558        checkWMTE(() -> { // index reference class
1559            vh.setRelease(array, Void.class, $value1$);
1560        });
1561        // Incorrect arity
1562        checkWMTE(() -> { // 0
1563            vh.setRelease();
1564        });
1565        checkWMTE(() -> { // >
1566            vh.setRelease(array, 0, $value1$, Void.class);
1567        });
1568
1569
1570#if[CAS]
1571        // CompareAndSet
1572        // Incorrect argument types
1573        checkNPE(() -> { // null receiver
1574            boolean r = vh.compareAndSet(null, 0, $value1$, $value1$);
1575        });
1576        checkCCE(() -> { // receiver reference class
1577            boolean r = vh.compareAndSet(Void.class, 0, $value1$, $value1$);
1578        });
1579        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
1580            boolean r = vh.compareAndSet(array, 0, Void.class, $value1$);
1581        });
1582        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
1583            boolean r = vh.compareAndSet(array, 0, $value1$, Void.class);
1584        });
1585        checkWMTE(() -> { // receiver primitive class
1586            boolean r = vh.compareAndSet(0, 0, $value1$, $value1$);
1587        });
1588        checkWMTE(() -> { // index reference class
1589            boolean r = vh.compareAndSet(array, Void.class, $value1$, $value1$);
1590        });
1591        // Incorrect arity
1592        checkWMTE(() -> { // 0
1593            boolean r = vh.compareAndSet();
1594        });
1595        checkWMTE(() -> { // >
1596            boolean r = vh.compareAndSet(array, 0, $value1$, $value1$, Void.class);
1597        });
1598
1599
1600        // WeakCompareAndSet
1601        // Incorrect argument types
1602        checkNPE(() -> { // null receiver
1603            boolean r = vh.weakCompareAndSet(null, 0, $value1$, $value1$);
1604        });
1605        checkCCE(() -> { // receiver reference class
1606            boolean r = vh.weakCompareAndSet(Void.class, 0, $value1$, $value1$);
1607        });
1608        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
1609            boolean r = vh.weakCompareAndSet(array, 0, Void.class, $value1$);
1610        });
1611        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
1612            boolean r = vh.weakCompareAndSet(array, 0, $value1$, Void.class);
1613        });
1614        checkWMTE(() -> { // receiver primitive class
1615            boolean r = vh.weakCompareAndSet(0, 0, $value1$, $value1$);
1616        });
1617        checkWMTE(() -> { // index reference class
1618            boolean r = vh.weakCompareAndSet(array, Void.class, $value1$, $value1$);
1619        });
1620        // Incorrect arity
1621        checkWMTE(() -> { // 0
1622            boolean r = vh.weakCompareAndSet();
1623        });
1624        checkWMTE(() -> { // >
1625            boolean r = vh.weakCompareAndSet(array, 0, $value1$, $value1$, Void.class);
1626        });
1627
1628
1629        // WeakCompareAndSetVolatile
1630        // Incorrect argument types
1631        checkNPE(() -> { // null receiver
1632            boolean r = vh.weakCompareAndSetVolatile(null, 0, $value1$, $value1$);
1633        });
1634        checkCCE(() -> { // receiver reference class
1635            boolean r = vh.weakCompareAndSetVolatile(Void.class, 0, $value1$, $value1$);
1636        });
1637        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
1638            boolean r = vh.weakCompareAndSetVolatile(array, 0, Void.class, $value1$);
1639        });
1640        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
1641            boolean r = vh.weakCompareAndSetVolatile(array, 0, $value1$, Void.class);
1642        });
1643        checkWMTE(() -> { // receiver primitive class
1644            boolean r = vh.weakCompareAndSetVolatile(0, 0, $value1$, $value1$);
1645        });
1646        checkWMTE(() -> { // index reference class
1647            boolean r = vh.weakCompareAndSetVolatile(array, Void.class, $value1$, $value1$);
1648        });
1649        // Incorrect arity
1650        checkWMTE(() -> { // 0
1651            boolean r = vh.weakCompareAndSetVolatile();
1652        });
1653        checkWMTE(() -> { // >
1654            boolean r = vh.weakCompareAndSetVolatile(array, 0, $value1$, $value1$, Void.class);
1655        });
1656
1657
1658        // WeakCompareAndSetAcquire
1659        // Incorrect argument types
1660        checkNPE(() -> { // null receiver
1661            boolean r = vh.weakCompareAndSetAcquire(null, 0, $value1$, $value1$);
1662        });
1663        checkCCE(() -> { // receiver reference class
1664            boolean r = vh.weakCompareAndSetAcquire(Void.class, 0, $value1$, $value1$);
1665        });
1666        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
1667            boolean r = vh.weakCompareAndSetAcquire(array, 0, Void.class, $value1$);
1668        });
1669        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
1670            boolean r = vh.weakCompareAndSetAcquire(array, 0, $value1$, Void.class);
1671        });
1672        checkWMTE(() -> { // receiver primitive class
1673            boolean r = vh.weakCompareAndSetAcquire(0, 0, $value1$, $value1$);
1674        });
1675        checkWMTE(() -> { // index reference class
1676            boolean r = vh.weakCompareAndSetAcquire(array, Void.class, $value1$, $value1$);
1677        });
1678        // Incorrect arity
1679        checkWMTE(() -> { // 0
1680            boolean r = vh.weakCompareAndSetAcquire();
1681        });
1682        checkWMTE(() -> { // >
1683            boolean r = vh.weakCompareAndSetAcquire(array, 0, $value1$, $value1$, Void.class);
1684        });
1685
1686
1687        // WeakCompareAndSetRelease
1688        // Incorrect argument types
1689        checkNPE(() -> { // null receiver
1690            boolean r = vh.weakCompareAndSetRelease(null, 0, $value1$, $value1$);
1691        });
1692        checkCCE(() -> { // receiver reference class
1693            boolean r = vh.weakCompareAndSetRelease(Void.class, 0, $value1$, $value1$);
1694        });
1695        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
1696            boolean r = vh.weakCompareAndSetRelease(array, 0, Void.class, $value1$);
1697        });
1698        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
1699            boolean r = vh.weakCompareAndSetRelease(array, 0, $value1$, Void.class);
1700        });
1701        checkWMTE(() -> { // receiver primitive class
1702            boolean r = vh.weakCompareAndSetRelease(0, 0, $value1$, $value1$);
1703        });
1704        checkWMTE(() -> { // index reference class
1705            boolean r = vh.weakCompareAndSetRelease(array, Void.class, $value1$, $value1$);
1706        });
1707        // Incorrect arity
1708        checkWMTE(() -> { // 0
1709            boolean r = vh.weakCompareAndSetRelease();
1710        });
1711        checkWMTE(() -> { // >
1712            boolean r = vh.weakCompareAndSetRelease(array, 0, $value1$, $value1$, Void.class);
1713        });
1714
1715
1716        // CompareAndExchangeVolatile
1717        // Incorrect argument types
1718        checkNPE(() -> { // null receiver
1719            $type$ x = ($type$) vh.compareAndExchangeVolatile(null, 0, $value1$, $value1$);
1720        });
1721        checkCCE(() -> { // array reference class
1722            $type$ x = ($type$) vh.compareAndExchangeVolatile(Void.class, 0, $value1$, $value1$);
1723        });
1724        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
1725            $type$ x = ($type$) vh.compareAndExchangeVolatile(array, 0, Void.class, $value1$);
1726        });
1727        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
1728            $type$ x = ($type$) vh.compareAndExchangeVolatile(array, 0, $value1$, Void.class);
1729        });
1730        checkWMTE(() -> { // array primitive class
1731            $type$ x = ($type$) vh.compareAndExchangeVolatile(0, 0, $value1$, $value1$);
1732        });
1733        checkWMTE(() -> { // index reference class
1734            $type$ x = ($type$) vh.compareAndExchangeVolatile(array, Void.class, $value1$, $value1$);
1735        });
1736        // Incorrect return type
1737        check{#if[String]?CCE:WMTE}(() -> { // reference class
1738            Void r = (Void) vh.compareAndExchangeVolatile(array, 0, $value1$, $value1$);
1739        });
1740        checkWMTE(() -> { // primitive class
1741            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeVolatile(array, 0, $value1$, $value1$);
1742        });
1743        // Incorrect arity
1744        checkWMTE(() -> { // 0
1745            $type$ x = ($type$) vh.compareAndExchangeVolatile();
1746        });
1747        checkWMTE(() -> { // >
1748            $type$ x = ($type$) vh.compareAndExchangeVolatile(array, 0, $value1$, $value1$, Void.class);
1749        });
1750
1751
1752        // CompareAndExchangeAcquire
1753        // Incorrect argument types
1754        checkNPE(() -> { // null receiver
1755            $type$ x = ($type$) vh.compareAndExchangeAcquire(null, 0, $value1$, $value1$);
1756        });
1757        checkCCE(() -> { // array reference class
1758            $type$ x = ($type$) vh.compareAndExchangeAcquire(Void.class, 0, $value1$, $value1$);
1759        });
1760        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
1761            $type$ x = ($type$) vh.compareAndExchangeAcquire(array, 0, Void.class, $value1$);
1762        });
1763        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
1764            $type$ x = ($type$) vh.compareAndExchangeAcquire(array, 0, $value1$, Void.class);
1765        });
1766        checkWMTE(() -> { // array primitive class
1767            $type$ x = ($type$) vh.compareAndExchangeAcquire(0, 0, $value1$, $value1$);
1768        });
1769        checkWMTE(() -> { // index reference class
1770            $type$ x = ($type$) vh.compareAndExchangeAcquire(array, Void.class, $value1$, $value1$);
1771        });
1772        // Incorrect return type
1773        check{#if[String]?CCE:WMTE}(() -> { // reference class
1774            Void r = (Void) vh.compareAndExchangeAcquire(array, 0, $value1$, $value1$);
1775        });
1776        checkWMTE(() -> { // primitive class
1777            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeAcquire(array, 0, $value1$, $value1$);
1778        });
1779        // Incorrect arity
1780        checkWMTE(() -> { // 0
1781            $type$ x = ($type$) vh.compareAndExchangeAcquire();
1782        });
1783        checkWMTE(() -> { // >
1784            $type$ x = ($type$) vh.compareAndExchangeAcquire(array, 0, $value1$, $value1$, Void.class);
1785        });
1786
1787
1788        // CompareAndExchangeRelease
1789        // Incorrect argument types
1790        checkNPE(() -> { // null receiver
1791            $type$ x = ($type$) vh.compareAndExchangeRelease(null, 0, $value1$, $value1$);
1792        });
1793        checkCCE(() -> { // array reference class
1794            $type$ x = ($type$) vh.compareAndExchangeRelease(Void.class, 0, $value1$, $value1$);
1795        });
1796        check{#if[String]?CCE:WMTE}(() -> { // expected reference class
1797            $type$ x = ($type$) vh.compareAndExchangeRelease(array, 0, Void.class, $value1$);
1798        });
1799        check{#if[String]?CCE:WMTE}(() -> { // actual reference class
1800            $type$ x = ($type$) vh.compareAndExchangeRelease(array, 0, $value1$, Void.class);
1801        });
1802        checkWMTE(() -> { // array primitive class
1803            $type$ x = ($type$) vh.compareAndExchangeRelease(0, 0, $value1$, $value1$);
1804        });
1805        checkWMTE(() -> { // index reference class
1806            $type$ x = ($type$) vh.compareAndExchangeRelease(array, Void.class, $value1$, $value1$);
1807        });
1808        // Incorrect return type
1809        check{#if[String]?CCE:WMTE}(() -> { // reference class
1810            Void r = (Void) vh.compareAndExchangeRelease(array, 0, $value1$, $value1$);
1811        });
1812        checkWMTE(() -> { // primitive class
1813            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.compareAndExchangeRelease(array, 0, $value1$, $value1$);
1814        });
1815        // Incorrect arity
1816        checkWMTE(() -> { // 0
1817            $type$ x = ($type$) vh.compareAndExchangeRelease();
1818        });
1819        checkWMTE(() -> { // >
1820            $type$ x = ($type$) vh.compareAndExchangeRelease(array, 0, $value1$, $value1$, Void.class);
1821        });
1822
1823
1824        // GetAndSet
1825        // Incorrect argument types
1826        checkNPE(() -> { // null array
1827            $type$ x = ($type$) vh.getAndSet(null, 0, $value1$);
1828        });
1829        checkCCE(() -> { // array reference class
1830            $type$ x = ($type$) vh.getAndSet(Void.class, 0, $value1$);
1831        });
1832        check{#if[String]?CCE:WMTE}(() -> { // value reference class
1833            $type$ x = ($type$) vh.getAndSet(array, 0, Void.class);
1834        });
1835        checkWMTE(() -> { // reciarrayever primitive class
1836            $type$ x = ($type$) vh.getAndSet(0, 0, $value1$);
1837        });
1838        checkWMTE(() -> { // index reference class
1839            $type$ x = ($type$) vh.getAndSet(array, Void.class, $value1$);
1840        });
1841        // Incorrect return type
1842        check{#if[String]?CCE:WMTE}(() -> { // reference class
1843            Void r = (Void) vh.getAndSet(array, 0, $value1$);
1844        });
1845        checkWMTE(() -> { // primitive class
1846            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndSet(array, 0, $value1$);
1847        });
1848        // Incorrect arity
1849        checkWMTE(() -> { // 0
1850            $type$ x = ($type$) vh.getAndSet();
1851        });
1852        checkWMTE(() -> { // >
1853            $type$ x = ($type$) vh.getAndSet(array, 0, $value1$, Void.class);
1854        });
1855#end[CAS]
1856
1857#if[AtomicAdd]
1858        // GetAndAdd
1859        // Incorrect argument types
1860        checkNPE(() -> { // null array
1861            $type$ x = ($type$) vh.getAndAdd(null, 0, $value1$);
1862        });
1863        checkCCE(() -> { // array reference class
1864            $type$ x = ($type$) vh.getAndAdd(Void.class, 0, $value1$);
1865        });
1866        check{#if[String]?CCE:WMTE}(() -> { // value reference class
1867            $type$ x = ($type$) vh.getAndAdd(array, 0, Void.class);
1868        });
1869        checkWMTE(() -> { // array primitive class
1870            $type$ x = ($type$) vh.getAndAdd(0, 0, $value1$);
1871        });
1872        checkWMTE(() -> { // index reference class
1873            $type$ x = ($type$) vh.getAndAdd(array, Void.class, $value1$);
1874        });
1875        // Incorrect return type
1876        check{#if[String]?CCE:WMTE}(() -> { // reference class
1877            Void r = (Void) vh.getAndAdd(array, 0, $value1$);
1878        });
1879        checkWMTE(() -> { // primitive class
1880            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.getAndAdd(array, 0, $value1$);
1881        });
1882        // Incorrect arity
1883        checkWMTE(() -> { // 0
1884            $type$ x = ($type$) vh.getAndAdd();
1885        });
1886        checkWMTE(() -> { // >
1887            $type$ x = ($type$) vh.getAndAdd(array, 0, $value1$, Void.class);
1888        });
1889
1890
1891        // AddAndGet
1892        // Incorrect argument types
1893        checkNPE(() -> { // null array
1894            $type$ x = ($type$) vh.addAndGet(null, 0, $value1$);
1895        });
1896        checkCCE(() -> { // array reference class
1897            $type$ x = ($type$) vh.addAndGet(Void.class, 0, $value1$);
1898        });
1899        check{#if[String]?CCE:WMTE}(() -> { // value reference class
1900            $type$ x = ($type$) vh.addAndGet(array, 0, Void.class);
1901        });
1902        checkWMTE(() -> { // array primitive class
1903            $type$ x = ($type$) vh.addAndGet(0, 0, $value1$);
1904        });
1905        checkWMTE(() -> { // index reference class
1906            $type$ x = ($type$) vh.addAndGet(array, Void.class, $value1$);
1907        });
1908        // Incorrect return type
1909        check{#if[String]?CCE:WMTE}(() -> { // reference class
1910            Void r = (Void) vh.addAndGet(array, 0, $value1$);
1911        });
1912        checkWMTE(() -> { // primitive class
1913            $wrong_primitive_type$ x = ($wrong_primitive_type$) vh.addAndGet(array, 0, $value1$);
1914        });
1915        // Incorrect arity
1916        checkWMTE(() -> { // 0
1917            $type$ x = ($type$) vh.addAndGet();
1918        });
1919        checkWMTE(() -> { // >
1920            $type$ x = ($type$) vh.addAndGet(array, 0, $value1$, Void.class);
1921        });
1922#end[AtomicAdd]
1923    }
1924
1925    static void testArrayWrongMethodType(Handles hs) throws Throwable {
1926        $type$[] array = new $type$[10];
1927        Arrays.fill(array, $value1$);
1928
1929        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
1930            // Incorrect argument types
1931            checkNPE(() -> { // null array
1932                $type$ x = ($type$) hs.get(am, methodType($type$.class, Void.class, int.class)).
1933                    invoke(null, 0);
1934            });
1935            checkCCE(() -> { // array reference class
1936                $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, int.class)).
1937                    invoke(Void.class, 0);
1938            });
1939            checkWMTE(() -> { // array primitive class
1940                $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class, int.class)).
1941                    invoke(0, 0);
1942            });
1943            checkWMTE(() -> { // index reference class
1944                $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, Class.class)).
1945                    invoke(array, Void.class);
1946            });
1947            // Incorrect return type
1948            check{#if[String]?CCE:WMTE}(() -> { // reference class
1949                Void x = (Void) hs.get(am, methodType(Void.class, $type$[].class, int.class)).
1950                    invoke(array, 0);
1951            });
1952            checkWMTE(() -> { // primitive class
1953                $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, $type$[].class, int.class)).
1954                    invoke(array, 0);
1955            });
1956            // Incorrect arity
1957            checkWMTE(() -> { // 0
1958                $type$ x = ($type$) hs.get(am, methodType($type$.class)).
1959                    invoke();
1960            });
1961            checkWMTE(() -> { // >
1962                $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, Class.class)).
1963                    invoke(array, 0, Void.class);
1964            });
1965        }
1966
1967        for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
1968            // Incorrect argument types
1969            checkNPE(() -> { // null array
1970                hs.get(am, methodType(void.class, Void.class, int.class, $type$.class)).
1971                    invoke(null, 0, $value1$);
1972            });
1973            checkCCE(() -> { // array reference class
1974                hs.get(am, methodType(void.class, Class.class, int.class, $type$.class)).
1975                    invoke(Void.class, 0, $value1$);
1976            });
1977            check{#if[String]?CCE:WMTE}(() -> { // value reference class
1978                hs.get(am, methodType(void.class, $type$[].class, int.class, Class.class)).
1979                    invoke(array, 0, Void.class);
1980            });
1981            checkWMTE(() -> { // receiver primitive class
1982                hs.get(am, methodType(void.class, int.class, int.class, $type$.class)).
1983                    invoke(0, 0, $value1$);
1984            });
1985            checkWMTE(() -> { // index reference class
1986                hs.get(am, methodType(void.class, $type$[].class, Class.class, $type$.class)).
1987                    invoke(array, Void.class, $value1$);
1988            });
1989            // Incorrect arity
1990            checkWMTE(() -> { // 0
1991                hs.get(am, methodType(void.class)).
1992                    invoke();
1993            });
1994            checkWMTE(() -> { // >
1995                hs.get(am, methodType(void.class, $type$[].class, int.class, Class.class)).
1996                    invoke(array, 0, $value1$, Void.class);
1997            });
1998        }
1999#if[CAS]
2000        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
2001            // Incorrect argument types
2002            checkNPE(() -> { // null receiver
2003                boolean r = (boolean) hs.get(am, methodType(boolean.class, Void.class, int.class, $type$.class, $type$.class)).
2004                    invoke(null, 0, $value1$, $value1$);
2005            });
2006            checkCCE(() -> { // receiver reference class
2007                boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, $type$.class, $type$.class)).
2008                    invoke(Void.class, 0, $value1$, $value1$);
2009            });
2010            check{#if[String]?CCE:WMTE}(() -> { // expected reference class
2011                boolean r = (boolean) hs.get(am, methodType(boolean.class, $type$[].class, int.class, Class.class, $type$.class)).
2012                    invoke(array, 0, Void.class, $value1$);
2013            });
2014            check{#if[String]?CCE:WMTE}(() -> { // actual reference class
2015                boolean r = (boolean) hs.get(am, methodType(boolean.class, $type$[].class, int.class, $type$.class, Class.class)).
2016                    invoke(array, 0, $value1$, Void.class);
2017            });
2018            checkWMTE(() -> { // receiver primitive class
2019                boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, $type$.class, $type$.class)).
2020                    invoke(0, 0, $value1$, $value1$);
2021            });
2022            checkWMTE(() -> { // index reference class
2023                boolean r = (boolean) hs.get(am, methodType(boolean.class, $type$[].class, Class.class, $type$.class, $type$.class)).
2024                    invoke(array, Void.class, $value1$, $value1$);
2025            });
2026            // Incorrect arity
2027            checkWMTE(() -> { // 0
2028                boolean r = (boolean) hs.get(am, methodType(boolean.class)).
2029                    invoke();
2030            });
2031            checkWMTE(() -> { // >
2032                boolean r = (boolean) hs.get(am, methodType(boolean.class, $type$[].class, int.class, $type$.class, $type$.class, Class.class)).
2033                    invoke(array, 0, $value1$, $value1$, Void.class);
2034            });
2035        }
2036
2037        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
2038            // Incorrect argument types
2039            checkNPE(() -> { // null receiver
2040                $type$ x = ($type$) hs.get(am, methodType($type$.class, Void.class, int.class, $type$.class, $type$.class)).
2041                    invoke(null, 0, $value1$, $value1$);
2042            });
2043            checkCCE(() -> { // array reference class
2044                $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, int.class, $type$.class, $type$.class)).
2045                    invoke(Void.class, 0, $value1$, $value1$);
2046            });
2047            check{#if[String]?CCE:WMTE}(() -> { // expected reference class
2048                $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, Class.class, $type$.class)).
2049                    invoke(array, 0, Void.class, $value1$);
2050            });
2051            check{#if[String]?CCE:WMTE}(() -> { // actual reference class
2052                $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, $type$.class, Class.class)).
2053                    invoke(array, 0, $value1$, Void.class);
2054            });
2055            checkWMTE(() -> { // array primitive class
2056                $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class, int.class, $type$.class, $type$.class)).
2057                    invoke(0, 0, $value1$, $value1$);
2058            });
2059            checkWMTE(() -> { // index reference class
2060                $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, Class.class, $type$.class, $type$.class)).
2061                    invoke(array, Void.class, $value1$, $value1$);
2062            });
2063            // Incorrect return type
2064            check{#if[String]?CCE:WMTE}(() -> { // reference class
2065                Void r = (Void) hs.get(am, methodType(Void.class, $type$[].class, int.class, $type$.class, $type$.class)).
2066                    invoke(array, 0, $value1$, $value1$);
2067            });
2068            checkWMTE(() -> { // primitive class
2069                $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, $type$[].class, int.class, $type$.class, $type$.class)).
2070                    invoke(array, 0, $value1$, $value1$);
2071            });
2072            // Incorrect arity
2073            checkWMTE(() -> { // 0
2074                $type$ x = ($type$) hs.get(am, methodType($type$.class)).
2075                    invoke();
2076            });
2077            checkWMTE(() -> { // >
2078                $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, $type$.class, $type$.class, Class.class)).
2079                    invoke(array, 0, $value1$, $value1$, Void.class);
2080            });
2081        }
2082
2083        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
2084            // Incorrect argument types
2085            checkNPE(() -> { // null array
2086                $type$ x = ($type$) hs.get(am, methodType($type$.class, Void.class, int.class, $type$.class)).
2087                    invoke(null, 0, $value1$);
2088            });
2089            checkCCE(() -> { // array reference class
2090                $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, int.class, $type$.class)).
2091                    invoke(Void.class, 0, $value1$);
2092            });
2093            check{#if[String]?CCE:WMTE}(() -> { // value reference class
2094                $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, Class.class)).
2095                    invoke(array, 0, Void.class);
2096            });
2097            checkWMTE(() -> { // array primitive class
2098                $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class, int.class, $type$.class)).
2099                    invoke(0, 0, $value1$);
2100            });
2101            checkWMTE(() -> { // index reference class
2102                $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, Class.class, $type$.class)).
2103                    invoke(array, Void.class, $value1$);
2104            });
2105            // Incorrect return type
2106            check{#if[String]?CCE:WMTE}(() -> { // reference class
2107                Void r = (Void) hs.get(am, methodType(Void.class, $type$[].class, int.class, $type$.class)).
2108                    invoke(array, 0, $value1$);
2109            });
2110            checkWMTE(() -> { // primitive class
2111                $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, $type$[].class, int.class, $type$.class)).
2112                    invoke(array, 0, $value1$);
2113            });
2114            // Incorrect arity
2115            checkWMTE(() -> { // 0
2116                $type$ x = ($type$) hs.get(am, methodType($type$.class)).
2117                    invoke();
2118            });
2119            checkWMTE(() -> { // >
2120                $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, $type$.class, Class.class)).
2121                    invoke(array, 0, $value1$, Void.class);
2122            });
2123        }
2124#end[CAS]
2125
2126#if[AtomicAdd]
2127        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
2128            // Incorrect argument types
2129            checkNPE(() -> { // null array
2130                $type$ x = ($type$) hs.get(am, methodType($type$.class, Void.class, int.class, $type$.class)).
2131                    invoke(null, 0, $value1$);
2132            });
2133            checkCCE(() -> { // array reference class
2134                $type$ x = ($type$) hs.get(am, methodType($type$.class, Class.class, int.class, $type$.class)).
2135                    invoke(Void.class, 0, $value1$);
2136            });
2137            check{#if[String]?CCE:WMTE}(() -> { // value reference class
2138                $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, Class.class)).
2139                    invoke(array, 0, Void.class);
2140            });
2141            checkWMTE(() -> { // array primitive class
2142                $type$ x = ($type$) hs.get(am, methodType($type$.class, int.class, int.class, $type$.class)).
2143                    invoke(0, 0, $value1$);
2144            });
2145            checkWMTE(() -> { // index reference class
2146                $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, Class.class, $type$.class)).
2147                    invoke(array, Void.class, $value1$);
2148            });
2149            // Incorrect return type
2150            check{#if[String]?CCE:WMTE}(() -> { // reference class
2151                Void r = (Void) hs.get(am, methodType(Void.class, $type$[].class, int.class, $type$.class)).
2152                    invoke(array, 0, $value1$);
2153            });
2154            checkWMTE(() -> { // primitive class
2155                $wrong_primitive_type$ x = ($wrong_primitive_type$) hs.get(am, methodType($wrong_primitive_type$.class, $type$[].class, int.class, $type$.class)).
2156                    invoke(array, 0, $value1$);
2157            });
2158            // Incorrect arity
2159            checkWMTE(() -> { // 0
2160                $type$ x = ($type$) hs.get(am, methodType($type$.class)).
2161                    invoke();
2162            });
2163            checkWMTE(() -> { // >
2164                $type$ x = ($type$) hs.get(am, methodType($type$.class, $type$[].class, int.class, $type$.class, Class.class)).
2165                    invoke(array, 0, $value1$, Void.class);
2166            });
2167        }
2168#end[AtomicAdd]
2169    }
2170}
2171
2172