Search in sources :

Example 21 with OptimizedCallTarget

use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.

the class TruffleBoundaryExceptionsTest method testExceptionOnTruffleBoundaryDoesNotDeop.

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

        protected DeoptCountingExceptionOverBoundaryRootNode() {
            super(null);
        }

        int deopCounter = 0;

        int catchCounter = 0;

        int interpretCount = 0;

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

        @CompilerDirectives.TruffleBoundary
        public void throwExceptionBoundary() {
            throw new RuntimeException();
        }
    }
    final int[] compilationCount = { 0 };
    GraalTruffleRuntimeListener listener = new GraalTruffleRuntimeListener() {

        @Override
        public void onCompilationStarted(OptimizedCallTarget target) {
            compilationCount[0]++;
        }
    };
    final OptimizedCallTarget outerTarget = (OptimizedCallTarget) runtime.createCallTarget(new DeoptCountingExceptionOverBoundaryRootNode());
    for (int i = 0; i < compilationThreshold; i++) {
        outerTarget.call();
    }
    assertCompiled(outerTarget);
    runtime.addListener(listener);
    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 interpretCount = ((DeoptCountingExceptionOverBoundaryRootNode) outerTarget.getRootNode()).interpretCount;
    int deopCount = ((DeoptCountingExceptionOverBoundaryRootNode) outerTarget.getRootNode()).deopCounter;
    Assert.assertEquals("Incorrect number of deops detected!", totalExecutions - interpretCount, deopCount);
    Assert.assertEquals("Compilation happened!", 0, compilationCount[0]);
    runtime.removeListener(listener);
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) GraalTruffleRuntimeListener(org.graalvm.compiler.truffle.runtime.GraalTruffleRuntimeListener) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Test(org.junit.Test)

Example 22 with OptimizedCallTarget

use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.

the class TruffleBoundaryExceptionsTest method testExceptionOnTruffleBoundaryWithNoCatchTransferFalse.

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

        protected DeoptCountingExceptionOverBoundaryRootNode() {
            super(null);
        }

        int deopCounter = 0;

        @Override
        public Object execute(VirtualFrame frame) {
            boolean startedCompiled = CompilerDirectives.inCompiledCode();
            throwExceptionBoundary();
            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++) {
        try {
            outerTarget.call();
        } catch (RuntimeException e) {
        // do nothing
        }
    }
    assertCompiled(outerTarget);
    final int execCount = 10;
    for (int i = 0; i < execCount; i++) {
        try {
            outerTarget.call();
        } catch (RuntimeException e) {
        // do nothing
        }
    }
    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 23 with OptimizedCallTarget

use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.

the class PartialEvaluationTest method assertPartialEvalEquals.

protected OptimizedCallTarget assertPartialEvalEquals(String methodName, RootNode root, Object[] arguments) {
    final OptimizedCallTarget compilable = (OptimizedCallTarget) Truffle.getRuntime().createCallTarget(root);
    CompilationIdentifier compilationId = getCompilationId(compilable);
    StructuredGraph actual = partialEval(compilable, arguments, AllowAssumptions.YES, compilationId);
    truffleCompiler.compilePEGraph(actual, methodName, null, compilable, asCompilationRequest(compilationId), null);
    removeFrameStates(actual);
    StructuredGraph expected = parseForComparison(methodName, actual.getDebug());
    Assert.assertEquals(getCanonicalGraphString(expected, true, true), getCanonicalGraphString(actual, true, true));
    return compilable;
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)

Example 24 with OptimizedCallTarget

use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.

the class PerformanceTruffleInliningTest method testHugeGraph.

@Test
public void testHugeGraph() {
    hugeGraphBuilderHelper(10, 4, "1");
    OptimizedCallTarget target = builder.target("main").calls("1").buildTarget();
    assertRootCallsExplored(target, 1);
    assertBudget(target);
}
Also used : OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Test(org.junit.Test)

Example 25 with OptimizedCallTarget

use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.

the class PerformanceTruffleInliningTest method testThreeTangledRecursions.

@Test
public void testThreeTangledRecursions() {
    // @formatter:off
    OptimizedCallTarget target = builder.target("three").calls("three").calls("two").calls("one").target("two").calls("two").calls("one").calls("three").target("one").calls("one").calls("two").calls("three").buildTarget();
    // @formatter:on
    assertRootCallsExplored(target, 2);
    assertBudget(target);
}
Also used : OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Test(org.junit.Test)

Aggregations

OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)57 Test (org.junit.Test)42 RootNode (com.oracle.truffle.api.nodes.RootNode)18 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)14 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)14 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)13 AbstractTestNode (org.graalvm.compiler.truffle.test.nodes.AbstractTestNode)11 TruffleOptionsOverrideScope (org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope)8 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)6 TruffleCompilerOptions (org.graalvm.compiler.truffle.common.TruffleCompilerOptions)6 Specialization (com.oracle.truffle.api.dsl.Specialization)4 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)4 GraalTruffleRuntime (org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime)4 OptimizedDirectCallNode (org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode)4 Theory (org.junit.experimental.theories.Theory)4 Assumption (com.oracle.truffle.api.Assumption)3 LoopNode (com.oracle.truffle.api.nodes.LoopNode)3 Ignore (org.junit.Ignore)3 Node (com.oracle.truffle.api.nodes.Node)2 WeakReference (java.lang.ref.WeakReference)2