use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class ExplicitCastArgumentsTest method testVarargsCollector.
/**
* Tests that MHs.explicitCastArguments does incorrect type checks for
* VarargsCollector. Bug 8066746.
*
* @throws java.lang.Throwable
*/
public static void testVarargsCollector() throws Throwable {
MethodType mt = MethodType.methodType(String[].class, String[].class);
MethodHandle mh = MethodHandles.publicLookup().findStatic(THIS_CLASS, "f", mt);
mh = MethodHandles.explicitCastArguments(mh, MethodType.methodType(Object.class, Object.class));
mh.invokeWithArguments((Object) (new String[] { "str1", "str2" }));
}
use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class LambdaReceiver method main.
public static void main(String[] args) throws Throwable {
l = MethodHandles.lookup();
h = l.findVirtual(LambdaReceiver_A.class, "f", mt(int.class));
MethodType X = mt(int.class, LambdaReceiver.class);
MethodType A = mt(int.class, LambdaReceiver_A.class);
MethodType mti = mt(IA.class);
CallSite cs = LambdaMetafactory.metafactory(l, "m", mti, A, h, X);
IA p = (IA) cs.dynamicInvoker().invoke();
LambdaReceiver_A lra = new LambdaReceiver_A();
try {
p.m(lra);
} catch (ClassCastException cce) {
return;
}
throw new AssertionError("CCE expected");
}
use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class LambdaReceiverBridge method main.
public static void main(String[] args) throws Throwable {
l = MethodHandles.lookup();
h = l.findVirtual(LambdaReceiver_A.class, "f", mt(int.class));
MethodType X = mt(int.class, LambdaReceiverBridge.class);
MethodType A = mt(int.class, LambdaReceiver_A.class);
MethodType mti = mt(IA.class);
CallSite cs = LambdaMetafactory.altMetafactory(l, "m", mti, X, h, X, LambdaMetafactory.FLAG_BRIDGES, 1, A);
IA p = (IA) cs.dynamicInvoker().invoke();
LambdaReceiver_A lra = new LambdaReceiver_A();
try {
p.m(lra);
} catch (ClassCastException cce) {
return;
}
throw new AssertionError("CCE expected");
}
use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class PermuteArgsTest method testPermutations.
static void testPermutations(MethodHandle mh) throws Throwable {
HashSet<String> done = new HashSet<>();
MethodType mt = mh.type();
int[] perm = nullPerm(mt.parameterCount());
final int MARGIN = (perm.length <= 10 ? 2 : 0);
int testCases0 = testCases;
for (int j = 0; j <= 1; j++) {
int maxStart = perm.length - 1;
if (j != 0)
maxStart /= 2;
for (int start = 0; start <= maxStart; start++) {
int maxOmit = (maxStart - start) / 2;
if (start != 0)
maxOmit = 2;
if (j != 0)
maxOmit = 1;
for (int omit = 0; omit <= maxOmit; omit++) {
int end = perm.length - omit;
if (end - start >= 2) {
//System.out.println("testPermutations"+Arrays.asList(start, end)+(j == 0 ? "" : " (reverse)"));
testPermutations(mh, perm, start, end, done);
}
omit = jump(omit, (start == 0 && j == 0 ? MARGIN : 0), maxOmit);
}
start = jump(start, (j == 0 ? MARGIN : 0), maxStart);
}
// do everything in reverse:
reverse(perm, 0, perm.length);
}
switch(perm.length) {
case 2:
assert (testCases - testCases0 == 2);
break;
case 3:
assert (testCases - testCases0 == 6);
break;
case 4:
assert (testCases - testCases0 == 24);
break;
case 5:
assert (testCases - testCases0 == 120);
break;
case 6:
assert (testCases - testCases0 > 720 / 3);
break;
}
}
use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class PermuteArgsTest method testOnePermutation.
static void testOnePermutation(MethodHandle mh, int[] perm, Object[] args) throws Throwable {
MethodType mt = mh.type();
MethodType pmt = methodType(mt.returnType(), unpermuteArgs(perm, mt.parameterArray(), Class[].class));
if (VERBOSE)
System.out.println(Arrays.toString(perm));
testCases += 1;
if (DRY_RUN)
return;
Object res = permuteArguments(mh, pmt, perm).invokeWithArguments(unpermuteArgs(perm, args));
String str = String.valueOf(res);
if (!Arrays.toString(args).equals(str)) {
System.out.println(Arrays.toString(perm) + " " + str + " *** WRONG ***");
}
}
Aggregations