Search in sources :

Example 11 with ConstantCallSite

use of java.lang.invoke.ConstantCallSite in project presto by prestodb.

the class TestInvokeDynamicBytecodeExpression method bootstrap.

public static CallSite bootstrap(MethodHandles.Lookup callerLookup, String name, MethodType type, String prefix) throws Exception {
    MethodHandle methodHandle = callerLookup.findVirtual(String.class, "concat", MethodType.methodType(String.class, String.class));
    methodHandle = methodHandle.bindTo(name + "-" + prefix + "-");
    return new ConstantCallSite(methodHandle);
}
Also used : ConstantCallSite(java.lang.invoke.ConstantCallSite) BytecodeExpressions.constantString(com.facebook.presto.bytecode.expression.BytecodeExpressions.constantString) MethodHandle(java.lang.invoke.MethodHandle)

Example 12 with ConstantCallSite

use of java.lang.invoke.ConstantCallSite in project gravel by gravel-st.

the class MethodLinker method constructorBootstrap.

public static CallSite constructorBootstrap(Lookup lookup, String selector, MethodType type, String referenceString) throws Throwable {
    Reference reference = Reference.factory.value_(referenceString);
    Constructor constructor = ImageBootstrapper.systemMapping.classMappingAtReference_(reference).identityClass().getConstructor();
    MethodHandle constructorHandle = lookup.unreflectConstructor(constructor);
    return new ConstantCallSite(constructorHandle.asType(type));
}
Also used : Reference(st.gravel.support.compiler.ast.Reference) AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference) Constructor(java.lang.reflect.Constructor) ConstantCallSite(java.lang.invoke.ConstantCallSite) MethodHandle(java.lang.invoke.MethodHandle)

Example 13 with ConstantCallSite

use of java.lang.invoke.ConstantCallSite in project gravel by gravel-st.

the class MethodLinker method globalReadBootstrap.

public static CallSite globalReadBootstrap(Lookup lookup, String selector, MethodType type, String namespaceString) throws Throwable {
    AbsoluteReference namespace = (AbsoluteReference) Reference.factory.value_(namespaceString);
    AbsoluteReference fullReference = namespace.$slash$(Symbol.value(selector));
    final AlmostFinalValue singletonHolder = ImageBootstrapper.systemMapping.resolveSingletonHolder_(fullReference);
    return new ConstantCallSite(singletonHolder.createGetter());
}
Also used : AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference) ConstantCallSite(java.lang.invoke.ConstantCallSite)

Example 14 with ConstantCallSite

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

the class Bootstrap method bootstrapDynamic.

/**
 * The invokedynamic bootstrapping method.
 *
 * @param caller
 *            the caller lookup
 * @param name
 *            the instruction name
 * @param type
 *            the expected method type
 * @return the invokedynamic call-site object
 */
