use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class MethodTypeTest method testMake_String_ClassLoader.
/**
* Test of make method, of class MethodType.
*/
@Test
public void testMake_String_ClassLoader() {
System.out.println("make (from bytecode signature)");
ClassLoader loader = null;
MethodType[] instances = { mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi };
String obj = "Ljava/lang/Object;";
assertEquals(obj, concat(Object.class));
String[] expResults = { "(ILjava/lang/String;)V", concat("(", obj, 2, ")", Object.class), "()V", "()" + obj, concat("(", String.class, Integer.class, ")I"), concat("(", String.class, "I)", Integer.class), concat("(", String.class, Integer.class, ")", Integer.class), concat("(", String.class, "I)I") };
for (int i = 0; i < instances.length; i++) {
MethodType instance = instances[i];
String result = instance.toMethodDescriptorString();
assertEquals("#" + i, expResults[i], result);
MethodType parsed = MethodType.fromMethodDescriptorString(result, loader);
assertSame("--#" + i, instance, parsed);
}
}
use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class MethodTypeTest method testParameterCount.
/**
* Test of parameterCount method, of class MethodType.
*/
@Test
public void testParameterCount() {
System.out.println("parameterCount");
MethodType instance = mt_viS;
int expResult = 2;
int result = instance.parameterCount();
assertEquals(expResult, result);
}
use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class MethodTypeTest method testDistinct.
/** Make sure the method types are all distinct. */
@Test
public void testDistinct() {
List<MethodType> gallery2 = new ArrayList<>();
for (MethodType mt : GALLERY) {
assertFalse(mt.toString(), gallery2.contains(mt));
gallery2.add(mt);
}
// check self-equality also:
assertEquals(Arrays.asList(GALLERY), gallery2);
}
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);
}
}
Aggregations