Search in sources :

Example 1 with ConstantCallSite

use of java.lang.invoke.ConstantCallSite in project es6draft by anba.

the class ScriptRuntime method runtimeBootstrap.

public static CallSite runtimeBootstrap(MethodHandles.Lookup caller, String name, MethodType type) {
    assert "rt:stack".equals(name) || "rt:locals".equals(name);
    MethodHandle mh = MethodHandles.identity(Object[].class);
    mh = mh.asCollector(Object[].class, type.parameterCount());
    mh = mh.asType(type);
    return new ConstantCallSite(mh);
}
Also used : ConstantCallSite(java.lang.invoke.ConstantCallSite) GeneratorObject(com.github.anba.es6draft.runtime.objects.iteration.GeneratorObject) TypedArrayObject(com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject) CompiledObject(com.github.anba.es6draft.compiler.CompiledObject) MethodHandle(java.lang.invoke.MethodHandle)

Example 2 with ConstantCallSite

use of java.lang.invoke.ConstantCallSite in project openj9 by eclipse.

the class BootstrapMethods method bootstrap_guard_with_test_let_input_decide.

// Bootstrap method for guardWithTest MH test where decision is made based on an incoming argument
public static CallSite bootstrap_guard_with_test_let_input_decide(Lookup lookup, String name, MethodType type) throws Throwable {
    MethodHandle mh_isDivisibleByThree = lookup.findStatic(Helper.class, "isDivisibleByThree", methodType(boolean.class, int.class));
    MethodHandle mh_isDivisibleByFive = lookup.findStatic(Helper.class, "isDivisibleByFive", methodType(boolean.class, int.class));
    MethodHandle mh_returnFizz = lookup.findStatic(Helper.class, "returnFizz", methodType(String.class, int.class));
    MethodHandle mh_returnBuzz = lookup.findStatic(Helper.class, "returnBuzz", methodType(String.class, int.class));
    MethodHandle mh_returnNothing = lookup.findStatic(Helper.class, "returnNothing", methodType(String.class, int.class));
    // if input % 3 , return "fizz", else if input % 5 , return "buzz" , else return "nothing"
    MethodHandle otherGWT = MethodHandles.guardWithTest(mh_isDivisibleByFive, mh_returnBuzz, mh_returnNothing);
    MethodHandle result = MethodHandles.guardWithTest(mh_isDivisibleByThree, mh_returnFizz, otherGWT);
    return new ConstantCallSite(result);
}
Also used : ConstantCallSite(java.lang.invoke.ConstantCallSite) MethodHandle(java.lang.invoke.MethodHandle)

Example 3 with ConstantCallSite

use of java.lang.invoke.ConstantCallSite in project openj9 by eclipse.

the class BootstrapMethods method bootstrap_guard_with_test_constant_true.

// Bootstrap method for guardWithTest MH test using a constant true condition
public static CallSite bootstrap_guard_with_test_constant_true(Lookup lookup, String name, MethodType type) throws Throwable {
    MethodHandle constant_true = MethodHandles.constant(boolean.class, true);
    MethodHandle trueTarget = lookup.findStatic(Helper.class, "negativeInt", methodType(int.class, int.class));
    MethodHandle falseTarget = MethodHandles.identity(int.class);
    // if (true_gwt()) { negativeInt(5) } else { identity(5) }
    MethodHandle true_gwt = MethodHandles.guardWithTest(constant_true, trueTarget, falseTarget);
    return new ConstantCallSite(true_gwt);
}
Also used : ConstantCallSite(java.lang.invoke.ConstantCallSite) MethodHandle(java.lang.invoke.MethodHandle)

Example 4 with ConstantCallSite

use of java.lang.invoke.ConstantCallSite in project openj9 by eclipse.

the class BootstrapMethods method bootstrap_bind_mh_to_receiver.

// Bootstrap method for bindTo MH test
public static CallSite bootstrap_bind_mh_to_receiver(Lookup lookup, String name, MethodType type) throws Throwable {
    MethodHandle mh = lookup.findGetter(Helper.class, "publicInt", int.class);
    mh = mh.bindTo(new Helper());
    return new ConstantCallSite(mh);
}
Also used : CrossPackageHelper(differentpackage.CrossPackageHelper) ConstantCallSite(java.lang.invoke.ConstantCallSite) MethodHandle(java.lang.invoke.MethodHandle)

Example 5 with ConstantCallSite

use of java.lang.invoke.ConstantCallSite 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

ConstantCallSite (java.lang.invoke.ConstantCallSite)28 MethodHandle (java.lang.invoke.MethodHandle)25 Test (org.testng.annotations.Test)9 MethodType (java.lang.invoke.MethodType)5 MethodHandles (java.lang.invoke.MethodHandles)4 Lookup (java.lang.invoke.MethodHandles.Lookup)3 AbsoluteReference (st.gravel.support.compiler.ast.AbsoluteReference)3 WrongMethodTypeException (java.lang.invoke.WrongMethodTypeException)2 Constructor (java.lang.reflect.Constructor)2 DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)1 BytecodeExpressions.constantString (com.facebook.presto.bytecode.expression.BytecodeExpressions.constantString)1 CompiledObject (com.github.anba.es6draft.compiler.CompiledObject)1 TypedArrayObject (com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject)1 GeneratorObject (com.github.anba.es6draft.runtime.objects.iteration.GeneratorObject)1 HTMLDDAObject (com.github.anba.es6draft.runtime.types.HTMLDDAObject)1 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)1 StringObject (com.github.anba.es6draft.runtime.types.builtins.StringObject)1 CrossPackageHelper (differentpackage.CrossPackageHelper)1 NonNull (dyvil.annotation.internal.NonNull)1 MutableCallSite (java.lang.invoke.MutableCallSite)1