author | amurillo |
Tue, 17 May 2016 05:38:15 -0700 | |
changeset 38368 | c8eb5d6812c5 |
parent 38328 | 40435a469d25 |
child 39470 | d6f8b4a85fb0 |
permissions | -rw-r--r-- |
36934 | 1 |
/* |
2 |
* Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
26 |
* @bug 8156486 |
36934 | 27 |
* @run testng/othervm VarHandleTestMethodTypeByte |
28 |
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestMethodTypeByte |
|
29 |
*/ |
|
30 |
||
31 |
import org.testng.annotations.BeforeClass; |
|
32 |
import org.testng.annotations.DataProvider; |
|
33 |
import org.testng.annotations.Test; |
|
34 |
||
35 |
import java.lang.invoke.MethodHandles; |
|
36 |
import java.lang.invoke.VarHandle; |
|
37 |
import java.util.ArrayList; |
|
38 |
import java.util.Arrays; |
|
39 |
import java.util.List; |
|
40 |
||
41 |
import static org.testng.Assert.*; |
|
42 |
||
43 |
import static java.lang.invoke.MethodType.*; |
|
44 |
||
45 |
public class VarHandleTestMethodTypeByte extends VarHandleBaseTest { |
|
46 |
static final byte static_final_v = (byte)1; |
|
47 |
||
48 |
static byte static_v = (byte)1; |
|
49 |
||
50 |
final byte final_v = (byte)1; |
|
51 |
||
52 |
byte v = (byte)1; |
|
53 |
||
54 |
VarHandle vhFinalField; |
|
55 |
||
56 |
VarHandle vhField; |
|
57 |
||
58 |
VarHandle vhStaticField; |
|
59 |
||
60 |
VarHandle vhStaticFinalField; |
|
61 |
||
62 |
VarHandle vhArray; |
|
63 |
||
64 |
@BeforeClass |
|
65 |
public void setup() throws Exception { |
|
66 |
vhFinalField = MethodHandles.lookup().findVarHandle( |
|
67 |
VarHandleTestMethodTypeByte.class, "final_v", byte.class); |
|
68 |
||
69 |
vhField = MethodHandles.lookup().findVarHandle( |
|
70 |
VarHandleTestMethodTypeByte.class, "v", byte.class); |
|
71 |
||
72 |
vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( |
|
73 |
VarHandleTestMethodTypeByte.class, "static_final_v", byte.class); |
|
74 |
||
75 |
vhStaticField = MethodHandles.lookup().findStaticVarHandle( |
|
76 |
VarHandleTestMethodTypeByte.class, "static_v", byte.class); |
|
77 |
||
78 |
vhArray = MethodHandles.arrayElementVarHandle(byte[].class); |
|
79 |
} |
|
80 |
||
81 |
@DataProvider |
|
82 |
public Object[][] accessTestCaseProvider() throws Exception { |
|
83 |
List<AccessTestCase<?>> cases = new ArrayList<>(); |
|
84 |
||
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
85 |
cases.add(new VarHandleAccessTestCase("Instance field", |
36934 | 86 |
vhField, vh -> testInstanceFieldWrongMethodType(this, vh), |
87 |
false)); |
|
88 |
||
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
89 |
cases.add(new VarHandleAccessTestCase("Static field", |
36934 | 90 |
vhStaticField, VarHandleTestMethodTypeByte::testStaticFieldWrongMethodType, |
91 |
false)); |
|
92 |
||
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
93 |
cases.add(new VarHandleAccessTestCase("Array", |
36934 | 94 |
vhArray, VarHandleTestMethodTypeByte::testArrayWrongMethodType, |
95 |
false)); |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
96 |
|
36934 | 97 |
for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) { |
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
98 |
cases.add(new MethodHandleAccessTestCase("Instance field", |
36934 | 99 |
vhField, f, hs -> testInstanceFieldWrongMethodType(this, hs), |
100 |
false)); |
|
101 |
||
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
102 |
cases.add(new MethodHandleAccessTestCase("Static field", |
36934 | 103 |
vhStaticField, f, VarHandleTestMethodTypeByte::testStaticFieldWrongMethodType, |
104 |
false)); |
|
105 |
||
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
106 |
cases.add(new MethodHandleAccessTestCase("Array", |
36934 | 107 |
vhArray, f, VarHandleTestMethodTypeByte::testArrayWrongMethodType, |
108 |
false)); |
|
109 |
} |
|
110 |
// Work around issue with jtreg summary reporting which truncates |
|
111 |
// the String result of Object.toString to 30 characters, hence |
|
112 |
// the first dummy argument |
|
113 |
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); |
|
114 |
} |
|
115 |
||
116 |
@Test(dataProvider = "accessTestCaseProvider") |
|
117 |
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable { |
|
118 |
T t = atc.get(); |
|
119 |
int iters = atc.requiresLoop() ? ITERS : 1; |
|
120 |
for (int c = 0; c < iters; c++) { |
|
121 |
atc.testAccess(t); |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
||
126 |
static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeByte recv, VarHandle vh) throws Throwable { |
|
127 |
// Get |
|
128 |
// Incorrect argument types |
|
129 |
checkNPE(() -> { // null receiver |
|
130 |
byte x = (byte) vh.get(null); |
|
131 |
}); |
|
132 |
checkCCE(() -> { // receiver reference class |
|
133 |
byte x = (byte) vh.get(Void.class); |
|
134 |
}); |
|
135 |
checkWMTE(() -> { // receiver primitive class |
|
136 |
byte x = (byte) vh.get(0); |
|
137 |
}); |
|
138 |
// Incorrect return type |
|
139 |
checkWMTE(() -> { // reference class |
|
140 |
Void x = (Void) vh.get(recv); |
|
141 |
}); |
|
142 |
checkWMTE(() -> { // primitive class |
|
143 |
boolean x = (boolean) vh.get(recv); |
|
144 |
}); |
|
145 |
// Incorrect arity |
|
146 |
checkWMTE(() -> { // 0 |
|
147 |
byte x = (byte) vh.get(); |
|
148 |
}); |
|
149 |
checkWMTE(() -> { // > |
|
150 |
byte x = (byte) vh.get(recv, Void.class); |
|
151 |
}); |
|
152 |
||
153 |
||
154 |
// Set |
|
155 |
// Incorrect argument types |
|
156 |
checkNPE(() -> { // null receiver |
|
157 |
vh.set(null, (byte)1); |
|
158 |
}); |
|
159 |
checkCCE(() -> { // receiver reference class |
|
160 |
vh.set(Void.class, (byte)1); |
|
161 |
}); |
|
162 |
checkWMTE(() -> { // value reference class |
|
163 |
vh.set(recv, Void.class); |
|
164 |
}); |
|
165 |
checkWMTE(() -> { // receiver primitive class |
|
166 |
vh.set(0, (byte)1); |
|
167 |
}); |
|
168 |
// Incorrect arity |
|
169 |
checkWMTE(() -> { // 0 |
|
170 |
vh.set(); |
|
171 |
}); |
|
172 |
checkWMTE(() -> { // > |
|
173 |
vh.set(recv, (byte)1, Void.class); |
|
174 |
}); |
|
175 |
||
176 |
||
177 |
// GetVolatile |
|
178 |
// Incorrect argument types |
|
179 |
checkNPE(() -> { // null receiver |
|
180 |
byte x = (byte) vh.getVolatile(null); |
|
181 |
}); |
|
182 |
checkCCE(() -> { // receiver reference class |
|
183 |
byte x = (byte) vh.getVolatile(Void.class); |
|
184 |
}); |
|
185 |
checkWMTE(() -> { // receiver primitive class |
|
186 |
byte x = (byte) vh.getVolatile(0); |
|
187 |
}); |
|
188 |
// Incorrect return type |
|
189 |
checkWMTE(() -> { // reference class |
|
190 |
Void x = (Void) vh.getVolatile(recv); |
|
191 |
}); |
|
192 |
checkWMTE(() -> { // primitive class |
|
193 |
boolean x = (boolean) vh.getVolatile(recv); |
|
194 |
}); |
|
195 |
// Incorrect arity |
|
196 |
checkWMTE(() -> { // 0 |
|
197 |
byte x = (byte) vh.getVolatile(); |
|
198 |
}); |
|
199 |
checkWMTE(() -> { // > |
|
200 |
byte x = (byte) vh.getVolatile(recv, Void.class); |
|
201 |
}); |
|
202 |
||
203 |
||
204 |
// SetVolatile |
|
205 |
// Incorrect argument types |
|
206 |
checkNPE(() -> { // null receiver |
|
207 |
vh.setVolatile(null, (byte)1); |
|
208 |
}); |
|
209 |
checkCCE(() -> { // receiver reference class |
|
210 |
vh.setVolatile(Void.class, (byte)1); |
|
211 |
}); |
|
212 |
checkWMTE(() -> { // value reference class |
|
213 |
vh.setVolatile(recv, Void.class); |
|
214 |
}); |
|
215 |
checkWMTE(() -> { // receiver primitive class |
|
216 |
vh.setVolatile(0, (byte)1); |
|
217 |
}); |
|
218 |
// Incorrect arity |
|
219 |
checkWMTE(() -> { // 0 |
|
220 |
vh.setVolatile(); |
|
221 |
}); |
|
222 |
checkWMTE(() -> { // > |
|
223 |
vh.setVolatile(recv, (byte)1, Void.class); |
|
224 |
}); |
|
225 |
||
226 |
||
227 |
// GetOpaque |
|
228 |
// Incorrect argument types |
|
229 |
checkNPE(() -> { // null receiver |
|
230 |
byte x = (byte) vh.getOpaque(null); |
|
231 |
}); |
|
232 |
checkCCE(() -> { // receiver reference class |
|
233 |
byte x = (byte) vh.getOpaque(Void.class); |
|
234 |
}); |
|
235 |
checkWMTE(() -> { // receiver primitive class |
|
236 |
byte x = (byte) vh.getOpaque(0); |
|
237 |
}); |
|
238 |
// Incorrect return type |
|
239 |
checkWMTE(() -> { // reference class |
|
240 |
Void x = (Void) vh.getOpaque(recv); |
|
241 |
}); |
|
242 |
checkWMTE(() -> { // primitive class |
|
243 |
boolean x = (boolean) vh.getOpaque(recv); |
|
244 |
}); |
|
245 |
// Incorrect arity |
|
246 |
checkWMTE(() -> { // 0 |
|
247 |
byte x = (byte) vh.getOpaque(); |
|
248 |
}); |
|
249 |
checkWMTE(() -> { // > |
|
250 |
byte x = (byte) vh.getOpaque(recv, Void.class); |
|
251 |
}); |
|
252 |
||
253 |
||
254 |
// SetOpaque |
|
255 |
// Incorrect argument types |
|
256 |
checkNPE(() -> { // null receiver |
|
257 |
vh.setOpaque(null, (byte)1); |
|
258 |
}); |
|
259 |
checkCCE(() -> { // receiver reference class |
|
260 |
vh.setOpaque(Void.class, (byte)1); |
|
261 |
}); |
|
262 |
checkWMTE(() -> { // value reference class |
|
263 |
vh.setOpaque(recv, Void.class); |
|
264 |
}); |
|
265 |
checkWMTE(() -> { // receiver primitive class |
|
266 |
vh.setOpaque(0, (byte)1); |
|
267 |
}); |
|
268 |
// Incorrect arity |
|
269 |
checkWMTE(() -> { // 0 |
|
270 |
vh.setOpaque(); |
|
271 |
}); |
|
272 |
checkWMTE(() -> { // > |
|
273 |
vh.setOpaque(recv, (byte)1, Void.class); |
|
274 |
}); |
|
275 |
||
276 |
||
277 |
// GetAcquire |
|
278 |
// Incorrect argument types |
|
279 |
checkNPE(() -> { // null receiver |
|
280 |
byte x = (byte) vh.getAcquire(null); |
|
281 |
}); |
|
282 |
checkCCE(() -> { // receiver reference class |
|
283 |
byte x = (byte) vh.getAcquire(Void.class); |
|
284 |
}); |
|
285 |
checkWMTE(() -> { // receiver primitive class |
|
286 |
byte x = (byte) vh.getAcquire(0); |
|
287 |
}); |
|
288 |
// Incorrect return type |
|
289 |
checkWMTE(() -> { // reference class |
|
290 |
Void x = (Void) vh.getAcquire(recv); |
|
291 |
}); |
|
292 |
checkWMTE(() -> { // primitive class |
|
293 |
boolean x = (boolean) vh.getAcquire(recv); |
|
294 |
}); |
|
295 |
// Incorrect arity |
|
296 |
checkWMTE(() -> { // 0 |
|
297 |
byte x = (byte) vh.getAcquire(); |
|
298 |
}); |
|
299 |
checkWMTE(() -> { // > |
|
300 |
byte x = (byte) vh.getAcquire(recv, Void.class); |
|
301 |
}); |
|
302 |
||
303 |
||
304 |
// SetRelease |
|
305 |
// Incorrect argument types |
|
306 |
checkNPE(() -> { // null receiver |
|
307 |
vh.setRelease(null, (byte)1); |
|
308 |
}); |
|
309 |
checkCCE(() -> { // receiver reference class |
|
310 |
vh.setRelease(Void.class, (byte)1); |
|
311 |
}); |
|
312 |
checkWMTE(() -> { // value reference class |
|
313 |
vh.setRelease(recv, Void.class); |
|
314 |
}); |
|
315 |
checkWMTE(() -> { // receiver primitive class |
|
316 |
vh.setRelease(0, (byte)1); |
|
317 |
}); |
|
318 |
// Incorrect arity |
|
319 |
checkWMTE(() -> { // 0 |
|
320 |
vh.setRelease(); |
|
321 |
}); |
|
322 |
checkWMTE(() -> { // > |
|
323 |
vh.setRelease(recv, (byte)1, Void.class); |
|
324 |
}); |
|
325 |
||
326 |
||
327 |
||
328 |
} |
|
329 |
||
330 |
static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeByte recv, Handles hs) throws Throwable { |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
331 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) { |
36934 | 332 |
// Incorrect argument types |
333 |
checkNPE(() -> { // null receiver |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
334 |
byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class)). |
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
335 |
invokeExact((VarHandleTestMethodTypeByte) null); |
36934 | 336 |
}); |
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
337 |
hs.checkWMTEOrCCE(() -> { // receiver reference class |
36934 | 338 |
byte x = (byte) hs.get(am, methodType(byte.class, Class.class)). |
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
339 |
invokeExact(Void.class); |
36934 | 340 |
}); |
341 |
checkWMTE(() -> { // receiver primitive class |
|
342 |
byte x = (byte) hs.get(am, methodType(byte.class, int.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
343 |
invokeExact(0); |
36934 | 344 |
}); |
345 |
// Incorrect return type |
|
346 |
checkWMTE(() -> { // reference class |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
347 |
Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeByte.class)). |
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
348 |
invokeExact(recv); |
36934 | 349 |
}); |
350 |
checkWMTE(() -> { // primitive class |
|
351 |
boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
352 |
invokeExact(recv); |
36934 | 353 |
}); |
354 |
// Incorrect arity |
|
355 |
checkWMTE(() -> { // 0 |
|
356 |
byte x = (byte) hs.get(am, methodType(byte.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
357 |
invokeExact(); |
36934 | 358 |
}); |
359 |
checkWMTE(() -> { // > |
|
360 |
byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, Class.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
361 |
invokeExact(recv, Void.class); |
36934 | 362 |
}); |
363 |
} |
|
364 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
365 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { |
36934 | 366 |
// Incorrect argument types |
367 |
checkNPE(() -> { // null receiver |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
368 |
hs.get(am, methodType(void.class, VarHandleTestMethodTypeByte.class, byte.class)). |
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
369 |
invokeExact((VarHandleTestMethodTypeByte) null, (byte)1); |
36934 | 370 |
}); |
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
371 |
hs.checkWMTEOrCCE(() -> { // receiver reference class |
36934 | 372 |
hs.get(am, methodType(void.class, Class.class, byte.class)). |
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
373 |
invokeExact(Void.class, (byte)1); |
36934 | 374 |
}); |
375 |
checkWMTE(() -> { // value reference class |
|
376 |
hs.get(am, methodType(void.class, VarHandleTestMethodTypeByte.class, Class.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
377 |
invokeExact(recv, Void.class); |
36934 | 378 |
}); |
379 |
checkWMTE(() -> { // receiver primitive class |
|
380 |
hs.get(am, methodType(void.class, int.class, byte.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
381 |
invokeExact(0, (byte)1); |
36934 | 382 |
}); |
383 |
// Incorrect arity |
|
384 |
checkWMTE(() -> { // 0 |
|
385 |
hs.get(am, methodType(void.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
386 |
invokeExact(); |
36934 | 387 |
}); |
388 |
checkWMTE(() -> { // > |
|
389 |
hs.get(am, methodType(void.class, VarHandleTestMethodTypeByte.class, byte.class, Class.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
390 |
invokeExact(recv, (byte)1, Void.class); |
36934 | 391 |
}); |
392 |
} |
|
393 |
||
394 |
||
395 |
} |
|
396 |
||
397 |
||
398 |
static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable { |
|
399 |
// Get |
|
400 |
// Incorrect return type |
|
401 |
checkWMTE(() -> { // reference class |
|
402 |
Void x = (Void) vh.get(); |
|
403 |
}); |
|
404 |
checkWMTE(() -> { // primitive class |
|
405 |
boolean x = (boolean) vh.get(); |
|
406 |
}); |
|
407 |
// Incorrect arity |
|
408 |
checkWMTE(() -> { // > |
|
409 |
byte x = (byte) vh.get(Void.class); |
|
410 |
}); |
|
411 |
||
412 |
||
413 |
// Set |
|
414 |
// Incorrect argument types |
|
415 |
checkWMTE(() -> { // value reference class |
|
416 |
vh.set(Void.class); |
|
417 |
}); |
|
418 |
// Incorrect arity |
|
419 |
checkWMTE(() -> { // 0 |
|
420 |
vh.set(); |
|
421 |
}); |
|
422 |
checkWMTE(() -> { // > |
|
423 |
vh.set((byte)1, Void.class); |
|
424 |
}); |
|
425 |
||
426 |
||
427 |
// GetVolatile |
|
428 |
// Incorrect return type |
|
429 |
checkWMTE(() -> { // reference class |
|
430 |
Void x = (Void) vh.getVolatile(); |
|
431 |
}); |
|
432 |
checkWMTE(() -> { // primitive class |
|
433 |
boolean x = (boolean) vh.getVolatile(); |
|
434 |
}); |
|
435 |
checkWMTE(() -> { // > |
|
436 |
byte x = (byte) vh.getVolatile(Void.class); |
|
437 |
}); |
|
438 |
||
439 |
||
440 |
// SetVolatile |
|
441 |
// Incorrect argument types |
|
442 |
checkWMTE(() -> { // value reference class |
|
443 |
vh.setVolatile(Void.class); |
|
444 |
}); |
|
445 |
// Incorrect arity |
|
446 |
checkWMTE(() -> { // 0 |
|
447 |
vh.setVolatile(); |
|
448 |
}); |
|
449 |
checkWMTE(() -> { // > |
|
450 |
vh.setVolatile((byte)1, Void.class); |
|
451 |
}); |
|
452 |
||
453 |
||
454 |
// GetOpaque |
|
455 |
// Incorrect return type |
|
456 |
checkWMTE(() -> { // reference class |
|
457 |
Void x = (Void) vh.getOpaque(); |
|
458 |
}); |
|
459 |
checkWMTE(() -> { // primitive class |
|
460 |
boolean x = (boolean) vh.getOpaque(); |
|
461 |
}); |
|
462 |
checkWMTE(() -> { // > |
|
463 |
byte x = (byte) vh.getOpaque(Void.class); |
|
464 |
}); |
|
465 |
||
466 |
||
467 |
// SetOpaque |
|
468 |
// Incorrect argument types |
|
469 |
checkWMTE(() -> { // value reference class |
|
470 |
vh.setOpaque(Void.class); |
|
471 |
}); |
|
472 |
// Incorrect arity |
|
473 |
checkWMTE(() -> { // 0 |
|
474 |
vh.setOpaque(); |
|
475 |
}); |
|
476 |
checkWMTE(() -> { // > |
|
477 |
vh.setOpaque((byte)1, Void.class); |
|
478 |
}); |
|
479 |
||
480 |
||
481 |
// GetAcquire |
|
482 |
// Incorrect return type |
|
483 |
checkWMTE(() -> { // reference class |
|
484 |
Void x = (Void) vh.getAcquire(); |
|
485 |
}); |
|
486 |
checkWMTE(() -> { // primitive class |
|
487 |
boolean x = (boolean) vh.getAcquire(); |
|
488 |
}); |
|
489 |
checkWMTE(() -> { // > |
|
490 |
byte x = (byte) vh.getAcquire(Void.class); |
|
491 |
}); |
|
492 |
||
493 |
||
494 |
// SetRelease |
|
495 |
// Incorrect argument types |
|
496 |
checkWMTE(() -> { // value reference class |
|
497 |
vh.setRelease(Void.class); |
|
498 |
}); |
|
499 |
// Incorrect arity |
|
500 |
checkWMTE(() -> { // 0 |
|
501 |
vh.setRelease(); |
|
502 |
}); |
|
503 |
checkWMTE(() -> { // > |
|
504 |
vh.setRelease((byte)1, Void.class); |
|
505 |
}); |
|
506 |
||
507 |
||
508 |
||
509 |
} |
|
510 |
||
511 |
static void testStaticFieldWrongMethodType(Handles hs) throws Throwable { |
|
512 |
int i = 0; |
|
513 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
514 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) { |
36934 | 515 |
// Incorrect return type |
516 |
checkWMTE(() -> { // reference class |
|
517 |
Void x = (Void) hs.get(am, methodType(Void.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
518 |
invokeExact(); |
36934 | 519 |
}); |
520 |
checkWMTE(() -> { // primitive class |
|
521 |
boolean x = (boolean) hs.get(am, methodType(boolean.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
522 |
invokeExact(); |
36934 | 523 |
}); |
524 |
// Incorrect arity |
|
525 |
checkWMTE(() -> { // > |
|
526 |
byte x = (byte) hs.get(am, methodType(Class.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
527 |
invokeExact(Void.class); |
36934 | 528 |
}); |
529 |
} |
|
530 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
531 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { |
36934 | 532 |
checkWMTE(() -> { // value reference class |
533 |
hs.get(am, methodType(void.class, Class.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
534 |
invokeExact(Void.class); |
36934 | 535 |
}); |
536 |
// Incorrect arity |
|
537 |
checkWMTE(() -> { // 0 |
|
538 |
hs.get(am, methodType(void.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
539 |
invokeExact(); |
36934 | 540 |
}); |
541 |
checkWMTE(() -> { // > |
|
542 |
hs.get(am, methodType(void.class, byte.class, Class.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
543 |
invokeExact((byte)1, Void.class); |
36934 | 544 |
}); |
545 |
} |
|
546 |
||
547 |
} |
|
548 |
||
549 |
||
550 |
static void testArrayWrongMethodType(VarHandle vh) throws Throwable { |
|
551 |
byte[] array = new byte[10]; |
|
552 |
Arrays.fill(array, (byte)1); |
|
553 |
||
554 |
// Get |
|
555 |
// Incorrect argument types |
|
556 |
checkNPE(() -> { // null array |
|
557 |
byte x = (byte) vh.get(null, 0); |
|
558 |
}); |
|
559 |
checkCCE(() -> { // array reference class |
|
560 |
byte x = (byte) vh.get(Void.class, 0); |
|
561 |
}); |
|
562 |
checkWMTE(() -> { // array primitive class |
|
563 |
byte x = (byte) vh.get(0, 0); |
|
564 |
}); |
|
565 |
checkWMTE(() -> { // index reference class |
|
566 |
byte x = (byte) vh.get(array, Void.class); |
|
567 |
}); |
|
568 |
// Incorrect return type |
|
569 |
checkWMTE(() -> { // reference class |
|
570 |
Void x = (Void) vh.get(array, 0); |
|
571 |
}); |
|
572 |
checkWMTE(() -> { // primitive class |
|
573 |
boolean x = (boolean) vh.get(array, 0); |
|
574 |
}); |
|
575 |
// Incorrect arity |
|
576 |
checkWMTE(() -> { // 0 |
|
577 |
byte x = (byte) vh.get(); |
|
578 |
}); |
|
579 |
checkWMTE(() -> { // > |
|
580 |
byte x = (byte) vh.get(array, 0, Void.class); |
|
581 |
}); |
|
582 |
||
583 |
||
584 |
// Set |
|
585 |
// Incorrect argument types |
|
586 |
checkNPE(() -> { // null array |
|
587 |
vh.set(null, 0, (byte)1); |
|
588 |
}); |
|
589 |
checkCCE(() -> { // array reference class |
|
590 |
vh.set(Void.class, 0, (byte)1); |
|
591 |
}); |
|
592 |
checkWMTE(() -> { // value reference class |
|
593 |
vh.set(array, 0, Void.class); |
|
594 |
}); |
|
595 |
checkWMTE(() -> { // receiver primitive class |
|
596 |
vh.set(0, 0, (byte)1); |
|
597 |
}); |
|
598 |
checkWMTE(() -> { // index reference class |
|
599 |
vh.set(array, Void.class, (byte)1); |
|
600 |
}); |
|
601 |
// Incorrect arity |
|
602 |
checkWMTE(() -> { // 0 |
|
603 |
vh.set(); |
|
604 |
}); |
|
605 |
checkWMTE(() -> { // > |
|
606 |
vh.set(array, 0, (byte)1, Void.class); |
|
607 |
}); |
|
608 |
||
609 |
||
610 |
// GetVolatile |
|
611 |
// Incorrect argument types |
|
612 |
checkNPE(() -> { // null array |
|
613 |
byte x = (byte) vh.getVolatile(null, 0); |
|
614 |
}); |
|
615 |
checkCCE(() -> { // array reference class |
|
616 |
byte x = (byte) vh.getVolatile(Void.class, 0); |
|
617 |
}); |
|
618 |
checkWMTE(() -> { // array primitive class |
|
619 |
byte x = (byte) vh.getVolatile(0, 0); |
|
620 |
}); |
|
621 |
checkWMTE(() -> { // index reference class |
|
622 |
byte x = (byte) vh.getVolatile(array, Void.class); |
|
623 |
}); |
|
624 |
// Incorrect return type |
|
625 |
checkWMTE(() -> { // reference class |
|
626 |
Void x = (Void) vh.getVolatile(array, 0); |
|
627 |
}); |
|
628 |
checkWMTE(() -> { // primitive class |
|
629 |
boolean x = (boolean) vh.getVolatile(array, 0); |
|
630 |
}); |
|
631 |
// Incorrect arity |
|
632 |
checkWMTE(() -> { // 0 |
|
633 |
byte x = (byte) vh.getVolatile(); |
|
634 |
}); |
|
635 |
checkWMTE(() -> { // > |
|
636 |
byte x = (byte) vh.getVolatile(array, 0, Void.class); |
|
637 |
}); |
|
638 |
||
639 |
||
640 |
// SetVolatile |
|
641 |
// Incorrect argument types |
|
642 |
checkNPE(() -> { // null array |
|
643 |
vh.setVolatile(null, 0, (byte)1); |
|
644 |
}); |
|
645 |
checkCCE(() -> { // array reference class |
|
646 |
vh.setVolatile(Void.class, 0, (byte)1); |
|
647 |
}); |
|
648 |
checkWMTE(() -> { // value reference class |
|
649 |
vh.setVolatile(array, 0, Void.class); |
|
650 |
}); |
|
651 |
checkWMTE(() -> { // receiver primitive class |
|
652 |
vh.setVolatile(0, 0, (byte)1); |
|
653 |
}); |
|
654 |
checkWMTE(() -> { // index reference class |
|
655 |
vh.setVolatile(array, Void.class, (byte)1); |
|
656 |
}); |
|
657 |
// Incorrect arity |
|
658 |
checkWMTE(() -> { // 0 |
|
659 |
vh.setVolatile(); |
|
660 |
}); |
|
661 |
checkWMTE(() -> { // > |
|
662 |
vh.setVolatile(array, 0, (byte)1, Void.class); |
|
663 |
}); |
|
664 |
||
665 |
||
666 |
// GetOpaque |
|
667 |
// Incorrect argument types |
|
668 |
checkNPE(() -> { // null array |
|
669 |
byte x = (byte) vh.getOpaque(null, 0); |
|
670 |
}); |
|
671 |
checkCCE(() -> { // array reference class |
|
672 |
byte x = (byte) vh.getOpaque(Void.class, 0); |
|
673 |
}); |
|
674 |
checkWMTE(() -> { // array primitive class |
|
675 |
byte x = (byte) vh.getOpaque(0, 0); |
|
676 |
}); |
|
677 |
checkWMTE(() -> { // index reference class |
|
678 |
byte x = (byte) vh.getOpaque(array, Void.class); |
|
679 |
}); |
|
680 |
// Incorrect return type |
|
681 |
checkWMTE(() -> { // reference class |
|
682 |
Void x = (Void) vh.getOpaque(array, 0); |
|
683 |
}); |
|
684 |
checkWMTE(() -> { // primitive class |
|
685 |
boolean x = (boolean) vh.getOpaque(array, 0); |
|
686 |
}); |
|
687 |
// Incorrect arity |
|
688 |
checkWMTE(() -> { // 0 |
|
689 |
byte x = (byte) vh.getOpaque(); |
|
690 |
}); |
|
691 |
checkWMTE(() -> { // > |
|
692 |
byte x = (byte) vh.getOpaque(array, 0, Void.class); |
|
693 |
}); |
|
694 |
||
695 |
||
696 |
// SetOpaque |
|
697 |
// Incorrect argument types |
|
698 |
checkNPE(() -> { // null array |
|
699 |
vh.setOpaque(null, 0, (byte)1); |
|
700 |
}); |
|
701 |
checkCCE(() -> { // array reference class |
|
702 |
vh.setOpaque(Void.class, 0, (byte)1); |
|
703 |
}); |
|
704 |
checkWMTE(() -> { // value reference class |
|
705 |
vh.setOpaque(array, 0, Void.class); |
|
706 |
}); |
|
707 |
checkWMTE(() -> { // receiver primitive class |
|
708 |
vh.setOpaque(0, 0, (byte)1); |
|
709 |
}); |
|
710 |
checkWMTE(() -> { // index reference class |
|
711 |
vh.setOpaque(array, Void.class, (byte)1); |
|
712 |
}); |
|
713 |
// Incorrect arity |
|
714 |
checkWMTE(() -> { // 0 |
|
715 |
vh.setOpaque(); |
|
716 |
}); |
|
717 |
checkWMTE(() -> { // > |
|
718 |
vh.setOpaque(array, 0, (byte)1, Void.class); |
|
719 |
}); |
|
720 |
||
721 |
||
722 |
// GetAcquire |
|
723 |
// Incorrect argument types |
|
724 |
checkNPE(() -> { // null array |
|
725 |
byte x = (byte) vh.getAcquire(null, 0); |
|
726 |
}); |
|
727 |
checkCCE(() -> { // array reference class |
|
728 |
byte x = (byte) vh.getAcquire(Void.class, 0); |
|
729 |
}); |
|
730 |
checkWMTE(() -> { // array primitive class |
|
731 |
byte x = (byte) vh.getAcquire(0, 0); |
|
732 |
}); |
|
733 |
checkWMTE(() -> { // index reference class |
|
734 |
byte x = (byte) vh.getAcquire(array, Void.class); |
|
735 |
}); |
|
736 |
// Incorrect return type |
|
737 |
checkWMTE(() -> { // reference class |
|
738 |
Void x = (Void) vh.getAcquire(array, 0); |
|
739 |
}); |
|
740 |
checkWMTE(() -> { // primitive class |
|
741 |
boolean x = (boolean) vh.getAcquire(array, 0); |
|
742 |
}); |
|
743 |
// Incorrect arity |
|
744 |
checkWMTE(() -> { // 0 |
|
745 |
byte x = (byte) vh.getAcquire(); |
|
746 |
}); |
|
747 |
checkWMTE(() -> { // > |
|
748 |
byte x = (byte) vh.getAcquire(array, 0, Void.class); |
|
749 |
}); |
|
750 |
||
751 |
||
752 |
// SetRelease |
|
753 |
// Incorrect argument types |
|
754 |
checkNPE(() -> { // null array |
|
755 |
vh.setRelease(null, 0, (byte)1); |
|
756 |
}); |
|
757 |
checkCCE(() -> { // array reference class |
|
758 |
vh.setRelease(Void.class, 0, (byte)1); |
|
759 |
}); |
|
760 |
checkWMTE(() -> { // value reference class |
|
761 |
vh.setRelease(array, 0, Void.class); |
|
762 |
}); |
|
763 |
checkWMTE(() -> { // receiver primitive class |
|
764 |
vh.setRelease(0, 0, (byte)1); |
|
765 |
}); |
|
766 |
checkWMTE(() -> { // index reference class |
|
767 |
vh.setRelease(array, Void.class, (byte)1); |
|
768 |
}); |
|
769 |
// Incorrect arity |
|
770 |
checkWMTE(() -> { // 0 |
|
771 |
vh.setRelease(); |
|
772 |
}); |
|
773 |
checkWMTE(() -> { // > |
|
774 |
vh.setRelease(array, 0, (byte)1, Void.class); |
|
775 |
}); |
|
776 |
||
777 |
||
778 |
||
779 |
} |
|
780 |
||
781 |
static void testArrayWrongMethodType(Handles hs) throws Throwable { |
|
782 |
byte[] array = new byte[10]; |
|
783 |
Arrays.fill(array, (byte)1); |
|
784 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
785 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) { |
36934 | 786 |
// Incorrect argument types |
787 |
checkNPE(() -> { // null array |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
788 |
byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class)). |
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
789 |
invokeExact((byte[]) null, 0); |
36934 | 790 |
}); |
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
791 |
hs.checkWMTEOrCCE(() -> { // array reference class |
36934 | 792 |
byte x = (byte) hs.get(am, methodType(byte.class, Class.class, int.class)). |
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
793 |
invokeExact(Void.class, 0); |
36934 | 794 |
}); |
795 |
checkWMTE(() -> { // array primitive class |
|
796 |
byte x = (byte) hs.get(am, methodType(byte.class, int.class, int.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
797 |
invokeExact(0, 0); |
36934 | 798 |
}); |
799 |
checkWMTE(() -> { // index reference class |
|
800 |
byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, Class.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
801 |
invokeExact(array, Void.class); |
36934 | 802 |
}); |
803 |
// Incorrect return type |
|
804 |
checkWMTE(() -> { // reference class |
|
805 |
Void x = (Void) hs.get(am, methodType(Void.class, byte[].class, int.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
806 |
invokeExact(array, 0); |
36934 | 807 |
}); |
808 |
checkWMTE(() -> { // primitive class |
|
809 |
boolean x = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
810 |
invokeExact(array, 0); |
36934 | 811 |
}); |
812 |
// Incorrect arity |
|
813 |
checkWMTE(() -> { // 0 |
|
814 |
byte x = (byte) hs.get(am, methodType(byte.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
815 |
invokeExact(); |
36934 | 816 |
}); |
817 |
checkWMTE(() -> { // > |
|
818 |
byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, Class.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
819 |
invokeExact(array, 0, Void.class); |
36934 | 820 |
}); |
821 |
} |
|
822 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
823 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { |
36934 | 824 |
// Incorrect argument types |
825 |
checkNPE(() -> { // null array |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
826 |
hs.get(am, methodType(void.class, byte[].class, int.class, byte.class)). |
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
827 |
invokeExact((byte[]) null, 0, (byte)1); |
36934 | 828 |
}); |
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
829 |
hs.checkWMTEOrCCE(() -> { // array reference class |
36934 | 830 |
hs.get(am, methodType(void.class, Class.class, int.class, byte.class)). |
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
831 |
invokeExact(Void.class, 0, (byte)1); |
36934 | 832 |
}); |
833 |
checkWMTE(() -> { // value reference class |
|
834 |
hs.get(am, methodType(void.class, byte[].class, int.class, Class.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
835 |
invokeExact(array, 0, Void.class); |
36934 | 836 |
}); |
837 |
checkWMTE(() -> { // receiver primitive class |
|
838 |
hs.get(am, methodType(void.class, int.class, int.class, byte.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
839 |
invokeExact(0, 0, (byte)1); |
36934 | 840 |
}); |
841 |
checkWMTE(() -> { // index reference class |
|
842 |
hs.get(am, methodType(void.class, byte[].class, Class.class, byte.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
843 |
invokeExact(array, Void.class, (byte)1); |
36934 | 844 |
}); |
845 |
// Incorrect arity |
|
846 |
checkWMTE(() -> { // 0 |
|
847 |
hs.get(am, methodType(void.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
848 |
invokeExact(); |
36934 | 849 |
}); |
850 |
checkWMTE(() -> { // > |
|
851 |
hs.get(am, methodType(void.class, byte[].class, int.class, Class.class)). |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37343
diff
changeset
|
852 |
invokeExact(array, 0, (byte)1, Void.class); |
36934 | 853 |
}); |
854 |
} |
|
855 |
||
856 |
} |
|
857 |
} |
|
858 |