use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class OptimizedCallTargetTest method testCompilationHeuristics.
/*
* GR-1328
*/
@Test
@Ignore("Fails non deterministically")
public void testCompilationHeuristics() {
testInvalidationCounterCompiled = 0;
testInvalidationCounterInterpreted = 0;
doInvalidate = false;
OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {
@Override
public Object execute(VirtualFrame frame) {
if (CompilerDirectives.inInterpreter()) {
testInvalidationCounterInterpreted++;
} else {
testInvalidationCounterCompiled++;
}
// doInvalidate needs to be volatile otherwise it floats up.
if (doInvalidate) {
CompilerDirectives.transferToInterpreterAndInvalidate();
}
return null;
}
});
final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
final int reprofileCount = TruffleCompilerOptions.getValue(TruffleReplaceReprofileCount);
assertTrue(compilationThreshold >= 2);
int expectedCompiledCount = 0;
int expectedInterpreterCount = 0;
for (int i = 0; i < compilationThreshold; i++) {
assertNotCompiled(target);
target.call();
}
assertCompiled(target);
expectedInterpreterCount += compilationThreshold;
assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
for (int j = 1; j < 100; j++) {
target.invalidate(this, "test");
for (int i = 0; i < reprofileCount; i++) {
assertNotCompiled(target);
target.call();
}
assertCompiled(target);
expectedInterpreterCount += reprofileCount;
assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
doInvalidate = true;
expectedCompiledCount++;
target.call();
assertNotCompiled(target);
doInvalidate = false;
assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
for (int i = 0; i < reprofileCount; i++) {
assertNotCompiled(target);
target.call();
}
assertCompiled(target);
expectedInterpreterCount += reprofileCount;
assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
for (int i = 0; i < compilationThreshold; i++) {
assertCompiled(target);
target.call();
}
assertCompiled(target);
expectedCompiledCount += compilationThreshold;
assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
}
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class OptimizedCallTargetTest method testInCompilationRootDirective.
@Ignore
@Test
public void testInCompilationRootDirective() {
final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
int[] outerExecute = { 0 };
int[] outerMethod = { 0 };
int[] outerBoundary = { 0 };
int[] innerExecute = { 0 };
int[] innerMethod = { 0 };
int[] innerBoundary = { 0 };
final OptimizedCallTarget innerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {
@Override
public String toString() {
return "inner";
}
@Override
public Object execute(VirtualFrame frame) {
// FALSE
if (CompilerDirectives.inCompilationRoot()) {
innerExecute[0]++;
}
innerMethod();
return null;
}
@CompilerDirectives.TruffleBoundary
void innerMethod() {
// FALSE
if (CompilerDirectives.inCompilationRoot()) {
innerMethod[0]++;
}
}
@CompilerDirectives.TruffleBoundary
void innerBoundary() {
// FALSE
if (CompilerDirectives.inCompilationRoot()) {
innerBoundary[0] = 1;
}
}
});
final OptimizedCallTarget outerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {
@Override
public String toString() {
return "outer";
}
@Child
private DirectCallNode child = runtime.createDirectCallNode(innerTarget);
@Override
public Object execute(VirtualFrame frame) {
// TRUE
if (CompilerDirectives.inCompilationRoot()) {
outerExecute[0]++;
}
outerMethod();
return child.call(new Object[0]);
}
void outerMethod() {
// TRUE
if (CompilerDirectives.inCompilationRoot()) {
outerMethod[0]++;
outerBoundary();
}
}
@CompilerDirectives.TruffleBoundary
void outerBoundary() {
// FALSE
if (CompilerDirectives.inCompilationRoot()) {
outerBoundary[0]++;
}
}
});
for (int i = 0; i < compilationThreshold; i++) {
outerTarget.call();
}
assertCompiled(outerTarget);
final int executionCount = 10;
for (int i = 0; i < executionCount; i++) {
outerTarget.call();
}
Assert.assertEquals(executionCount, outerExecute[0]);
Assert.assertEquals(executionCount, outerMethod[0]);
Assert.assertEquals(0, outerBoundary[0]);
Assert.assertEquals(0, innerExecute[0]);
Assert.assertEquals(0, innerMethod[0]);
Assert.assertEquals(0, innerBoundary[0]);
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class CastExactPartialEvaluationTest method testCommon.
private void testCommon(AbstractTestNode testNode, String testName) {
FrameDescriptor fd = new FrameDescriptor();
RootNode rootNode = new RootTestNode(fd, testName, testNode);
RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
Assert.assertEquals(42, callTarget.call(newBuffer()));
assertPartialEvalNoInvokes(callTarget, new Object[] { newBuffer() });
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class TruffleSplittingStrategy method shouldSplit.
private static boolean shouldSplit(OptimizedDirectCallNode call, GraalTVMCI.EngineData engineData) {
if (engineData.splitCount + call.getCurrentCallTarget().getUninitializedNodeCount() > engineData.splitLimit) {
return false;
}
if (!canSplit(call)) {
return false;
}
OptimizedCallTarget callTarget = call.getCallTarget();
int nodeCount = callTarget.getNonTrivialNodeCount();
if (nodeCount > TruffleCompilerOptions.getValue(TruffleSplittingMaxCalleeSize)) {
return false;
}
RootNode rootNode = call.getRootNode();
if (rootNode == null) {
return false;
}
// disable recursive splitting for now
OptimizedCallTarget root = (OptimizedCallTarget) rootNode.getCallTarget();
if (root == callTarget || root.getSourceCallTarget() == callTarget) {
// recursive call found
return false;
}
// Disable splitting if it will cause a deep split-only recursion
if (isRecursiveSplit(call)) {
return false;
}
// max one child call and callCount > 2 and kind of small number of nodes
if (isMaxSingleCall(call)) {
return true;
}
return countPolymorphic(call) >= 1;
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class TruffleSplittingStrategy method isRecursiveSplit.
private static boolean isRecursiveSplit(OptimizedDirectCallNode call) {
final OptimizedCallTarget splitCandidateTarget = call.getCallTarget();
OptimizedCallTarget callRootTarget = (OptimizedCallTarget) call.getRootNode().getCallTarget();
OptimizedCallTarget callSourceTarget = callRootTarget.getSourceCallTarget();
int depth = 0;
while (callSourceTarget != null) {
if (callSourceTarget == splitCandidateTarget) {
depth++;
if (depth == 2) {
return true;
}
}
final OptimizedDirectCallNode splitCallSite = callRootTarget.getCallSiteForSplit();
if (splitCallSite == null) {
break;
}
final RootNode splitCallSiteRootNode = splitCallSite.getRootNode();
if (splitCallSiteRootNode == null) {
break;
}
callRootTarget = (OptimizedCallTarget) splitCallSiteRootNode.getCallTarget();
if (callRootTarget == null) {
break;
}
callSourceTarget = callRootTarget.getSourceCallTarget();
}
return false;
}
Aggregations