Search in sources :

Example 31 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.

the class TruffleBoundaryExceptionsTest method testExceptionOnTruffleBoundaryWithNoTransferToInterpreter.

@Test
public void testExceptionOnTruffleBoundaryWithNoTransferToInterpreter() {
    final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
    class DeoptCountingExceptionOverBoundaryRootNode extends RootNode {

        protected DeoptCountingExceptionOverBoundaryRootNode() {
            super(null);
        }

        int deopCounter = 0;

        int catchCounter = 0;

        @Override
        public Object execute(VirtualFrame frame) {
            boolean startedCompiled = CompilerDirectives.inCompiledCode();
            try {
                throwExceptionBoundary();
            } catch (RuntimeException e) {
                catchCounter++;
            }
            if (startedCompiled && CompilerDirectives.inInterpreter()) {
                deopCounter++;
            }
            return null;
        }

        @CompilerDirectives.TruffleBoundary(transferToInterpreterOnException = false)
        public void throwExceptionBoundary() {
            throw new RuntimeException();
        }
    }
    final OptimizedCallTarget outerTarget = (OptimizedCallTarget) runtime.createCallTarget(new DeoptCountingExceptionOverBoundaryRootNode());
    for (int i = 0; i < compilationThreshold; i++) {
        outerTarget.call();
    }
    assertCompiled(outerTarget);
    final int execCount = 10;
    for (int i = 0; i < execCount; i++) {
        outerTarget.call();
    }
    final int totalExecutions = compilationThreshold + execCount;
    int catchCount = ((DeoptCountingExceptionOverBoundaryRootNode) outerTarget.getRootNode()).catchCounter;
    Assert.assertEquals("Incorrect number of catch block executions", totalExecutions, catchCount);
    int deopCount = ((DeoptCountingExceptionOverBoundaryRootNode) outerTarget.getRootNode()).deopCounter;
    Assert.assertEquals("Incorrect number of deops detected!", 0, deopCount);
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Test(org.junit.Test)

Example 32 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.

the class IndirectCallSiteTest method testIndirectCallNodeDoesNotDeopOnFirstCall.

@Test
public void testIndirectCallNodeDoesNotDeopOnFirstCall() {
    final Object[] noArguments = new Object[0];
    final OptimizedCallTarget innerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {

        @Override
        public Object execute(VirtualFrame frame) {
            return null;
        }
    });
    final OptimizedCallTarget uninitializedInnerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {

        @Override
        public Object execute(VirtualFrame frame) {
            return null;
        }
    });
    final OptimizedCallTarget outerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {

        @Child
        OptimizedIndirectCallNode indirectCallNode = (OptimizedIndirectCallNode) runtime.createIndirectCallNode();

        @Override
        public Object execute(VirtualFrame frame) {
            if (frame.getArguments().length == 0) {
                return indirectCallNode.call(innerTarget, noArguments);
            } else {
                return indirectCallNode.call(uninitializedInnerTarget, noArguments);
            }
        }
    });
    final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
    for (int i = 0; i < compilationThreshold; i++) {
        outerTarget.call(noArguments);
    }
    assertCompiled(outerTarget);
    outerTarget.call(new Object[] { null });
    assertCompiled(outerTarget);
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) OptimizedIndirectCallNode(org.graalvm.compiler.truffle.runtime.OptimizedIndirectCallNode) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Test(org.junit.Test)

Example 33 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.

the class OptimizedCallTargetTest method testCompileOnly4.

