use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.
the class InstrumentableNodeTest method testSimpleMaterializeSyntax.
/*
* Directly instrument and materialize all nodes.
*/
@Test
public void testSimpleMaterializeSyntax() {
SourceSectionFilter filter = SourceSectionFilter.newBuilder().tagIs(StandardTags.StatementTag.class, StandardTags.ExpressionTag.class).build();
instrumenter.attachExecutionEventFactory(filter, null, factory);
execute("MATERIALIZE_CHILD_EXPRESSION");
assertOn(ENTER, (e) -> {
assertTrue(e.context.getInstrumentedNode() instanceof MaterializedChildExpressionNode);
});
assertOn(ENTER, (e) -> {
assertTrue(e.context.getInstrumentedNode() instanceof ExpressionNode);
});
assertOn(RETURN_VALUE, (e) -> {
assertTrue(e.context.getInstrumentedNode() instanceof ExpressionNode);
});
assertOn(RETURN_VALUE, (e) -> {
assertTrue(e.context.getInstrumentedNode() instanceof MaterializedChildExpressionNode);
});
}
use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.
the class InstrumentableNodeTest method testMaterializeSyntaxNotInstrumented.
/*
* Test materialize if the parent node is not instrumented. We need to call materializeSyntax
* for all visited instrumentable nodes. Not just for instrumented ones.
*/
@Test
public void testMaterializeSyntaxNotInstrumented() {
SourceSectionFilter expressionFilter = SourceSectionFilter.newBuilder().tagIs(StandardTags.ExpressionTag.class).build();
instrumenter.attachExecutionEventFactory(expressionFilter, null, factory);
execute("MATERIALIZE_CHILD_EXPRESSION");
assertOn(ENTER, (e) -> {
assertTrue(e.context.getInstrumentedNode() instanceof ExpressionNode);
});
assertOn(RETURN_VALUE, (e) -> {
assertTrue(e.context.getInstrumentedNode() instanceof ExpressionNode);
});
}
use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.
the class SourceSectionFilterTest method testComplexFilter.
@Test
public void testComplexFilter() {
Source sampleSource1 = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType("mime2").build();
Node root = createNode(sampleSource1.createSection(0, 23));
SourceSectionFilter filter = //
SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.EXPRESSION, InstrumentationTestLanguage.DEFINE).tagIsNot(InstrumentationTestLanguage.DEFINE, //
InstrumentationTestLanguage.ROOT).indexIn(0, //
3).sourceIs(sampleSource1).sourceSectionEquals(//
sampleSource1.createSection(0, 5)).lineIn(1, 1).lineIs(1).mimeTypeIs("mime1", "mime2").build();
Assert.assertFalse(isInstrumented(filter, root, source()));
Assert.assertTrue(isInstrumentedRoot(filter, null));
Assert.assertFalse(isInstrumentedNode(filter, source()));
Assert.assertFalse(isInstrumented(filter, root, createNode(sampleSource1.createUnavailableSection())));
Assert.assertTrue(isInstrumentedRoot(filter, createNode(sampleSource1.createUnavailableSection())));
Assert.assertFalse(isInstrumentedNode(filter, createNode(sampleSource1.createUnavailableSection())));
Assert.assertTrue(isInstrumented(filter, root, createNode(sampleSource1.createSection(0, 5), tags(InstrumentationTestLanguage.EXPRESSION))));
Assert.assertTrue(isInstrumentedRoot(filter, createNode(sampleSource1.createSection(0, 5))));
Assert.assertTrue(isInstrumentedNode(filter, createNode(sampleSource1.createSection(0, 5), tags(InstrumentationTestLanguage.EXPRESSION))));
Assert.assertFalse(isInstrumented(filter, root, createNode(sampleSource1.createSection(0, 5), tags(InstrumentationTestLanguage.STATEMENT))));
Assert.assertTrue(isInstrumentedRoot(filter, createNode(sampleSource1.createSection(0, 5))));
Assert.assertTrue(isInstrumentedRoot(filter, createNode(sampleSource1.createSection(10, 5))));
Assert.assertFalse(isInstrumentedNode(filter, createNode(sampleSource1.createSection(0, 5), tags(InstrumentationTestLanguage.STATEMENT))));
Assert.assertNotNull(filter.toString());
}
use of com.oracle.truffle.api.instrumentation.SourceSectionFilter 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.instrumentation.SourceSectionFilter in project graal by oracle.
the class BreakpointSnippets method install.
private void install() {
assert Thread.holdsLock(this);
if (sourceBinding == null) {
SourceFilter filter = locationKey.createSourceFilter();
final boolean[] sourceResolved = new boolean[] { false };
sourceBinding = debugger.getInstrumenter().attachExecuteSourceListener(filter, new ExecuteSourceListener() {
@Override
public void onExecute(ExecuteSourceEvent event) {
if (sourceResolved[0]) {
return;
}
sourceResolved[0] = true;
synchronized (Breakpoint.this) {
if (sourceBinding != null) {
sourceBinding.dispose();
}
}
Source source = event.getSource();
SourceSection location = locationKey.adjustLocation(source, debugger.getEnv(), suspendAnchor);
if (location != null) {
resolveBreakpoint(location);
}
SourceSectionFilter locationFilter = locationKey.createLocationFilter(source, suspendAnchor);
breakpointBinding = createBinding(locationFilter);
}
}, true);
if (sourceResolved[0]) {
sourceBinding.dispose();
}
} else if (breakpointBinding == null && sourceBinding.isDisposed()) {
// re-installing breakpoint
SourceSectionFilter locationFilter = locationKey.createLocationFilter(null, suspendAnchor);
breakpointBinding = createBinding(locationFilter);
}
}
Aggregations