use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class TruffleBoundaryExceptionsTest method testExceptionOnTruffleBoundaryWithNoTransferToInterpreter.
@Test
public void testExceptionOnTruffleBoundaryWithNoTransferToInterpreter() {
final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
class DeoptCountingExceptionOverBoundaryRootNode extends RootNode {
protected DeoptCountingExceptionOverBoundaryRootNode() {
super(null);
}
int deopCounter = 0;
int catchCounter = 0;
@Override
public Object execute(VirtualFrame frame) {
boolean startedCompiled = CompilerDirectives.inCompiledCode();
try {
throwExceptionBoundary();
} catch (RuntimeException e) {
catchCounter++;
}
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++) {
outerTarget.call();
}
assertCompiled(outerTarget);
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 deopCount = ((DeoptCountingExceptionOverBoundaryRootNode) outerTarget.getRootNode()).deopCounter;
Assert.assertEquals("Incorrect number of deops detected!", 0, deopCount);
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class IndirectCallSiteTest method testIndirectCallNodeDoesNotDeopOnFirstCall.
@Test
public void testIndirectCallNodeDoesNotDeopOnFirstCall() {
final Object[] noArguments = new Object[0];
final OptimizedCallTarget innerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {
@Override
public Object execute(VirtualFrame frame) {
return null;
}
});
final OptimizedCallTarget uninitializedInnerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {
@Override
public Object execute(VirtualFrame frame) {
return null;
}
});
final OptimizedCallTarget outerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {
@Child
OptimizedIndirectCallNode indirectCallNode = (OptimizedIndirectCallNode) runtime.createIndirectCallNode();
@Override
public Object execute(VirtualFrame frame) {
if (frame.getArguments().length == 0) {
return indirectCallNode.call(innerTarget, noArguments);
} else {
return indirectCallNode.call(uninitializedInnerTarget, noArguments);
}
}
});
final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
for (int i = 0; i < compilationThreshold; i++) {
outerTarget.call(noArguments);
}
assertCompiled(outerTarget);
outerTarget.call(new Object[] { null });
assertCompiled(outerTarget);
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class OptimizedCallTargetTest method testCompileOnly4.
@Test
public void testCompileOnly4() {
// OSR should not trigger for compile-only includes
try (TruffleOptionsOverrideScope scope = TruffleCompilerOptions.overrideOptions(TruffleCompileOnly, "foobar")) {
final OSRRepeatingNode repeating = new OSRRepeatingNode(TruffleCompilerOptions.getValue(TruffleOSRCompilationThreshold));
final LoopNode loop = runtime.createLoopNode(repeating);
OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(new NamedRootNode("foobar") {
@Child
LoopNode loopChild = loop;
@Override
public Object execute(VirtualFrame frame) {
loopChild.executeLoop(frame);
return super.execute(frame);
}
});
target.call();
OptimizedCallTarget osrTarget = findOSRTarget(loop);
if (osrTarget != null) {
assertNotCompiled(osrTarget);
}
}
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class BailoutPartialEvaluationTest method partialEvaluationConstantBailout2.
@Test(expected = BailoutException.class)
public void partialEvaluationConstantBailout2() {
FrameDescriptor fd = new FrameDescriptor();
RootTestNode rootNode = new RootTestNode(fd, "partialEvaluationConstantBailout2", new AbstractTestNode() {
@Override
public int execute(VirtualFrame frame) {
CompilerAsserts.partialEvaluationConstant(notConstantInt);
return 0;
}
});
compileHelper("partialEvaluationConstantBailout2", rootNode, new Object[] {});
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class SLInstrumentTest method testLexicalScopes.
@Test
public void testLexicalScopes() throws Exception {
String code = "function test(n) {\n" + // 2
" a = 1;\n" + " if (a > 0) {\n" + " b = 10;\n" + // 5
" println(b);\n" + " }\n" + " if (a == 1) {\n" + " b = 20;\n" + " a = 0;\n" + // 10
" c = 1;\n" + " if (b > 0) {\n" + " a = 4;\n" + " b = 5;\n" + " c = 6;\n" + // 15
" d = 7;\n" + " println(d);\n" + " }\n" + " }\n" + " println(b);\n" + // 20
" println(a);\n" + "}\n" + "function main() {\n" + " test(\"n_n\");\n" + "}";
Source source = Source.newBuilder("sl", code, "testing").build();
List<Throwable> throwables;
try (Engine engine = Engine.newBuilder().out(new java.io.OutputStream() {
// null output stream
@Override
public void write(int b) throws IOException {
}
}).build()) {
Instrument envInstr = engine.getInstruments().get("testEnvironmentHandlerInstrument");
TruffleInstrument.Env env = envInstr.lookup(Environment.class).env;
throwables = new ArrayList<>();
env.getInstrumenter().attachExecutionEventListener(SourceSectionFilter.newBuilder().lineIn(1, source.getLineCount()).build(), new ExecutionEventListener() {
@Override
public void onEnter(EventContext context, VirtualFrame frame) {
Node node = context.getInstrumentedNode();
Iterable<Scope> lexicalScopes = env.findLocalScopes(node, null);
Iterable<Scope> dynamicScopes = env.findLocalScopes(node, frame);
try {
verifyLexicalScopes(lexicalScopes, dynamicScopes, context.getInstrumentedSourceSection().getStartLine(), frame.materialize());
} catch (ThreadDeath t) {
throw t;
} catch (Throwable t) {
CompilerDirectives.transferToInterpreter();
PrintStream lsErr = System.err;
lsErr.println("Line = " + context.getInstrumentedSourceSection().getStartLine());
lsErr.println("Node = " + node + ", class = " + node.getClass().getName());
t.printStackTrace(lsErr);
throwables.add(t);
}
}
@Override
public void onReturnValue(EventContext context, VirtualFrame frame, Object result) {
}
@Override
public void onReturnExceptional(EventContext context, VirtualFrame frame, Throwable exception) {
}
});
Context.newBuilder().engine(engine).build().eval(source);
}
assertTrue(throwables.toString(), throwables.isEmpty());
}
Aggregations