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);
}
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);
}
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);
}
}
Aggregations