use of java.lang.invoke.MethodHandles.lookup in project openj9 by eclipse.
the class BootstrapMethods method permuteBootstrap.
// (int, int, String) --> (String, int, int) --> (String)
public static CallSite permuteBootstrap(Lookup ignored, String name, MethodType type) throws Throwable {
Lookup lookup = lookup();
MethodHandle object_toString = lookup.findVirtual(Object.class, "toString", methodType(String.class));
MethodHandle drop = dropArguments(object_toString, 1, int.class, int.class);
MethodHandle permute = permuteArguments(drop, methodType(String.class, int.class, int.class, Object.class), new int[] { 2, 0, 1 });
return new MutableCallSite(permute);
}
use of java.lang.invoke.MethodHandles.lookup in project openj9 by eclipse.
the class BootstrapMethods method fibBootstrap.
public static CallSite fibBootstrap(Lookup ignored, String name, MethodType type) throws Throwable {
Lookup lookup = lookup();
MethodHandle fib = lookup.findStatic(Class.forName("com.ibm.j9.jsr292.indyn.ComplexIndy"), "fibIndy", methodType(int.class, int.class));
return new MutableCallSite(fib);
}
use of java.lang.invoke.MethodHandles.lookup in project openj9 by eclipse.
the class BootstrapMethods method switchpointBootstrap.
public static CallSite switchpointBootstrap(Lookup ignored, String name, MethodType type) throws Throwable {
Lookup lookup = lookup();
MethodHandle add = lookup.findStatic(BootstrapMethods.class, "add", methodType(int.class, int.class, int.class));
MethodHandle fallback = lookup.findStatic(BootstrapMethods.class, "throwRuntimeException", methodType(int.class, int.class, int.class));
MethodHandle handle = new SwitchPoint().guardWithTest(add, fallback);
return new MutableCallSite(handle);
}
use of java.lang.invoke.MethodHandles.lookup in project openj9 by eclipse.
the class TestDefenderMethodLookup method testDirectSuperInterface.
/**
* Get a <b>SPECIAL</b> MethodHandle for the method "test()V" in the <b>DIRECT</b> super interface DefenderInterface. The method
* has a default implementation in DefenderInterface and does <b>NOT</b> have an implementation in the class.
* Invoke the MethodHandle, and assert that the DefenderInterface.test was invoked (should return "default").
*
* @throws Throwable No exceptions is expected. Any exception should be treated as an error.
*/
@Test
public void testDirectSuperInterface() throws Throwable {
DefenderInterface impl = new DefenderInterface() {
public MethodHandle run() throws Throwable {
Lookup l = DefenderInterface.lookup();
Class<? extends DefenderInterface> defc = this.getClass();
Class<DefenderInterface> target = DefenderInterface.class;
MethodType mt = MethodType.methodType(String.class);
return l.findSpecial(defc, "test", mt, target);
}
};
MethodHandle mh = impl.run();
String result = (String) mh.invoke(impl);
AssertJUnit.assertEquals("default", result);
}
use of java.lang.invoke.MethodHandles.lookup in project openj9 by eclipse.
the class BootstrapMethods method bootstrapAddInts.
public static CallSite bootstrapAddInts(Lookup caller, String name, MethodType type) throws Throwable {
MethodHandles.Lookup lookup = MethodHandles.lookup();
Class<?> thisClass = lookup.lookupClass();
MethodHandle addIntegers = lookup.findStatic(thisClass, "addIntegers", type);
return new ConstantCallSite(addIntegers);
}
Aggregations