Search in sources :

Example 36 with MethodHandles.lookup

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

Example 37 with MethodHandles.lookup

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

Example 38 with MethodHandles.lookup

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

Example 39 with MethodHandles.lookup

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

Example 40 with MethodHandles.lookup

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

Aggregations

Lookup (java.lang.invoke.MethodHandles.Lookup)218 Test (org.testng.annotations.Test)176 MethodHandle (java.lang.invoke.MethodHandle)96 MethodHandles.publicLookup (java.lang.invoke.MethodHandles.publicLookup)39 Method (java.lang.reflect.Method)37 SamePackageInnerClass (com.ibm.j9.jsr292.SamePackageExample.SamePackageInnerClass)17 MutableCallSite (java.lang.invoke.MutableCallSite)11 MethodHandles (java.lang.invoke.MethodHandles)10 SamePackageInnerClass_Nested_Level2 (com.ibm.j9.jsr292.SamePackageExample.SamePackageInnerClass.SamePackageInnerClass_Nested_Level2)7 PackageExamples (examples.PackageExamples)7 MethodHandles.constant (java.lang.invoke.MethodHandles.constant)4 MethodHandles.dropArguments (java.lang.invoke.MethodHandles.dropArguments)4 MethodHandles.exactInvoker (java.lang.invoke.MethodHandles.exactInvoker)4 MethodHandles.foldArguments (java.lang.invoke.MethodHandles.foldArguments)4 MethodType.methodType (java.lang.invoke.MethodType.methodType)4 Constructor (java.lang.reflect.Constructor)4 ArrayList (java.util.ArrayList)4 Objects (java.util.Objects)4 Function (java.util.function.Function)4 ToDoubleFunction (java.util.function.ToDoubleFunction)4