Search in sources :

Example 26 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 {
        if (!name.startsWith("native:")) {
            throw new IllegalArgumentException();
        }
        String methodName = name.substring("native:".length());
        MethodHandle mh = nativeMethods.computeIfAbsent(methodName, NativeCalls::getNativeMethodHandle);
        if (mh == null) {
            return createRuntimeCallSite(methodName, type);
        }
        target = adaptMethodHandle(methodName, type, mh);
    } catch (IllegalArgumentException e) {
        target = invalidCallHandle(name, type);
    }
    return new ConstantCallSite(target);
}
Also used : ConstantCallSite(java.lang.invoke.ConstantCallSite) MethodHandle(java.lang.invoke.MethodHandle)

Example 27 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) {
    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);
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) ConstantCallSite(java.lang.invoke.ConstantCallSite) MethodHandle(java.lang.invoke.MethodHandle)

Example 28 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)

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