Java源码示例:com.oracle.truffle.api.nodes.DirectCallNode
示例1
@SuppressWarnings("unused")
@Specialization(guards = {"!isNotProvided(arg5)", "closure.getCompiledBlock() == cachedBlock", "cachedBlock.getNumArgs() == 5"}, assumptions = {
"cachedBlock.getCallTargetStable()"}, limit = "INLINE_CACHE_SIZE")
protected static final Object doValue5Direct(final VirtualFrame frame, final BlockClosureObject closure, final Object arg1, final Object arg2, final Object arg3, final Object arg4,
final Object arg5,
@Cached("closure.getCompiledBlock()") final CompiledBlockObject cachedBlock,
@Cached final GetContextOrMarkerNode getContextOrMarkerNode,
@Cached("create(cachedBlock.getCallTarget())") final DirectCallNode directCallNode) {
final Object[] frameArguments = FrameAccess.newClosureArgumentsTemplate(closure, cachedBlock, getContextOrMarkerNode.execute(frame), 5);
frameArguments[FrameAccess.getArgumentStartIndex()] = arg1;
frameArguments[FrameAccess.getArgumentStartIndex() + 1] = arg2;
frameArguments[FrameAccess.getArgumentStartIndex() + 2] = arg3;
frameArguments[FrameAccess.getArgumentStartIndex() + 3] = arg4;
frameArguments[FrameAccess.getArgumentStartIndex() + 4] = arg5;
return directCallNode.call(frameArguments);
}
示例2
@Specialization(guards = {"stringsEqual(cachedId, id)", "stringsEqual(cachedCode, code)"})
public Object evalCached(String id, String code,
@Cached("id") String cachedId,
@Cached("code") String cachedCode,
@CachedContext(HashemLanguage.class) HashemContext context,
@Cached("create(parse(id, code, context))") DirectCallNode callNode) {
return callNode.call(new Object[]{});
}
示例3
@Specialization(guards = {"method == cachedMethod"}, //
limit = "INLINE_CACHE_SIZE", assumptions = "cachedMethod.getCallTargetStable()")
protected static final Object doDirect(@SuppressWarnings("unused") final CompiledMethodObject method, final Object[] receiverAndArguments, final Object contextOrMarker,
@SuppressWarnings("unused") @Cached("method") final CompiledMethodObject cachedMethod,
@Cached("create(cachedMethod.getCallTarget())") final DirectCallNode callNode) {
return callNode.call(FrameAccess.newWith(cachedMethod, contextOrMarker, null, receiverAndArguments));
}
示例4
@Specialization(guards = {"method == cachedMethod"}, //
limit = "INLINE_CACHE_SIZE", assumptions = {"cachedMethod.getCallTargetStable()", "cachedMethod.getDoesNotNeedSenderAssumption()"}, replaces = "doPrimitiveEagerly")
protected static final Object doDirect(final VirtualFrame frame, @SuppressWarnings("unused") final CompiledMethodObject method,
@SuppressWarnings("unused") @Cached("method") final CompiledMethodObject cachedMethod,
@Cached final GetContextOrMarkerNode getContextOrMarkerNode,
@Cached("create(argumentCount)") final CreateFrameArgumentsNode argumentsNode,
@Cached("create(cachedMethod.getCallTarget())") final DirectCallNode callNode) {
return callNode.call(argumentsNode.execute(frame, cachedMethod, getContextOrMarkerNode.execute(frame)));
}
示例5
@Specialization(guards = {"method == cachedMethod"}, //
limit = "INLINE_CACHE_SIZE", assumptions = {"cachedMethod.getCallTargetStable()"}, replaces = {"doPrimitiveEagerly"})
protected static final Object doDirectWithSender(final VirtualFrame frame, @SuppressWarnings("unused") final CompiledMethodObject method,
@SuppressWarnings("unused") @Cached("method") final CompiledMethodObject cachedMethod,
@Cached("create(true)") final GetOrCreateContextNode getOrCreateContextNode,
@Cached("create(argumentCount)") final CreateFrameArgumentsNode argumentsNode,
@Cached("create(cachedMethod.getCallTarget())") final DirectCallNode callNode) {
return callNode.call(argumentsNode.execute(frame, cachedMethod, getOrCreateContextNode.executeGet(frame)));
}
示例6
@SuppressWarnings("unused")
@Specialization(guards = {"closure.getCompiledBlock() == cachedBlock", "cachedBlock.getNumArgs() == 0"}, assumptions = {"cachedBlock.getCallTargetStable()"}, limit = "INLINE_CACHE_SIZE")
protected static final Object doValueDirect(final VirtualFrame frame, final BlockClosureObject closure,
@Cached("closure.getCompiledBlock()") final CompiledBlockObject cachedBlock,
@Cached final GetContextOrMarkerNode getContextOrMarkerNode,
@Cached("create(cachedBlock.getCallTarget())") final DirectCallNode directCallNode) {
return directCallNode.call(FrameAccess.newClosureArgumentsTemplate(closure, cachedBlock, getContextOrMarkerNode.execute(frame), 0));
}
示例7
@SuppressWarnings("unused")
@Specialization(guards = {"closure.getCompiledBlock() == cachedBlock", "cachedBlock.getNumArgs() == 1"}, assumptions = {"cachedBlock.getCallTargetStable()"}, limit = "INLINE_CACHE_SIZE")
protected static final Object doValueDirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg,
@Cached("closure.getCompiledBlock()") final CompiledBlockObject cachedBlock,
@Cached final GetContextOrMarkerNode getContextOrMarkerNode,
@Cached("create(cachedBlock.getCallTarget())") final DirectCallNode directCallNode) {
final Object[] frameArguments = FrameAccess.newClosureArgumentsTemplate(closure, cachedBlock, getContextOrMarkerNode.execute(frame), 1);
frameArguments[FrameAccess.getArgumentStartIndex()] = arg;
return directCallNode.call(frameArguments);
}
示例8
@SuppressWarnings("unused")
@Specialization(guards = {"closure.getCompiledBlock() == cachedBlock", "cachedBlock.getNumArgs() == 2"}, assumptions = {"cachedBlock.getCallTargetStable()"}, limit = "INLINE_CACHE_SIZE")
protected static final Object doValueDirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg1, final Object arg2,
@Cached("closure.getCompiledBlock()") final CompiledBlockObject cachedBlock,
@Cached final GetContextOrMarkerNode getContextOrMarkerNode,
@Cached("create(cachedBlock.getCallTarget())") final DirectCallNode directCallNode) {
final Object[] frameArguments = FrameAccess.newClosureArgumentsTemplate(closure, cachedBlock, getContextOrMarkerNode.execute(frame), 2);
frameArguments[FrameAccess.getArgumentStartIndex()] = arg1;
frameArguments[FrameAccess.getArgumentStartIndex() + 1] = arg2;
return directCallNode.call(frameArguments);
}
示例9
@SuppressWarnings("unused")
@Specialization(guards = {"closure.getCompiledBlock() == cachedBlock", "cachedBlock.getNumArgs() == 3"}, assumptions = {"cachedBlock.getCallTargetStable()"}, limit = "INLINE_CACHE_SIZE")
protected static final Object doValueDirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg1, final Object arg2, final Object arg3,
@Cached("closure.getCompiledBlock()") final CompiledBlockObject cachedBlock,
@Cached final GetContextOrMarkerNode getContextOrMarkerNode,
@Cached("create(cachedBlock.getCallTarget())") final DirectCallNode directCallNode) {
final Object[] frameArguments = FrameAccess.newClosureArgumentsTemplate(closure, cachedBlock, getContextOrMarkerNode.execute(frame), 3);
frameArguments[FrameAccess.getArgumentStartIndex()] = arg1;
frameArguments[FrameAccess.getArgumentStartIndex() + 1] = arg2;
frameArguments[FrameAccess.getArgumentStartIndex() + 2] = arg3;
return directCallNode.call(frameArguments);
}
示例10
@SuppressWarnings("unused")
@Specialization(guards = {"closure.getCompiledBlock() == cachedBlock", "cachedBlock.getNumArgs() == 4"}, assumptions = {"cachedBlock.getCallTargetStable()"}, limit = "INLINE_CACHE_SIZE")
protected static final Object doValue4Direct(final VirtualFrame frame, final BlockClosureObject closure, final Object arg1, final Object arg2, final Object arg3, final Object arg4,
final NotProvided arg5,
@Cached("closure.getCompiledBlock()") final CompiledBlockObject cachedBlock,
@Cached final GetContextOrMarkerNode getContextOrMarkerNode,
@Cached("create(cachedBlock.getCallTarget())") final DirectCallNode directCallNode) {
final Object[] frameArguments = FrameAccess.newClosureArgumentsTemplate(closure, cachedBlock, getContextOrMarkerNode.execute(frame), 4);
frameArguments[FrameAccess.getArgumentStartIndex()] = arg1;
frameArguments[FrameAccess.getArgumentStartIndex() + 1] = arg2;
frameArguments[FrameAccess.getArgumentStartIndex() + 2] = arg3;
frameArguments[FrameAccess.getArgumentStartIndex() + 3] = arg4;
return directCallNode.call(frameArguments);
}
示例11
@SuppressWarnings("unused")
@Specialization(guards = {"closure.getCompiledBlock() == cachedBlock", "cachedBlock.getNumArgs() == sizeNode.execute(argArray)"}, assumptions = {
"cachedBlock.getCallTargetStable()"}, limit = "INLINE_CACHE_SIZE")
protected static final Object doValueDirect(final VirtualFrame frame, final BlockClosureObject closure, final ArrayObject argArray,
@SuppressWarnings("unused") @Cached final SqueakObjectSizeNode sizeNode,
@Cached("closure.getCompiledBlock()") final CompiledBlockObject cachedBlock,
@Cached("createForFrameArguments()") final ArrayObjectCopyIntoObjectArrayNode copyIntoNode,
@Cached final GetContextOrMarkerNode getContextOrMarkerNode,
@Cached("create(cachedBlock.getCallTarget())") final DirectCallNode directCallNode) {
final Object[] frameArguments = FrameAccess.newClosureArgumentsTemplate(closure, getContextOrMarkerNode.execute(frame), sizeNode.execute(argArray));
copyIntoNode.execute(frameArguments, argArray);
return directCallNode.call(frameArguments);
}
示例12
@SuppressWarnings("unused")
@Specialization(guards = {"closure.getCompiledBlock() == cachedBlock"}, assumptions = {"cachedBlock.getCallTargetStable()"}, limit = "INLINE_CACHE_SIZE")
protected static final Object doDirect(final BlockClosureObject closure, final Object[] arguments,
@Cached("closure.getCompiledBlock()") final CompiledBlockObject cachedBlock,
@Cached("create(cachedBlock.getCallTarget())") final DirectCallNode directCallNode) {
return directCallNode.call(arguments);
}
示例13
@Specialization(guards = {"method == cachedMethod"}, //
limit = "INLINE_CACHE_SIZE", assumptions = {"cachedMethod.getCallTargetStable()", "cachedMethod.getDoesNotNeedSenderAssumption()"}, replaces = "doPrimitiveEagerly")
protected static final Object doDirect(final VirtualFrame frame, @SuppressWarnings("unused") final CompiledMethodObject method, final Object[] receiverAndArguments,
@SuppressWarnings("unused") @Cached("method") final CompiledMethodObject cachedMethod,
@Cached final GetContextOrMarkerNode getContextOrMarkerNode,
@Cached("create(cachedMethod.getCallTarget())") final DirectCallNode callNode) {
return callDirect(callNode, cachedMethod, getContextOrMarkerNode.execute(frame), receiverAndArguments);
}
示例14
@Specialization(guards = {"method == cachedMethod"}, //
limit = "INLINE_CACHE_SIZE", assumptions = {"cachedMethod.getCallTargetStable()"}, replaces = {"doPrimitiveEagerly"})
protected static final Object doDirectWithSender(final VirtualFrame frame, @SuppressWarnings("unused") final CompiledMethodObject method, final Object[] receiverAndArguments,
@SuppressWarnings("unused") @Cached("method") final CompiledMethodObject cachedMethod,
@Cached("create(true)") final GetOrCreateContextNode getOrCreateContextNode,
@Cached("create(cachedMethod.getCallTarget())") final DirectCallNode callNode) {
return callDirect(callNode, cachedMethod, getOrCreateContextNode.executeGet(frame), receiverAndArguments);
}
示例15
public HashemEvalRootNode(HashemLanguage language, RootCallTarget rootFunction, Map<String, RootCallTarget> functions) {
super(language);
this.functions = functions;
this.mainCallNode = rootFunction != null ? DirectCallNode.create(rootFunction) : null;
}
示例16
private static Object callDirect(final DirectCallNode callNode, final CompiledMethodObject cachedMethod, final Object contextOrMarker, final Object[] receiverAndArguments) {
return callNode.call(FrameAccess.newWith(cachedMethod, contextOrMarker, null, receiverAndArguments));
}
示例17
/**
* Inline cached specialization of the dispatch.
*
* <p>
* SinceHashemiis a quite simple language, the benefit of the inline cache seems small: after
* checking that the actual function to be executed is the same as the cachedFuntion, we can
* safely execute the cached call target. You can reasonably argue that caching the call
* target is overkill, since we could just retrieve it via {@code function.getCallTarget()}.
* However, caching the call target and using a {@link DirectCallNode} allows Truffle to
* perform method inlining. In addition, in a more complex language the lookup of the call
* target is usually much more complicated than in SL.
* </p>
*
* <p>
* {@code limit = "INLINE_CACHE_SIZE"} Specifies the limit number of inline cache
* specialization instantiations.
* </p>
* <p>
* {@code guards = "function.getCallTarget() == cachedTarget"} The inline cache check. Note
* that cachedTarget is a final field so that the compiler can optimize the check.
* </p>
* <p>
* {@code assumptions = "callTargetStable"} Support for function redefinition: When a
* function is redefined, the call target maintained by the SLFunction object is changed. To
* avoid a check for that, we use an Assumption that is invalidated by the SLFunction when
* the change is performed. Since checking an assumption is a no-op in compiled code, the
* assumption check performed by the DSL does not add any overhead during optimized
* execution.
* </p>
*
* @see Cached
* @see Specialization
*
* @param function the dynamically provided function
* @param cachedFunction the cached function of the specialization instance
* @param callNode the {@link DirectCallNode} specifically created for the
* {@link CallTarget} in cachedFunction.
*/
@Specialization(limit = "INLINE_CACHE_SIZE", //
guards = "function.getCallTarget() == cachedTarget", //
assumptions = "callTargetStable")
@SuppressWarnings("unused")
protected static Object doDirect(HashemBebin function, Object[] arguments,
@Cached("function.getCallTargetStable()") Assumption callTargetStable,
@Cached("function.getCallTarget()") RootCallTarget cachedTarget,
@Cached("create(cachedTarget)") DirectCallNode callNode) {
/* Inline cache hit, we are safe to execute the cached call target. */
Object returnValue = callNode.call(arguments);
return returnValue;
}