Search in sources :

Example 51 with RootNode

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

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

the class TruffleDirectCallNodeTest method testCanBeClonedWithoutParent.

@Test
public void testCanBeClonedWithoutParent() {
    final RootNode rootNode = new RootNode(null) {

        @Override
        public Object execute(VirtualFrame frame) {
            return 42;
        }

        @Override
        public boolean isCloningAllowed() {
            return true;
        }
    };
    final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
    final DirectCallNode callNode = Truffle.getRuntime().createDirectCallNode(callTarget);
    assertTrue(callNode.isCallTargetCloningAllowed());
    assertTrue(callNode.cloneCallTarget());
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) CallTarget(com.oracle.truffle.api.CallTarget) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) Test(org.junit.Test)

Example 53 with RootNode

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

the class PhiStampInferencePartialEvaluationTest method ifPhiStamp.

@Test
public void ifPhiStamp() {
    /*
         * The stamp of a phi should be inferred during partial evaluation so that its type
         * information can be used to devirtualize method calls.
         */
    FrameDescriptor fd = new FrameDescriptor();
    AbstractTestNode result = new IfPhiStampTestNode();
    RootNode rootNode = new RootTestNode(fd, "ifPhiStamp", result);
    RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
    callTarget.call(new Object[] { true });
    callTarget.call(new Object[] { false });
    // ensure method cannot be statically bound without receiver type info
    new D().get();
    assertPartialEvalNoInvokes(callTarget, new Object[] { true });
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) RootNode(com.oracle.truffle.api.nodes.RootNode) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) RootCallTarget(com.oracle.truffle.api.RootCallTarget) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 54 with RootNode

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

the class SLDisableSplittingBuiltin method disableSplitting.

@Specialization
@TruffleBoundary
public SLNull disableSplitting(@SuppressWarnings("unused") SLNull argument) {
    RootNode parentRoot = Truffle.getRuntime().getCallerFrame().getCallNode().getRootNode();
    ((SLRootNode) parentRoot).setCloningAllowed(false);
    return SLNull.SINGLETON;
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) SLRootNode(com.oracle.truffle.sl.nodes.SLRootNode) SLRootNode(com.oracle.truffle.sl.nodes.SLRootNode) Specialization(com.oracle.truffle.api.dsl.Specialization) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 55 with RootNode

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

the class LazyToTruffleConverterImpl method convert.

@Override
public RootCallTarget convert() {
    CompilerAsserts.neverPartOfCompilation();
    // parse the function block
    parser.parse(diProcessor, source);
    // prepare the phis
    final Map<InstructionBlock, List<Phi>> phis = LLVMPhiManager.getPhis(method);
    // setup the frameDescriptor
    final FrameDescriptor frame = StackManager.createFrame(method);
    LLVMLivenessAnalysisResult liveness = LLVMLivenessAnalysis.computeLiveness(frame, context, phis, method);
    LLVMSymbolReadResolver symbols = new LLVMSymbolReadResolver(runtime, frame);
    List<FrameSlot> notNullable = new ArrayList<>();
    LLVMRuntimeDebugInformation dbgInfoHandler = new LLVMRuntimeDebugInformation(frame, nodeFactory, context, notNullable, symbols, runtime);
    dbgInfoHandler.registerStaticDebugSymbols(method);
    LLVMBitcodeFunctionVisitor visitor = new LLVMBitcodeFunctionVisitor(runtime, frame, phis, nodeFactory, method.getParameters().size(), symbols, method, liveness, notNullable, dbgInfoHandler);
    method.accept(visitor);
    FrameSlot[][] nullableBeforeBlock = getNullableFrameSlots(frame, liveness.getNullableBeforeBlock(), notNullable);
    FrameSlot[][] nullableAfterBlock = getNullableFrameSlots(frame, liveness.getNullableAfterBlock(), notNullable);
    LLVMSourceLocation location = method.getLexicalScope();
    List<LLVMExpressionNode> copyArgumentsToFrame = copyArgumentsToFrame(frame);
    LLVMExpressionNode[] copyArgumentsToFrameArray = copyArgumentsToFrame.toArray(new LLVMExpressionNode[copyArgumentsToFrame.size()]);
    LLVMExpressionNode body = nodeFactory.createFunctionBlockNode(runtime, frame.findFrameSlot(LLVMException.FRAME_SLOT_ID), visitor.getBlocks(), nullableBeforeBlock, nullableAfterBlock, location, copyArgumentsToFrameArray);
    RootNode rootNode = nodeFactory.createFunctionStartNode(runtime, body, method.getSourceSection(), frame, method, source, location);
    return Truffle.getRuntime().createCallTarget(rootNode);
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) RootNode(com.oracle.truffle.api.nodes.RootNode) LLVMLivenessAnalysisResult(com.oracle.truffle.llvm.parser.LLVMLivenessAnalysis.LLVMLivenessAnalysisResult) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) LLVMSymbolReadResolver(com.oracle.truffle.llvm.parser.nodes.LLVMSymbolReadResolver) ArrayList(java.util.ArrayList) LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) ArrayList(java.util.ArrayList) List(java.util.List) InstructionBlock(com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock)

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