com.oracle.truffle.api.nodes.DirectCallNode Java Examples

The following examples show how to use com.oracle.truffle.api.nodes.DirectCallNode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlockClosurePrimitives.java    From trufflesqueak with MIT License 6 votes vote down vote up
@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);
}
 
Example #2
Source File: HashemEvalBuiltin.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@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[]{});
}
 
Example #3
Source File: DispatchEagerlyNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@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);
}
 
Example #4
Source File: DispatchEagerlyNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@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);
}
 
Example #5
Source File: DispatchClosureNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@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);
}
 
Example #6
Source File: BlockClosurePrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@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);
}
 
Example #7
Source File: BlockClosurePrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@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);
}
 
Example #8
Source File: BlockClosurePrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@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);
}
 
Example #9
Source File: BlockClosurePrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@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);
}
 
Example #10
Source File: BlockClosurePrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@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);
}
 
Example #11
Source File: BlockClosurePrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@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));
}
 
Example #12
Source File: DispatchEagerlyFromStackNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@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)));
}
 
Example #13
Source File: DispatchEagerlyFromStackNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@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)));
}
 
Example #14
Source File: DispatchUneagerlyNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@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));
}
 
Example #15
Source File: HashemEvalRootNode.java    From mr-hashemi with Universal Permissive License v1.0 4 votes vote down vote up
public HashemEvalRootNode(HashemLanguage language, RootCallTarget rootFunction, Map<String, RootCallTarget> functions) {
    super(language);
    this.functions = functions;
    this.mainCallNode = rootFunction != null ? DirectCallNode.create(rootFunction) : null;
}
 
Example #16
Source File: DispatchEagerlyNode.java    From trufflesqueak with MIT License 4 votes vote down vote up
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));
}
 
Example #17
Source File: HashemBebin.java    From mr-hashemi with Universal Permissive License v1.0 3 votes vote down vote up
/**
 * 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;
}