Search in sources :

Example 6 with ConstantCallSite

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

the class MethodLinker method globalWriteBootstrap.

public static CallSite globalWriteBootstrap(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);
    final MethodHandle target = lookup.findVirtual(AlmostFinalValue.class, "setValue", MethodType.methodType(Object.class, Object.class)).bindTo(singletonHolder);
    return new ConstantCallSite(target);
}
Also used : AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference) ConstantCallSite(java.lang.invoke.ConstantCallSite) MethodHandle(java.lang.invoke.MethodHandle)

Example 7 with ConstantCallSite

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

the class NativeCalls method bootstrapDynamic.

/**
     * Returns the native call {@code CallSite} object.
     * 
     * @param caller
     *            the caller lookup object
     * @param name
     *            the native call name
     * @param type
     *            the native call type
     * @return the native call {@code CallSite} object
     */
public static CallSite bootstrapDynamic(MethodHandles.Lookup caller, String name, MethodType type) {
    MethodHandle target;
    try {
        MethodHandle mh = nativeMethods.computeIfAbsent(name, NativeCalls::getNativeMethodHandle);
        if (isSpreadCall(mh, type)) {
            target = forSpreadCall(mh, type);
        } else {
            target = mh.asType(type);
        }
        if (target != mh) {
            MethodHandle invalidArgumentsHandle = invalidCallArgumentsExceptionHandle(name, type);
            target = MethodHandles.catchException(target, ClassCastException.class, invalidArgumentsHandle);
        }
    } catch (IllegalArgumentException e) {
        target = invalidCallHandle(name, type);
    } catch (WrongMethodTypeException e) {
        target = invalidCallArgumentsHandle(name, type, e);
    }
    return new ConstantCallSite(target);
}
Also used : ConstantCallSite(java.lang.invoke.ConstantCallSite) WrongMethodTypeException(java.lang.invoke.WrongMethodTypeException) MethodHandle(java.lang.invoke.MethodHandle)

Example 8 with ConstantCallSite

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

the class Bootstrap method bootstrap.

public static CallSite bootstrap(MethodHandles.Lookup callerLookup, String name, MethodType type, long bindingId) {
    try {
        ClassLoader classLoader = callerLookup.lookupClass().getClassLoader();
        checkArgument(classLoader instanceof DynamicClassLoader, "Expected %s's classloader to be of type %s", callerLookup.lookupClass().getName(), DynamicClassLoader.class.getName());
        DynamicClassLoader dynamicClassLoader = (DynamicClassLoader) classLoader;
        MethodHandle target = dynamicClassLoader.getCallSiteBindings().get(bindingId);
        checkArgument(target != null, "Binding %s for function %s%s not found", bindingId, name, type.parameterList());
        return new ConstantCallSite(target);
    } catch (Throwable e) {
        if (e instanceof InterruptedException) {
            Thread.currentThread().interrupt();
        }
        throw Throwables.propagate(e);
    }
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) ConstantCallSite(java.lang.invoke.ConstantCallSite) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

ConstantCallSite (java.lang.invoke.ConstantCallSite)8 MethodHandle (java.lang.invoke.MethodHandle)7 AbsoluteReference (st.gravel.support.compiler.ast.AbsoluteReference)3 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 MutableCallSite (java.lang.invoke.MutableCallSite)1 WrongMethodTypeException (java.lang.invoke.WrongMethodTypeException)1 Constructor (java.lang.reflect.Constructor)1 Reference (st.gravel.support.compiler.ast.Reference)1