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

The following examples show how to use com.oracle.truffle.api.nodes.IndirectCallNode. 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: HashemAddHandlerBuiltin.java    From mr-hashemi with Universal Permissive License v1.0 6 votes vote down vote up
@TruffleBoundary
public String doAddHandler(HashemWebServer server, HashemBebin source, HashemContext context, IndirectCallNode callNode) {
    server.getValue().createContext("/", new HttpHandler() {
        @Override
        public void handle(HttpExchange exchange) throws IOException {
            try {
                DynamicObject answer = (DynamicObject) callNode.call(source.getCallTarget());
                int rCode = ((Long) answer.get("status", 200)).intValue();
                String body = (String) answer.get("body", "");
                byte[] response = body.getBytes();
                exchange.sendResponseHeaders(rCode, response.length);
                exchange.getResponseBody().write(response);
                exchange.getResponseBody().close();
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    });
    return "";
}
 
Example #2
Source File: DispatchEagerlyNode.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Specialization(guards = {"cachedMethod.hasPrimitive()", "method == cachedMethod", "primitiveNode != null"}, //
                limit = "INLINE_CACHE_SIZE", assumptions = {"cachedMethod.getCallTargetStable()"}, rewriteOn = PrimitiveFailed.class)
protected static final Object doPrimitiveEagerly(final VirtualFrame frame, @SuppressWarnings("unused") final CompiledMethodObject method, final Object[] receiverAndArguments,
                @SuppressWarnings("unused") @Cached("method") final CompiledMethodObject cachedMethod,
                @Cached("forIndex(cachedMethod, false, cachedMethod.primitiveIndex())") final AbstractPrimitiveNode primitiveNode,
                @Cached final CreateEagerArgumentsNode createEagerArgumentsNode,
                @Cached final PrimitiveFailedCounter failureCounter) {
    try {
        return primitiveNode.executeWithArguments(frame, createEagerArgumentsNode.executeCreate(primitiveNode.getNumArguments(), receiverAndArguments));
    } catch (final PrimitiveFailed pf) {
        CompilerDirectives.transferToInterpreterAndInvalidate();
        if (failureCounter.shouldNoLongerSendEagerly()) {
            throw pf; // Rewrite specialization.
        } else {
            // Slow path send to fallback code.
            return IndirectCallNode.getUncached().call(cachedMethod.getCallTarget(),
                            FrameAccess.newWith(cachedMethod, FrameAccess.getContextOrMarkerSlow(frame), null, receiverAndArguments));
        }
    }
}
 
Example #3
Source File: BlockClosurePrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"closure.getNumArgs() == 2"}, replaces = "doValueDirect")
protected static final Object doValueIndirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg1, final Object arg2,
                @Cached final GetContextOrMarkerNode getContextOrMarkerNode,
                @Cached final IndirectCallNode indirectCallNode) {
    final Object[] frameArguments = FrameAccess.newClosureArgumentsTemplate(closure, getContextOrMarkerNode.execute(frame), 2);
    frameArguments[FrameAccess.getArgumentStartIndex()] = arg1;
    frameArguments[FrameAccess.getArgumentStartIndex() + 1] = arg2;
    return indirectCallNode.call(closure.getCompiledBlock().getCallTarget(), frameArguments);
}
 
Example #4
Source File: DispatchEagerlyNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = "!doesNotNeedSender(method, assumptionProfile)", replaces = {"doDirect", "doDirectWithSender"}, limit = "1")
protected static final Object doIndirectWithSender(final VirtualFrame frame, final CompiledMethodObject method, final Object[] receiverAndArguments,
                @Cached("create(true)") final GetOrCreateContextNode getOrCreateContextNode,
                @SuppressWarnings("unused") @Shared("assumptionProfile") @Cached("createClassProfile()") final ValueProfile assumptionProfile,
                @Cached final IndirectCallNode callNode) {
    return callIndirect(callNode, method, getOrCreateContextNode.executeGet(frame), receiverAndArguments);
}
 
Example #5
Source File: DispatchEagerlyNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = "doesNotNeedSender(method, assumptionProfile)", replaces = {"doDirect", "doDirectWithSender"}, limit = "1")
protected static final Object doIndirect(final VirtualFrame frame, final CompiledMethodObject method, final Object[] receiverAndArguments,
                @Cached final GetContextOrMarkerNode getContextOrMarkerNode,
                @SuppressWarnings("unused") @Shared("assumptionProfile") @Cached("createClassProfile()") final ValueProfile assumptionProfile,
                @Cached final IndirectCallNode callNode) {
    return callIndirect(callNode, method, getContextOrMarkerNode.execute(frame), receiverAndArguments);
}
 
