use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class SimplePartialEvaluationTest method synchronizedExceptionMerge.
@Test
public void synchronizedExceptionMerge() {
/*
* Multiple non-inlineable methods with exception edges called from a synchronized method
* lead to a complicated Graal graph that involves the BytecodeFrame.UNWIND_BCI. This test
* checks that partial evaluation handles that case correctly.
*/
FrameDescriptor fd = new FrameDescriptor();
AbstractTestNode result = new SynchronizedExceptionMergeNode();
RootNode rootNode = new RootTestNode(fd, "synchronizedExceptionMerge", result);
OptimizedCallTarget compilable = compileHelper("synchronizedExceptionMerge", rootNode, new Object[0]);
Assert.assertEquals(42, compilable.call(new Object[0]));
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class SimplePartialEvaluationTest method intrinsicVirtual.
@Test
public void intrinsicVirtual() {
/*
* The intrinsic for String.equals() is inlined late during Truffle partial evaluation,
* because we call equals() on a value that has the static type Object, but during partial
* evaluation the more precise type String is known.
*/
FrameDescriptor fd = new FrameDescriptor();
AbstractTestNode result = new ObjectEqualsNode("abc", "abf");
RootNode rootNode = new RootTestNode(fd, "intrinsicVirtual", result);
OptimizedCallTarget compilable = compileHelper("intrinsicVirtual", rootNode, new Object[0]);
Assert.assertEquals(42, compilable.call(new Object[0]));
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class SimplePartialEvaluationTest method loopExplosionPhi.
@Test
public void loopExplosionPhi() {
FrameDescriptor fd = new FrameDescriptor();
AbstractTestNode result = new LoopExplosionPhiNode();
RootNode rootNode = new RootTestNode(fd, "loopExplosionPhi", result);
OptimizedCallTarget compilable = compileHelper("loopExplosionPhi", rootNode, new Object[0]);
Assert.assertEquals(1, compilable.call(new Object[0]));
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class TransferToInterpreterTest method test.
@Test
public void test() {
RootNode rootNode = new TestRootNode();
GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime();
OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(rootNode);
target.call(0);
Assert.assertFalse(target.isValid());
OptionValues options = TruffleCompilerOptions.getOptions();
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
final OptimizedCallTarget compilable = target;
TruffleCompilerImpl compiler = (TruffleCompilerImpl) runtime.newTruffleCompiler();
CompilationIdentifier compilationId = compiler.getCompilationIdentifier(compilable);
TruffleInliningPlan inliningPlan = new TruffleInlining(compilable, new DefaultInliningPolicy());
compiler.compileAST(debug, compilable, inliningPlan, compilationId, null, null);
Assert.assertTrue(target.isValid());
target.call(0);
Assert.assertTrue(target.isValid());
target.call(1);
Assert.assertFalse(target.isValid());
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class TruffleBoundaryExceptionsTest method testExceptionOnTruffleBoundaryDoesNotDeop.
@Test
public void testExceptionOnTruffleBoundaryDoesNotDeop() {
final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
class DeoptCountingExceptionOverBoundaryRootNode extends RootNode {
protected DeoptCountingExceptionOverBoundaryRootNode() {
super(null);
}
int deopCounter = 0;
int catchCounter = 0;
int interpretCount = 0;
@Override
public Object execute(VirtualFrame frame) {
boolean startedCompiled = CompilerDirectives.inCompiledCode();
if (!startedCompiled) {
interpretCount++;
}
try {
throwExceptionBoundary();
} catch (RuntimeException e) {
catchCounter++;
}
if (startedCompiled && CompilerDirectives.inInterpreter()) {
deopCounter++;
}
return null;
}
@CompilerDirectives.TruffleBoundary
public void throwExceptionBoundary() {
throw new RuntimeException();
}
}
final int[] compilationCount = { 0 };
GraalTruffleRuntimeListener listener = new GraalTruffleRuntimeListener() {
@Override
public void onCompilationStarted(OptimizedCallTarget target) {
compilationCount[0]++;
}
};
final OptimizedCallTarget outerTarget = (OptimizedCallTarget) runtime.createCallTarget(new DeoptCountingExceptionOverBoundaryRootNode());
for (int i = 0; i < compilationThreshold; i++) {
outerTarget.call();
}
assertCompiled(outerTarget);
runtime.addListener(listener);
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 interpretCount = ((DeoptCountingExceptionOverBoundaryRootNode) outerTarget.getRootNode()).interpretCount;
int deopCount = ((DeoptCountingExceptionOverBoundaryRootNode) outerTarget.getRootNode()).deopCounter;
Assert.assertEquals("Incorrect number of deops detected!", totalExecutions - interpretCount, deopCount);
Assert.assertEquals("Compilation happened!", 0, compilationCount[0]);
runtime.removeListener(listener);
}
Aggregations