blob: b95a5d34f8a08932dbe8efca94290c75f0cebdf0 [file] [log] [blame]
jrose25aef892010-10-30 21:02:30 -07001/*
jroseada69fa2011-03-23 23:02:31 -07002 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
jrose25aef892010-10-30 21:02:30 -07003 * 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26/* @test
jrose79e0a6c2011-05-12 19:27:33 -070027 * @summary unit tests for java.lang.invoke.MethodHandle.invoke
alanb499341f2011-09-10 14:55:14 +010028 * @compile InvokeGenericTest.java
jrose9633f5f2011-04-07 22:07:06 -070029 * @run junit/othervm test.java.lang.invoke.InvokeGenericTest
jrose25aef892010-10-30 21:02:30 -070030 */
31
jroseada69fa2011-03-23 23:02:31 -070032package test.java.lang.invoke;
jrose25aef892010-10-30 21:02:30 -070033
jroseada69fa2011-03-23 23:02:31 -070034import java.lang.invoke.*;
35import static java.lang.invoke.MethodHandles.*;
36import static java.lang.invoke.MethodType.*;
jrose25aef892010-10-30 21:02:30 -070037import java.lang.reflect.*;
38import java.util.*;
39import org.junit.*;
40import static org.junit.Assert.*;
41import static org.junit.Assume.*;
42
43
44/**
45 *
46 * @author jrose
47 */
jrose49494522012-01-18 17:34:29 -080048@SuppressWarnings("cast") // various casts help emphasize arguments to invokeExact
jrose25aef892010-10-30 21:02:30 -070049public class InvokeGenericTest {
50 // How much output?
51 static int verbosity = 0;
52 static {
jroseada69fa2011-03-23 23:02:31 -070053 String vstr = System.getProperty("test.java.lang.invoke.InvokeGenericTest.verbosity");
jrose25aef892010-10-30 21:02:30 -070054 if (vstr != null) verbosity = Integer.parseInt(vstr);
55 }
56
jrosebb3eb372011-05-17 19:48:14 -070057// public static void main(String... av) throws Throwable {
58// new InvokeGenericTest().testFirst();
59// }
jrose320b7692011-05-12 19:27:49 -070060
jrose25aef892010-10-30 21:02:30 -070061 @Test
62 public void testFirst() throws Throwable {
63 verbosity += 9; try {
64 // left blank for debugging
65 } finally { printCounts(); verbosity -= 9; }
66 }
67
68 public InvokeGenericTest() {
69 }
70
71 @Before
72 public void checkImplementedPlatform() {
73 boolean platformOK = false;
74 Properties properties = System.getProperties();
75 String vers = properties.getProperty("java.vm.version");
76 String name = properties.getProperty("java.vm.name");
77 String arch = properties.getProperty("os.arch");
78 if ((arch.equals("amd64") || arch.equals("i386") || arch.equals("x86") ||
79 arch.equals("sparc") || arch.equals("sparcv9")) &&
80 (name.contains("Client") || name.contains("Server"))
81 ) {
82 platformOK = true;
83 } else {
84 System.err.println("Skipping tests for unsupported platform: "+Arrays.asList(vers, name, arch));
85 }
86 assumeTrue(platformOK);
87 }
88
89 String testName;
90 static int allPosTests, allNegTests;
91 int posTests, negTests;
92 @After
93 public void printCounts() {
94 if (verbosity >= 2 && (posTests | negTests) != 0) {
95 System.out.println();
96 if (posTests != 0) System.out.println("=== "+testName+": "+posTests+" positive test cases run");
97 if (negTests != 0) System.out.println("=== "+testName+": "+negTests+" negative test cases run");
98 allPosTests += posTests;
99 allNegTests += negTests;
100 posTests = negTests = 0;
101 }
102 }
103 void countTest(boolean positive) {
104 if (positive) ++posTests;
105 else ++negTests;
106 }
107 void countTest() { countTest(true); }
108 void startTest(String name) {
109 if (testName != null) printCounts();
110 if (verbosity >= 1)
jrose320b7692011-05-12 19:27:49 -0700111 System.out.println("["+name+"]");
jrose25aef892010-10-30 21:02:30 -0700112 posTests = negTests = 0;
113 testName = name;
114 }
115
116 @BeforeClass
117 public static void setUpClass() throws Exception {
118 calledLog.clear();
119 calledLog.add(null);
120 nextArgVal = INITIAL_ARG_VAL;
121 }
122
123 @AfterClass
124 public static void tearDownClass() throws Exception {
125 int posTests = allPosTests, negTests = allNegTests;
126 if (verbosity >= 2 && (posTests | negTests) != 0) {
127 System.out.println();
128 if (posTests != 0) System.out.println("=== "+posTests+" total positive test cases");
129 if (negTests != 0) System.out.println("=== "+negTests+" total negative test cases");
130 }
131 }
132
jrose49494522012-01-18 17:34:29 -0800133 static List<Object> calledLog = new ArrayList<>();
jrose25aef892010-10-30 21:02:30 -0700134 static Object logEntry(String name, Object... args) {
135 return Arrays.asList(name, Arrays.asList(args));
136 }
137 static Object called(String name, Object... args) {
138 Object entry = logEntry(name, args);
139 calledLog.add(entry);
140 return entry;
141 }
142 static void assertCalled(String name, Object... args) {
143 Object expected = logEntry(name, args);
144 Object actual = calledLog.get(calledLog.size() - 1);
145 if (expected.equals(actual) && verbosity < 9) return;
146 System.out.println("assertCalled "+name+":");
147 System.out.println("expected: "+expected);
148 System.out.println("actual: "+actual);
149 System.out.println("ex. types: "+getClasses(expected));
150 System.out.println("act. types: "+getClasses(actual));
151 assertEquals("previous method call", expected, actual);
152 }
153 static void printCalled(MethodHandle target, String name, Object... args) {
154 if (verbosity >= 3)
155 System.out.println("calling MH="+target+" to "+name+Arrays.toString(args));
156 }
157
158 static Object castToWrapper(Object value, Class<?> dst) {
159 Object wrap = null;
160 if (value instanceof Number)
161 wrap = castToWrapperOrNull(((Number)value).longValue(), dst);
162 if (value instanceof Character)
163 wrap = castToWrapperOrNull((char)(Character)value, dst);
164 if (wrap != null) return wrap;
165 return dst.cast(value);
166 }
167
168 static Object castToWrapperOrNull(long value, Class<?> dst) {
169 if (dst == int.class || dst == Integer.class)
170 return (int)(value);
171 if (dst == long.class || dst == Long.class)
172 return (long)(value);
173 if (dst == char.class || dst == Character.class)
174 return (char)(value);
175 if (dst == short.class || dst == Short.class)
176 return (short)(value);
177 if (dst == float.class || dst == Float.class)
178 return (float)(value);
179 if (dst == double.class || dst == Double.class)
180 return (double)(value);
181 if (dst == byte.class || dst == Byte.class)
182 return (byte)(value);
183 if (dst == boolean.class || dst == boolean.class)
184 return ((value % 29) & 1) == 0;
185 return null;
186 }
187
188 static final int ONE_MILLION = (1000*1000), // first int value
189 TEN_BILLION = (10*1000*1000*1000), // scale factor to reach upper 32 bits
190 INITIAL_ARG_VAL = ONE_MILLION << 1; // <<1 makes space for sign bit;
191 static long nextArgVal;
192 static long nextArg(boolean moreBits) {
193 long val = nextArgVal++;
194 long sign = -(val & 1); // alternate signs
195 val >>= 1;
196 if (moreBits)
197 // Guarantee some bits in the high word.
198 // In any case keep the decimal representation simple-looking,
199 // with lots of zeroes, so as not to make the printed decimal
200 // strings unnecessarily noisy.
201 val += (val % ONE_MILLION) * TEN_BILLION;
202 return val ^ sign;
203 }
204 static int nextArg() {
205 // Produce a 32-bit result something like ONE_MILLION+(smallint).
206 // Example: 1_000_042.
207 return (int) nextArg(false);
208 }
209 static long nextArg(Class<?> kind) {
210 if (kind == long.class || kind == Long.class ||
211 kind == double.class || kind == Double.class)
212 // produce a 64-bit result something like
213 // ((TEN_BILLION+1) * (ONE_MILLION+(smallint)))
214 // Example: 10_000_420_001_000_042.
215 return nextArg(true);
216 return (long) nextArg();
217 }
218
219 static Object randomArg(Class<?> param) {
220 Object wrap = castToWrapperOrNull(nextArg(param), param);
221 if (wrap != null) {
222 return wrap;
223 }
jroseada69fa2011-03-23 23:02:31 -0700224// import sun.invoke.util.Wrapper;
jrose25aef892010-10-30 21:02:30 -0700225// Wrapper wrap = Wrapper.forBasicType(dst);
226// if (wrap == Wrapper.OBJECT && Wrapper.isWrapperType(dst))
227// wrap = Wrapper.forWrapperType(dst);
228// if (wrap != Wrapper.OBJECT)
229// return wrap.wrap(nextArg++);
230 if (param.isInterface()) {
231 for (Class<?> c : param.getClasses()) {
232 if (param.isAssignableFrom(c) && !c.isInterface())
233 { param = c; break; }
234 }
235 }
236 if (param.isInterface() || param.isAssignableFrom(String.class))
237 return "#"+nextArg();
238 else
239 try {
240 return param.newInstance();
jrose49494522012-01-18 17:34:29 -0800241 } catch (InstantiationException | IllegalAccessException ex) {
jrose25aef892010-10-30 21:02:30 -0700242 }
243 return null; // random class not Object, String, Integer, etc.
244 }
245 static Object[] randomArgs(Class<?>... params) {
246 Object[] args = new Object[params.length];
247 for (int i = 0; i < args.length; i++)
248 args[i] = randomArg(params[i]);
249 return args;
250 }
251 static Object[] randomArgs(int nargs, Class<?> param) {
252 Object[] args = new Object[nargs];
253 for (int i = 0; i < args.length; i++)
254 args[i] = randomArg(param);
255 return args;
256 }
257
258 static final Object ANON_OBJ = new Object();
259 static Object zeroArg(Class<?> param) {
260 Object x = castToWrapperOrNull(0L, param);
261 if (x != null) return x;
262 if (param.isInterface() || param.isAssignableFrom(String.class)) return "\"\"";
263 if (param == Object.class) return ANON_OBJ;
264 if (param.getComponentType() != null) return Array.newInstance(param.getComponentType(), 0);
265 return null;
266 }
267 static Object[] zeroArgs(Class<?>... params) {
268 Object[] args = new Object[params.length];
269 for (int i = 0; i < args.length; i++)
270 args[i] = zeroArg(params[i]);
271 return args;
272 }
273 static Object[] zeroArgs(List<Class<?>> params) {
274 return zeroArgs(params.toArray(new Class<?>[0]));
275 }
276
jrose49494522012-01-18 17:34:29 -0800277 @SafeVarargs @SuppressWarnings("varargs")
jrose25aef892010-10-30 21:02:30 -0700278 static <T, E extends T> T[] array(Class<T[]> atype, E... a) {
279 return Arrays.copyOf(a, a.length, atype);
280 }
jrose49494522012-01-18 17:34:29 -0800281 @SafeVarargs @SuppressWarnings("varargs")
jrose25aef892010-10-30 21:02:30 -0700282 static <T> T[] cat(T[] a, T... b) {
283 int alen = a.length, blen = b.length;
284 if (blen == 0) return a;
285 T[] c = Arrays.copyOf(a, alen + blen);
286 System.arraycopy(b, 0, c, alen, blen);
287 return c;
288 }
289 static Integer[] boxAll(int... vx) {
290 Integer[] res = new Integer[vx.length];
291 for (int i = 0; i < res.length; i++) {
292 res[i] = vx[i];
293 }
294 return res;
295 }
296 static Object getClasses(Object x) {
297 if (x == null) return x;
298 if (x instanceof String) return x; // keep the name
299 if (x instanceof List) {
300 // recursively report classes of the list elements
301 Object[] xa = ((List)x).toArray();
302 for (int i = 0; i < xa.length; i++)
303 xa[i] = getClasses(xa[i]);
304 return Arrays.asList(xa);
305 }
306 return x.getClass().getSimpleName();
307 }
308
309 static MethodHandle changeArgTypes(MethodHandle target, Class<?> argType) {
310 return changeArgTypes(target, 0, 999, argType);
311 }
312 static MethodHandle changeArgTypes(MethodHandle target,
313 int beg, int end, Class<?> argType) {
314 MethodType targetType = target.type();
315 end = Math.min(end, targetType.parameterCount());
jrose49494522012-01-18 17:34:29 -0800316 ArrayList<Class<?>> argTypes = new ArrayList<>(targetType.parameterList());
jrose25aef892010-10-30 21:02:30 -0700317 Collections.fill(argTypes.subList(beg, end), argType);
318 MethodType ttype2 = MethodType.methodType(targetType.returnType(), argTypes);
jrose9b82ad62011-05-26 17:37:36 -0700319 return target.asType(ttype2);
jrose25aef892010-10-30 21:02:30 -0700320 }
321
322 // This lookup is good for all members in and under InvokeGenericTest.
323 static final Lookup LOOKUP = MethodHandles.lookup();
324
jrose49494522012-01-18 17:34:29 -0800325 Map<List<Class<?>>, MethodHandle> CALLABLES = new HashMap<>();
jrose25aef892010-10-30 21:02:30 -0700326 MethodHandle callable(List<Class<?>> params) {
327 MethodHandle mh = CALLABLES.get(params);
328 if (mh == null) {
jroseadc650a2011-02-11 01:26:28 -0800329 mh = collector_MH.asType(methodType(Object.class, params));
jrose25aef892010-10-30 21:02:30 -0700330 CALLABLES.put(params, mh);
331 }
332 return mh;
333 }
334 MethodHandle callable(Class<?>... params) {
335 return callable(Arrays.asList(params));
336 }
337 private static Object collector(Object... args) {
338 return Arrays.asList(args);
339 }
340 private static final MethodHandle collector_MH;
341 static {
342 try {
343 collector_MH
344 = LOOKUP.findStatic(LOOKUP.lookupClass(),
345 "collector",
346 methodType(Object.class, Object[].class));
jrosef15905c2011-02-11 01:26:32 -0800347 } catch (ReflectiveOperationException ex) {
jrose25aef892010-10-30 21:02:30 -0700348 throw new RuntimeException(ex);
349 }
350 }
351
352 @Test
353 public void testSimple() throws Throwable {
354 startTest("testSimple");
355 countTest();
356 String[] args = { "one", "two" };
357 MethodHandle mh = callable(Object.class, String.class);
jrose49494522012-01-18 17:34:29 -0800358 Object res; List<?> resl;
359 res = resl = (List<?>) mh.invoke((String)args[0], (Object)args[1]);
jrose79e0a6c2011-05-12 19:27:33 -0700360 //System.out.println(res);
361 assertEquals(Arrays.asList(args), res);
362 }
363
364 @Test
jrose320b7692011-05-12 19:27:49 -0700365 public void testSimplePrims() throws Throwable {
366 startTest("testSimplePrims");
367 countTest();
368 int[] args = { 1, 2 };
369 MethodHandle mh = callable(Object.class, Object.class);
jrose49494522012-01-18 17:34:29 -0800370 Object res; List<?> resl;
371 res = resl = (List<?>) mh.invoke(args[0], args[1]);
jrose320b7692011-05-12 19:27:49 -0700372 //System.out.println(res);
373 assertEquals(Arrays.toString(args), res.toString());
374 }
375
376 @Test
jrose79e0a6c2011-05-12 19:27:33 -0700377 public void testAlternateName() throws Throwable {
378 startTest("testAlternateName");
379 countTest();
380 String[] args = { "one", "two" };
381 MethodHandle mh = callable(Object.class, String.class);
jrose49494522012-01-18 17:34:29 -0800382 Object res; List<?> resl;
383 res = resl = (List<?>) mh.invoke((String)args[0], (Object)args[1]);
jrose25aef892010-10-30 21:02:30 -0700384 //System.out.println(res);
385 assertEquals(Arrays.asList(args), res);
386 }
387
388 @Test
389 public void testWrongArgumentCount() throws Throwable {
390 startTest("testWrongArgumentCount");
391 for (int i = 0; i <= 10; i++) {
392 testWrongArgumentCount(Collections.<Class<?>>nCopies(i, Integer.class));
393 if (i <= 4) {
394 testWrongArgumentCount(Collections.<Class<?>>nCopies(i, int.class));
395 testWrongArgumentCount(Collections.<Class<?>>nCopies(i, long.class));
396 }
397 }
398 }
399 public void testWrongArgumentCount(List<Class<?>> params) throws Throwable {
400 int max = params.size();
401 for (int i = 0; i < max; i++) {
402 List<Class<?>> params2 = params.subList(0, i);
403 for (int k = 0; k <= 2; k++) {
404 if (k == 1) params = methodType(Object.class, params).generic().parameterList();
405 if (k == 2) params2 = methodType(Object.class, params2).generic().parameterList();
406 testWrongArgumentCount(params, params2);
407 testWrongArgumentCount(params2, params);
408 }
409 }
410 }
411 public void testWrongArgumentCount(List<Class<?>> expect, List<Class<?>> observe) throws Throwable {
412 countTest(false);
413 if (expect.equals(observe))
414 assert(false);
415 MethodHandle target = callable(expect);
416 Object[] args = zeroArgs(observe);
417 Object junk;
418 try {
419 switch (args.length) {
420 case 0:
jrose79e0a6c2011-05-12 19:27:33 -0700421 junk = target.invoke(); break;
jrose25aef892010-10-30 21:02:30 -0700422 case 1:
jrose79e0a6c2011-05-12 19:27:33 -0700423 junk = target.invoke(args[0]); break;
jrose25aef892010-10-30 21:02:30 -0700424 case 2:
jrose79e0a6c2011-05-12 19:27:33 -0700425 junk = target.invoke(args[0], args[1]); break;
jrose25aef892010-10-30 21:02:30 -0700426 case 3:
jrose79e0a6c2011-05-12 19:27:33 -0700427 junk = target.invoke(args[0], args[1], args[2]); break;
jrose25aef892010-10-30 21:02:30 -0700428 case 4:
jrose79e0a6c2011-05-12 19:27:33 -0700429 junk = target.invoke(args[0], args[1], args[2], args[3]); break;
jrose25aef892010-10-30 21:02:30 -0700430 default:
jrose900bafd2010-10-30 21:08:23 -0700431 junk = target.invokeWithArguments(args); break;
jrose25aef892010-10-30 21:02:30 -0700432 }
433 } catch (WrongMethodTypeException ex) {
434 return;
435 } catch (Exception ex) {
jrose320b7692011-05-12 19:27:49 -0700436 throw new RuntimeException("wrong exception calling "+target+" on "+Arrays.asList(args), ex);
jrose25aef892010-10-30 21:02:30 -0700437 }
jrose320b7692011-05-12 19:27:49 -0700438 throw new RuntimeException("bad success calling "+target+" on "+Arrays.asList(args));
jrose25aef892010-10-30 21:02:30 -0700439 }
440
441 /** Make a list of all combinations of the given types, with the given arities.
442 * A void return type is possible iff the first type is void.class.
443 */
444 static List<MethodType> allMethodTypes(int minargc, int maxargc, Class<?>... types) {
jrose49494522012-01-18 17:34:29 -0800445 ArrayList<MethodType> result = new ArrayList<>();
jrose25aef892010-10-30 21:02:30 -0700446 if (types.length > 0) {
jrose49494522012-01-18 17:34:29 -0800447 ArrayList<MethodType> argcTypes = new ArrayList<>();
jrose25aef892010-10-30 21:02:30 -0700448 // build arity-zero types first
449 for (Class<?> rtype : types) {
450 argcTypes.add(MethodType.methodType(rtype));
451 }
452 if (types[0] == void.class)
453 // void is not an argument type
454 types = Arrays.copyOfRange(types, 1, types.length);
455 for (int argc = 0; argc <= maxargc; argc++) {
456 if (argc >= minargc)
457 result.addAll(argcTypes);
458 if (argc >= maxargc)
459 break;
460 ArrayList<MethodType> prevTypes = argcTypes;
jrose49494522012-01-18 17:34:29 -0800461 argcTypes = new ArrayList<>();
jrose25aef892010-10-30 21:02:30 -0700462 for (MethodType prevType : prevTypes) {
463 for (Class<?> ptype : types) {
464 argcTypes.add(prevType.insertParameterTypes(argc, ptype));
465 }
466 }
467 }
468 }
469 return Collections.unmodifiableList(result);
470 }
471 static List<MethodType> allMethodTypes(int argc, Class<?>... types) {
472 return allMethodTypes(argc, argc, types);
473 }
474
jrose25aef892010-10-30 21:02:30 -0700475 MethodHandle toString_MH;
476
477 @Test
478 public void testReferenceConversions() throws Throwable {
479 startTest("testReferenceConversions");
480 toString_MH = LOOKUP.
481 findVirtual(Object.class, "toString", MethodType.methodType(String.class));
jrose79e0a6c2011-05-12 19:27:33 -0700482 Object[] args = { "one", "two" };
jrosebb3eb372011-05-17 19:48:14 -0700483 for (MethodType type : allMethodTypes(2, Object.class, String.class, CharSequence.class)) {
jrose25aef892010-10-30 21:02:30 -0700484 testReferenceConversions(type, args);
485 }
486 }
487 public void testReferenceConversions(MethodType type, Object... args) throws Throwable {
488 countTest();
jrosebb3eb372011-05-17 19:48:14 -0700489 int nargs = args.length;
490 List<Object> argList = Arrays.asList(args);
491 String expectString = argList.toString();
492 if (verbosity > 3) System.out.println("target type: "+type+expectString);
jrose25aef892010-10-30 21:02:30 -0700493 MethodHandle mh = callable(type.parameterList());
jrosebb3eb372011-05-17 19:48:14 -0700494 mh = MethodHandles.filterReturnValue(mh, toString_MH);
jrose25aef892010-10-30 21:02:30 -0700495 mh = mh.asType(type);
jrosebb3eb372011-05-17 19:48:14 -0700496 Object res = null;
497 if (nargs == 2) {
498 res = mh.invoke((Object)args[0], (Object)args[1]);
499 assertEquals(expectString, res);
500 res = mh.invoke((String)args[0], (Object)args[1]);
501 assertEquals(expectString, res);
502 res = mh.invoke((Object)args[0], (String)args[1]);
503 assertEquals(expectString, res);
504 res = mh.invoke((String)args[0], (String)args[1]);
505 assertEquals(expectString, res);
506 res = mh.invoke((String)args[0], (CharSequence)args[1]);
507 assertEquals(expectString, res);
508 res = mh.invoke((CharSequence)args[0], (Object)args[1]);
509 assertEquals(expectString, res);
510 res = (String) mh.invoke((Object)args[0], (Object)args[1]);
511 assertEquals(expectString, res);
512 res = (String) mh.invoke((String)args[0], (Object)args[1]);
513 assertEquals(expectString, res);
514 res = (CharSequence) mh.invoke((String)args[0], (Object)args[1]);
515 assertEquals(expectString, res);
516 } else {
517 assert(false); // write this code
518 }
jrose25aef892010-10-30 21:02:30 -0700519 //System.out.println(res);
jrose25aef892010-10-30 21:02:30 -0700520 }
521
522
jrosebb3eb372011-05-17 19:48:14 -0700523 @Test
jrose25aef892010-10-30 21:02:30 -0700524 public void testBoxConversions() throws Throwable {
525 startTest("testBoxConversions");
526 countTest();
jrose79e0a6c2011-05-12 19:27:33 -0700527 Object[] args = { 1, 2 };
jrose25aef892010-10-30 21:02:30 -0700528 MethodHandle mh = callable(Object.class, int.class);
jrose49494522012-01-18 17:34:29 -0800529 Object res; List<?> resl; int resi;
530 res = resl = (List<?>) mh.invoke((int)args[0], (Object)args[1]);
jrose25aef892010-10-30 21:02:30 -0700531 //System.out.println(res);
532 assertEquals(Arrays.asList(args), res);
jrosebb3eb372011-05-17 19:48:14 -0700533 mh = MethodHandles.identity(int.class);
534 mh = MethodHandles.dropArguments(mh, 1, int.class);
535 res = resi = (int) mh.invoke((Object) args[0], (Object) args[1]);
536 assertEquals(args[0], res);
537 res = resi = (int) mh.invoke((int) args[0], (Object) args[1]);
538 assertEquals(args[0], res);
jrose25aef892010-10-30 21:02:30 -0700539 }
540
541}