Example #6
Source File: BlockClosurePrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"closure.getNumArgs() == sizeNode.execute(argArray)"}, replaces = "doValueDirect", limit = "1")
protected static final Object doValueIndirect(final VirtualFrame frame, final BlockClosureObject closure, final ArrayObject argArray,
                @SuppressWarnings("unused") @Cached final SqueakObjectSizeNode sizeNode,
                @Cached("createForFrameArguments()") final ArrayObjectCopyIntoObjectArrayNode copyIntoNode,
                @Cached final GetContextOrMarkerNode getContextOrMarkerNode,
                @Cached final IndirectCallNode indirectCallNode) {
    final Object[] frameArguments = FrameAccess.newClosureArgumentsTemplate(closure, getContextOrMarkerNode.execute(frame), sizeNode.execute(argArray));
    copyIntoNode.execute(frameArguments, argArray);
    return indirectCallNode.call(closure.getCompiledBlock().getCallTarget(), frameArguments);
}
 
Example #7
Source File: BlockClosurePrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"!isNotProvided(arg5)", "closure.getNumArgs() == 5"}, replaces = "doValue5Direct")
protected static final Object doValue5Indirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg1, final Object arg2, final Object arg3, final Object arg4,
                final Object arg5,
                @Cached final GetContextOrMarkerNode getContextOrMarkerNode,
                @Cached final IndirectCallNode indirectCallNode) {
    final Object[] frameArguments = FrameAccess.newClosureArgumentsTemplate(closure, getContextOrMarkerNode.execute(frame), 4);
    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 indirectCallNode.call(closure.getCompiledBlock().getCallTarget(), frameArguments);
}
 
Example #8
Source File: BlockClosurePrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"closure.getNumArgs() == 4"}, replaces = "doValue4Direct")
protected static final Object doValue4Indirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg1, final Object arg2, final Object arg3, final Object arg4,
                @SuppressWarnings("unused") final NotProvided arg5,
                @Cached final GetContextOrMarkerNode getContextOrMarkerNode,
                @Cached final IndirectCallNode indirectCallNode) {
    final Object[] frameArguments = FrameAccess.newClosureArgumentsTemplate(closure, getContextOrMarkerNode.execute(frame), 4);
    frameArguments[FrameAccess.getArgumentStartIndex()] = arg1;
    frameArguments[FrameAccess.getArgumentStartIndex() + 1] = arg2;
    frameArguments[FrameAccess.getArgumentStartIndex() + 2] = arg3;
    frameArguments[FrameAccess.getArgumentStartIndex() + 3] = arg4;
    return indirectCallNode.call(closure.getCompiledBlock().getCallTarget(), frameArguments);
}
 
Example #9
Source File: BlockClosurePrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"closure.getNumArgs() == 3"}, replaces = "doValueDirect")
protected static final Object doValueIndirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg1, final Object arg2, final Object arg3,
                @Cached final GetContextOrMarkerNode getContextOrMarkerNode,
                @Cached final IndirectCallNode indirectCallNode) {
    final Object[] frameArguments = FrameAccess.newClosureArgumentsTemplate(closure, getContextOrMarkerNode.execute(frame), 3);
    frameArguments[FrameAccess.getArgumentStartIndex()] = arg1;
    frameArguments[FrameAccess.getArgumentStartIndex() + 1] = arg2;
    frameArguments[FrameAccess.getArgumentStartIndex() + 2] = arg3;
    return indirectCallNode.call(closure.getCompiledBlock().getCallTarget(), frameArguments);
}
 
Example #10
Source File: HashemAddHandlerBuiltin.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@Specialization
public String addHandler(HashemWebServer server,
                         HashemBebin source,
                         @CachedContext(HashemLanguage.class) HashemContext context,
                         @Cached() IndirectCallNode callNode) {
    return doAddHandler(server, source, context, callNode);
}
 
Example #11
Source File: BlockClosurePrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"closure.getNumArgs() == 1"}, replaces = "doValueDirect")
protected static final Object doValueIndirect(final VirtualFrame frame, final BlockClosureObject closure, final Object arg,
                @Cached final GetContextOrMarkerNode getContextOrMarkerNode,
                @Cached final IndirectCallNode indirectCallNode) {
    final Object[] frameArguments = FrameAccess.newClosureArgumentsTemplate(closure, getContextOrMarkerNode.execute(frame), 1);
    frameArguments[FrameAccess.getArgumentStartIndex()] = arg;
    return indirectCallNode.call(closure.getCompiledBlock().getCallTarget(), frameArguments);
}
 
Example #12
Source File: DispatchEagerlyFromStackNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = "!doesNotNeedSender(method, assumptionProfile)", replaces = {"doDirect", "doDirectWithSender"}, limit = "1")
protected static final Object doIndirectWithSender(final VirtualFrame frame, final CompiledMethodObject method,
                @Cached("create(true)") final GetOrCreateContextNode getOrCreateContextNode,
                @Cached("create(argumentCount)") final CreateFrameArgumentsNode argumentsNode,
                @SuppressWarnings("unused") @Shared("assumptionProfile") @Cached("createClassProfile()") final ValueProfile assumptionProfile,
                @Cached final IndirectCallNode callNode) {
    return callNode.call(method.getCallTarget(), argumentsNode.execute(frame, method, getOrCreateContextNode.executeGet(frame)));
}
 
