Search in sources :

Example 6 with VirtualFrame

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

the class OptimizedCallTargetTest method testCompileOnly5.

@Test
public void testCompileOnly5() {
    // OSR should trigger if compile-only with excludes
    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);
        assertCompiled(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 7 with VirtualFrame

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

the class OptimizedCallTargetTest method testInCompilationRootDirective.

@Ignore
@Test
public void testInCompilationRootDirective() {
    final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
    int[] outerExecute = { 0 };
    int[] outerMethod = { 0 };
    int[] outerBoundary = { 0 };
    int[] innerExecute = { 0 };
    int[] innerMethod = { 0 };
    int[] innerBoundary = { 0 };
    final OptimizedCallTarget innerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {

        @Override
        public String toString() {
            return "inner";
        }

        @Override
        public Object execute(VirtualFrame frame) {
            // FALSE
            if (CompilerDirectives.inCompilationRoot()) {
                innerExecute[0]++;
            }
            innerMethod();
            return null;
        }

        @CompilerDirectives.TruffleBoundary
        void innerMethod() {
            // FALSE
            if (CompilerDirectives.inCompilationRoot()) {
                innerMethod[0]++;
            }
        }

        @CompilerDirectives.TruffleBoundary
        void innerBoundary() {
            // FALSE
            if (CompilerDirectives.inCompilationRoot()) {
                innerBoundary[0] = 1;
            }
        }
    });
    final OptimizedCallTarget outerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {

        @Override
        public String toString() {
            return "outer";
        }

        @Child
        private DirectCallNode child = runtime.createDirectCallNode(innerTarget);

        @Override
        public Object execute(VirtualFrame frame) {
            // TRUE
            if (CompilerDirectives.inCompilationRoot()) {
                outerExecute[0]++;
            }
            outerMethod();
            return child.call(new Object[0]);
        }

        void outerMethod() {
            // TRUE
            if (CompilerDirectives.inCompilationRoot()) {
                outerMethod[0]++;
                outerBoundary();
            }
        }

        @CompilerDirectives.TruffleBoundary
        void outerBoundary() {
            // FALSE
            if (CompilerDirectives.inCompilationRoot()) {
                outerBoundary[0]++;
            }
        }
    });
    for (int i = 0; i < compilationThreshold; i++) {
        outerTarget.call();
    }
    assertCompiled(outerTarget);
    final int executionCount = 10;
    for (int i = 0; i < executionCount; i++) {
        outerTarget.call();
    }
    Assert.assertEquals(executionCount, outerExecute[0]);
    Assert.assertEquals(executionCount, outerMethod[0]);
    Assert.assertEquals(0, outerBoundary[0]);
    Assert.assertEquals(0, innerExecute[0]);
    Assert.assertEquals(0, innerMethod[0]);
    Assert.assertEquals(0, innerBoundary[0]);
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with VirtualFrame

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

the class OptimizedCallTargetTest method testRewriteAssumption.

