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);
}
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);
}
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;
}
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);
}
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;
}
}
Aggregations