Example #13
Source File: DispatchEagerlyFromStackNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = "doesNotNeedSender(method, assumptionProfile)", replaces = {"doDirect", "doDirectWithSender"}, limit = "1")
protected static final Object doIndirect(final VirtualFrame frame, final CompiledMethodObject method,
                @Cached final GetContextOrMarkerNode getContextOrMarkerNode,
                @Cached("create(argumentCount)") final CreateFrameArgumentsNode argumentsNode,
                @SuppressWarnings("unused") @Shared("assumptionProfile") @Cached("createClassProfile()") final ValueProfile assumptionProfile,
                @Cached final IndirectCallNode callNode) {
    return callNode.call(method.getCallTarget(), argumentsNode.execute(frame, method, getContextOrMarkerNode.execute(frame)));
}
 
Example #14
Source File: DispatchEagerlyFromStackNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"cachedMethod.hasPrimitive()", "method == cachedMethod", "primitiveNode != null"}, //
                limit = "INLINE_CACHE_SIZE", assumptions = {"cachedMethod.getCallTargetStable()"}, rewriteOn = PrimitiveFailed.class)
protected final Object doPrimitiveEagerly(final VirtualFrame frame, @SuppressWarnings("unused") final CompiledMethodObject method,
                @SuppressWarnings("unused") @Cached("method") final CompiledMethodObject cachedMethod,
                @Cached("forIndex(cachedMethod, true, cachedMethod.primitiveIndex())") final AbstractPrimitiveNode primitiveNode,
                @Cached("getStackPointerSlot(frame)") final FrameSlot stackPointerSlot,
                @Cached("getStackPointer(frame, stackPointerSlot)") final int stackPointer,
                @Cached final PrimitiveFailedCounter failureCounter) {
    /**
     * Pretend that values are popped off the stack. Primitive nodes will read them using
     * ArgumentOnStackNodes.
     */
    FrameAccess.setStackPointer(frame, stackPointerSlot, stackPointer - 1 - argumentCount);
    try {
        return primitiveNode.executePrimitive(frame);
    } catch (final PrimitiveFailed pf) {
        CompilerDirectives.transferToInterpreterAndInvalidate();
        // Restore stackPointer.
        FrameAccess.setStackPointer(frame, stackPointerSlot, stackPointer);
        if (failureCounter.shouldNoLongerSendEagerly()) {
            throw pf; // Rewrite specialization.
        } else {
            // Slow path send to fallback code.
            final Object[] receiverAndArguments = FrameStackPopNNode.create(1 + argumentCount).execute(frame);
            return IndirectCallNode.getUncached().call(method.getCallTarget(),
                            FrameAccess.newWith(cachedMethod, FrameAccess.getContextOrMarkerSlow(frame), null, receiverAndArguments));
        }
    }
}
 
Example #15
Source File: HashemBebin.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
/**
 * Slow-path code for a call, used when the polymorphic inline cache exceeded its maximum
 * size specified in <code>INLINE_CACHE_SIZE</code>. Such calls are not optimized any
 * further, e.g., no method inlining is performed.
 */
@Specialization(replaces = "doDirect")
protected static Object doIndirect(HashemBebin function, Object[] arguments,
                                   @Cached IndirectCallNode callNode) {
    /*
     *Hashemi has a quite simple call lookup: just ask the function for the current call target,
     * and call it.
     */
    return callNode.call(function.getCallTarget(), arguments);
}
 
Example #16
Source File: BlockClosurePrimitives.java    From trufflesqueak with MIT License 4 votes vote down vote up
@Specialization(guards = {"closure.getNumArgs() == 0"}, replaces = "doValueDirect")
protected static final Object doValueIndirect(final VirtualFrame frame, final BlockClosureObject closure,
                @Cached final GetContextOrMarkerNode getContextOrMarkerNode,
                @Cached final IndirectCallNode indirectCallNode) {
    return indirectCallNode.call(closure.getCompiledBlock().getCallTarget(), FrameAccess.newClosureArgumentsTemplate(closure, getContextOrMarkerNode.execute(frame), 0));
}
 
Example #17
Source File: DispatchClosureNode.java    From trufflesqueak with MIT License 4 votes vote down vote up
@Specialization(replaces = "doDirect")
protected static final Object doIndirect(final BlockClosureObject closure, final Object[] arguments,
                @Cached final IndirectCallNode indirectCallNode) {
    return indirectCallNode.call(closure.getCompiledBlock().getCallTarget(), arguments);
}
 
Example #18
Source File: DispatchUneagerlyNode.java    From trufflesqueak with MIT License 4 votes vote down vote up
@Specialization(replaces = "doDirect")
protected static final Object doIndirect(final CompiledMethodObject method, final Object[] receiverAndArguments, final Object contextOrMarker,
                @Cached final IndirectCallNode callNode) {
    return callNode.call(method.getCallTarget(), FrameAccess.newWith(method, contextOrMarker, null, receiverAndArguments));
}
 
Example #19
Source File: DispatchEagerlyNode.java    From trufflesqueak with MIT License 4 votes vote down vote up
private static Object callIndirect(final IndirectCallNode callNode, final CompiledMethodObject method, final Object contextOrMarker, final Object[] receiverAndArguments) {
    return callNode.call(method.getCallTarget(), FrameAccess.newWith(method, contextOrMarker, null, receiverAndArguments));
}