Search in sources :

Example 1 with RootNode

use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.

the class OptimizedCallTargetTest method testCompilationHeuristics.

/*
     * GR-1328
     */
@Test
@Ignore("Fails non deterministically")
public void testCompilationHeuristics() {
    testInvalidationCounterCompiled = 0;
    testInvalidationCounterInterpreted = 0;
    doInvalidate = false;
    OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {

        @Override
        public Object execute(VirtualFrame frame) {
            if (CompilerDirectives.inInterpreter()) {
                testInvalidationCounterInterpreted++;
            } else {
                testInvalidationCounterCompiled++;
            }
            // doInvalidate needs to be volatile otherwise it floats up.
            if (doInvalidate) {
                CompilerDirectives.transferToInterpreterAndInvalidate();
            }
            return null;
        }
    });
    final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
    final int reprofileCount = TruffleCompilerOptions.getValue(TruffleReplaceReprofileCount);
    assertTrue(compilationThreshold >= 2);
    int expectedCompiledCount = 0;
    int expectedInterpreterCount = 0;
    for (int i = 0; i < compilationThreshold; i++) {
        assertNotCompiled(target);
        target.call();
    }
    assertCompiled(target);
    expectedInterpreterCount += compilationThreshold;
    assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
    assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
    for (int j = 1; j < 100; j++) {
        target.invalidate(this, "test");
        for (int i = 0; i < reprofileCount; i++) {
            assertNotCompiled(target);
            target.call();
        }
        assertCompiled(target);
        expectedInterpreterCount += reprofileCount;
        assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
        assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
        doInvalidate = true;
        expectedCompiledCount++;
        target.call();
        assertNotCompiled(target);
        doInvalidate = false;
        assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
        assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
        for (int i = 0; i < reprofileCount; i++) {
            assertNotCompiled(target);
            target.call();
        }
        assertCompiled(target);
        expectedInterpreterCount += reprofileCount;
        assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
        assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
        for (int i = 0; i < compilationThreshold; i++) {
            assertCompiled(target);
            target.call();
        }
        assertCompiled(target);
        expectedCompiledCount += compilationThreshold;
        assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
        assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
    }
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with RootNode

use of com.oracle.truffle.api.nodes.RootNode 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 3 with RootNode

use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.

the class CastExactPartialEvaluationTest method testCommon.

private void testCommon(AbstractTestNode testNode, String testName) {
    FrameDescriptor fd = new FrameDescriptor();
    RootNode rootNode = new RootTestNode(fd, testName, testNode);
    RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
    Assert.assertEquals(42, callTarget.call(newBuffer()));
    assertPartialEvalNoInvokes(callTarget, new Object[] { newBuffer() });
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) RootNode(com.oracle.truffle.api.nodes.RootNode) RootCallTarget(com.oracle.truffle.api.RootCallTarget) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode)

Example 4 with RootNode

use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.

the class TruffleSplittingStrategy method shouldSplit.

private static boolean shouldSplit(OptimizedDirectCallNode call, GraalTVMCI.EngineData engineData) {
    if (engineData.splitCount + call.getCurrentCallTarget().getUninitializedNodeCount() > engineData.splitLimit) {
        return false;
    }
    if (!canSplit(call)) {
        return false;
    }
    OptimizedCallTarget callTarget = call.getCallTarget();
    int nodeCount = callTarget.getNonTrivialNodeCount();
    if (nodeCount > TruffleCompilerOptions.getValue(TruffleSplittingMaxCalleeSize)) {
        return false;
    }
    RootNode rootNode = call.getRootNode();
    if (rootNode == null) {
        return false;
    }
    // disable recursive splitting for now
    OptimizedCallTarget root = (OptimizedCallTarget) rootNode.getCallTarget();
    if (root == callTarget || root.getSourceCallTarget() == callTarget) {
        // recursive call found
        return false;
    }
    // Disable splitting if it will cause a deep split-only recursion
    if (isRecursiveSplit(call)) {
        return false;
    }
    // max one child call and callCount > 2 and kind of small number of nodes
    if (isMaxSingleCall(call)) {
        return true;
    }
    return countPolymorphic(call) >= 1;
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode)

Example 5 with RootNode

use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.

the class TruffleSplittingStrategy method isRecursiveSplit.

private static boolean isRecursiveSplit(OptimizedDirectCallNode call) {
    final OptimizedCallTarget splitCandidateTarget = call.getCallTarget();
    OptimizedCallTarget callRootTarget = (OptimizedCallTarget) call.getRootNode().getCallTarget();
    OptimizedCallTarget callSourceTarget = callRootTarget.getSourceCallTarget();
    int depth = 0;
    while (callSourceTarget != null) {
        if (callSourceTarget == splitCandidateTarget) {
            depth++;
            if (depth == 2) {
                return true;
            }
        }
        final OptimizedDirectCallNode splitCallSite = callRootTarget.getCallSiteForSplit();
        if (splitCallSite == null) {
            break;
        }
        final RootNode splitCallSiteRootNode = splitCallSite.getRootNode();
        if (splitCallSiteRootNode == null) {
            break;
        }
        callRootTarget = (OptimizedCallTarget) splitCallSiteRootNode.getCallTarget();
        if (callRootTarget == null) {
            break;
        }
        callSourceTarget = callRootTarget.getSourceCallTarget();
    }
    return false;
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode)

Aggregations

RootNode (com.oracle.truffle.api.nodes.RootNode)86 Test (org.junit.Test)36 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)24 Node (com.oracle.truffle.api.nodes.Node)23 CallTarget (com.oracle.truffle.api.CallTarget)16 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)16 RootCallTarget (com.oracle.truffle.api.RootCallTarget)12 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)12 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)9 Source (com.oracle.truffle.api.source.Source)8 AbstractTestNode (org.graalvm.compiler.truffle.test.nodes.AbstractTestNode)8 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)7 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)6 SourceSection (com.oracle.truffle.api.source.SourceSection)6 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)5 ArrayList (java.util.ArrayList)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)4 TruffleContext (com.oracle.truffle.api.TruffleContext)3 TruffleException (com.oracle.truffle.api.TruffleException)3 TruffleLanguage (com.oracle.truffle.api.TruffleLanguage)3