use of com.oracle.truffle.api.instrumentation.ExecutionEventListener in project graal by oracle.
the class InputFilterTest method assertCleanedUp.
private void assertCleanedUp(String code) {
// first we capture all root nodes used by the code.
Set<RootNode> rootNodes = new HashSet<>();
EventBinding<?> binding = instrumenter.attachExecutionEventListener(SourceSectionFilter.ANY, new ExecutionEventListener() {
public void onEnter(EventContext c, VirtualFrame frame) {
addRoot(c);
}
@TruffleBoundary
private void addRoot(EventContext c) {
rootNodes.add(c.getInstrumentedNode().getRootNode());
}
public void onReturnValue(EventContext c, VirtualFrame frame, Object result) {
}
public void onReturnExceptional(EventContext c, VirtualFrame frame, Throwable exception) {
}
});
execute(code);
binding.dispose();
// we execute again to let the instrumentation wrappers be cleaned up
execute(code);
for (RootNode root : rootNodes) {
// all frame slots got removed
assertEquals(new HashSet<>(), root.getFrameDescriptor().getIdentifiers());
// no wrappers left
root.accept(new NodeVisitor() {
public boolean visit(Node node) {
if (node instanceof WrapperNode) {
throw new AssertionError();
}
return true;
}
});
}
}
use of com.oracle.truffle.api.instrumentation.ExecutionEventListener 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());
}
use of com.oracle.truffle.api.instrumentation.ExecutionEventListener in project graal by oracle.
the class InstrumentationMultiThreadingTest method createDummyBindings.
private static EventBinding<?>[] createDummyBindings(Instrumenter instrumenter) {
EventBinding<?>[] bindings = new EventBinding<?>[5];
int bi = 0;
ExecutionEventListener dummyListener = new ExecutionEventListener() {
public void onReturnValue(EventContext context, VirtualFrame frame, Object result) {
}
public void onReturnExceptional(EventContext context, VirtualFrame frame, Throwable exception) {
}
public void onEnter(EventContext context, VirtualFrame frame) {
}
};
bindings[bi++] = instrumenter.attachExecutionEventListener(SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.EXPRESSION).build(), dummyListener);
bindings[bi++] = instrumenter.attachExecutionEventListener(SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.STATEMENT).build(), dummyListener);
bindings[bi++] = instrumenter.attachLoadSourceListener(SourceFilter.ANY, new LoadSourceListener() {
public void onLoad(LoadSourceEvent event) {
}
}, true);
bindings[bi++] = instrumenter.attachLoadSourceSectionListener(SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.EXPRESSION).build(), new LoadSourceSectionListener() {
public void onLoad(LoadSourceSectionEvent event) {
}
}, true);
bindings[bi++] = instrumenter.attachLoadSourceSectionListener(SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.STATEMENT).build(), new LoadSourceSectionListener() {
public void onLoad(LoadSourceSectionEvent event) {
}
}, true);
return bindings;
}
use of com.oracle.truffle.api.instrumentation.ExecutionEventListener in project graal by oracle.
the class InstrumentationUpdateTest method setEventFilter.
private void setEventFilter(SourceSectionFilter filter) {
EventBinding<?> old = this.eventBinding;
eventBinding = instrumentEnv.getInstrumenter().attachExecutionEventListener(filter, new ExecutionEventListener() {
public void onReturnValue(EventContext ctx, VirtualFrame frame, Object result) {
}
public void onReturnExceptional(EventContext ctx, VirtualFrame frame, Throwable exception) {
}
public void onEnter(EventContext ctx, VirtualFrame frame) {
executionEvents.add(ctx);
}
});
instrumentEnv.getInstrumenter().attachLoadSourceSectionListener(filter, new LoadSourceSectionListener() {
public void onLoad(LoadSourceSectionEvent event) {
loadEvents.add(event);
}
}, true);
// dispose afterwards to avoid disposal of instrumentation wrappers
if (old != null) {
old.dispose();
}
}
Aggregations