use of java.lang.invoke.MutableCallSite in project openj9 by eclipse.
the class MutableCallSiteTest method testBasic_MutableCallSite.
/**
* Basic sanity test for MutableCallSite
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void testBasic_MutableCallSite() throws Throwable {
MethodType mt = MethodType.methodType(double.class, String.class);
MethodHandle mh = MethodHandles.lookup().findStatic(Double.class, "parseDouble", mt);
MutableCallSite mcs = new MutableCallSite(mt);
mcs.setTarget(mh);
double d = (double) mcs.dynamicInvoker().invokeExact("1.1");
AssertJUnit.assertEquals(1.1, d);
}
use of java.lang.invoke.MutableCallSite in project openj9 by eclipse.
the class MutableCallSiteTest method testType.
/**
* Test for MutableCallSite.type()
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void testType() throws Throwable {
MethodType mt = MethodType.methodType(String.class);
MethodHandle mh = MethodHandles.lookup().findStatic(SamePackageExample.class, "returnOne", mt);
MutableCallSite mcs = new MutableCallSite(mh);
AssertJUnit.assertEquals(mt, mcs.type());
}
use of java.lang.invoke.MutableCallSite 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.MutableCallSite 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.MutableCallSite 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);
}
Aggregations