< prev index next >

test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeLong.java

Print this page

   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 


  24 /*
  25  * @test
  26  * @bug 8156486
  27  * @run testng/othervm VarHandleTestMethodTypeLong
  28  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeLong
  29  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeLong
  30  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeLong
  31  */
  32 
  33 import org.testng.annotations.BeforeClass;
  34 import org.testng.annotations.DataProvider;
  35 import org.testng.annotations.Test;
  36 
  37 import java.lang.invoke.MethodHandles;
  38 import java.lang.invoke.VarHandle;
  39 import java.util.ArrayList;
  40 import java.util.Arrays;
  41 import java.util.List;
  42 
  43 import static org.testng.Assert.*;
  44 
  45 import static java.lang.invoke.MethodType.*;
  46 
  47 public class VarHandleTestMethodTypeLong extends VarHandleBaseTest {


  48     static final long static_final_v = 0x0123456789ABCDEFL;
  49 
  50     static long static_v = 0x0123456789ABCDEFL;
  51 
  52     final long final_v = 0x0123456789ABCDEFL;
  53 
  54     long v = 0x0123456789ABCDEFL;
  55 
  56     VarHandle vhFinalField;
  57 
  58     VarHandle vhField;
  59 
  60     VarHandle vhStaticField;
  61 
  62     VarHandle vhStaticFinalField;
  63 
  64     VarHandle vhArray;
  65 
  66     @BeforeClass
  67     public void setup() throws Exception {
  68         vhFinalField = MethodHandles.lookup().findVarHandle(
  69                 VarHandleTestMethodTypeLong.class, "final_v", long.class);
  70 
  71         vhField = MethodHandles.lookup().findVarHandle(
  72                 VarHandleTestMethodTypeLong.class, "v", long.class);
  73 
  74         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
  75             VarHandleTestMethodTypeLong.class, "static_final_v", long.class);
  76 
  77         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
  78             VarHandleTestMethodTypeLong.class, "static_v", long.class);
  79 
  80         vhArray = MethodHandles.arrayElementVarHandle(long[].class);
  81     }
  82 
  83     @DataProvider
  84     public Object[][] accessTestCaseProvider() throws Exception {
  85         List<AccessTestCase<?>> cases = new ArrayList<>();
  86 
  87         cases.add(new VarHandleAccessTestCase("Instance field",
  88                                               vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
  89                                               false));
  90 
  91         cases.add(new VarHandleAccessTestCase("Static field",
  92                                               vhStaticField, VarHandleTestMethodTypeLong::testStaticFieldWrongMethodType,
  93                                               false));
  94 
  95         cases.add(new VarHandleAccessTestCase("Array",
  96                                               vhArray, VarHandleTestMethodTypeLong::testArrayWrongMethodType,
  97                                               false));
  98 

 986         // Incorrect return type
 987         checkWMTE(() -> { // reference class
 988             Void r = (Void) vh.getAndBitwiseXor(recv, 0x0123456789ABCDEFL);
 989         });
 990         checkWMTE(() -> { // primitive class
 991             boolean x = (boolean) vh.getAndBitwiseXor(recv, 0x0123456789ABCDEFL);
 992         });
 993         // Incorrect arity
 994         checkWMTE(() -> { // 0
 995             long x = (long) vh.getAndBitwiseXor();
 996         });
 997         checkWMTE(() -> { // >
 998             long x = (long) vh.getAndBitwiseXor(recv, 0x0123456789ABCDEFL, Void.class);
 999         });
1000     }
1001 
1002     static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeLong recv, Handles hs) throws Throwable {
1003         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
1004             // Incorrect argument types
1005             checkNPE(() -> { // null receiver
1006                 long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class)).
1007                     invokeExact((VarHandleTestMethodTypeLong) null);
1008             });
1009             hs.checkWMTEOrCCE(() -> { // receiver reference class
1010                 long x = (long) hs.get(am, methodType(long.class, Class.class)).
1011                     invokeExact(Void.class);
1012             });
1013             checkWMTE(() -> { // receiver primitive class
1014                 long x = (long) hs.get(am, methodType(long.class, int.class)).
1015                     invokeExact(0);
1016             });
1017             // Incorrect return type
1018             checkWMTE(() -> { // reference class
1019                 Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeLong.class)).
1020                     invokeExact(recv);
1021             });
1022             checkWMTE(() -> { // primitive class
1023                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class)).
1024                     invokeExact(recv);
1025             });
1026             // Incorrect arity
1027             checkWMTE(() -> { // 0
1028                 long x = (long) hs.get(am, methodType(long.class)).
1029                     invokeExact();
1030             });
1031             checkWMTE(() -> { // >
1032                 long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, Class.class)).
1033                     invokeExact(recv, Void.class);
1034             });
1035         }
1036 
1037         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
1038             // Incorrect argument types
1039             checkNPE(() -> { // null receiver
1040                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeLong.class, long.class)).
1041                     invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL);
1042             });
1043             hs.checkWMTEOrCCE(() -> { // receiver reference class
1044                 hs.get(am, methodType(void.class, Class.class, long.class)).
1045                     invokeExact(Void.class, 0x0123456789ABCDEFL);
1046             });
1047             checkWMTE(() -> { // value reference class
1048                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeLong.class, Class.class)).
1049                     invokeExact(recv, Void.class);
1050             });
1051             checkWMTE(() -> { // receiver primitive class
1052                 hs.get(am, methodType(void.class, int.class, long.class)).
1053                     invokeExact(0, 0x0123456789ABCDEFL);
1054             });
1055             // Incorrect arity
1056             checkWMTE(() -> { // 0
1057                 hs.get(am, methodType(void.class)).
1058                     invokeExact();
1059             });
1060             checkWMTE(() -> { // >
1061                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeLong.class, long.class, Class.class)).
1062                     invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
1063             });
1064         }
1065 
1066         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
1067             // Incorrect argument types
1068             checkNPE(() -> { // null receiver
1069                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, long.class, long.class)).
1070                     invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1071             });
1072             hs.checkWMTEOrCCE(() -> { // receiver reference class
1073                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, long.class, long.class)).
1074                     invokeExact(Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1075             });
1076             checkWMTE(() -> { // expected reference class
1077                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, Class.class, long.class)).
1078                     invokeExact(recv, Void.class, 0x0123456789ABCDEFL);
1079             });
1080             checkWMTE(() -> { // actual reference class
1081                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, long.class, Class.class)).
1082                     invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
1083             });
1084             checkWMTE(() -> { // receiver primitive class
1085                 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , long.class, long.class)).
1086                     invokeExact(0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1087             });
1088             // Incorrect arity
1089             checkWMTE(() -> { // 0
1090                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
1091                     invokeExact();
1092             });
1093             checkWMTE(() -> { // >
1094                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, long.class, long.class, Class.class)).
1095                     invokeExact(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
1096             });
1097         }
1098 
1099         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1100             checkNPE(() -> { // null receiver
1101                 long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class, long.class)).
1102                     invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1103             });
1104             hs.checkWMTEOrCCE(() -> { // receiver reference class
1105                 long x = (long) hs.get(am, methodType(long.class, Class.class, long.class, long.class)).
1106                     invokeExact(Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1107             });
1108             checkWMTE(() -> { // expected reference class
1109                 long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, Class.class, long.class)).
1110                     invokeExact(recv, Void.class, 0x0123456789ABCDEFL);
1111             });
1112             checkWMTE(() -> { // actual reference class
1113                 long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class, Class.class)).
1114                     invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
1115             });
1116             checkWMTE(() -> { // reciever primitive class
1117                 long x = (long) hs.get(am, methodType(long.class, int.class , long.class, long.class)).
1118                     invokeExact(0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1119             });
1120             // Incorrect return type
1121             checkWMTE(() -> { // reference class
1122                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeLong.class , long.class, long.class)).
1123                     invokeExact(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1124             });
1125             checkWMTE(() -> { // primitive class
1126                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class , long.class, long.class)).
1127                     invokeExact(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1128             });
1129             // Incorrect arity
1130             checkWMTE(() -> { // 0
1131                 long x = (long) hs.get(am, methodType(long.class)).
1132                     invokeExact();
1133             });
1134             checkWMTE(() -> { // >
1135                 long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class, long.class, Class.class)).
1136                     invokeExact(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
1137             });
1138         }
1139 
1140         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1141             checkNPE(() -> { // null receiver
1142                 long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class)).
1143                     invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL);
1144             });
1145             hs.checkWMTEOrCCE(() -> { // receiver reference class
1146                 long x = (long) hs.get(am, methodType(long.class, Class.class, long.class)).
1147                     invokeExact(Void.class, 0x0123456789ABCDEFL);
1148             });
1149             checkWMTE(() -> { // value reference class
1150                 long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, Class.class)).
1151                     invokeExact(recv, Void.class);
1152             });
1153             checkWMTE(() -> { // reciever primitive class
1154                 long x = (long) hs.get(am, methodType(long.class, int.class, long.class)).
1155                     invokeExact(0, 0x0123456789ABCDEFL);
1156             });
1157             // Incorrect return type
1158             checkWMTE(() -> { // reference class
1159                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeLong.class, long.class)).
1160                     invokeExact(recv, 0x0123456789ABCDEFL);
1161             });
1162             checkWMTE(() -> { // primitive class
1163                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, long.class)).
1164                     invokeExact(recv, 0x0123456789ABCDEFL);
1165             });
1166             // Incorrect arity
1167             checkWMTE(() -> { // 0
1168                 long x = (long) hs.get(am, methodType(long.class)).
1169                     invokeExact();
1170             });
1171             checkWMTE(() -> { // >
1172                 long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class)).
1173                     invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
1174             });
1175         }
1176 
1177         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
1178             checkNPE(() -> { // null receiver
1179                 long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class)).
1180                     invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL);
1181             });
1182             hs.checkWMTEOrCCE(() -> { // receiver reference class
1183                 long x = (long) hs.get(am, methodType(long.class, Class.class, long.class)).
1184                     invokeExact(Void.class, 0x0123456789ABCDEFL);
1185             });
1186             checkWMTE(() -> { // value reference class
1187                 long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, Class.class)).
1188                     invokeExact(recv, Void.class);
1189             });
1190             checkWMTE(() -> { // reciever primitive class
1191                 long x = (long) hs.get(am, methodType(long.class, int.class, long.class)).
1192                     invokeExact(0, 0x0123456789ABCDEFL);
1193             });
1194             // Incorrect return type
1195             checkWMTE(() -> { // reference class
1196                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeLong.class, long.class)).
1197                     invokeExact(recv, 0x0123456789ABCDEFL);
1198             });
1199             checkWMTE(() -> { // primitive class
1200                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, long.class)).
1201                     invokeExact(recv, 0x0123456789ABCDEFL);
1202             });
1203             // Incorrect arity
1204             checkWMTE(() -> { // 0
1205                 long x = (long) hs.get(am, methodType(long.class)).
1206                     invokeExact();
1207             });
1208             checkWMTE(() -> { // >
1209                 long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class)).
1210                     invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
1211             });
1212         }
1213 
1214         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
1215             checkNPE(() -> { // null receiver
1216                 long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class)).
1217                     invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL);
1218             });
1219             hs.checkWMTEOrCCE(() -> { // receiver reference class
1220                 long x = (long) hs.get(am, methodType(long.class, Class.class, long.class)).
1221                     invokeExact(Void.class, 0x0123456789ABCDEFL);
1222             });
1223             checkWMTE(() -> { // value reference class
1224                 long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, Class.class)).
1225                     invokeExact(recv, Void.class);
1226             });
1227             checkWMTE(() -> { // reciever primitive class
1228                 long x = (long) hs.get(am, methodType(long.class, int.class, long.class)).
1229                     invokeExact(0, 0x0123456789ABCDEFL);
1230             });
1231             // Incorrect return type
1232             checkWMTE(() -> { // reference class
1233                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeLong.class, long.class)).
1234                     invokeExact(recv, 0x0123456789ABCDEFL);
1235             });
1236             checkWMTE(() -> { // primitive class
1237                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, long.class)).
1238                     invokeExact(recv, 0x0123456789ABCDEFL);
1239             });
1240             // Incorrect arity
1241             checkWMTE(() -> { // 0
1242                 long x = (long) hs.get(am, methodType(long.class)).
1243                     invokeExact();
1244             });
1245             checkWMTE(() -> { // >
1246                 long x = (long) hs.get(am, methodType(long.class, VarHandleTestMethodTypeLong.class, long.class)).
1247                     invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
1248             });
1249         }
1250     }
1251 
1252 
1253     static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
1254         // Get
1255         // Incorrect return type
1256         checkWMTE(() -> { // reference class
1257             Void x = (Void) vh.get();
1258         });
1259         checkWMTE(() -> { // primitive class
1260             boolean x = (boolean) vh.get();
1261         });
1262         // Incorrect arity
1263         checkWMTE(() -> { // >
1264             long x = (long) vh.get(Void.class);
1265         });
1266 

