Search in sources :

Example 56 with RootNode

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

the class SimplePartialEvaluationTest method inliningNullCheck2.

@Test
public void inliningNullCheck2() {
    FrameDescriptor fd = new FrameDescriptor();
    AbstractTestNode result = new InliningNullCheckNode2();
    RootNode rootNode = new RootTestNode(fd, "inliningNullCheck2", result);
    OptimizedCallTarget compilable = compileHelper("inliningNullCheck2", rootNode, new Object[0]);
    Assert.assertEquals(42, compilable.call(new Object[0]));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) RootNode(com.oracle.truffle.api.nodes.RootNode) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) InliningNullCheckNode2(org.graalvm.compiler.truffle.test.nodes.InliningNullCheckNode2) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 57 with RootNode

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

the class SimplePartialEvaluationTest method inliningNullCheck1.

@Test
public void inliningNullCheck1() {
    FrameDescriptor fd = new FrameDescriptor();
    AbstractTestNode result = new InliningNullCheckNode1();
    RootNode rootNode = new RootTestNode(fd, "inliningNullCheck1", result);
    OptimizedCallTarget compilable = compileHelper("inliningNullCheck1", rootNode, new Object[0]);
    Assert.assertEquals(42, compilable.call(new Object[0]));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) RootNode(com.oracle.truffle.api.nodes.RootNode) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) InliningNullCheckNode1(org.graalvm.compiler.truffle.test.nodes.InliningNullCheckNode1) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 58 with RootNode

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

the class SimplePartialEvaluationTest method intrinsicStatic.

@Test
public void intrinsicStatic() {
    /*
         * The intrinsic for String.equals() is inlined early during bytecode parsing, because we
         * call equals() on a value that has the static type String.
         */
    FrameDescriptor fd = new FrameDescriptor();
    AbstractTestNode result = new StringEqualsNode("abc", "abf");
    RootNode rootNode = new RootTestNode(fd, "intrinsicStatic", result);
    OptimizedCallTarget compilable = compileHelper("intrinsicStatic", rootNode, new Object[0]);
    Assert.assertEquals(42, compilable.call(new Object[0]));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) RootNode(com.oracle.truffle.api.nodes.RootNode) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) StringEqualsNode(org.graalvm.compiler.truffle.test.nodes.StringEqualsNode) Test(org.junit.Test)

Example 59 with RootNode

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

the class TruffleBoundaryExceptionsTest method testExceptionOnTruffleBoundaryWithNoCatch.

@Test
public void testExceptionOnTruffleBoundaryWithNoCatch() {
    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
        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 60 with RootNode

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

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