public static CallSite bootstrapDynamic(MethodHandles.Lookup caller, String name, MethodType type) {
    // System.out.printf("type: %s\n", type);
    try {
        MutableCallSite callsite = new MutableCallSite(type);
        MethodHandle setup;
        switch(name) {
            case CallNames.CALL:
                setup = MethodHandles.insertArguments(callSetupMH, 0, callsite);
                break;
            case CallNames.CONSTRUCT:
                setup = MethodHandles.insertArguments(constructSetupMH, 0, callsite);
                break;
            case CallNames.SUPER:
                setup = MethodHandles.insertArguments(superSetupMH, 0, callsite);
                break;
            case CallNames.ADD:
                setup = MethodHandles.insertArguments(addSetupMH, 0, callsite);
                break;
            case CallNames.SUB:
                setup = MethodHandles.insertArguments(subSetupMH, 0, callsite);
                break;
            case CallNames.EXP:
                setup = MethodHandles.insertArguments(expSetupMH, 0, callsite);
                break;
            case CallNames.MUL:
                setup = MethodHandles.insertArguments(mulSetupMH, 0, callsite);
                break;
            case CallNames.DIV:
                setup = MethodHandles.insertArguments(divSetupMH, 0, callsite);
                break;
            case CallNames.MOD:
                setup = MethodHandles.insertArguments(modSetupMH, 0, callsite);
                break;
            case CallNames.SHL:
                setup = MethodHandles.insertArguments(shlSetupMH, 0, callsite);
                break;
            case CallNames.SHR:
                setup = MethodHandles.insertArguments(shrSetupMH, 0, callsite);
                break;
            case CallNames.USHR:
                setup = MethodHandles.insertArguments(ushrSetupMH, 0, callsite);
                break;
            case CallNames.BITAND:
                setup = MethodHandles.insertArguments(bitAndSetupMH, 0, callsite);
                break;
            case CallNames.BITOR:
                setup = MethodHandles.insertArguments(bitOrSetupMH, 0, callsite);
                break;
            case CallNames.BITXOR:
                setup = MethodHandles.insertArguments(bitXorSetupMH, 0, callsite);
                break;
            case CallNames.EQ:
                setup = MethodHandles.insertArguments(eqCmpSetupMH, 0, callsite);
                break;
            case CallNames.SHEQ:
                setup = MethodHandles.insertArguments(strictEqCmpSetupMH, 0, callsite);
                break;
            case CallNames.LT:
                setup = MethodHandles.insertArguments(relCmpSetupMH, 0, callsite, RelationalOperator.LessThan);
                break;
            case CallNames.GT:
                setup = MethodHandles.insertArguments(relCmpSetupMH, 0, callsite, RelationalOperator.GreaterThan);
                break;
            case CallNames.LE:
                setup = MethodHandles.insertArguments(relCmpSetupMH, 0, callsite, RelationalOperator.LessThanEquals);
                break;
            case CallNames.GE:
                setup = MethodHandles.insertArguments(relCmpSetupMH, 0, callsite, RelationalOperator.GreaterThanEquals);
                break;
            case CallNames.CONCAT:
                concatSetup(callsite, type);
                return callsite;
            case CallNames.BITNOT:
                setup = MethodHandles.insertArguments(bitNotSetupMH, 0, callsite);
                break;
            case CallNames.NEG:
                setup = MethodHandles.insertArguments(negSetupMH, 0, callsite);
                break;
            case CallNames.INC:
                setup = MethodHandles.insertArguments(incSetupMH, 0, callsite);
                break;
            case CallNames.DEC:
                setup = MethodHandles.insertArguments(decSetupMH, 0, callsite);
                break;
            default:
                throw new IllegalArgumentException(name);
        }
        callsite.setTarget(setupCallSiteTarget(type, setup));
        return callsite;
    } catch (StackOverflowError e) {
        switch(name) {
            case CallNames.CALL:
                return stackOverFlow_Call;
            case CallNames.CONSTRUCT:
                return stackOverFlow_Construct;
            case CallNames.SUPER:
                return stackOverFlow_Super;
            case CallNames.CONCAT:
                return new ConstantCallSite(MethodHandles.dropArguments(stackOverFlow_Concat, 0, type.parameterArray()));
            case CallNames.ADD:
                return stackOverFlow_Add;
            case CallNames.SUB:
            case CallNames.EXP:
            case CallNames.MUL:
            case CallNames.DIV:
            case CallNames.MOD:
            case CallNames.SHL:
            case CallNames.SHR:
            case CallNames.USHR:
            case CallNames.BITAND:
            case CallNames.BITOR:
            case CallNames.BITXOR:
                return stackOverFlow_BinaryNumber;
            case CallNames.EQ:
                return stackOverFlow_Eq;
            case CallNames.SHEQ:
                return stackOverFlow_StrictEq;
            case CallNames.LT:
            case CallNames.GT:
            case CallNames.LE:
            case CallNames.GE:
                return stackOverFlow_Cmp;
            case CallNames.BITNOT:
            case CallNames.NEG:
            case CallNames.INC:
            case CallNames.DEC:
                return stackOverFlow_UnaryNumber;
            default:
                throw new IllegalArgumentException(name);
        }
    }
}
Also used : MutableCallSite(java.lang.invoke.MutableCallSite) ConstantCallSite(java.lang.invoke.ConstantCallSite) MethodHandle(java.lang.invoke.MethodHandle)

Example 15 with ConstantCallSite

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

the class Operators 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) HTMLDDAObject(com.github.anba.es6draft.runtime.types.HTMLDDAObject) StringObject(com.github.anba.es6draft.runtime.types.builtins.StringObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) 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