1844                     invokeExact();
1845             });
1846             // Incorrect arity
1847             checkWMTE(() -> { // >
1848                 long x = (long) hs.get(am, methodType(Class.class)).
1849                     invokeExact(Void.class);
1850             });
1851         }
1852 
1853         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
1854             checkWMTE(() -> { // value reference class
1855                 hs.get(am, methodType(void.class, Class.class)).
1856                     invokeExact(Void.class);
1857             });
1858             // Incorrect arity
1859             checkWMTE(() -> { // 0
1860                 hs.get(am, methodType(void.class)).
1861                     invokeExact();
1862             });
1863             checkWMTE(() -> { // >
1864                 hs.get(am, methodType(void.class, long.class, Class.class)).
1865                     invokeExact(0x0123456789ABCDEFL, Void.class);
1866             });
1867         }
1868         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
1869             // Incorrect argument types
1870             checkWMTE(() -> { // expected reference class
1871                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, long.class)).
1872                     invokeExact(Void.class, 0x0123456789ABCDEFL);
1873             });
1874             checkWMTE(() -> { // actual reference class
1875                 boolean r = (boolean) hs.get(am, methodType(boolean.class, long.class, Class.class)).
1876                     invokeExact(0x0123456789ABCDEFL, Void.class);
1877             });
1878             // Incorrect arity
1879             checkWMTE(() -> { // 0
1880                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
1881                     invokeExact();
1882             });
1883             checkWMTE(() -> { // >
1884                 boolean r = (boolean) hs.get(am, methodType(boolean.class, long.class, long.class, Class.class)).
1885                     invokeExact(0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
1886             });
1887         }
1888 
1889         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1890             // Incorrect argument types
1891             checkWMTE(() -> { // expected reference class
1892                 long x = (long) hs.get(am, methodType(long.class, Class.class, long.class)).
1893                     invokeExact(Void.class, 0x0123456789ABCDEFL);
1894             });
1895             checkWMTE(() -> { // actual reference class
1896                 long x = (long) hs.get(am, methodType(long.class, long.class, Class.class)).
1897                     invokeExact(0x0123456789ABCDEFL, Void.class);
1898             });
1899             // Incorrect return type
1900             checkWMTE(() -> { // reference class
1901                 Void r = (Void) hs.get(am, methodType(Void.class, long.class, long.class)).
1902                     invokeExact(0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1903             });
1904             checkWMTE(() -> { // primitive class
1905                 boolean x = (boolean) hs.get(am, methodType(boolean.class, long.class, long.class)).
1906                     invokeExact(0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1907             });
1908             // Incorrect arity
1909             checkWMTE(() -> { // 0
1910                 long x = (long) hs.get(am, methodType(long.class)).
1911                     invokeExact();
1912             });
1913             checkWMTE(() -> { // >
1914                 long x = (long) hs.get(am, methodType(long.class, long.class, long.class, Class.class)).
1915                     invokeExact(0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
1916             });
1917         }
1918 
1919         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1920             // Incorrect argument types
1921             checkWMTE(() -> { // value reference class
1922                 long x = (long) hs.get(am, methodType(long.class, Class.class)).
1923                     invokeExact(Void.class);
1924             });
1925             // Incorrect return type
1926             checkWMTE(() -> { // reference class
1927                 Void r = (Void) hs.get(am, methodType(Void.class, long.class)).
1928                     invokeExact(0x0123456789ABCDEFL);
1929             });
1930             checkWMTE(() -> { // primitive class
1931                 boolean x = (boolean) hs.get(am, methodType(boolean.class, long.class)).
1932                     invokeExact(0x0123456789ABCDEFL);
1933             });
1934             // Incorrect arity
1935             checkWMTE(() -> { // 0
1936                 long x = (long) hs.get(am, methodType(long.class)).
1937                     invokeExact();
1938             });
1939             checkWMTE(() -> { // >
1940                 long x = (long) hs.get(am, methodType(long.class, long.class, Class.class)).
1941                     invokeExact(0x0123456789ABCDEFL, Void.class);
1942             });
1943         }
1944 
1945         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
1946             // Incorrect argument types
1947             checkWMTE(() -> { // value reference class
1948                 long x = (long) hs.get(am, methodType(long.class, Class.class)).
1949                     invokeExact(Void.class);
1950             });
1951             // Incorrect return type
1952             checkWMTE(() -> { // reference class
1953                 Void r = (Void) hs.get(am, methodType(Void.class, long.class)).
1954                     invokeExact(0x0123456789ABCDEFL);
1955             });
1956             checkWMTE(() -> { // primitive class
1957                 boolean x = (boolean) hs.get(am, methodType(boolean.class, long.class)).
1958                     invokeExact(0x0123456789ABCDEFL);
1959             });
1960             // Incorrect arity
1961             checkWMTE(() -> { // 0
1962                 long x = (long) hs.get(am, methodType(long.class)).
1963                     invokeExact();
1964             });
1965             checkWMTE(() -> { // >
1966                 long x = (long) hs.get(am, methodType(long.class, long.class, Class.class)).
1967                     invokeExact(0x0123456789ABCDEFL, Void.class);
1968             });
1969         }
1970 
1971         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
1972             // Incorrect argument types
1973             checkWMTE(() -> { // value reference class
1974                 long x = (long) hs.get(am, methodType(long.class, Class.class)).
1975                     invokeExact(Void.class);
1976             });
1977             // Incorrect return type
1978             checkWMTE(() -> { // reference class
1979                 Void r = (Void) hs.get(am, methodType(Void.class, long.class)).
1980                     invokeExact(0x0123456789ABCDEFL);
1981             });
1982             checkWMTE(() -> { // primitive class
1983                 boolean x = (boolean) hs.get(am, methodType(boolean.class, long.class)).
1984                     invokeExact(0x0123456789ABCDEFL);
1985             });
1986             // Incorrect arity
1987             checkWMTE(() -> { // 0
1988                 long x = (long) hs.get(am, methodType(long.class)).
1989                     invokeExact();
1990             });
1991             checkWMTE(() -> { // >
1992                 long x = (long) hs.get(am, methodType(long.class, long.class, Class.class)).
1993                     invokeExact(0x0123456789ABCDEFL, Void.class);
1994             });
1995         }
1996     }
1997 
1998 
1999     static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
2000         long[] array = new long[10];
2001         Arrays.fill(array, 0x0123456789ABCDEFL);
2002 
2003         // Get
2004         // Incorrect argument types
2005         checkNPE(() -> { // null array
2006             long x = (long) vh.get(null, 0);
2007         });
2008         checkCCE(() -> { // array reference class
2009             long x = (long) vh.get(Void.class, 0);
2010         });
2011         checkWMTE(() -> { // array primitive class
2012             long x = (long) vh.get(0, 0);

2960         });
2961         checkWMTE(() -> { // primitive class
2962             boolean x = (boolean) vh.getAndBitwiseXorRelease(array, 0, 0x0123456789ABCDEFL);
2963         });
2964         // Incorrect arity
2965         checkWMTE(() -> { // 0
2966             long x = (long) vh.getAndBitwiseXorRelease();
2967         });
2968         checkWMTE(() -> { // >
2969             long x = (long) vh.getAndBitwiseXorRelease(array, 0, 0x0123456789ABCDEFL, Void.class);
2970         });
2971     }
2972 
2973     static void testArrayWrongMethodType(Handles hs) throws Throwable {
2974         long[] array = new long[10];
2975         Arrays.fill(array, 0x0123456789ABCDEFL);
2976 
2977         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
2978             // Incorrect argument types
2979             checkNPE(() -> { // null array
2980                 long x = (long) hs.get(am, methodType(long.class, long[].class, int.class)).
2981                     invokeExact((long[]) null, 0);
2982             });
2983             hs.checkWMTEOrCCE(() -> { // array reference class
2984                 long x = (long) hs.get(am, methodType(long.class, Class.class, int.class)).
2985                     invokeExact(Void.class, 0);
2986             });
2987             checkWMTE(() -> { // array primitive class
2988                 long x = (long) hs.get(am, methodType(long.class, int.class, int.class)).
2989                     invokeExact(0, 0);
2990             });
2991             checkWMTE(() -> { // index reference class
2992                 long x = (long) hs.get(am, methodType(long.class, long[].class, Class.class)).
2993                     invokeExact(array, Void.class);
2994             });
2995             // Incorrect return type
2996             checkWMTE(() -> { // reference class
2997                 Void x = (Void) hs.get(am, methodType(Void.class, long[].class, int.class)).
2998                     invokeExact(array, 0);
2999             });
3000             checkWMTE(() -> { // primitive class
3001                 boolean x = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class)).
3002                     invokeExact(array, 0);
3003             });
3004             // Incorrect arity
3005             checkWMTE(() -> { // 0
3006                 long x = (long) hs.get(am, methodType(long.class)).
3007                     invokeExact();
3008             });
3009             checkWMTE(() -> { // >
3010                 long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, Class.class)).
3011                     invokeExact(array, 0, Void.class);
3012             });
3013         }
3014 
3015         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
3016             // Incorrect argument types
3017             checkNPE(() -> { // null array
3018                 hs.get(am, methodType(void.class, long[].class, int.class, long.class)).
3019                     invokeExact((long[]) null, 0, 0x0123456789ABCDEFL);
3020             });
3021             hs.checkWMTEOrCCE(() -> { // array reference class
3022                 hs.get(am, methodType(void.class, Class.class, int.class, long.class)).
3023                     invokeExact(Void.class, 0, 0x0123456789ABCDEFL);
3024             });
3025             checkWMTE(() -> { // value reference class
3026                 hs.get(am, methodType(void.class, long[].class, int.class, Class.class)).
3027                     invokeExact(array, 0, Void.class);
3028             });
3029             checkWMTE(() -> { // receiver primitive class
3030                 hs.get(am, methodType(void.class, int.class, int.class, long.class)).
3031                     invokeExact(0, 0, 0x0123456789ABCDEFL);
3032             });
3033             checkWMTE(() -> { // index reference class
3034                 hs.get(am, methodType(void.class, long[].class, Class.class, long.class)).
3035                     invokeExact(array, Void.class, 0x0123456789ABCDEFL);
3036             });
3037             // Incorrect arity
3038             checkWMTE(() -> { // 0
3039                 hs.get(am, methodType(void.class)).
3040                     invokeExact();
3041             });
3042             checkWMTE(() -> { // >
3043                 hs.get(am, methodType(void.class, long[].class, int.class, Class.class)).
3044                     invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
3045             });
3046         }
3047         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
3048             // Incorrect argument types
3049             checkNPE(() -> { // null receiver
3050                 boolean r = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, long.class, long.class)).
3051                     invokeExact((long[]) null, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3052             });
3053             hs.checkWMTEOrCCE(() -> { // receiver reference class
3054                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, long.class, long.class)).
3055                     invokeExact(Void.class, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3056             });
3057             checkWMTE(() -> { // expected reference class
3058                 boolean r = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, Class.class, long.class)).
3059                     invokeExact(array, 0, Void.class, 0x0123456789ABCDEFL);
3060             });
3061             checkWMTE(() -> { // actual reference class
3062                 boolean r = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, long.class, Class.class)).
3063                     invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
3064             });
3065             checkWMTE(() -> { // receiver primitive class
3066                 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, long.class, long.class)).
3067                     invokeExact(0, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3068             });
3069             checkWMTE(() -> { // index reference class
3070                 boolean r = (boolean) hs.get(am, methodType(boolean.class, long[].class, Class.class, long.class, long.class)).
3071                     invokeExact(array, Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3072             });
3073             // Incorrect arity
3074             checkWMTE(() -> { // 0
3075                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
3076                     invokeExact();
3077             });
3078             checkWMTE(() -> { // >
3079                 boolean r = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, long.class, long.class, Class.class)).
3080                     invokeExact(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
3081             });
3082         }
3083 
3084         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
3085             // Incorrect argument types
3086             checkNPE(() -> { // null receiver
3087                 long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class, long.class)).
3088                     invokeExact((long[]) null, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3089             });
3090             hs.checkWMTEOrCCE(() -> { // array reference class
3091                 long x = (long) hs.get(am, methodType(long.class, Class.class, int.class, long.class, long.class)).
3092                     invokeExact(Void.class, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3093             });
3094             checkWMTE(() -> { // expected reference class
3095                 long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, Class.class, long.class)).
3096                     invokeExact(array, 0, Void.class, 0x0123456789ABCDEFL);
3097             });
3098             checkWMTE(() -> { // actual reference class
3099                 long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class, Class.class)).
3100                     invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
3101             });
3102             checkWMTE(() -> { // array primitive class
3103                 long x = (long) hs.get(am, methodType(long.class, int.class, int.class, long.class, long.class)).
3104                     invokeExact(0, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3105             });
3106             checkWMTE(() -> { // index reference class
3107                 long x = (long) hs.get(am, methodType(long.class, long[].class, Class.class, long.class, long.class)).
3108                     invokeExact(array, Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3109             });
3110             // Incorrect return type
3111             checkWMTE(() -> { // reference class
3112                 Void r = (Void) hs.get(am, methodType(Void.class, long[].class, int.class, long.class, long.class)).
3113                     invokeExact(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3114             });
3115             checkWMTE(() -> { // primitive class
3116                 boolean x = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, long.class, long.class)).
3117                     invokeExact(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3118             });
3119             // Incorrect arity
3120             checkWMTE(() -> { // 0
3121                 long x = (long) hs.get(am, methodType(long.class)).
3122                     invokeExact();
3123             });
3124             checkWMTE(() -> { // >
3125                 long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class, long.class, Class.class)).
3126                     invokeExact(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
3127             });
3128         }
3129 
3130         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
3131             // Incorrect argument types
3132             checkNPE(() -> { // null array
3133                 long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class)).
3134                     invokeExact((long[]) null, 0, 0x0123456789ABCDEFL);
3135             });
3136             hs.checkWMTEOrCCE(() -> { // array reference class
3137                 long x = (long) hs.get(am, methodType(long.class, Class.class, int.class, long.class)).
3138                     invokeExact(Void.class, 0, 0x0123456789ABCDEFL);
3139             });
3140             checkWMTE(() -> { // value reference class
3141                 long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, Class.class)).
3142                     invokeExact(array, 0, Void.class);
3143             });
3144             checkWMTE(() -> { // array primitive class
3145                 long x = (long) hs.get(am, methodType(long.class, int.class, int.class, long.class)).
3146                     invokeExact(0, 0, 0x0123456789ABCDEFL);
3147             });
3148             checkWMTE(() -> { // index reference class
3149                 long x = (long) hs.get(am, methodType(long.class, long[].class, Class.class, long.class)).
3150                     invokeExact(array, Void.class, 0x0123456789ABCDEFL);
3151             });
3152             // Incorrect return type
3153             checkWMTE(() -> { // reference class
3154                 Void r = (Void) hs.get(am, methodType(Void.class, long[].class, int.class, long.class)).
3155                     invokeExact(array, 0, 0x0123456789ABCDEFL);
3156             });
3157             checkWMTE(() -> { // primitive class
3158                 boolean x = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, long.class)).
3159                     invokeExact(array, 0, 0x0123456789ABCDEFL);
3160             });
3161             // Incorrect arity
3162             checkWMTE(() -> { // 0
3163                 long x = (long) hs.get(am, methodType(long.class)).
3164                     invokeExact();
3165             });
3166             checkWMTE(() -> { // >
3167                 long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class, Class.class)).
3168                     invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
3169             });
3170         }
3171 
3172         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
3173             // Incorrect argument types
3174             checkNPE(() -> { // null array
3175                 long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class)).
3176                     invokeExact((long[]) null, 0, 0x0123456789ABCDEFL);
3177             });
3178             hs.checkWMTEOrCCE(() -> { // array reference class
3179                 long x = (long) hs.get(am, methodType(long.class, Class.class, int.class, long.class)).
3180                     invokeExact(Void.class, 0, 0x0123456789ABCDEFL);
3181             });
3182             checkWMTE(() -> { // value reference class
3183                 long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, Class.class)).
3184                     invokeExact(array, 0, Void.class);
3185             });
3186             checkWMTE(() -> { // array primitive class
3187                 long x = (long) hs.get(am, methodType(long.class, int.class, int.class, long.class)).
3188                     invokeExact(0, 0, 0x0123456789ABCDEFL);
3189             });
3190             checkWMTE(() -> { // index reference class
3191                 long x = (long) hs.get(am, methodType(long.class, long[].class, Class.class, long.class)).
3192                     invokeExact(array, Void.class, 0x0123456789ABCDEFL);
3193             });
3194             // Incorrect return type
3195             checkWMTE(() -> { // reference class
3196                 Void r = (Void) hs.get(am, methodType(Void.class, long[].class, int.class, long.class)).
3197                     invokeExact(array, 0, 0x0123456789ABCDEFL);
3198             });
3199             checkWMTE(() -> { // primitive class
3200                 boolean x = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, long.class)).
3201                     invokeExact(array, 0, 0x0123456789ABCDEFL);
3202             });
3203             // Incorrect arity
3204             checkWMTE(() -> { // 0
3205                 long x = (long) hs.get(am, methodType(long.class)).
3206                     invokeExact();
3207             });
3208             checkWMTE(() -> { // >
3209                 long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class, Class.class)).
3210                     invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
3211             });
3212         }
3213 
3214         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
3215             // Incorrect argument types
3216             checkNPE(() -> { // null array
3217                 long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class)).
3218                     invokeExact((long[]) null, 0, 0x0123456789ABCDEFL);
3219             });
3220             hs.checkWMTEOrCCE(() -> { // array reference class
3221                 long x = (long) hs.get(am, methodType(long.class, Class.class, int.class, long.class)).
3222                     invokeExact(Void.class, 0, 0x0123456789ABCDEFL);
3223             });
3224             checkWMTE(() -> { // value reference class
3225                 long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, Class.class)).
3226                     invokeExact(array, 0, Void.class);
3227             });
3228             checkWMTE(() -> { // array primitive class
3229                 long x = (long) hs.get(am, methodType(long.class, int.class, int.class, long.class)).
3230                     invokeExact(0, 0, 0x0123456789ABCDEFL);
3231             });
3232             checkWMTE(() -> { // index reference class
3233                 long x = (long) hs.get(am, methodType(long.class, long[].class, Class.class, long.class)).
3234                     invokeExact(array, Void.class, 0x0123456789ABCDEFL);
3235             });
3236             // Incorrect return type
3237             checkWMTE(() -> { // reference class
3238                 Void r = (Void) hs.get(am, methodType(Void.class, long[].class, int.class, long.class)).
3239                     invokeExact(array, 0, 0x0123456789ABCDEFL);
3240             });
3241             checkWMTE(() -> { // primitive class
3242                 boolean x = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, long.class)).
3243                     invokeExact(array, 0, 0x0123456789ABCDEFL);
3244             });
3245             // Incorrect arity
3246             checkWMTE(() -> { // 0
3247                 long x = (long) hs.get(am, methodType(long.class)).
3248                     invokeExact();
3249             });
3250             checkWMTE(() -> { // >
3251                 long x = (long) hs.get(am, methodType(long.class, long[].class, int.class, long.class, Class.class)).
3252                     invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
3253             });
3254         }
3255     }
3256 }

   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 // -- This file was mechanically generated: Do not edit! -- //
  25 
  26 /*
  27  * @test
  28  * @bug 8156486
  29  * @run testng/othervm VarHandleTestMethodTypeLong
  30  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeLong
  31  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeLong
  32  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeLong
  33  */
  34 
  35 import org.testng.annotations.BeforeClass;
  36 import org.testng.annotations.DataProvider;
  37 import org.testng.annotations.Test;
  38 
  39 import java.lang.invoke.MethodHandles;
  40 import java.lang.invoke.VarHandle;
  41 import java.util.ArrayList;
  42 import java.util.Arrays;
  43 import java.util.List;
  44 
  45 import static org.testng.Assert.*;
  46 
  47 import static java.lang.invoke.MethodType.*;
  48 
  49 public class VarHandleTestMethodTypeLong extends VarHandleBaseTest {
  50     static final Class<?> type = long.class;
  51 
  52     static final long static_final_v = 0x0123456789ABCDEFL;
  53 
  54     static long static_v = 0x0123456789ABCDEFL;
  55 
  56     final long final_v = 0x0123456789ABCDEFL;
  57 
  58     long v = 0x0123456789ABCDEFL;
  59 
  60     VarHandle vhFinalField;
  61 
  62     VarHandle vhField;
  63 
  64     VarHandle vhStaticField;
  65 
  66     VarHandle vhStaticFinalField;
  67 
  68     VarHandle vhArray;
  69 
  70     @BeforeClass
  71     public void setup() throws Exception {
  72         vhFinalField = MethodHandles.lookup().findVarHandle(
  73                 VarHandleTestMethodTypeLong.class, "final_v", type);
  74 
  75         vhField = MethodHandles.lookup().findVarHandle(
  76                 VarHandleTestMethodTypeLong.class, "v", type);
  77 
  78         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
  79             VarHandleTestMethodTypeLong.class, "static_final_v", type);
  80 
  81         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
  82             VarHandleTestMethodTypeLong.class, "static_v", type);
  83 
  84         vhArray = MethodHandles.arrayElementVarHandle(long[].class);
  85     }
  86 
  87     @DataProvider
  88     public Object[][] accessTestCaseProvider() throws Exception {
  89         List<AccessTestCase<?>> cases = new ArrayList<>();
  90 
  91         cases.add(new VarHandleAccessTestCase("Instance field",
  92                                               vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
  93                                               false));
  94 
  95         cases.add(new VarHandleAccessTestCase("Static field",
  96                                               vhStaticField, VarHandleTestMethodTypeLong::testStaticFieldWrongMethodType,
  97                                               false));
  98 
  99         cases.add(new VarHandleAccessTestCase("Array",
 100                                               vhArray, VarHandleTestMethodTypeLong::testArrayWrongMethodType,
 101                                               false));
 102 

 990         // Incorrect return type
 991         checkWMTE(() -> { // reference class
 992             Void r = (Void) vh.getAndBitwiseXor(recv, 0x0123456789ABCDEFL);
 993         });
 994         checkWMTE(() -> { // primitive class
 995             boolean x = (boolean) vh.getAndBitwiseXor(recv, 0x0123456789ABCDEFL);
 996         });
 997         // Incorrect arity
 998         checkWMTE(() -> { // 0
 999             long x = (long) vh.getAndBitwiseXor();
1000         });
1001         checkWMTE(() -> { // >
1002             long x = (long) vh.getAndBitwiseXor(recv, 0x0123456789ABCDEFL, Void.class);
1003         });
1004     }
1005 
1006     static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeLong recv, Handles hs) throws Throwable {
1007         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
1008             // Incorrect argument types
1009             checkNPE(() -> { // null receiver
1010                 long x = (long) hs.get(am, methodType(type, VarHandleTestMethodTypeLong.class)).
1011                     invokeExact((VarHandleTestMethodTypeLong) null);
1012             });
1013             hs.checkWMTEOrCCE(() -> { // receiver reference class
1014                 long x = (long) hs.get(am, methodType(type, Class.class)).
1015                     invokeExact(Void.class);
1016             });
1017             checkWMTE(() -> { // receiver primitive class
1018                 long x = (long) hs.get(am, methodType(type, int.class)).
1019                     invokeExact(0);
1020             });
1021             // Incorrect return type
1022             checkWMTE(() -> { // reference class
1023                 Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeLong.class)).
1024                     invokeExact(recv);
1025             });
1026             checkWMTE(() -> { // primitive class
1027                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class)).
1028                     invokeExact(recv);
1029             });
1030             // Incorrect arity
1031             checkWMTE(() -> { // 0
1032                 long x = (long) hs.get(am, methodType(type)).
1033                     invokeExact();
1034             });
1035             checkWMTE(() -> { // >
1036                 long x = (long) hs.get(am, methodType(type, VarHandleTestMethodTypeLong.class, Class.class)).
1037                     invokeExact(recv, Void.class);
1038             });
1039         }
1040 
1041         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
1042             // Incorrect argument types
1043             checkNPE(() -> { // null receiver
1044                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeLong.class, type)).
1045                     invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL);
1046             });
1047             hs.checkWMTEOrCCE(() -> { // receiver reference class
1048                 hs.get(am, methodType(void.class, Class.class, type)).
1049                     invokeExact(Void.class, 0x0123456789ABCDEFL);
1050             });
1051             checkWMTE(() -> { // value reference class
1052                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeLong.class, Class.class)).
1053                     invokeExact(recv, Void.class);
1054             });
1055             checkWMTE(() -> { // receiver primitive class
1056                 hs.get(am, methodType(void.class, int.class, type)).
1057                     invokeExact(0, 0x0123456789ABCDEFL);
1058             });
1059             // Incorrect arity
1060             checkWMTE(() -> { // 0
1061                 hs.get(am, methodType(void.class)).
1062                     invokeExact();
1063             });
1064             checkWMTE(() -> { // >
1065                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeLong.class, type, Class.class)).
1066                     invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
1067             });
1068         }
1069 
1070         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
1071             // Incorrect argument types
1072             checkNPE(() -> { // null receiver
1073                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, type, type)).
1074                     invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1075             });
1076             hs.checkWMTEOrCCE(() -> { // receiver reference class
1077                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, type, type)).
1078                     invokeExact(Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1079             });
1080             checkWMTE(() -> { // expected reference class
1081                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, Class.class, type)).
1082                     invokeExact(recv, Void.class, 0x0123456789ABCDEFL);
1083             });
1084             checkWMTE(() -> { // actual reference class
1085                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, type, Class.class)).
1086                     invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
1087             });
1088             checkWMTE(() -> { // receiver primitive class
1089                 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , type, type)).
1090                     invokeExact(0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1091             });
1092             // Incorrect arity
1093             checkWMTE(() -> { // 0
1094                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
1095                     invokeExact();
1096             });
1097             checkWMTE(() -> { // >
1098                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, type, type, Class.class)).
1099                     invokeExact(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
1100             });
1101         }
1102 
1103         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1104             checkNPE(() -> { // null receiver
1105                 long x = (long) hs.get(am, methodType(type, VarHandleTestMethodTypeLong.class, type, type)).
1106                     invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1107             });
1108             hs.checkWMTEOrCCE(() -> { // receiver reference class
1109                 long x = (long) hs.get(am, methodType(type, Class.class, type, type)).
1110                     invokeExact(Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1111             });
1112             checkWMTE(() -> { // expected reference class
1113                 long x = (long) hs.get(am, methodType(type, VarHandleTestMethodTypeLong.class, Class.class, type)).
1114                     invokeExact(recv, Void.class, 0x0123456789ABCDEFL);
1115             });
1116             checkWMTE(() -> { // actual reference class
1117                 long x = (long) hs.get(am, methodType(type, VarHandleTestMethodTypeLong.class, type, Class.class)).
1118                     invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
1119             });
1120             checkWMTE(() -> { // reciever primitive class
1121                 long x = (long) hs.get(am, methodType(type, int.class , type, type)).
1122                     invokeExact(0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1123             });
1124             // Incorrect return type
1125             checkWMTE(() -> { // reference class
1126                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeLong.class , type, type)).
1127                     invokeExact(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1128             });
1129             checkWMTE(() -> { // primitive class
1130                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class , type, type)).
1131                     invokeExact(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1132             });
1133             // Incorrect arity
1134             checkWMTE(() -> { // 0
1135                 long x = (long) hs.get(am, methodType(type)).
1136                     invokeExact();
1137             });
1138             checkWMTE(() -> { // >
1139                 long x = (long) hs.get(am, methodType(type, VarHandleTestMethodTypeLong.class, type, type, Class.class)).
1140                     invokeExact(recv, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
1141             });
1142         }
1143 
1144         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1145             checkNPE(() -> { // null receiver
1146                 long x = (long) hs.get(am, methodType(type, VarHandleTestMethodTypeLong.class, type)).
1147                     invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL);
1148             });
1149             hs.checkWMTEOrCCE(() -> { // receiver reference class
1150                 long x = (long) hs.get(am, methodType(type, Class.class, type)).
1151                     invokeExact(Void.class, 0x0123456789ABCDEFL);
1152             });
1153             checkWMTE(() -> { // value reference class
1154                 long x = (long) hs.get(am, methodType(type, VarHandleTestMethodTypeLong.class, Class.class)).
1155                     invokeExact(recv, Void.class);
1156             });
1157             checkWMTE(() -> { // reciever primitive class
1158                 long x = (long) hs.get(am, methodType(type, int.class, type)).
1159                     invokeExact(0, 0x0123456789ABCDEFL);
1160             });
1161             // Incorrect return type
1162             checkWMTE(() -> { // reference class
1163                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeLong.class, type)).
1164                     invokeExact(recv, 0x0123456789ABCDEFL);
1165             });
1166             checkWMTE(() -> { // primitive class
1167                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, type)).
1168                     invokeExact(recv, 0x0123456789ABCDEFL);
1169             });
1170             // Incorrect arity
1171             checkWMTE(() -> { // 0
1172                 long x = (long) hs.get(am, methodType(type)).
1173                     invokeExact();
1174             });
1175             checkWMTE(() -> { // >
1176                 long x = (long) hs.get(am, methodType(type, VarHandleTestMethodTypeLong.class, type)).
1177                     invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
1178             });
1179         }
1180 
1181         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
1182             checkNPE(() -> { // null receiver
1183                 long x = (long) hs.get(am, methodType(type, VarHandleTestMethodTypeLong.class, type)).
1184                     invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL);
1185             });
1186             hs.checkWMTEOrCCE(() -> { // receiver reference class
1187                 long x = (long) hs.get(am, methodType(type, Class.class, type)).
1188                     invokeExact(Void.class, 0x0123456789ABCDEFL);
1189             });
1190             checkWMTE(() -> { // value reference class
1191                 long x = (long) hs.get(am, methodType(type, VarHandleTestMethodTypeLong.class, Class.class)).
1192                     invokeExact(recv, Void.class);
1193             });
1194             checkWMTE(() -> { // reciever primitive class
1195                 long x = (long) hs.get(am, methodType(type, int.class, type)).
1196                     invokeExact(0, 0x0123456789ABCDEFL);
1197             });
1198             // Incorrect return type
1199             checkWMTE(() -> { // reference class
1200                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeLong.class, type)).
1201                     invokeExact(recv, 0x0123456789ABCDEFL);
1202             });
1203             checkWMTE(() -> { // primitive class
1204                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, type)).
1205                     invokeExact(recv, 0x0123456789ABCDEFL);
1206             });
1207             // Incorrect arity
1208             checkWMTE(() -> { // 0
1209                 long x = (long) hs.get(am, methodType(type)).
1210                     invokeExact();
1211             });
1212             checkWMTE(() -> { // >
1213                 long x = (long) hs.get(am, methodType(type, VarHandleTestMethodTypeLong.class, type)).
1214                     invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
1215             });
1216         }
1217 
1218         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
1219             checkNPE(() -> { // null receiver
1220                 long x = (long) hs.get(am, methodType(type, VarHandleTestMethodTypeLong.class, type)).
1221                     invokeExact((VarHandleTestMethodTypeLong) null, 0x0123456789ABCDEFL);
1222             });
1223             hs.checkWMTEOrCCE(() -> { // receiver reference class
1224                 long x = (long) hs.get(am, methodType(type, Class.class, type)).
1225                     invokeExact(Void.class, 0x0123456789ABCDEFL);
1226             });
1227             checkWMTE(() -> { // value reference class
1228                 long x = (long) hs.get(am, methodType(type, VarHandleTestMethodTypeLong.class, Class.class)).
1229                     invokeExact(recv, Void.class);
1230             });
1231             checkWMTE(() -> { // reciever primitive class
1232                 long x = (long) hs.get(am, methodType(type, int.class, type)).
1233                     invokeExact(0, 0x0123456789ABCDEFL);
1234             });
1235             // Incorrect return type
1236             checkWMTE(() -> { // reference class
1237                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeLong.class, type)).
1238                     invokeExact(recv, 0x0123456789ABCDEFL);
1239             });
1240             checkWMTE(() -> { // primitive class
1241                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeLong.class, type)).
1242                     invokeExact(recv, 0x0123456789ABCDEFL);
1243             });
1244             // Incorrect arity
1245             checkWMTE(() -> { // 0
1246                 long x = (long) hs.get(am, methodType(type)).
1247                     invokeExact();
1248             });
1249             checkWMTE(() -> { // >
1250                 long x = (long) hs.get(am, methodType(type, VarHandleTestMethodTypeLong.class, type)).
1251                     invokeExact(recv, 0x0123456789ABCDEFL, Void.class);
1252             });
1253         }
1254     }
1255 
1256 
1257     static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
1258         // Get
1259         // Incorrect return type
1260         checkWMTE(() -> { // reference class
1261             Void x = (Void) vh.get();
1262         });
1263         checkWMTE(() -> { // primitive class
1264             boolean x = (boolean) vh.get();
1265         });
1266         // Incorrect arity
1267         checkWMTE(() -> { // >
1268             long x = (long) vh.get(Void.class);
1269         });
1270 

