use of com.oracle.truffle.api.source.SourceSection 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.source.SourceSection 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;
}
use of com.oracle.truffle.api.source.SourceSection in project graal by oracle.
the class InstrumentationHandler method lazyInitializeSourcesExecutedList.
/**
* Initializes sourcesExecuted and sourcesExecutedList by populating them from executedRoots.
*/
private void lazyInitializeSourcesExecutedList() {
assert Thread.holdsLock(sourcesExecuted);
if (sourcesExecutedListRef.get() == null) {
// build the sourcesExecutedList, we need it now
Collection<Source> sourcesExecutedList = new WeakAsyncList<>(16);
sourcesExecutedListRef.set(sourcesExecutedList);
for (RootNode root : executedRoots) {
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 (!sourcesExecuted.containsKey(source)) {
sourcesExecuted.put(source, null);
sourcesExecutedList.add(source);
}
} else {
if (sourceSection != null) {
findSourcesExecutedVisitor.adoptSource(sourceSection.getSource());
}
visitRoot(root, root, findSourcesExecutedVisitor, false);
for (Source source : findSourcesExecutedVisitor.rootSources) {
if (!sourcesExecuted.containsKey(source)) {
sourcesExecuted.put(source, null);
sourcesExecutedList.add(source);
}
}
findSourcesExecutedVisitor.rootSources.clear();
}
}
}
}
}
use of com.oracle.truffle.api.source.SourceSection in project graal by oracle.
the class SourceSectionTest method testSourceSections.
@Theory
public void testSourceSections(int value0, int value1, int value2) {
TestRootNode<MutableSourceSectionNode> root = createRoot(SourceSectionTestFactory.MutableSourceSectionNodeFactory.getInstance());
SourceSection section = Source.newBuilder("").name("a").mimeType("").build().createUnavailableSection();
root.getNode().changeSourceSection(section);
expectSourceSection(root.getNode(), section);
assertThat((int) executeWith(root, value0), is(value0));
expectSourceSection(root.getNode(), section);
assertThat((int) executeWith(root, value1), is(value1));
expectSourceSection(root.getNode(), section);
assertThat((int) executeWith(root, value2), is(value2));
expectSourceSection(root.getNode(), section);
}
use of com.oracle.truffle.api.source.SourceSection in project graal by oracle.
the class SourceSectionTest method testCreateCast.
@Test
public void testCreateCast() {
SourceSection section = Source.newBuilder("").name("a").mimeType("").build().createUnavailableSection();
TestRootNode<NodeWithFixedSourceSection> root = createRootPrefix(SourceSectionTestFactory.NodeWithFixedSourceSectionFactory.getInstance(), true, section);
expectSourceSection(root.getNode(), section);
assertThat((int) executeWith(root, 1), is(1));
expectSourceSection(root.getNode(), section);
}
Aggregations