Search in sources :

Example 71 with RootNode

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

the class OptimizedCallTarget method pullOutParentChain.

private static void pullOutParentChain(Node node, List<Node> toDump) {
    Node rootNode = node;
    while (rootNode.getParent() != null) {
        toDump.add(rootNode);
        rootNode = rootNode.getParent();
    }
    toDump.add(rootNode);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node)

Example 72 with RootNode

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

the class OptimizedCallTarget method cloneUninitialized.

OptimizedCallTarget cloneUninitialized() {
    assert sourceCallTarget == null;
    if (compilationProfile == null) {
        initialize();
    }
    RootNode clonedRoot;
    GraalTVMCI tvmci = runtime().getTvmci();
    if (tvmci.isCloneUninitializedSupported(rootNode)) {
        assert uninitializedRootNode == null;
        clonedRoot = tvmci.cloneUninitialized(rootNode);
    } else {
        clonedRoot = NodeUtil.cloneNode(uninitializedRootNode);
    }
    return (OptimizedCallTarget) runtime().createClonedCallTarget(this, clonedRoot);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode)

Example 73 with RootNode

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

the class OptimizedCallTarget method maybeSetNeedsSplit.

private boolean maybeSetNeedsSplit(int depth, List<Node> toDump) {
    final int numberOfKnownCallNodes;
    final OptimizedDirectCallNode onlyCaller;
    synchronized (this) {
        numberOfKnownCallNodes = knownCallNodes.size();
        onlyCaller = numberOfKnownCallNodes == 1 ? knownCallNodes.get(0).get() : null;
    }
    if (depth > TruffleCompilerOptions.getValue(TruffleExperimentalSplittingMaxPropagationDepth) || needsSplit || numberOfKnownCallNodes == 0 || compilationProfile.getInterpreterCallCount() == 1) {
        return false;
    }
    if (numberOfKnownCallNodes == 1) {
        if (onlyCaller != null) {
            final RootNode callerRootNode = onlyCaller.getRootNode();
            if (callerRootNode != null && callerRootNode.getCallTarget() != null) {
                final OptimizedCallTarget callerTarget = (OptimizedCallTarget) callerRootNode.getCallTarget();
                if (TruffleCompilerOptions.getValue(TruffleExperimentalSplittingDumpDecisions)) {
                    pullOutParentChain(onlyCaller, toDump);
                }
                needsSplit = callerTarget.maybeSetNeedsSplit(depth + 1, toDump);
            }
        }
    } else {
        needsSplit = true;
        maybeDump(toDump);
    }
    return needsSplit;
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode)

Example 74 with RootNode

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

the class AllocationReporterPartialEvaluationTest method testConsistentAssertions.

