Search in sources :

Example 6 with RootCallTarget

use of com.oracle.truffle.api.RootCallTarget in project graal by oracle.

the class DebugStackFrame method findCurrentRoot.

RootNode findCurrentRoot() {
    SuspendedContext context = getContext();
    if (currentFrame == null) {
        return context.getInstrumentedNode().getRootNode();
    } else {
        Node callNode = currentFrame.getCallNode();
        if (callNode != null) {
            return callNode.getRootNode();
        }
        CallTarget target = currentFrame.getCallTarget();
        if (target instanceof RootCallTarget) {
            return ((RootCallTarget) target).getRootNode();
        }
        return null;
    }
}
Also used : RootCallTarget(com.oracle.truffle.api.RootCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) RootCallTarget(com.oracle.truffle.api.RootCallTarget)

Example 7 with RootCallTarget

use of com.oracle.truffle.api.RootCallTarget in project graal by oracle.

the class TruffleRuntimeTest method testCreateCallTarget.

@Test
public void testCreateCallTarget() {
    RootNode rootNode = createTestRootNode(null);
    RootCallTarget target = runtime.createCallTarget(rootNode);
    assertNotNull(target);
    assertEquals(target.call(), 42);
    assertSame(rootNode, target.getRootNode());
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) RootCallTarget(com.oracle.truffle.api.RootCallTarget) Test(org.junit.Test)

Example 8 with RootCallTarget

use of com.oracle.truffle.api.RootCallTarget in project graal by oracle.

the class Context method initializeContext.

@Override
protected void initializeContext(Context context) throws Exception {
    super.initializeContext(context);
    Source code = context.initSource;
    if (code != null) {
        SourceSection outer = code.createSection(0, code.getLength());
        BaseNode node = parse(code);
        RootCallTarget rct = Truffle.getRuntime().createCallTarget(new InstrumentationTestRootNode(this, "", outer, node));
        rct.call();
        if (context.runInitAfterExec) {
            context.afterTarget = rct;
        }
    }
}
Also used : SourceSection(com.oracle.truffle.api.source.SourceSection) RootCallTarget(com.oracle.truffle.api.RootCallTarget) Source(com.oracle.truffle.api.source.Source)

Example 9 with RootCallTarget

use of com.oracle.truffle.api.RootCallTarget in project graal by oracle.

the class SLLanguage method parse.

@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
    Source source = request.getSource();
    Map<String, RootCallTarget> functions;
    /*
         * Parse the provided source. At this point, we do not have a SLContext yet. Registration of
         * the functions with the SLContext happens lazily in SLEvalRootNode.
         */
    if (request.getArgumentNames().isEmpty()) {
        functions = Parser.parseSL(this, source);
    } else {
        StringBuilder sb = new StringBuilder();
        sb.append("function main(");
        String sep = "";
        for (String argumentName : request.getArgumentNames()) {
            sb.append(sep);
            sb.append(argumentName);
            sep = ",";
        }
        sb.append(") { return ");
        sb.append(request.getSource().getCharacters());
        sb.append(";}");
        Source decoratedSource = Source.newBuilder(sb.toString()).mimeType(request.getSource().getMimeType()).name(request.getSource().getName()).build();
        functions = Parser.parseSL(this, decoratedSource);
    }
    RootCallTarget main = functions.get("main");
    RootNode evalMain;
    if (main != null) {
        /*
             * We have a main function, so "evaluating" the parsed source means invoking that main
             * function. However, we need to lazily register functions into the SLContext first, so
             * we cannot use the original SLRootNode for the main function. Instead, we create a new
             * SLEvalRootNode that does everything we need.
             */
        evalMain = new SLEvalRootNode(this, main, functions);
    } else {
        /*
             * Even without a main function, "evaluating" the parsed source needs to register the
             * functions into the SLContext.
             */
        evalMain = new SLEvalRootNode(this, null, functions);
    }
    return Truffle.getRuntime().createCallTarget(evalMain);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) SLEvalRootNode(com.oracle.truffle.sl.nodes.SLEvalRootNode) SLEvalRootNode(com.oracle.truffle.sl.nodes.SLEvalRootNode) RootCallTarget(com.oracle.truffle.api.RootCallTarget) Source(com.oracle.truffle.api.source.Source)

Example 10 with RootCallTarget

use of com.oracle.truffle.api.RootCallTarget in project graal by oracle.

the class OptimizedOSRLoopNodeTest method testNoOSRAfterMinInvocationThreshold.

/*
     * Test that if a call target is called a min invocation theshold times it is unlikely that it
     * needs OSR at all.
     */
@Theory
public void testNoOSRAfterMinInvocationThreshold(OSRLoopFactory factory) {
    TestRootNode rootNode = new TestRootNode(factory, new TestRepeatingNode());
    RootCallTarget target = runtime.createCallTarget(rootNode);
    int i;
    for (i = 0; i < TruffleCompilerOptions.getValue(TruffleMinInvokeThreshold); i++) {
        target.call(0);
        assertNotCompiled(rootNode.getOSRTarget());
    }
    target.call(OSR_THRESHOLD);
    assertNotCompiled(rootNode.getOSRTarget());
}
Also used : RootCallTarget(com.oracle.truffle.api.RootCallTarget) DataPoint(org.junit.experimental.theories.DataPoint) Theory(org.junit.experimental.theories.Theory)

Aggregations

RootCallTarget (com.oracle.truffle.api.RootCallTarget)26 RootNode (com.oracle.truffle.api.nodes.RootNode)8 CallTarget (com.oracle.truffle.api.CallTarget)4 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)4 Source (com.oracle.truffle.api.source.Source)4 Test (org.junit.Test)4 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)3 StackPointer (com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer)3 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)2 SourceSection (com.oracle.truffle.api.source.SourceSection)2 GlobalValueSymbol (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol)2 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)2 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)2 OptimizedDirectCallNode (org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode)2 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 Truffle (com.oracle.truffle.api.Truffle)1 TruffleContext (com.oracle.truffle.api.TruffleContext)1 Env (com.oracle.truffle.api.TruffleLanguage.Env)1 ControlFlowException (com.oracle.truffle.api.nodes.ControlFlowException)1