Search in sources :

Example 6 with MutableCallSite

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);
}
Also used : MethodType(java.lang.invoke.MethodType) MutableCallSite(java.lang.invoke.MutableCallSite) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 7 with MutableCallSite

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());
}
Also used : MethodType(java.lang.invoke.MethodType) MutableCallSite(java.lang.invoke.MutableCallSite) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 8 with MutableCallSite

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);
}
Also used : MutableCallSite(java.lang.invoke.MutableCallSite) Lookup(java.lang.invoke.MethodHandles.Lookup) MethodHandle(java.lang.invoke.MethodHandle)

Example 9 with MutableCallSite

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);
}
Also used : SwitchPoint(java.lang.invoke.SwitchPoint) MutableCallSite(java.lang.invoke.MutableCallSite) Lookup(java.lang.invoke.MethodHandles.Lookup) MethodHandle(java.lang.invoke.MethodHandle)

Example 10 with MutableCallSite

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);
}
Also used : MutableCallSite(java.lang.invoke.MutableCallSite) Lookup(java.lang.invoke.MethodHandles.Lookup) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

MutableCallSite (java.lang.invoke.MutableCallSite)17 MethodHandle (java.lang.invoke.MethodHandle)15 Lookup (java.lang.invoke.MethodHandles.Lookup)7 Test (org.testng.annotations.Test)7 MethodType (java.lang.invoke.MethodType)4 SwitchPoint (java.lang.invoke.SwitchPoint)3 ConstantCallSite (java.lang.invoke.ConstantCallSite)1 WrongMethodTypeException (java.lang.invoke.WrongMethodTypeException)1