use of com.oracle.truffle.api.source.Source in project graal by oracle.
the class SourceSectionFilterTest method testIgnoreInternal.
@Test
public void testIgnoreInternal() throws Exception {
SourceSectionFilter internalFilter = SourceSectionFilter.newBuilder().includeInternal(false).build();
SourceSectionFilter defaultFilter = SourceSectionFilter.newBuilder().build();
Assert.assertTrue(isInstrumented(internalFilter, null, source()));
Source nonInternalSource = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
// Default non-internal RootNode
RootNode root = createRootNode(nonInternalSource.createSection(0, 23), null);
Assert.assertTrue(isInstrumented(internalFilter, root, createNode(nonInternalSource.createSection(1))));
// Internal RootNode
root = createRootNode(nonInternalSource.createSection(0, 23), true);
Assert.assertFalse(isInstrumented(internalFilter, root, createNode(nonInternalSource.createSection(1))));
Assert.assertTrue(isInstrumented(defaultFilter, root, createNode(nonInternalSource.createSection(1))));
Source internalSource = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).internal().build();
// Default internal RootNode
root = createRootNode(internalSource.createSection(0, 23), null);
Assert.assertFalse(isInstrumented(internalFilter, root, createNode(internalSource.createSection(1))));
// Non-internal RootNode
root = createRootNode(nonInternalSource.createSection(0, 23), false);
Assert.assertTrue(isInstrumented(internalFilter, root, createNode(internalSource.createSection(1))));
}
use of com.oracle.truffle.api.source.Source in project graal by oracle.
the class SourceSectionFilterTest method testColumnStartIn.
@Test
public void testColumnStartIn() {
Source sampleSource = Source.newBuilder("123456789\n123456789").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
Node root = createNode(sampleSource.createSection(0, 19));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(2, 1)).build(), root, createNode(sampleSource.createSection(1, 1))));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(2, 1)).build(), root, createNode(sampleSource.createSection(0, 2))));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(0, 2))));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(0, 2))));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(1, 2))));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(2, 1))));
}
use of com.oracle.truffle.api.source.Source in project graal by oracle.
the class SourceSectionFilterTest method testColumnIn.
@Test
public void testColumnIn() {
Source sampleSource = Source.newBuilder("123456789\n123456789").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
Node root = createNode(sampleSource.createSection(0, 19));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 1).build(), root, createNode(sampleSource.createSection(1, 5), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(1, 2).build(), root, createNode(sampleSource.createSection(0, 1), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnIn(1, 1).build(), root, createNode(sampleSource.createSection(1, 1), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 2).build(), root, createNode(sampleSource.createSection(4, 1), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 2).build(), root, createNode(sampleSource.createSection(1, 1), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 2).build(), root, createNode(sampleSource.createSection(1, 5), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 2).build(), root, createNode(sampleSource.createSection(0, 1), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 2).build(), root, createNode(sampleSource.createSection(0, 2), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 2).build(), root, createNode(sampleSource.createSection(1, 5), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 2).build(), root, createNode(sampleSource.createSection(1, 1), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 2).build(), root, createNode(sampleSource.createSection(0, 5), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnIn(1, 1).build(), root, createNode(sampleSource.createUnavailableSection())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnIn(IndexRange.byLength(1, 1)).build(), root, createNode(sampleSource.createSection(1, 1), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(IndexRange.byLength(1, 1), IndexRange.between(2, 3), IndexRange.byLength(3, 1)).build(), root, createNode(sampleSource.createSection(1, 1), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnIn(IndexRange.byLength(1, 1), IndexRange.byLength(3, 1)).build(), root, createNode(sampleSource.createSection(1, 1), tags())));
Assert.assertNotNull(SourceSectionFilter.newBuilder().columnIn(2, 2).build().toString());
}
use of com.oracle.truffle.api.source.Source in project graal by oracle.
the class InstrumentationHandler method addSourceExecutionBinding.
<T> EventBinding<T> addSourceExecutionBinding(EventBinding.Source<T> binding, boolean notifyLoaded) {
if (TRACE) {
trace("BEGIN: Adding source execution binding %s, %s%n", binding.getFilter(), binding.getElement());
}
this.sourceExecutedBindings.add(binding);
this.hasSourceExecutedBindings = true;
if (notifyLoaded) {
synchronized (sourcesExecuted) {
lazyInitializeSourcesExecutedList();
}
for (Source source : sourcesExecutedListRef.get()) {
notifySourceExecutedBinding(binding, source);
}
}
if (TRACE) {
trace("END: Added source execution binding %s, %s%n", binding.getFilter(), binding.getElement());
}
return binding;
}
use of com.oracle.truffle.api.source.Source in project graal by oracle.
the class InstrumentationHandler method onLoad.
void onLoad(RootNode root) {
if (!AccessorInstrumentHandler.nodesAccess().isInstrumentable(root)) {
return;
}
assert root.getLanguageInfo() != null;
if (hasSourceBindings) {
final Source[] rootSources;
synchronized (sources) {
if (!sourceBindings.isEmpty()) {
// we'll add to the sourcesList, so it needs to be initialized
lazyInitializeSourcesList();
SourceSection sourceSection = root.getSourceSection();
if (sourceSection != null) {
findSourcesVisitor.adoptSource(sourceSection.getSource());
}
visitRoot(root, root, findSourcesVisitor, false);
rootSources = findSourcesVisitor.getSources();
} else {
hasSourceBindings = false;
sources.clear();
sourcesListRef.set(null);
rootSources = null;
}
}
loadedRoots.add(root);
// Do not invoke foreign code while holding a lock to avoid deadlocks.
if (rootSources != null) {
for (Source src : rootSources) {
notifySourceBindingsLoaded(sourceBindings, src);
}
}
} else {
loadedRoots.add(root);
}
// fast path no bindings attached
if (!sourceSectionBindings.isEmpty()) {
visitRoot(root, root, new NotifyLoadedListenerVisitor(sourceSectionBindings), false);
}
}
Aggregations