@Test
public void testRewriteAssumption() {
    String testName = "testRewriteAssumption";
    assertTrue("test only works with inlining enabled", TruffleCompilerOptions.getValue(TruffleFunctionInlining));
    try (TruffleOptionsOverrideScope s = TruffleCompilerOptions.overrideOptions(TruffleCompilerOptions.TruffleCompilationThreshold, 20)) {
        final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
        assertTrue(compilationThreshold >= 2);
        OptimizedCallTarget innermostCallTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootTestNode(new FrameDescriptor(), testName + 0, new AbstractTestNode() {

            @Child
            private AbstractTestNode child = new ConstantTestNode(42);

            @Child
            private AbstractTestNode dummy = new ConstantTestNode(17);

            @Override
            public int execute(VirtualFrame frame) {
                int k = (int) frame.getArguments()[0];
                if (k > compilationThreshold) {
                    CompilerDirectives.transferToInterpreter();
                    dummy.replace(new ConstantTestNode(k));
                }
                return child.execute(frame);
            }
        }));
        OptimizedCallTarget ct = innermostCallTarget;
        ct = (OptimizedCallTarget) runtime.createCallTarget(new RootTestNode(new FrameDescriptor(), testName + 1, new CallTestNode(ct)));
        ct = (OptimizedCallTarget) runtime.createCallTarget(new RootTestNode(new FrameDescriptor(), testName + 2, new CallTestNode(ct)));
        final OptimizedCallTarget outermostCallTarget = ct;
        assertNull("assumption is initially null", getRewriteAssumption(innermostCallTarget));
        IntStream.range(0, compilationThreshold / 2).parallel().forEach(k -> {
            assertEquals(42, outermostCallTarget.call(k));
            assertNull("assumption stays null in the interpreter", getRewriteAssumption(innermostCallTarget));
        });
        outermostCallTarget.compile();
        assertCompiled(outermostCallTarget);
        Assumption firstRewriteAssumption = getRewriteAssumption(innermostCallTarget);
        assertNotNull("assumption must not be null after compilation", firstRewriteAssumption);
        assertTrue(firstRewriteAssumption.isValid());
        List<Assumption> rewriteAssumptions = IntStream.range(0, 2 * compilationThreshold).parallel().mapToObj(k -> {
            assertEquals(42, outermostCallTarget.call(k));
            Assumption rewriteAssumptionAfter = getRewriteAssumption(innermostCallTarget);
            assertNotNull("assumption must not be null after compilation", rewriteAssumptionAfter);
            return rewriteAssumptionAfter;
        }).collect(Collectors.toList());
        Assumption finalRewriteAssumption = getRewriteAssumption(innermostCallTarget);
        assertNotNull("assumption must not be null after compilation", finalRewriteAssumption);
        assertNotSame(firstRewriteAssumption, finalRewriteAssumption);
        assertFalse(firstRewriteAssumption.isValid());
        assertTrue(finalRewriteAssumption.isValid());
        assertFalse(rewriteAssumptions.stream().filter(a -> a != finalRewriteAssumption).anyMatch(Assumption::isValid));
    }
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) IntStream(java.util.stream.IntStream) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) ConstantTestNode(org.graalvm.compiler.truffle.test.nodes.ConstantTestNode) Assert.assertNotSame(org.junit.Assert.assertNotSame) TruffleCompileOnly(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleCompileOnly) TruffleOptionsOverrideScope(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope) FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) CompilerDirectives(com.oracle.truffle.api.CompilerDirectives) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) LoopNode(com.oracle.truffle.api.nodes.LoopNode) RootNode(com.oracle.truffle.api.nodes.RootNode) TruffleReplaceReprofileCount(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleReplaceReprofileCount) TruffleOSRCompilationThreshold(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOSRCompilationThreshold) RepeatingNode(com.oracle.truffle.api.nodes.RepeatingNode) Node(com.oracle.truffle.api.nodes.Node) TruffleFunctionInlining(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleFunctionInlining) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Assumption(com.oracle.truffle.api.Assumption) Test(org.junit.Test) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) GraalTruffleRuntime(org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) Assert.assertFalse(org.junit.Assert.assertFalse) OptimizedOSRLoopNode(org.graalvm.compiler.truffle.runtime.OptimizedOSRLoopNode) TruffleCompilerOptions(org.graalvm.compiler.truffle.common.TruffleCompilerOptions) Truffle(com.oracle.truffle.api.Truffle) TruffleCompilationThreshold(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleCompilationThreshold) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Util(org.graalvm.compiler.core.common.util.Util) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Assumption(com.oracle.truffle.api.Assumption) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) ConstantTestNode(org.graalvm.compiler.truffle.test.nodes.ConstantTestNode) TruffleOptionsOverrideScope(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 9 with VirtualFrame

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

the class BailoutPartialEvaluationTest method partialEvaluationConstantBailout1.

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

        @Override
        public int execute(VirtualFrame frame) {
            CompilerAsserts.partialEvaluationConstant(notConstant);
            return 0;
        }
    });
    compileHelper("partialEvaluationConstantBailout1", 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 10 with VirtualFrame

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

the class OptimizedOSRLoopNode method forceOSR.

/**
 * Forces OSR compilation for this loop.
 */
public final void forceOSR() {
    baseLoopCount = getThreshold();
    RootNode rootNode = getRootNode();
    VirtualFrame dummyFrame = Truffle.getRuntime().createVirtualFrame(new Object[0], rootNode != null ? rootNode.getFrameDescriptor() : new FrameDescriptor());
    compileLoop(dummyFrame);
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) RootNode(com.oracle.truffle.api.nodes.RootNode)

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