use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class ThrowExceptionsTest method makeStackOverflow.
private static MethodHandle makeStackOverflow() {
MethodType cellType = methodType(void.class);
// recursion point
MethodHandle[] cell = { null };
MethodHandle getCell = insertArguments(arrayElementGetter(cell.getClass()), 0, cell, 0);
MethodHandle invokeCell = foldArguments(exactInvoker(cellType), getCell);
assert (invokeCell.type() == cellType);
cell[0] = invokeCell;
// make it conformable to any type:
invokeCell = dropArguments(invokeCell, 0, Object[].class).asVarargsCollector(Object[].class);
return invokeCell;
}
use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class VMAnonymousClass method test.
private static void test(String pkg) throws Throwable {
byte[] bytes = dumpClass(pkg);
// Define VM anonymous class in privileged context (on BCP).
Class anonClass = unsafe.defineAnonymousClass(Object.class, bytes, null);
MethodType t = MethodType.methodType(Object.class, int.class);
MethodHandle target = MethodHandles.lookup().findStatic(anonClass, "get", t);
// Wrap target into LF (convert) to get "target" referenced from LF
MethodHandle wrappedMH = target.asType(MethodType.methodType(Object.class, Integer.class));
// Invoke enough times to provoke LF compilation to bytecode.
for (int i = 0; i < 100; i++) {
Object r = wrappedMH.invokeExact((Integer) 1);
}
}
use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class TestPrivateMemberPackageSibling method test.
public void test() throws Throwable {
MethodHandles.Lookup lookup = MethodHandles.lookup();
MethodType mt = MethodType.methodType(void.class);
try {
Class<?> checkInittedHolder = TestPrivateMemberPackageSibling.class;
// Original model: checkInittedHolder = Class.class;
// Not using Class.checkInitted because it could change without notice.
MethodHandle mh = lookup.findStatic(checkInittedHolder, "checkInitted", mt);
throw new RuntimeException("IllegalAccessException not thrown");
} catch (IllegalAccessException e) {
// okay
System.out.println("Expected exception: " + e.getMessage());
}
}
use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class LambdaReturn method main.
public static void main(String[] args) throws Throwable {
l = MethodHandles.lookup();
MethodHandle hV = l.findStatic(LambdaReturn.class, "hereV", mt(void.class));
MethodHandle hS = l.findStatic(LambdaReturn.class, "hereS", mt(String.class));
List<String> errs = new ArrayList<>();
MethodType V = mt(void.class);
MethodType S = mt(String.class);
MethodType O = mt(Object.class);
MethodType I = mt(int.class);
amf(errs, hS, S, S, O, true);
amf(errs, hS, S, S, V, false);
amf(errs, hS, S, S, I, false);
amf(errs, hS, O, S, S, true);
amf(errs, hS, V, S, S, false);
amf(errs, hS, I, S, S, false);
amf(errs, hS, O, O, S, false);
amf(errs, hS, S, O, O, false);
amf(errs, hV, V, V, O, false);
amf(errs, hV, V, V, I, false);
amf(errs, hV, V, V, S, false);
amf(errs, hV, O, V, V, false);
amf(errs, hV, I, V, V, false);
amf(errs, hV, S, V, V, false);
if (errs.size() > 0) {
for (String err : errs) {
System.err.println(err);
}
throw new AssertionError("Errors: " + errs.size());
}
}
use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class RevealDirectTest method consistent.
static boolean consistent(UnreflectResult res, MethodHandleInfo info) {
assert (res.mh != null);
assertEquals(res.kind, info.getReferenceKind());
assertEquals(res.mem.getModifiers(), info.getModifiers());
assertEquals(res.mem.getDeclaringClass(), info.getDeclaringClass());
String expectName = res.mem.getName();
if (res.kind == REF_newInvokeSpecial)
expectName = "<init>";
assertEquals(expectName, info.getName());
MethodType expectType = res.mh.type();
if ((res.kind & 1) == (REF_getField & 1))
expectType = expectType.dropParameterTypes(0, 1);
if (res.kind == REF_newInvokeSpecial)
expectType = expectType.changeReturnType(void.class);
assertEquals(expectType, info.getMethodType());
assertEquals(res.mh.isVarargsCollector(), isVarArgs(info));
assertEquals(res.toInfoString(), info.toString());
assertEquals(res.toInfoString(), MethodHandleInfo.toString(info.getReferenceKind(), info.getDeclaringClass(), info.getName(), info.getMethodType()));
return true;
}
Aggregations