@Test
public void testCompileOnly4() {
    // OSR should not trigger for compile-only includes
    try (TruffleOptionsOverrideScope scope = TruffleCompilerOptions.overrideOptions(TruffleCompileOnly, "foobar")) {
        final OSRRepeatingNode repeating = new OSRRepeatingNode(TruffleCompilerOptions.getValue(TruffleOSRCompilationThreshold));
        final LoopNode loop = runtime.createLoopNode(repeating);
        OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(new NamedRootNode("foobar") {

            @Child
            LoopNode loopChild = loop;

            @Override
            public Object execute(VirtualFrame frame) {
                loopChild.executeLoop(frame);
                return super.execute(frame);
            }
        });
        target.call();
        OptimizedCallTarget osrTarget = findOSRTarget(loop);
        if (osrTarget != null) {
            assertNotCompiled(osrTarget);
        }
    }
}
Also used : LoopNode(com.oracle.truffle.api.nodes.LoopNode) OptimizedOSRLoopNode(org.graalvm.compiler.truffle.runtime.OptimizedOSRLoopNode) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) TruffleOptionsOverrideScope(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Test(org.junit.Test)

Example 34 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.

the class BailoutPartialEvaluationTest method partialEvaluationConstantBailout2.

@Test(expected = BailoutException.class)
public void partialEvaluationConstantBailout2() {
    FrameDescriptor fd = new FrameDescriptor();
    RootTestNode rootNode = new RootTestNode(fd, "partialEvaluationConstantBailout2", new AbstractTestNode() {

        @Override
        public int execute(VirtualFrame frame) {
            CompilerAsserts.partialEvaluationConstant(notConstantInt);
            return 0;
        }
    });
    compileHelper("partialEvaluationConstantBailout2", rootNode, new Object[] {});
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 35 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.

the class SLInstrumentTest method testLexicalScopes.

@Test
public void testLexicalScopes() throws Exception {
    String code = "function test(n) {\n" + // 2
    "  a = 1;\n" + "  if (a > 0) {\n" + "    b = 10;\n" + // 5
    "    println(b);\n" + "  }\n" + "  if (a == 1) {\n" + "    b = 20;\n" + "    a = 0;\n" + // 10
    "    c = 1;\n" + "    if (b > 0) {\n" + "      a = 4;\n" + "      b = 5;\n" + "      c = 6;\n" + // 15
    "      d = 7;\n" + "      println(d);\n" + "    }\n" + "  }\n" + "  println(b);\n" + // 20
    "  println(a);\n" + "}\n" + "function main() {\n" + "  test(\"n_n\");\n" + "}";
    Source source = Source.newBuilder("sl", code, "testing").build();
    List<Throwable> throwables;
    try (Engine engine = Engine.newBuilder().out(new java.io.OutputStream() {

        // null output stream
        @Override
        public void write(int b) throws IOException {
        }
    }).build()) {
        Instrument envInstr = engine.getInstruments().get("testEnvironmentHandlerInstrument");
        TruffleInstrument.Env env = envInstr.lookup(Environment.class).env;
        throwables = new ArrayList<>();
        env.getInstrumenter().attachExecutionEventListener(SourceSectionFilter.newBuilder().lineIn(1, source.getLineCount()).build(), new ExecutionEventListener() {

            @Override
            public void onEnter(EventContext context, VirtualFrame frame) {
                Node node = context.getInstrumentedNode();
                Iterable<Scope> lexicalScopes = env.findLocalScopes(node, null);
                Iterable<Scope> dynamicScopes = env.findLocalScopes(node, frame);
                try {
                    verifyLexicalScopes(lexicalScopes, dynamicScopes, context.getInstrumentedSourceSection().getStartLine(), frame.materialize());
                } catch (ThreadDeath t) {
                    throw t;
                } catch (Throwable t) {
                    CompilerDirectives.transferToInterpreter();
                    PrintStream lsErr = System.err;
                    lsErr.println("Line = " + context.getInstrumentedSourceSection().getStartLine());
                    lsErr.println("Node = " + node + ", class = " + node.getClass().getName());
                    t.printStackTrace(lsErr);
                    throwables.add(t);
                }
            }

            @Override
            public void onReturnValue(EventContext context, VirtualFrame frame, Object result) {
            }

            @Override
            public void onReturnExceptional(EventContext context, VirtualFrame frame, Throwable exception) {
            }
        });
        Context.newBuilder().engine(engine).build().eval(source);
    }
    assertTrue(throwables.toString(), throwables.isEmpty());
}
Also used : TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RootNode(com.oracle.truffle.api.nodes.RootNode) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) Node(com.oracle.truffle.api.nodes.Node) Source(org.graalvm.polyglot.Source) ExecutionEventListener(com.oracle.truffle.api.instrumentation.ExecutionEventListener) EventContext(com.oracle.truffle.api.instrumentation.EventContext) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) Instrument(org.graalvm.polyglot.Instrument) TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Engine(org.graalvm.polyglot.Engine) Test(org.junit.Test)

Aggregations

VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)48 Test (org.junit.Test)34 RootNode (com.oracle.truffle.api.nodes.RootNode)27 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)14 CallTarget (com.oracle.truffle.api.CallTarget)11 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)9 RootCallTarget (com.oracle.truffle.api.RootCallTarget)6 EventContext (com.oracle.truffle.api.instrumentation.EventContext)5 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)5 ExecutionEventListener (com.oracle.truffle.api.instrumentation.ExecutionEventListener)4 Node (com.oracle.truffle.api.nodes.Node)4 AbstractTestNode (org.graalvm.compiler.truffle.test.nodes.AbstractTestNode)4 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)4 Ignore (org.junit.Ignore)4 TruffleContext (com.oracle.truffle.api.TruffleContext)3 TruffleException (com.oracle.truffle.api.TruffleException)3 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)3 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)3 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)3 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)3