author | vlivanov |
Mon, 09 May 2016 12:39:41 +0300 | |
changeset 38358 | cb99c6d2af1b |
parent 37719 | add11bc0e6e2 |
parent 38355 | 674cfd9b90cf |
child 38368 | c8eb5d6812c5 |
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 |
import java.lang.invoke.MethodHandle; |
|
25 |
import java.lang.invoke.MethodHandleInfo; |
|
26 |
import java.lang.invoke.MethodHandles; |
|
27 |
import java.lang.invoke.MethodType; |
|
28 |
import java.lang.invoke.VarHandle; |
|
29 |
import java.lang.invoke.WrongMethodTypeException; |
|
30 |
import java.lang.reflect.Method; |
|
31 |
import java.nio.ReadOnlyBufferException; |
|
32 |
import java.util.EnumMap; |
|
33 |
import java.util.HashMap; |
|
34 |
import java.util.List; |
|
35 |
import java.util.Map; |
|
36 |
import java.util.stream.Stream; |
|
37 |
||
38 |
import static java.util.stream.Collectors.toList; |
|
39 |
import static org.testng.Assert.*; |
|
40 |
||
41 |
abstract class VarHandleBaseTest { |
|
42 |
static final int ITERS = Integer.getInteger("iters", 1); |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
43 |
static final int WEAK_ATTEMPTS = Integer.getInteger("weakAttempts", 10); |
36934 | 44 |
|
45 |
interface ThrowingRunnable { |
|
46 |
void run() throws Throwable; |
|
47 |
} |
|
48 |
||
49 |
static void checkUOE(ThrowingRunnable r) { |
|
50 |
checkWithThrowable(UnsupportedOperationException.class, null, r); |
|
51 |
} |
|
52 |
||
53 |
static void checkUOE(Object message, ThrowingRunnable r) { |
|
54 |
checkWithThrowable(UnsupportedOperationException.class, message, r); |
|
55 |
} |
|
56 |
||
57 |
static void checkROBE(ThrowingRunnable r) { |
|
58 |
checkWithThrowable(ReadOnlyBufferException.class, null, r); |
|
59 |
} |
|
60 |
||
61 |
static void checkROBE(Object message, ThrowingRunnable r) { |
|
62 |
checkWithThrowable(ReadOnlyBufferException.class, message, r); |
|
63 |
} |
|
64 |
||
65 |
static void checkIOOBE(ThrowingRunnable r) { |
|
66 |
checkWithThrowable(IndexOutOfBoundsException.class, null, r); |
|
67 |
} |
|
68 |
||
69 |
static void checkIOOBE(Object message, ThrowingRunnable r) { |
|
70 |
checkWithThrowable(IndexOutOfBoundsException.class, message, r); |
|
71 |
} |
|
72 |
||
73 |
static void checkISE(ThrowingRunnable r) { |
|
74 |
checkWithThrowable(IllegalStateException.class, null, r); |
|
75 |
} |
|
76 |
||
77 |
static void checkISE(Object message, ThrowingRunnable r) { |
|
78 |
checkWithThrowable(IllegalStateException.class, message, r); |
|
79 |
} |
|
80 |
||
81 |
static void checkIAE(ThrowingRunnable r) { |
|
82 |
checkWithThrowable(IllegalAccessException.class, null, r); |
|
83 |
} |
|
84 |
||
85 |
static void checkIAE(Object message, ThrowingRunnable r) { |
|
86 |
checkWithThrowable(IllegalAccessException.class, message, r); |
|
87 |
} |
|
88 |
||
89 |
static void checkWMTE(ThrowingRunnable r) { |
|
90 |
checkWithThrowable(WrongMethodTypeException.class, null, r); |
|
91 |
} |
|
92 |
||
93 |
static void checkWMTE(Object message, ThrowingRunnable r) { |
|
94 |
checkWithThrowable(WrongMethodTypeException.class, message, r); |
|
95 |
} |
|
96 |
||
97 |
static void checkCCE(ThrowingRunnable r) { |
|
98 |
checkWithThrowable(ClassCastException.class, null, r); |
|
99 |
} |
|
100 |
||
101 |
static void checkCCE(Object message, ThrowingRunnable r) { |
|
102 |
checkWithThrowable(ClassCastException.class, message, r); |
|
103 |
} |
|
104 |
||
105 |
static void checkNPE(ThrowingRunnable r) { |
|
106 |
checkWithThrowable(NullPointerException.class, null, r); |
|
107 |
} |
|
108 |
||
109 |
static void checkNPE(Object message, ThrowingRunnable r) { |
|
110 |
checkWithThrowable(NullPointerException.class, message, r); |
|
111 |
} |
|
112 |
||
113 |
static void checkWithThrowable(Class<? extends Throwable> re, |
|
114 |
Object message, |
|
115 |
ThrowingRunnable r) { |
|
116 |
Throwable _e = null; |
|
117 |
try { |
|
118 |
r.run(); |
|
119 |
} |
|
120 |
catch (Throwable e) { |
|
121 |
_e = e; |
|
122 |
} |
|
123 |
message = message == null ? "" : message + ". "; |
|
124 |
assertNotNull(_e, String.format("%sNo throwable thrown. Expected %s", message, re)); |
|
125 |
assertTrue(re.isInstance(_e), String.format("%sIncorrect throwable thrown, %s. Expected %s", message, _e, re)); |
|
126 |
} |
|
127 |
||
128 |
||
129 |
enum TestAccessType { |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
130 |
GET, |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
131 |
SET, |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
132 |
COMPARE_AND_SET, |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
133 |
COMPARE_AND_EXCHANGE, |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
134 |
GET_AND_SET, |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
135 |
GET_AND_ADD; |
36934 | 136 |
} |
137 |
||
138 |
enum TestAccessMode { |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
139 |
GET(TestAccessType.GET), |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
140 |
SET(TestAccessType.SET), |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
141 |
GET_VOLATILE(TestAccessType.GET), |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
142 |
SET_VOLATILE(TestAccessType.SET), |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
143 |
GET_ACQUIRE(TestAccessType.GET), |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
144 |
SET_RELEASE(TestAccessType.SET), |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
145 |
GET_OPAQUE(TestAccessType.GET), |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
146 |
SET_OPAQUE(TestAccessType.SET), |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
147 |
COMPARE_AND_SET(TestAccessType.COMPARE_AND_SET), |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
148 |
COMPARE_AND_EXCHANGE_VOLATILE(TestAccessType.COMPARE_AND_EXCHANGE), |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
149 |
COMPARE_AND_EXCHANGE_ACQUIRE(TestAccessType.COMPARE_AND_EXCHANGE), |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
150 |
COMPARE_AND_EXCHANGE_RELEASE(TestAccessType.COMPARE_AND_EXCHANGE), |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
151 |
WEAK_COMPARE_AND_SET(TestAccessType.COMPARE_AND_SET), |
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
152 |
WEAK_COMPARE_AND_SET_VOLATILE(TestAccessType.COMPARE_AND_SET), |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
153 |
WEAK_COMPARE_AND_SET_ACQUIRE(TestAccessType.COMPARE_AND_SET), |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
154 |
WEAK_COMPARE_AND_SET_RELEASE(TestAccessType.COMPARE_AND_SET), |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
155 |
GET_AND_SET(TestAccessType.GET_AND_SET), |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
156 |
GET_AND_ADD(TestAccessType.GET_AND_ADD), |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
157 |
ADD_AND_GET(TestAccessType.GET_AND_ADD),; |
36934 | 158 |
|
159 |
final TestAccessType at; |
|
160 |
final boolean isPolyMorphicInReturnType; |
|
161 |
final Class<?> returnType; |
|
162 |
||
163 |
TestAccessMode(TestAccessType at) { |
|
164 |
this.at = at; |
|
165 |
||
166 |
try { |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
167 |
VarHandle.AccessMode vh_am = toAccessMode(); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
168 |
Method m = VarHandle.class.getMethod(vh_am.methodName(), Object[].class); |
36934 | 169 |
this.returnType = m.getReturnType(); |
170 |
isPolyMorphicInReturnType = returnType != Object.class; |
|
171 |
} |
|
172 |
catch (Exception e) { |
|
173 |
throw new Error(e); |
|
174 |
} |
|
175 |
} |
|
176 |
||
177 |
boolean isOfType(TestAccessType at) { |
|
178 |
return this.at == at; |
|
179 |
} |
|
180 |
||
181 |
VarHandle.AccessMode toAccessMode() { |
|
182 |
return VarHandle.AccessMode.valueOf(name()); |
|
183 |
} |
|
184 |
} |
|
185 |
||
186 |
static List<TestAccessMode> testAccessModes() { |
|
187 |
return Stream.of(TestAccessMode.values()).collect(toList()); |
|
188 |
} |
|
189 |
||
190 |
static List<TestAccessMode> testAccessModesOfType(TestAccessType... ats) { |
|
191 |
Stream<TestAccessMode> s = Stream.of(TestAccessMode.values()); |
|
192 |
for (TestAccessType at : ats) { |
|
193 |
s = s.filter(e -> e.isOfType(at)); |
|
194 |
} |
|
195 |
return s.collect(toList()); |
|
196 |
} |
|
197 |
||
198 |
static List<VarHandle.AccessMode> accessModes() { |
|
199 |
return Stream.of(VarHandle.AccessMode.values()).collect(toList()); |
|
200 |
} |
|
201 |
||
202 |
static List<VarHandle.AccessMode> accessModesOfType(TestAccessType... ats) { |
|
203 |
Stream<TestAccessMode> s = Stream.of(TestAccessMode.values()); |
|
204 |
for (TestAccessType at : ats) { |
|
205 |
s = s.filter(e -> e.isOfType(at)); |
|
206 |
} |
|
207 |
return s.map(TestAccessMode::toAccessMode).collect(toList()); |
|
208 |
} |
|
209 |
||
210 |
static MethodHandle toMethodHandle(VarHandle vh, TestAccessMode tam, MethodType mt) { |
|
211 |
return vh.toMethodHandle(tam.toAccessMode()); |
|
212 |
} |
|
213 |
||
214 |
static MethodHandle findVirtual(VarHandle vh, TestAccessMode tam, MethodType mt) { |
|
215 |
mt = vh.accessModeType(tam.toAccessMode()); |
|
216 |
MethodHandle mh; |
|
217 |
try { |
|
218 |
mh = MethodHandles.publicLookup(). |
|
219 |
findVirtual(VarHandle.class, |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
220 |
tam.toAccessMode().methodName(), |
36934 | 221 |
mt); |
222 |
} catch (Exception e) { |
|
223 |
throw new RuntimeException(e); |
|
224 |
} |
|
225 |
return bind(vh, tam, mh, mt); |
|
226 |
} |
|
227 |
||
228 |
static MethodHandle varHandleInvokerWithAccessModeType(VarHandle vh, TestAccessMode tam, MethodType mt) { |
|
229 |
mt = vh.accessModeType(tam.toAccessMode()); |
|
230 |
MethodHandle mh = MethodHandles.varHandleInvoker( |
|
231 |
tam.toAccessMode(), |
|
232 |
mt); |
|
233 |
||
234 |
return bind(vh, tam, mh, mt); |
|
235 |
} |
|
236 |
||
237 |
static MethodHandle varHandleInvokerWithSymbolicTypeDescriptor(VarHandle vh, TestAccessMode tam, MethodType mt) { |
|
238 |
MethodHandle mh = MethodHandles.varHandleInvoker( |
|
239 |
tam.toAccessMode(), |
|
240 |
mt); |
|
241 |
||
242 |
return bind(vh, tam, mh, mt); |
|
243 |
} |
|
244 |
||
245 |
static MethodHandle varHandleExactInvokerWithAccessModeType(VarHandle vh, TestAccessMode tam, MethodType mt) { |
|
246 |
mt = vh.accessModeType(tam.toAccessMode()); |
|
247 |
MethodHandle mh = MethodHandles.varHandleExactInvoker( |
|
248 |
tam.toAccessMode(), |
|
249 |
mt); |
|
250 |
||
251 |
return bind(vh, tam, mh, mt); |
|
252 |
} |
|
253 |
||
254 |
private static MethodHandle bind(VarHandle vh, TestAccessMode testAccessMode, MethodHandle mh, MethodType emt) { |
|
255 |
assertEquals(mh.type(), emt.insertParameterTypes(0, VarHandle.class), |
|
256 |
"MethodHandle type differs from access mode type"); |
|
257 |
||
258 |
MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh); |
|
259 |
assertEquals(info.getMethodType(), emt, |
|
260 |
"MethodHandleInfo method type differs from access mode type"); |
|
261 |
||
262 |
return mh.bindTo(vh); |
|
263 |
} |
|
264 |
||
265 |
private interface TriFunction<T, U, V, R> { |
|
266 |
R apply(T t, U u, V v); |
|
267 |
} |
|
268 |
||
269 |
enum VarHandleToMethodHandle { |
|
270 |
VAR_HANDLE_TO_METHOD_HANDLE( |
|
271 |
"VarHandle.toMethodHandle", |
|
272 |
VarHandleBaseTest::toMethodHandle), |
|
273 |
METHOD_HANDLES_LOOKUP_FIND_VIRTUAL( |
|
274 |
"Lookup.findVirtual", |
|
275 |
VarHandleBaseTest::findVirtual), |
|
276 |
METHOD_HANDLES_VAR_HANDLE_INVOKER_WITH_ACCESS_MODE_TYPE( |
|
277 |
"MethodHandles.varHandleInvoker(accessModeType)", |
|
278 |
VarHandleBaseTest::varHandleInvokerWithAccessModeType), |
|
279 |
METHOD_HANDLES_VAR_HANDLE_INVOKER_WITH_SYMBOLIC_TYPE_DESCRIPTOR( |
|
280 |
"MethodHandles.varHandleInvoker(symbolicTypeDescriptor)", |
|
281 |
VarHandleBaseTest::varHandleInvokerWithSymbolicTypeDescriptor), |
|
282 |
METHOD_HANDLES_VAR_HANDLE_EXACT_INVOKER_WITH_ACCESS_MODE_TYPE( |
|
283 |
"MethodHandles.varHandleExactInvoker(accessModeType)", |
|
284 |
VarHandleBaseTest::varHandleExactInvokerWithAccessModeType); |
|
285 |
||
286 |
final String desc; |
|
287 |
final TriFunction<VarHandle, TestAccessMode, MethodType, MethodHandle> f; |
|
288 |
final boolean exact; |
|
289 |
||
290 |
VarHandleToMethodHandle(String desc, TriFunction<VarHandle, TestAccessMode, MethodType, MethodHandle> f) { |
|
291 |
this(desc, f, false); |
|
292 |
} |
|
293 |
||
294 |
VarHandleToMethodHandle(String desc, TriFunction<VarHandle, TestAccessMode, MethodType, MethodHandle> f, |
|
295 |
boolean exact) { |
|
296 |
this.desc = desc; |
|
297 |
this.f = f; |
|
298 |
this.exact = exact; |
|
299 |
} |
|
300 |
||
301 |
MethodHandle apply(VarHandle vh, TestAccessMode am, MethodType mt) { |
|
302 |
return f.apply(vh, am, mt); |
|
303 |
} |
|
304 |
||
305 |
@Override |
|
306 |
public String toString() { |
|
307 |
return desc; |
|
308 |
} |
|
309 |
} |
|
310 |
||
311 |
static class Handles { |
|
312 |
static class AccessModeAndType { |
|
313 |
final TestAccessMode tam; |
|
314 |
final MethodType t; |
|
315 |
||
316 |
public AccessModeAndType(TestAccessMode tam, MethodType t) { |
|
317 |
this.tam = tam; |
|
318 |
this.t = t; |
|
319 |
} |
|
320 |
||
321 |
@Override |
|
322 |
public boolean equals(Object o) { |
|
323 |
if (this == o) return true; |
|
324 |
if (o == null || getClass() != o.getClass()) return false; |
|
325 |
||
326 |
AccessModeAndType x = (AccessModeAndType) o; |
|
327 |
||
328 |
if (tam != x.tam) return false; |
|
329 |
if (t != null ? !t.equals(x.t) : x.t != null) return false; |
|
330 |
||
331 |
return true; |
|
332 |
} |
|
333 |
||
334 |
@Override |
|
335 |
public int hashCode() { |
|
336 |
int result = tam != null ? tam.hashCode() : 0; |
|
337 |
result = 31 * result + (t != null ? t.hashCode() : 0); |
|
338 |
return result; |
|
339 |
} |
|
340 |
} |
|
341 |
||
342 |
final VarHandle vh; |
|
343 |
final VarHandleToMethodHandle f; |
|
344 |
final EnumMap<TestAccessMode, MethodType> amToType; |
|
345 |
final Map<AccessModeAndType, MethodHandle> amToHandle; |
|
346 |
||
347 |
Handles(VarHandle vh, VarHandleToMethodHandle f) throws Exception { |
|
348 |
this.vh = vh; |
|
349 |
this.f = f; |
|
350 |
this.amToHandle = new HashMap<>(); |
|
351 |
||
352 |
amToType = new EnumMap<>(TestAccessMode.class); |
|
353 |
for (TestAccessMode am : testAccessModes()) { |
|
354 |
amToType.put(am, vh.accessModeType(am.toAccessMode())); |
|
355 |
} |
|
356 |
} |
|
357 |
||
358 |
MethodHandle get(TestAccessMode am) { |
|
359 |
return get(am, amToType.get(am)); |
|
360 |
} |
|
361 |
||
362 |
MethodHandle get(TestAccessMode am, MethodType mt) { |
|
363 |
AccessModeAndType amt = new AccessModeAndType(am, mt); |
|
364 |
return amToHandle.computeIfAbsent( |
|
365 |
amt, k -> f.apply(vh, am, mt)); |
|
366 |
} |
|
367 |
} |
|
368 |
||
369 |
interface AccessTestAction<T> { |
|
370 |
void action(T t) throws Throwable; |
|
371 |
} |
|
372 |
||
373 |
static abstract class AccessTestCase<T> { |
|
374 |
final String desc; |
|
375 |
final AccessTestAction<T> ata; |
|
376 |
final boolean loop; |
|
377 |
||
378 |
AccessTestCase(String desc, AccessTestAction<T> ata, boolean loop) { |
|
379 |
this.desc = desc; |
|
380 |
this.ata = ata; |
|
381 |
this.loop = loop; |
|
382 |
} |
|
383 |
||
384 |
boolean requiresLoop() { |
|
385 |
return loop; |
|
386 |
} |
|
387 |
||
388 |
abstract T get() throws Exception; |
|
389 |
||
390 |
void testAccess(T t) throws Throwable { |
|
391 |
ata.action(t); |
|
392 |
} |
|
393 |
||
394 |
@Override |
|
395 |
public String toString() { |
|
396 |
return desc; |
|
397 |
} |
|
398 |
} |
|
399 |
||
400 |
static class VarHandleAccessTestCase extends AccessTestCase<VarHandle> { |
|
401 |
final VarHandle vh; |
|
402 |
||
403 |
VarHandleAccessTestCase(String desc, VarHandle vh, AccessTestAction<VarHandle> ata) { |
|
404 |
this(desc, vh, ata, true); |
|
405 |
} |
|
406 |
||
407 |
VarHandleAccessTestCase(String desc, VarHandle vh, AccessTestAction<VarHandle> ata, boolean loop) { |
|
408 |
super("VarHandle -> " + desc, ata, loop); |
|
409 |
this.vh = vh; |
|
410 |
} |
|
411 |
||
412 |
@Override |
|
413 |
VarHandle get() { |
|
414 |
return vh; |
|
415 |
} |
|
416 |
} |
|
417 |
||
418 |
static class MethodHandleAccessTestCase extends AccessTestCase<Handles> { |
|
419 |
final VarHandle vh; |
|
420 |
final VarHandleToMethodHandle f; |
|
421 |
||
422 |
MethodHandleAccessTestCase(String desc, VarHandle vh, VarHandleToMethodHandle f, AccessTestAction<Handles> ata) { |
|
423 |
this(desc, vh, f, ata, true); |
|
424 |
} |
|
425 |
||
426 |
MethodHandleAccessTestCase(String desc, VarHandle vh, VarHandleToMethodHandle f, AccessTestAction<Handles> ata, boolean loop) { |
|
427 |
super("VarHandle -> " + f.toString() + " -> " + desc, ata, loop); |
|
428 |
this.vh = vh; |
|
429 |
this.f = f; |
|
430 |
} |
|
431 |
||
432 |
@Override |
|
433 |
Handles get() throws Exception { |
|
434 |
return new Handles(vh, f); |
|
435 |
} |
|
436 |
} |
|
437 |
||
438 |
static void testTypes(VarHandle vh) { |
|
439 |
List<Class<?>> pts = vh.coordinateTypes(); |
|
440 |
||
441 |
for (TestAccessMode accessMode : testAccessModes()) { |
|
442 |
MethodType amt = vh.accessModeType(accessMode.toAccessMode()); |
|
443 |
||
444 |
assertEquals(amt.parameterList().subList(0, pts.size()), pts); |
|
445 |
} |
|
446 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
447 |
for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.GET)) { |
36934 | 448 |
MethodType mt = vh.accessModeType(testAccessMode.toAccessMode()); |
449 |
assertEquals(mt.returnType(), vh.varType()); |
|
450 |
assertEquals(mt.parameterList(), pts); |
|
451 |
} |
|
452 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
453 |
for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.SET)) { |
36934 | 454 |
MethodType mt = vh.accessModeType(testAccessMode.toAccessMode()); |
455 |
assertEquals(mt.returnType(), void.class); |
|
456 |
assertEquals(mt.parameterType(mt.parameterCount() - 1), vh.varType()); |
|
457 |
} |
|
458 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
459 |
for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
36934 | 460 |
MethodType mt = vh.accessModeType(testAccessMode.toAccessMode()); |
461 |
assertEquals(mt.returnType(), boolean.class); |
|
462 |
assertEquals(mt.parameterType(mt.parameterCount() - 1), vh.varType()); |
|
463 |
assertEquals(mt.parameterType(mt.parameterCount() - 2), vh.varType()); |
|
464 |
} |
|
465 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
466 |
for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 467 |
MethodType mt = vh.accessModeType(testAccessMode.toAccessMode()); |
468 |
assertEquals(mt.returnType(), vh.varType()); |
|
469 |
assertEquals(mt.parameterType(mt.parameterCount() - 1), vh.varType()); |
|
470 |
assertEquals(mt.parameterType(mt.parameterCount() - 2), vh.varType()); |
|
471 |
} |
|
472 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
473 |
for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.GET_AND_SET, TestAccessType.GET_AND_ADD)) { |
36934 | 474 |
MethodType mt = vh.accessModeType(testAccessMode.toAccessMode()); |
475 |
assertEquals(mt.returnType(), vh.varType()); |
|
476 |
assertEquals(mt.parameterType(mt.parameterCount() - 1), vh.varType()); |
|
477 |
} |
|
478 |
} |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
479 |
} |