本文整理汇总了Java中jdk.internal.dynalink.linker.GuardedInvocation.replaceMethods方法的典型用法代码示例。如果您正苦于以下问题:Java GuardedInvocation.replaceMethods方法的具体用法?Java GuardedInvocation.replaceMethods怎么用?Java GuardedInvocation.replaceMethods使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.internal.dynalink.linker.GuardedInvocation
的用法示例。
在下文中一共展示了GuardedInvocation.replaceMethods方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getGuardedInvocation
import jdk.internal.dynalink.linker.GuardedInvocation; //导入方法依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
final LinkRequest request = linkRequest.withoutRuntimeContext(); // Nashorn has no runtime context
final Object self = request.getReceiver();
if (self.getClass() != StaticClass.class) {
return null;
}
final Class<?> receiverClass = ((StaticClass) self).getRepresentedClass();
Bootstrap.checkReflectionAccess(receiverClass, true);
final CallSiteDescriptor desc = request.getCallSiteDescriptor();
// We intercept "new" on StaticClass instances to provide additional capabilities
if ("new".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
if (! Modifier.isPublic(receiverClass.getModifiers())) {
throw ECMAErrors.typeError("new.on.nonpublic.javatype", receiverClass.getName());
}
// make sure new is on accessible Class
Context.checkPackageAccess(receiverClass);
// Is the class abstract? (This includes interfaces.)
if (NashornLinker.isAbstractClass(receiverClass)) {
// Change this link request into a link request on the adapter class.
final Object[] args = request.getArguments();
args[0] = JavaAdapterFactory.getAdapterClassFor(new Class<?>[] { receiverClass }, null,
linkRequest.getCallSiteDescriptor().getLookup());
final LinkRequest adapterRequest = request.replaceArguments(request.getCallSiteDescriptor(), args);
final GuardedInvocation gi = checkNullConstructor(delegate(linkerServices, adapterRequest), receiverClass);
// Finally, modify the guard to test for the original abstract class.
return gi.replaceMethods(gi.getInvocation(), Guards.getIdentityGuard(self));
}
// If the class was not abstract, just delegate linking to the standard StaticClass linker. Make an
// additional check to ensure we have a constructor. We could just fall through to the next "return"
// statement, except we also insert a call to checkNullConstructor() which throws an ECMAScript TypeError
// with a more intuitive message when no suitable constructor is found.
return checkNullConstructor(delegate(linkerServices, request), receiverClass);
}
// In case this was not a "new" operation, just delegate to the the standard StaticClass linker.
return delegate(linkerServices, request);
}
示例2: filterOptimisticReturnValue
import jdk.internal.dynalink.linker.GuardedInvocation; //导入方法依赖的package包/类
/**
* Given a guarded invocation and a callsite descriptor, perform return value filtering
* according to the optimistic type coercion rules, using the return value from the descriptor
* @param inv the invocation
* @param desc the descriptor
* @return filtered invocation
*/
public static GuardedInvocation filterOptimisticReturnValue(final GuardedInvocation inv, final CallSiteDescriptor desc) {
if(!NashornCallSiteDescriptor.isOptimistic(desc)) {
return inv;
}
return inv.replaceMethods(filterOptimisticReturnValue(inv.getInvocation(), desc.getMethodType().returnType(),
NashornCallSiteDescriptor.getProgramPoint(desc)), inv.getGuard());
}
示例3: findCallMethodMethod
import jdk.internal.dynalink.linker.GuardedInvocation; //导入方法依赖的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());
}
示例4: createVarArgApplyOrCallCall
import jdk.internal.dynalink.linker.GuardedInvocation; //导入方法依赖的package包/类
private GuardedInvocation createVarArgApplyOrCallCall(final boolean isApply, final CallSiteDescriptor desc,
final LinkRequest request, final Object[] args) {
final MethodType descType = desc.getMethodType();
final int paramCount = descType.parameterCount();
final Object[] varArgs = (Object[])args[paramCount - 1];
// -1 'cause we're not passing the vararg array itself
final int copiedArgCount = args.length - 1;
final int varArgCount = varArgs.length;
// Spread arguments for the delegate createApplyOrCallCall invocation.
final Object[] spreadArgs = new Object[copiedArgCount + varArgCount];
System.arraycopy(args, 0, spreadArgs, 0, copiedArgCount);
System.arraycopy(varArgs, 0, spreadArgs, copiedArgCount, varArgCount);
// Spread call site descriptor for the delegate createApplyOrCallCall invocation. We drop vararg array and
// replace it with a list of Object.class.
final MethodType spreadType = descType.dropParameterTypes(paramCount - 1, paramCount).appendParameterTypes(
Collections.<Class<?>>nCopies(varArgCount, Object.class));
final CallSiteDescriptor spreadDesc = desc.changeMethodType(spreadType);
// Delegate back to createApplyOrCallCall with the spread (that is, reverted to non-vararg) request/
final LinkRequest spreadRequest = request.replaceArguments(spreadDesc, spreadArgs);
final GuardedInvocation spreadInvocation = createApplyOrCallCall(isApply, spreadDesc, spreadRequest, spreadArgs);
// Add spreader combinators to returned invocation and guard.
return spreadInvocation.replaceMethods(
// Use standard ScriptObject.pairArguments on the invocation
pairArguments(spreadInvocation.getInvocation(), descType),
// Use our specialized spreadGuardArguments on the guard (see below).
spreadGuardArguments(spreadInvocation.getGuard(), descType));
}
示例5: fixExpressionCallSite
import jdk.internal.dynalink.linker.GuardedInvocation; //导入方法依赖的package包/类
private static GuardedInvocation fixExpressionCallSite(final NashornCallSiteDescriptor desc, final GuardedInvocation link) {
// If it's not a getMethod, just add an expression filter that converts WithObject in "this" position to its
// expression.
if (!"getMethod".equals(desc.getFirstOperator())) {
return fixReceiverType(link, WITHEXPRESSIONFILTER).filterArguments(0, WITHEXPRESSIONFILTER);
}
final MethodHandle linkInvocation = link.getInvocation();
final MethodType linkType = linkInvocation.type();
final boolean linkReturnsFunction = ScriptFunction.class.isAssignableFrom(linkType.returnType());
return link.replaceMethods(
// Make sure getMethod will bind the script functions it receives to WithObject.expression
MH.foldArguments(
linkReturnsFunction ?
BIND_TO_EXPRESSION_FN :
BIND_TO_EXPRESSION_OBJ,
filterReceiver(
linkInvocation.asType(
linkType.changeReturnType(
linkReturnsFunction ?
ScriptFunction.class :
Object.class).
changeParameterType(
0,
Object.class)),
WITHEXPRESSIONFILTER)),
filterGuardReceiver(link, WITHEXPRESSIONFILTER));
// No clever things for the guard -- it is still identically filtered.
}
示例6: fixScopeCallSite
import jdk.internal.dynalink.linker.GuardedInvocation; //导入方法依赖的package包/类
private GuardedInvocation fixScopeCallSite(final GuardedInvocation link, final String name, final ScriptObject owner) {
final GuardedInvocation newLink = fixReceiverType(link, WITHSCOPEFILTER);
final MethodHandle expressionGuard = expressionGuard(name, owner);
final MethodHandle filterGuardReceiver = filterGuardReceiver(newLink, WITHSCOPEFILTER);
return link.replaceMethods(
filterReceiver(
newLink.getInvocation(),
WITHSCOPEFILTER),
NashornGuards.combineGuards(
expressionGuard,
filterGuardReceiver));
}
示例7: findGetIndexMethod
import jdk.internal.dynalink.linker.GuardedInvocation; //导入方法依赖的package包/类
private static GuardedInvocation findGetIndexMethod(final GuardedInvocation inv) {
final MethodHandle getter = MH.insertArguments(JSOBJECTLINKER_GET, 0, inv.getInvocation());
return inv.replaceMethods(getter, inv.getGuard());
}
示例8: findMegaMorphicSetMethod
import jdk.internal.dynalink.linker.GuardedInvocation; //导入方法依赖的package包/类
private GuardedInvocation findMegaMorphicSetMethod(final CallSiteDescriptor desc, final String name) {
final MethodType type = desc.getMethodType().insertParameterTypes(1, Object.class);
//never bother with ClassCastExceptionGuard for megamorphic callsites
final GuardedInvocation inv = findSetIndexMethod(getClass(), desc, false, type);
return inv.replaceMethods(MH.insertArguments(inv.getInvocation(), 1, name), inv.getGuard());
}