use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class SourceListenerTest method testBindingDisposalImpl.
private void testBindingDisposalImpl(boolean load) throws Exception {
Instrument instrument = engine.getInstruments().get("testBindingDisposal");
TestBindingDisposal impl = instrument.lookup(TestBindingDisposal.class);
impl.doAttach(load);
Source source1 = lines("STATEMENT");
run(source1);
assertEvents(impl.onlyNewEvents, source1);
assertEvents(impl.allEvents, source1);
impl.onlyNewBinding.dispose();
impl.allBinding.dispose();
// No new events received after bindings are disposed
com.oracle.truffle.api.source.Source source2a = com.oracle.truffle.api.source.Source.newBuilder("line2a").mimeType("mime").name("NoName2a").build();
com.oracle.truffle.api.source.Source source2b = com.oracle.truffle.api.source.Source.newBuilder("line2b").mimeType("mime").name("NoName2b").build();
Node node2a = new SourceSectionFilterTest.SourceSectionNode(source2a.createSection(1));
Node node2b = new SourceSectionFilterTest.SourceSectionNode(source2b.createSection(1));
RootNode root2 = SourceSectionFilterTest.createRootNode(engine, null, Boolean.FALSE, node2a, node2b);
Truffle.getRuntime().createCallTarget(root2).call();
assertEvents(impl.onlyNewEvents, source1);
assertEvents(impl.allEvents, source1);
// Clear and reattach
impl.onlyNewEvents.clear();
impl.allEvents.clear();
impl.doAttach(load);
Source source3 = lines("VARIABLE(a, 10)");
run(source3);
assertEvents(impl.onlyNewEvents, source3);
assertEvents(impl.allEvents, getSourceImpl(source1), source2a, source2b, getSourceImpl(source3));
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class SourceSectionFilterTest method isInstrumentedRoot.
private static boolean isInstrumentedRoot(SourceSectionFilter filter, Node root, int rootNodeBits) {
try {
Method m = filter.getClass().getDeclaredMethod("isInstrumentedRoot", Set.class, SourceSection.class, RootNode.class, int.class);
ReflectionUtils.setAccessible(m, true);
RootNode rootNode = null;
if (root instanceof RootNode) {
rootNode = (RootNode) root;
}
return (boolean) m.invoke(filter, ALL_TAGS, root != null ? root.getSourceSection() : null, rootNode, rootNodeBits);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.oracle.truffle.api.nodes.RootNode 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.nodes.RootNode in project graal by oracle.
the class InstrumentationHandler method lazyInitializeSourcesList.
/**
* Initializes sources and sourcesList by populating them from loadedRoots.
*/
private void lazyInitializeSourcesList() {
assert Thread.holdsLock(sources);
if (sourcesListRef.get() == null) {
// build the sourcesList, we need it now
Collection<Source> sourcesList = new WeakAsyncList<>(16);
sourcesListRef.set(sourcesList);
for (RootNode root : loadedRoots) {
int rootBits = RootNodeBits.get(root);
if (RootNodeBits.isNoSourceSection(rootBits)) {
continue;
} else {
SourceSection sourceSection = root.getSourceSection();
if (RootNodeBits.isSameSource(rootBits) && sourceSection != null) {
Source source = sourceSection.getSource();
if (!sources.containsKey(source)) {
sources.put(source, null);
sourcesList.add(source);
}
} else {
if (sourceSection != null) {
findSourcesVisitor.adoptSource(sourceSection.getSource());
}
visitRoot(root, root, findSourcesVisitor, false);
for (Source source : findSourcesVisitor.rootSources) {
if (!sources.containsKey(source)) {
sources.put(source, null);
sourcesList.add(source);
}
}
findSourcesVisitor.rootSources.clear();
}
}
}
}
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class InstrumentationHandler method createBindings.
EventChainNode createBindings(VirtualFrame frame, ProbeNode probeNodeImpl) {
EventContext context = probeNodeImpl.getContext();
SourceSection sourceSection = context.getInstrumentedSourceSection();
if (TRACE) {
trace("BEGIN: Lazy update for %s%n", sourceSection);
}
RootNode rootNode;
Node parentInstrumentable = null;
SourceSection parentInstrumentableSourceSection = null;
Node parentNode = probeNodeImpl.getParent();
while (parentNode != null && parentNode.getParent() != null) {
if (parentInstrumentable == null) {
SourceSection parentSourceSection = parentNode.getSourceSection();
if (isInstrumentableNode(parentNode, parentSourceSection)) {
parentInstrumentable = parentNode;
parentInstrumentableSourceSection = parentSourceSection;
}
}
parentNode = parentNode.getParent();
}
if (parentNode instanceof RootNode) {
rootNode = (RootNode) parentNode;
} else {
throw new AssertionError();
}
Node instrumentedNode = probeNodeImpl.getContext().getInstrumentedNode();
Set<Class<?>> providedTags = getProvidedTags(rootNode);
EventChainNode root = null;
EventChainNode parent = null;
for (EventBinding.Source<?> binding : executionBindings) {
if (binding.isChildInstrumentedFull(providedTags, rootNode, parentInstrumentable, parentInstrumentableSourceSection, instrumentedNode, sourceSection)) {
if (TRACE) {
trace(" Found input value binding %s, %s%n", binding.getInputFilter(), System.identityHashCode(binding));
}
EventChainNode next = probeNodeImpl.createParentEventChainCallback(frame, binding, rootNode, providedTags);
if (next == null) {
// inconsistent AST
continue;
}
if (root == null) {
root = next;
} else {
assert parent != null;
parent.setNext(next);
}
parent = next;
}
if (binding.isInstrumentedFull(providedTags, rootNode, instrumentedNode, sourceSection)) {
if (TRACE) {
trace(" Found binding %s, %s%n", binding.getFilter(), binding.getElement());
}
EventChainNode next = probeNodeImpl.createEventChainCallback(frame, binding, rootNode, providedTags, instrumentedNode, sourceSection);
if (next == null) {
continue;
}
if (root == null) {
root = next;
} else {
assert parent != null;
parent.setNext(next);
}
parent = next;
}
}
if (TRACE) {
trace("END: Lazy updated for %s%n", sourceSection);
}
return root;
}
Aggregations