@Test
public void testConsistentAssertions() {
    // Test that onEnter()/onReturnValue() are not broken
    // when only one of them is compiled with PE.
    Context context = Context.newBuilder(AllocationReporterLanguage.ID).build();
    context.initialize(AllocationReporterLanguage.ID);
    final TestAllocationReporter tester = context.getEngine().getInstruments().get(TestAllocationReporter.ID).lookup(TestAllocationReporter.class);
    assertNotNull(tester);
    final AllocationReporter reporter = (AllocationReporter) context.getPolyglotBindings().getMember(AllocationReporter.class.getSimpleName()).asHostObject();
    final Long[] value = new Long[] { 1L };
    OptimizedCallTarget enterTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {

        @Override
        public Object execute(VirtualFrame frame) {
            reporter.onEnter(value[0], 4, 8);
            return null;
        }
    });
    OptimizedCallTarget returnTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {

        @Override
        public Object execute(VirtualFrame frame) {
            reporter.onReturnValue(value[0], 4, 8);
            return null;
        }
    });
    // Interpret both:
    assertNotCompiled(enterTarget);
    enterTarget.call();
    assertNotCompiled(returnTarget);
    returnTarget.call();
    value[0]++;
    enterTarget.compile();
    returnTarget.compile();
    assertCompiled(enterTarget);
    assertCompiled(returnTarget);
    long expectedCounters = allocCounter(value[0]);
    assertEquals(expectedCounters, tester.getEnterCount());
    assertEquals(expectedCounters, tester.getReturnCount());
    for (int j = 0; j < 2; j++) {
        // Compile both:
        for (int i = 0; i < 5; i++) {
            assertCompiled(enterTarget);
            enterTarget.call();
            assertCompiled(returnTarget);
            returnTarget.call();
            value[0]++;
        }
        expectedCounters = allocCounter(value[0]);
        assertEquals(expectedCounters, tester.getEnterCount());
        assertEquals(expectedCounters, tester.getReturnCount());
        // Deoptimize enter:
        enterTarget.invalidate(this, "test");
        assertNotCompiled(enterTarget);
        enterTarget.call();
        assertCompiled(returnTarget);
        returnTarget.call();
        value[0]++;
        enterTarget.compile();
        returnTarget.compile();
        assertCompiled(enterTarget);
        assertCompiled(returnTarget);
        // Deoptimize return:
        returnTarget.invalidate(this, "test");
        assertCompiled(enterTarget);
        enterTarget.call();
        assertNotCompiled(returnTarget);
        returnTarget.call();
        value[0]++;
        enterTarget.compile();
        returnTarget.compile();
        assertCompiled(enterTarget);
        assertCompiled(returnTarget);
        // Deoptimize both:
        enterTarget.invalidate(this, "test");
        returnTarget.invalidate(this, "test");
        assertNotCompiled(enterTarget);
        enterTarget.call();
        assertNotCompiled(returnTarget);
        returnTarget.call();
        value[0]++;
        enterTarget.compile();
        returnTarget.compile();
        assertCompiled(enterTarget);
        assertCompiled(returnTarget);
    }
    // Check that the allocation calls happened:
    expectedCounters = allocCounter(value[0]);
    assertEquals(expectedCounters, tester.getEnterCount());
    assertEquals(expectedCounters, tester.getReturnCount());
    assertCompiled(enterTarget);
    assertCompiled(returnTarget);
    // Verify that the assertions work in the compiled code:
    value[0] = null;
    boolean expectedFailure = true;
    // Deoptimize for assertions to be active
    enterTarget.invalidate(this, "test");
    try {
        enterTarget.call();
        expectedFailure = false;
    } catch (AssertionError err) {
    // O.K.
    }
    assertTrue("onEnter(null) did not fail!", expectedFailure);
    // Deoptimize for assertions to be active
    returnTarget.invalidate(this, "test");
    value[0] = Long.MIN_VALUE;
    try {
        returnTarget.call();
        expectedFailure = false;
    } catch (AssertionError err) {
    // O.K.
    }
    assertTrue("onReturn(<unseen value>) did not fail!", expectedFailure);
}
Also used : Context(org.graalvm.polyglot.Context) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) AllocationReporter(com.oracle.truffle.api.instrumentation.AllocationReporter) Test(org.junit.Test)

Example 75 with RootNode

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

the class DebugStackFrame method getName.

/**
 * A description of the AST (expected to be a method or procedure name in most languages) that
 * identifies the AST for the benefit of guest language programmers using tools; it might
 * appear, for example in the context of a stack dump or trace and is not expected to be called
 * often. If the language does not provide such a description then <code>null</code> is
 * returned.
 *
 * <p>
 * This method is thread-safe.
 *
 * @since 0.17
 */
public String getName() {
    verifyValidState(true);
    RootNode root = findCurrentRoot();
    if (root == null) {
        return null;
    }
    try {
        return root.getName();
    } catch (Throwable e) {
        /* Throw error if assertions are enabled. */
        try {
            assert false;
        } catch (AssertionError e1) {
            throw e;
        }
        return null;
    }
}
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