本文整理汇总了Java中jdk.nashorn.internal.runtime.linker.Bootstrap.createDynamicInvoker方法的典型用法代码示例。如果您正苦于以下问题:Java Bootstrap.createDynamicInvoker方法的具体用法?Java Bootstrap.createDynamicInvoker怎么用?Java Bootstrap.createDynamicInvoker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.runtime.linker.Bootstrap
的用法示例。
在下文中一共展示了Bootstrap.createDynamicInvoker方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bindAllProperties
import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
/**
* Binds the source mirror object's properties to the target object. Binding
* properties allows two-way read/write for the properties of the source object.
* All inherited, enumerable properties are also bound. This method is used to
* to make 'with' statement work with ScriptObjectMirror as scope object.
*
* @param target the target object to which the source object's properties are bound
* @param source the source object whose properties are bound to the target
* @return the target object after property binding
*/
public static Object bindAllProperties(final ScriptObject target, final ScriptObjectMirror source) {
final Set<String> keys = source.keySet();
// make accessor properties using dynamic invoker getters and setters
final AccessorProperty[] props = new AccessorProperty[keys.size()];
int idx = 0;
for (final String name : keys) {
final MethodHandle getter = Bootstrap.createDynamicInvoker("dyn:getMethod|getProp|getElem:" + name, MIRROR_GETTER_TYPE);
final MethodHandle setter = Bootstrap.createDynamicInvoker("dyn:setProp|setElem:" + name, MIRROR_SETTER_TYPE);
props[idx] = AccessorProperty.create(name, 0, getter, setter);
idx++;
}
target.addBoundProperties(source, props);
return target;
}
示例2: findCallMethodMethod
import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
/**
* Find an implementation for a "dyn:callMethod" operation. Note that Nashorn internally never uses
* "dyn:callMethod", but instead always emits two call sites in bytecode, one for "dyn:getMethod", and then another
* one for "dyn:call". Explicit support for "dyn:callMethod" is provided for the benefit of potential external
* callers. The implementation itself actually folds a "dyn:getMethod" method handle into a "dyn:call" method handle.
*
* @param desc the call site descriptor.
* @param request the link request
*
* @return GuardedInvocation to be invoked at call site.
*/
protected GuardedInvocation findCallMethodMethod(final CallSiteDescriptor desc, final LinkRequest request) {
// R(P0, P1, ...)
final MethodType callType = desc.getMethodType();
// use type Object(P0) for the getter
final CallSiteDescriptor getterType = desc.changeMethodType(MethodType.methodType(Object.class, callType.parameterType(0)));
final GuardedInvocation getter = findGetMethod(getterType, request, "getMethod");
// Object(P0) => Object(P0, P1, ...)
final MethodHandle argDroppingGetter = MH.dropArguments(getter.getInvocation(), 1, callType.parameterList().subList(1, callType.parameterCount()));
// R(Object, P0, P1, ...)
final MethodHandle invoker = Bootstrap.createDynamicInvoker("dyn:call", callType.insertParameterTypes(0, argDroppingGetter.type().returnType()));
// Fold Object(P0, P1, ...) into R(Object, P0, P1, ...) => R(P0, P1, ...)
return getter.replaceMethods(MH.foldArguments(invoker, argDroppingGetter), getter.getGuard());
}
示例3: getINVOKE_UA_GETTER
import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
static MethodHandle getINVOKE_UA_GETTER(final Class<?> returnType, final int programPoint) {
if (UnwarrantedOptimismException.isValid(programPoint)) {
final int flags = NashornCallSiteDescriptor.CALLSITE_OPTIMISTIC | programPoint << CALLSITE_PROGRAM_POINT_SHIFT;
return Bootstrap.createDynamicInvoker("dyn:call", flags, returnType, Object.class, Object.class);
} else {
return Bootstrap.createDynamicInvoker("dyn:call", Object.class, Object.class, Object.class);
}
}
示例4: getINVOKE_UA_GETTER
import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
static MethodHandle getINVOKE_UA_GETTER(final Class<?> returnType, final int programPoint) {
if (UnwarrantedOptimismException.isValid(programPoint)) {
final int flags = NashornCallSiteDescriptor.CALL | NashornCallSiteDescriptor.CALLSITE_OPTIMISTIC | programPoint << CALLSITE_PROGRAM_POINT_SHIFT;
return Bootstrap.createDynamicInvoker("", flags, returnType, Object.class, Object.class);
} else {
return Bootstrap.createDynamicCallInvoker(Object.class, Object.class, Object.class);
}
}
示例5: findCallMethodMethod
import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
/**
* Find an implementation for a CALL_METHOD operation. Note that Nashorn internally never uses
* CALL_METHOD, but instead always emits two call sites in bytecode, one for GET_METHOD, and then another
* one for CALL. Explicit support for CALL_METHOD is provided for the benefit of potential external
* callers. The implementation itself actually folds a GET_METHOD method handle into a CALL method handle.
*
* @param desc the call site descriptor.
* @param request the link request
*
* @return GuardedInvocation to be invoked at call site.
*/
protected GuardedInvocation findCallMethodMethod(final CallSiteDescriptor desc, final LinkRequest request) {
// R(P0, P1, ...)
final MethodType callType = desc.getMethodType();
// use type Object(P0) for the getter
final CallSiteDescriptor getterType = desc.changeMethodType(MethodType.methodType(Object.class, callType.parameterType(0)));
final GuardedInvocation getter = findGetMethod(getterType, request, StandardOperation.GET_METHOD);
// Object(P0) => Object(P0, P1, ...)
final MethodHandle argDroppingGetter = MH.dropArguments(getter.getInvocation(), 1, callType.parameterList().subList(1, callType.parameterCount()));
// R(Object, P0, P1, ...)
final MethodHandle invoker = Bootstrap.createDynamicInvoker("", NashornCallSiteDescriptor.CALL, callType.insertParameterTypes(0, argDroppingGetter.type().returnType()));
// Fold Object(P0, P1, ...) into R(Object, P0, P1, ...) => R(P0, P1, ...)
return getter.replaceMethods(MH.foldArguments(invoker, argDroppingGetter), getter.getGuard());
}
示例6: invokerCreator
import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
private static Callable<MethodHandle> invokerCreator(final Class<?> rtype, final Class<?>... ptypes) {
return new Callable<MethodHandle>() {
@Override
public MethodHandle call() {
return Bootstrap.createDynamicInvoker("dyn:call", rtype, ptypes);
}
};
}
示例7: getINVOKE_UA_SETTER
import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
static MethodHandle getINVOKE_UA_SETTER(final Class<?> valueType) {
return Bootstrap.createDynamicInvoker("dyn:call", void.class, Object.class, Object.class, valueType);
}
示例8: createAccessorProperty
import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
private static AccessorProperty createAccessorProperty(final String name) {
final MethodHandle getter = Bootstrap.createDynamicInvoker(name, NashornCallSiteDescriptor.GET_METHOD_PROPERTY, MIRROR_GETTER_TYPE);
final MethodHandle setter = Bootstrap.createDynamicInvoker(name, NashornCallSiteDescriptor.SET_PROPERTY, MIRROR_SETTER_TYPE);
return AccessorProperty.create(name, 0, getter, setter);
}