1848                     invokeExact();
1849             });
1850             // Incorrect arity
1851             checkWMTE(() -> { // >
1852                 long x = (long) hs.get(am, methodType(Class.class)).
1853                     invokeExact(Void.class);
1854             });
1855         }
1856 
1857         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
1858             checkWMTE(() -> { // value reference class
1859                 hs.get(am, methodType(void.class, Class.class)).
1860                     invokeExact(Void.class);
1861             });
1862             // Incorrect arity
1863             checkWMTE(() -> { // 0
1864                 hs.get(am, methodType(void.class)).
1865                     invokeExact();
1866             });
1867             checkWMTE(() -> { // >
1868                 hs.get(am, methodType(void.class, type, Class.class)).
1869                     invokeExact(0x0123456789ABCDEFL, Void.class);
1870             });
1871         }
1872         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
1873             // Incorrect argument types
1874             checkWMTE(() -> { // expected reference class
1875                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, type)).
1876                     invokeExact(Void.class, 0x0123456789ABCDEFL);
1877             });
1878             checkWMTE(() -> { // actual reference class
1879                 boolean r = (boolean) hs.get(am, methodType(boolean.class, type, Class.class)).
1880                     invokeExact(0x0123456789ABCDEFL, Void.class);
1881             });
1882             // Incorrect arity
1883             checkWMTE(() -> { // 0
1884                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
1885                     invokeExact();
1886             });
1887             checkWMTE(() -> { // >
1888                 boolean r = (boolean) hs.get(am, methodType(boolean.class, type, type, Class.class)).
1889                     invokeExact(0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
1890             });
1891         }
1892 
1893         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1894             // Incorrect argument types
1895             checkWMTE(() -> { // expected reference class
1896                 long x = (long) hs.get(am, methodType(type, Class.class, type)).
1897                     invokeExact(Void.class, 0x0123456789ABCDEFL);
1898             });
1899             checkWMTE(() -> { // actual reference class
1900                 long x = (long) hs.get(am, methodType(type, type, Class.class)).
1901                     invokeExact(0x0123456789ABCDEFL, Void.class);
1902             });
1903             // Incorrect return type
1904             checkWMTE(() -> { // reference class
1905                 Void r = (Void) hs.get(am, methodType(Void.class, type, type)).
1906                     invokeExact(0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1907             });
1908             checkWMTE(() -> { // primitive class
1909                 boolean x = (boolean) hs.get(am, methodType(boolean.class, type, type)).
1910                     invokeExact(0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
1911             });
1912             // Incorrect arity
1913             checkWMTE(() -> { // 0
1914                 long x = (long) hs.get(am, methodType(type)).
1915                     invokeExact();
1916             });
1917             checkWMTE(() -> { // >
1918                 long x = (long) hs.get(am, methodType(type, type, type, Class.class)).
1919                     invokeExact(0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
1920             });
1921         }
1922 
1923         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1924             // Incorrect argument types
1925             checkWMTE(() -> { // value reference class
1926                 long x = (long) hs.get(am, methodType(type, Class.class)).
1927                     invokeExact(Void.class);
1928             });
1929             // Incorrect return type
1930             checkWMTE(() -> { // reference class
1931                 Void r = (Void) hs.get(am, methodType(Void.class, type)).
1932                     invokeExact(0x0123456789ABCDEFL);
1933             });
1934             checkWMTE(() -> { // primitive class
1935                 boolean x = (boolean) hs.get(am, methodType(boolean.class, type)).
1936                     invokeExact(0x0123456789ABCDEFL);
1937             });
1938             // Incorrect arity
1939             checkWMTE(() -> { // 0
1940                 long x = (long) hs.get(am, methodType(type)).
1941                     invokeExact();
1942             });
1943             checkWMTE(() -> { // >
1944                 long x = (long) hs.get(am, methodType(type, type, Class.class)).
1945                     invokeExact(0x0123456789ABCDEFL, Void.class);
1946             });
1947         }
1948 
1949         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
1950             // Incorrect argument types
1951             checkWMTE(() -> { // value reference class
1952                 long x = (long) hs.get(am, methodType(type, Class.class)).
1953                     invokeExact(Void.class);
1954             });
1955             // Incorrect return type
1956             checkWMTE(() -> { // reference class
1957                 Void r = (Void) hs.get(am, methodType(Void.class, type)).
1958                     invokeExact(0x0123456789ABCDEFL);
1959             });
1960             checkWMTE(() -> { // primitive class
1961                 boolean x = (boolean) hs.get(am, methodType(boolean.class, type)).
1962                     invokeExact(0x0123456789ABCDEFL);
1963             });
1964             // Incorrect arity
1965             checkWMTE(() -> { // 0
1966                 long x = (long) hs.get(am, methodType(type)).
1967                     invokeExact();
1968             });
1969             checkWMTE(() -> { // >
1970                 long x = (long) hs.get(am, methodType(type, type, Class.class)).
1971                     invokeExact(0x0123456789ABCDEFL, Void.class);
1972             });
1973         }
1974 
1975         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
1976             // Incorrect argument types
1977             checkWMTE(() -> { // value reference class
1978                 long x = (long) hs.get(am, methodType(type, Class.class)).
1979                     invokeExact(Void.class);
1980             });
1981             // Incorrect return type
1982             checkWMTE(() -> { // reference class
1983                 Void r = (Void) hs.get(am, methodType(Void.class, type)).
1984                     invokeExact(0x0123456789ABCDEFL);
1985             });
1986             checkWMTE(() -> { // primitive class
1987                 boolean x = (boolean) hs.get(am, methodType(boolean.class, type)).
1988                     invokeExact(0x0123456789ABCDEFL);
1989             });
1990             // Incorrect arity
1991             checkWMTE(() -> { // 0
1992                 long x = (long) hs.get(am, methodType(type)).
1993                     invokeExact();
1994             });
1995             checkWMTE(() -> { // >
1996                 long x = (long) hs.get(am, methodType(type, type, Class.class)).
1997                     invokeExact(0x0123456789ABCDEFL, Void.class);
1998             });
1999         }
2000     }
2001 
2002 
2003     static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
2004         long[] array = new long[10];
2005         Arrays.fill(array, 0x0123456789ABCDEFL);
2006 
2007         // Get
2008         // Incorrect argument types
2009         checkNPE(() -> { // null array
2010             long x = (long) vh.get(null, 0);
2011         });
2012         checkCCE(() -> { // array reference class
2013             long x = (long) vh.get(Void.class, 0);
2014         });
2015         checkWMTE(() -> { // array primitive class
2016             long x = (long) vh.get(0, 0);

2964         });
2965         checkWMTE(() -> { // primitive class
2966             boolean x = (boolean) vh.getAndBitwiseXorRelease(array, 0, 0x0123456789ABCDEFL);
2967         });
2968         // Incorrect arity
2969         checkWMTE(() -> { // 0
2970             long x = (long) vh.getAndBitwiseXorRelease();
2971         });
2972         checkWMTE(() -> { // >
2973             long x = (long) vh.getAndBitwiseXorRelease(array, 0, 0x0123456789ABCDEFL, Void.class);
2974         });
2975     }
2976 
2977     static void testArrayWrongMethodType(Handles hs) throws Throwable {
2978         long[] array = new long[10];
2979         Arrays.fill(array, 0x0123456789ABCDEFL);
2980 
2981         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
2982             // Incorrect argument types
2983             checkNPE(() -> { // null array
2984                 long x = (long) hs.get(am, methodType(type, long[].class, int.class)).
2985                     invokeExact((long[]) null, 0);
2986             });
2987             hs.checkWMTEOrCCE(() -> { // array reference class
2988                 long x = (long) hs.get(am, methodType(type, Class.class, int.class)).
2989                     invokeExact(Void.class, 0);
2990             });
2991             checkWMTE(() -> { // array primitive class
2992                 long x = (long) hs.get(am, methodType(type, int.class, int.class)).
2993                     invokeExact(0, 0);
2994             });
2995             checkWMTE(() -> { // index reference class
2996                 long x = (long) hs.get(am, methodType(type, long[].class, Class.class)).
2997                     invokeExact(array, Void.class);
2998             });
2999             // Incorrect return type
3000             checkWMTE(() -> { // reference class
3001                 Void x = (Void) hs.get(am, methodType(Void.class, long[].class, int.class)).
3002                     invokeExact(array, 0);
3003             });
3004             checkWMTE(() -> { // primitive class
3005                 boolean x = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class)).
3006                     invokeExact(array, 0);
3007             });
3008             // Incorrect arity
3009             checkWMTE(() -> { // 0
3010                 long x = (long) hs.get(am, methodType(type)).
3011                     invokeExact();
3012             });
3013             checkWMTE(() -> { // >
3014                 long x = (long) hs.get(am, methodType(type, long[].class, int.class, Class.class)).
3015                     invokeExact(array, 0, Void.class);
3016             });
3017         }
3018 
3019         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
3020             // Incorrect argument types
3021             checkNPE(() -> { // null array
3022                 hs.get(am, methodType(void.class, long[].class, int.class, type)).
3023                     invokeExact((long[]) null, 0, 0x0123456789ABCDEFL);
3024             });
3025             hs.checkWMTEOrCCE(() -> { // array reference class
3026                 hs.get(am, methodType(void.class, Class.class, int.class, type)).
3027                     invokeExact(Void.class, 0, 0x0123456789ABCDEFL);
3028             });
3029             checkWMTE(() -> { // value reference class
3030                 hs.get(am, methodType(void.class, long[].class, int.class, Class.class)).
3031                     invokeExact(array, 0, Void.class);
3032             });
3033             checkWMTE(() -> { // receiver primitive class
3034                 hs.get(am, methodType(void.class, int.class, int.class, type)).
3035                     invokeExact(0, 0, 0x0123456789ABCDEFL);
3036             });
3037             checkWMTE(() -> { // index reference class
3038                 hs.get(am, methodType(void.class, long[].class, Class.class, type)).
3039                     invokeExact(array, Void.class, 0x0123456789ABCDEFL);
3040             });
3041             // Incorrect arity
3042             checkWMTE(() -> { // 0
3043                 hs.get(am, methodType(void.class)).
3044                     invokeExact();
3045             });
3046             checkWMTE(() -> { // >
3047                 hs.get(am, methodType(void.class, long[].class, int.class, Class.class)).
3048                     invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
3049             });
3050         }
3051         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
3052             // Incorrect argument types
3053             checkNPE(() -> { // null receiver
3054                 boolean r = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, type, type)).
3055                     invokeExact((long[]) null, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3056             });
3057             hs.checkWMTEOrCCE(() -> { // receiver reference class
3058                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, type, type)).
3059                     invokeExact(Void.class, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3060             });
3061             checkWMTE(() -> { // expected reference class
3062                 boolean r = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, Class.class, type)).
3063                     invokeExact(array, 0, Void.class, 0x0123456789ABCDEFL);
3064             });
3065             checkWMTE(() -> { // actual reference class
3066                 boolean r = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, type, Class.class)).
3067                     invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
3068             });
3069             checkWMTE(() -> { // receiver primitive class
3070                 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, type, type)).
3071                     invokeExact(0, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3072             });
3073             checkWMTE(() -> { // index reference class
3074                 boolean r = (boolean) hs.get(am, methodType(boolean.class, long[].class, Class.class, type, type)).
3075                     invokeExact(array, Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3076             });
3077             // Incorrect arity
3078             checkWMTE(() -> { // 0
3079                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
3080                     invokeExact();
3081             });
3082             checkWMTE(() -> { // >
3083                 boolean r = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, type, type, Class.class)).
3084                     invokeExact(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
3085             });
3086         }
3087 
3088         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
3089             // Incorrect argument types
3090             checkNPE(() -> { // null receiver
3091                 long x = (long) hs.get(am, methodType(type, long[].class, int.class, type, type)).
3092                     invokeExact((long[]) null, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3093             });
3094             hs.checkWMTEOrCCE(() -> { // array reference class
3095                 long x = (long) hs.get(am, methodType(type, Class.class, int.class, type, type)).
3096                     invokeExact(Void.class, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3097             });
3098             checkWMTE(() -> { // expected reference class
3099                 long x = (long) hs.get(am, methodType(type, long[].class, int.class, Class.class, type)).
3100                     invokeExact(array, 0, Void.class, 0x0123456789ABCDEFL);
3101             });
3102             checkWMTE(() -> { // actual reference class
3103                 long x = (long) hs.get(am, methodType(type, long[].class, int.class, type, Class.class)).
3104                     invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
3105             });
3106             checkWMTE(() -> { // array primitive class
3107                 long x = (long) hs.get(am, methodType(type, int.class, int.class, type, type)).
3108                     invokeExact(0, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3109             });
3110             checkWMTE(() -> { // index reference class
3111                 long x = (long) hs.get(am, methodType(type, long[].class, Class.class, type, type)).
3112                     invokeExact(array, Void.class, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3113             });
3114             // Incorrect return type
3115             checkWMTE(() -> { // reference class
3116                 Void r = (Void) hs.get(am, methodType(Void.class, long[].class, int.class, type, type)).
3117                     invokeExact(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3118             });
3119             checkWMTE(() -> { // primitive class
3120                 boolean x = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, type, type)).
3121                     invokeExact(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL);
3122             });
3123             // Incorrect arity
3124             checkWMTE(() -> { // 0
3125                 long x = (long) hs.get(am, methodType(type)).
3126                     invokeExact();
3127             });
3128             checkWMTE(() -> { // >
3129                 long x = (long) hs.get(am, methodType(type, long[].class, int.class, type, type, Class.class)).
3130                     invokeExact(array, 0, 0x0123456789ABCDEFL, 0x0123456789ABCDEFL, Void.class);
3131             });
3132         }
3133 
3134         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
3135             // Incorrect argument types
3136             checkNPE(() -> { // null array
3137                 long x = (long) hs.get(am, methodType(type, long[].class, int.class, type)).
3138                     invokeExact((long[]) null, 0, 0x0123456789ABCDEFL);
3139             });
3140             hs.checkWMTEOrCCE(() -> { // array reference class
3141                 long x = (long) hs.get(am, methodType(type, Class.class, int.class, type)).
3142                     invokeExact(Void.class, 0, 0x0123456789ABCDEFL);
3143             });
3144             checkWMTE(() -> { // value reference class
3145                 long x = (long) hs.get(am, methodType(type, long[].class, int.class, Class.class)).
3146                     invokeExact(array, 0, Void.class);
3147             });
3148             checkWMTE(() -> { // array primitive class
3149                 long x = (long) hs.get(am, methodType(type, int.class, int.class, type)).
3150                     invokeExact(0, 0, 0x0123456789ABCDEFL);
3151             });
3152             checkWMTE(() -> { // index reference class
3153                 long x = (long) hs.get(am, methodType(type, long[].class, Class.class, type)).
3154                     invokeExact(array, Void.class, 0x0123456789ABCDEFL);
3155             });
3156             // Incorrect return type
3157             checkWMTE(() -> { // reference class
3158                 Void r = (Void) hs.get(am, methodType(Void.class, long[].class, int.class, type)).
3159                     invokeExact(array, 0, 0x0123456789ABCDEFL);
3160             });
3161             checkWMTE(() -> { // primitive class
3162                 boolean x = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, type)).
3163                     invokeExact(array, 0, 0x0123456789ABCDEFL);
3164             });
3165             // Incorrect arity
3166             checkWMTE(() -> { // 0
3167                 long x = (long) hs.get(am, methodType(type)).
3168                     invokeExact();
3169             });
3170             checkWMTE(() -> { // >
3171                 long x = (long) hs.get(am, methodType(type, long[].class, int.class, type, Class.class)).
3172                     invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
3173             });
3174         }
3175 
3176         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
3177             // Incorrect argument types
3178             checkNPE(() -> { // null array
3179                 long x = (long) hs.get(am, methodType(type, long[].class, int.class, type)).
3180                     invokeExact((long[]) null, 0, 0x0123456789ABCDEFL);
3181             });
3182             hs.checkWMTEOrCCE(() -> { // array reference class
3183                 long x = (long) hs.get(am, methodType(type, Class.class, int.class, type)).
3184                     invokeExact(Void.class, 0, 0x0123456789ABCDEFL);
3185             });
3186             checkWMTE(() -> { // value reference class
3187                 long x = (long) hs.get(am, methodType(type, long[].class, int.class, Class.class)).
3188                     invokeExact(array, 0, Void.class);
3189             });
3190             checkWMTE(() -> { // array primitive class
3191                 long x = (long) hs.get(am, methodType(type, int.class, int.class, type)).
3192                     invokeExact(0, 0, 0x0123456789ABCDEFL);
3193             });
3194             checkWMTE(() -> { // index reference class
3195                 long x = (long) hs.get(am, methodType(type, long[].class, Class.class, type)).
3196                     invokeExact(array, Void.class, 0x0123456789ABCDEFL);
3197             });
3198             // Incorrect return type
3199             checkWMTE(() -> { // reference class
3200                 Void r = (Void) hs.get(am, methodType(Void.class, long[].class, int.class, type)).
3201                     invokeExact(array, 0, 0x0123456789ABCDEFL);
3202             });
3203             checkWMTE(() -> { // primitive class
3204                 boolean x = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, type)).
3205                     invokeExact(array, 0, 0x0123456789ABCDEFL);
3206             });
3207             // Incorrect arity
3208             checkWMTE(() -> { // 0
3209                 long x = (long) hs.get(am, methodType(type)).
3210                     invokeExact();
3211             });
3212             checkWMTE(() -> { // >
3213                 long x = (long) hs.get(am, methodType(type, long[].class, int.class, type, Class.class)).
3214                     invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
3215             });
3216         }
3217 
3218         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
3219             // Incorrect argument types
3220             checkNPE(() -> { // null array
3221                 long x = (long) hs.get(am, methodType(type, long[].class, int.class, type)).
3222                     invokeExact((long[]) null, 0, 0x0123456789ABCDEFL);
3223             });
3224             hs.checkWMTEOrCCE(() -> { // array reference class
3225                 long x = (long) hs.get(am, methodType(type, Class.class, int.class, type)).
3226                     invokeExact(Void.class, 0, 0x0123456789ABCDEFL);
3227             });
3228             checkWMTE(() -> { // value reference class
3229                 long x = (long) hs.get(am, methodType(type, long[].class, int.class, Class.class)).
3230                     invokeExact(array, 0, Void.class);
3231             });
3232             checkWMTE(() -> { // array primitive class
3233                 long x = (long) hs.get(am, methodType(type, int.class, int.class, type)).
3234                     invokeExact(0, 0, 0x0123456789ABCDEFL);
3235             });
3236             checkWMTE(() -> { // index reference class
3237                 long x = (long) hs.get(am, methodType(type, long[].class, Class.class, type)).
3238                     invokeExact(array, Void.class, 0x0123456789ABCDEFL);
3239             });
3240             // Incorrect return type
3241             checkWMTE(() -> { // reference class
3242                 Void r = (Void) hs.get(am, methodType(Void.class, long[].class, int.class, type)).
3243                     invokeExact(array, 0, 0x0123456789ABCDEFL);
3244             });
3245             checkWMTE(() -> { // primitive class
3246                 boolean x = (boolean) hs.get(am, methodType(boolean.class, long[].class, int.class, type)).
3247                     invokeExact(array, 0, 0x0123456789ABCDEFL);
3248             });
3249             // Incorrect arity
3250             checkWMTE(() -> { // 0
3251                 long x = (long) hs.get(am, methodType(type)).
3252                     invokeExact();
3253             });
3254             checkWMTE(() -> { // >
3255                 long x = (long) hs.get(am, methodType(type, long[].class, int.class, type, Class.class)).
3256                     invokeExact(array, 0, 0x0123456789ABCDEFL, Void.class);
3257             });
3258         }
3259     }
3260 }
< prev index next >