Search in sources :

Example 26 with SourceSectionFilter

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);
    });
}
Also used : ExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.ExpressionNode) MaterializeChildExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializeChildExpressionNode) MaterializedChildExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializedChildExpressionNode) ExpressionTag(com.oracle.truffle.api.instrumentation.StandardTags.ExpressionTag) MaterializedChildExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializedChildExpressionNode) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Test(org.junit.Test)

Example 27 with SourceSectionFilter

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);
    });
}
Also used : ExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.ExpressionNode) MaterializeChildExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializeChildExpressionNode) MaterializedChildExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializedChildExpressionNode) ExpressionTag(com.oracle.truffle.api.instrumentation.StandardTags.ExpressionTag) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Test(org.junit.Test)

Example 28 with SourceSectionFilter

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());
}
Also used : Node(com.oracle.truffle.api.nodes.Node) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) RootNode(com.oracle.truffle.api.nodes.RootNode) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 29 with SourceSectionFilter

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))));
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 30 with SourceSectionFilter

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);
    }
}
Also used : SourceFilter(com.oracle.truffle.api.instrumentation.SourceFilter) ExecuteSourceEvent(com.oracle.truffle.api.instrumentation.ExecuteSourceEvent) ExecuteSourceListener(com.oracle.truffle.api.instrumentation.ExecuteSourceListener) SourceSection(com.oracle.truffle.api.source.SourceSection) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Source(com.oracle.truffle.api.source.Source)

Aggregations

SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)32 Test (org.junit.Test)21 StandardTags (com.oracle.truffle.api.instrumentation.StandardTags)7 Source (com.oracle.truffle.api.source.Source)7 ExpressionNode (com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.ExpressionNode)5 MaterializeChildExpressionNode (com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializeChildExpressionNode)5 MaterializedChildExpressionNode (com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializedChildExpressionNode)5 ExpressionTag (com.oracle.truffle.api.instrumentation.StandardTags.ExpressionTag)4 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)3 Node (com.oracle.truffle.api.nodes.Node)3 RootNode (com.oracle.truffle.api.nodes.RootNode)3 EventContext (com.oracle.truffle.api.instrumentation.EventContext)2 ExecutionEventNodeFactory (com.oracle.truffle.api.instrumentation.ExecutionEventNodeFactory)2 Instrumenter (com.oracle.truffle.api.instrumentation.Instrumenter)2 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)2 Builder (com.oracle.truffle.api.instrumentation.SourceSectionFilter.Builder)2 SourceSection (com.oracle.truffle.api.source.SourceSection)2 Source (org.graalvm.polyglot.Source)2 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)1 AllocationListener (com.oracle.truffle.api.instrumentation.AllocationListener)1