Search in sources :

Example 6 with SourceSectionFilter

use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.

the class SourceSectionFilterTest method testEmpty.

@Test
public void testEmpty() {
    Source sampleSource = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Node root = createNode(sampleSource.createSection(0, 23));
    Node unavailable = createNode(sampleSource.createUnavailableSection());
    SourceSectionFilter filter = SourceSectionFilter.ANY;
    Node sampleSection = createNode(sampleSource.createSection(2));
    Assert.assertTrue(isInstrumentedNode(filter, source()));
    Assert.assertTrue(isInstrumentedNode(filter, unavailable));
    Assert.assertTrue(isInstrumentedNode(filter, sampleSection));
    Assert.assertTrue(isInstrumentedRoot(filter, null));
    Assert.assertTrue(isInstrumentedRoot(filter, unavailable));
    Assert.assertTrue(isInstrumentedRoot(filter, sampleSection));
    Assert.assertTrue(isInstrumented(filter, root, source()));
    Assert.assertTrue(isInstrumented(filter, root, unavailable));
    Assert.assertTrue(isInstrumented(filter, root, sampleSection));
    Class<?> prevTag = null;
    for (Class<?> tag : InstrumentationTestLanguage.TAGS) {
        Assert.assertTrue(isInstrumented(filter, root, source(tag)));
        Assert.assertTrue(isInstrumented(filter, root, unavailable));
        Assert.assertTrue(isInstrumented(filter, root, createNode(sampleSource.createSection(0, 4), tag)));
        if (prevTag != null) {
            Assert.assertTrue(isInstrumented(filter, root, source(tag)));
            Assert.assertTrue(isInstrumented(filter, root, unavailable));
            Assert.assertTrue(isInstrumented(filter, root, createNode(sampleSource.createSection(0, 4), tag, prevTag)));
        }
        prevTag = tag;
    }
    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 7 with SourceSectionFilter

use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.

the class SourceSectionFilterTest method testRootNodeBits.

@Test
public void testRootNodeBits() {
    Source sampleSource1 = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType("mime2").build();
    Source sampleSource2 = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType("mime2").build();
    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(isInstrumentedRoot(filter, null, ROOT_NODE_BITS_NO_SOURCE_SECTION));
    Assert.assertFalse(isInstrumentedRoot(filter, createNode(sampleSource1.createSection(1)), ROOT_NODE_BITS_NO_SOURCE_SECTION));
    Assert.assertFalse(isInstrumentedRoot(filter, createNode(sampleSource1.createSection(1)), ROOT_NODE_BITS_NO_SOURCE_SECTION));
    Assert.assertTrue(isInstrumentedRoot(filter, null, ROOT_NODE_BITS_SAME_SOURCE));
    Assert.assertTrue(isInstrumentedRoot(filter, createNode(sampleSource1.createSection(1)), ROOT_NODE_BITS_SAME_SOURCE));
    Assert.assertTrue(isInstrumentedRoot(filter, createNode(sampleSource1.createSection(1)), ROOT_NODE_BITS_UNINITIALIZED));
    Assert.assertTrue(isInstrumentedRoot(filter, createNode(sampleSource2.createSection(1)), ROOT_NODE_BITS_UNINITIALIZED));
    Assert.assertFalse(isInstrumentedRoot(filter, createNode(sampleSource2.createSection(1)), ROOT_NODE_BITS_SAME_SOURCE));
    Assert.assertTrue(isInstrumentedRoot(filter, null, ROOT_NODE_BITS_SOURCE_SECTION_HIERARCHICAL));
    Assert.assertTrue(isInstrumentedRoot(filter, createNode(sampleSource1.createSection(1)), ROOT_NODE_BITS_SOURCE_SECTION_HIERARCHICAL));
    Assert.assertFalse(isInstrumentedRoot(filter, createNode(sampleSource1.createSection(5, 10)), ROOT_NODE_BITS_SOURCE_SECTION_HIERARCHICAL));
    Assert.assertTrue(isInstrumentedRoot(filter, createNode(sampleSource1.createSection(5, 10)), ROOT_NODE_BITS_UNINITIALIZED));
}
Also used : SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 8 with SourceSectionFilter

use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.

the class SourceSectionListenerTest method testLoadSourceSectionImpl.

private void testLoadSourceSectionImpl(int runTimes) throws IOException {
    Instrument instrument = engine.getInstruments().get("testLoadSourceSection1");
    SourceSection[] sourceSections1 = sections("STATEMENT(EXPRESSION, EXPRESSION)", "STATEMENT(EXPRESSION, EXPRESSION)", "EXPRESSION");
    final SourceSectionFilter statementFilter = SourceSectionFilter.newBuilder().tagIs(StandardTags.StatementTag.class).build();
    final SourceSectionFilter exprFilter = SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.EXPRESSION).build();
    Source source1 = sourceSections1[0].getSource();
    for (int i = 0; i < runTimes; i++) {
        run(source1);
    }
    assureEnabled(instrument);
    TestLoadSourceSection1 impl = instrument.lookup(TestLoadSourceSection1.class);
    assertSections(impl.query(SourceSectionFilter.ANY), sourceSections1);
    assertSections(impl.query(statementFilter), sourceSections1[0]);
    assertSections(impl.query(exprFilter), sourceSections1[2], sourceSections1[3]);
    SourceSection[] sourceSections2 = sections("STATEMENT(EXPRESSION)", "STATEMENT(EXPRESSION)", "EXPRESSION");
    Source source2 = sourceSections2[0].getSource();
    for (int i = 0; i < runTimes; i++) {
        run(source2);
    }
    assertEvents(impl.allEvents, merge(sourceSections1, sourceSections2));
    assertEvents(impl.onlyNewEvents, sourceSections2);
    assertEvents(impl.onlyStatements, sourceSections1[0], sourceSections2[0]);
    assertEvents(impl.onlyExpressions, sourceSections1[2], sourceSections1[3], sourceSections2[2]);
    assertSections(impl.query(SourceSectionFilter.ANY), merge(sourceSections1, sourceSections2));
    assertSections(impl.query(statementFilter), sourceSections1[0], sourceSections2[0]);
    assertSections(impl.query(exprFilter), sourceSections1[2], sourceSections1[3], sourceSections2[2]);
    // disables the instrument
    engine.close();
    engine = null;
    engine = getEngine();
    SourceSection[] sourceSections3 = sections("STATEMENT(EXPRESSION, EXPRESSION, EXPRESSION)", "STATEMENT(EXPRESSION, EXPRESSION, EXPRESSION)", "EXPRESSION");
    Source source3 = sourceSections3[0].getSource();
    for (int i = 0; i < runTimes; i++) {
        run(source3);
    }
    assertEvents(impl.allEvents, merge(sourceSections1, sourceSections2));
    assertEvents(impl.onlyNewEvents, sourceSections2);
    assertEvents(impl.onlyStatements, sourceSections1[0], sourceSections2[0]);
    assertEvents(impl.onlyExpressions, sourceSections1[2], sourceSections1[3], sourceSections2[2]);
    assertSections(impl.query(SourceSectionFilter.ANY), merge(sourceSections1, sourceSections2));
    assertSections(impl.query(statementFilter), sourceSections1[0], sourceSections2[0]);
    assertEvents(impl.onlyExpressions, sourceSections1[2], sourceSections1[3], sourceSections2[2]);
    instrument = engine.getInstruments().get("testLoadSourceSection1");
    assureEnabled(instrument);
    // new instrument needs update
    impl = instrument.lookup(TestLoadSourceSection1.class);
    assertEvents(impl.onlyNewEvents);
    assertEvents(impl.allEvents, sourceSections3);
    assertEvents(impl.onlyStatements, sourceSections3[0]);
    assertEvents(impl.onlyExpressions, sourceSections3[2], sourceSections3[3], sourceSections3[4]);
}
Also used : Instrument(org.graalvm.polyglot.Instrument) TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) SourceSection(org.graalvm.polyglot.SourceSection) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Source(org.graalvm.polyglot.Source)

Example 9 with SourceSectionFilter

use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.

the class InputFilterTest method testFilterChildren3.

@Test
public void testFilterChildren3() {
    SourceSectionFilter bogusLine = SourceSectionFilter.newBuilder().tagIs(StandardTags.ExpressionTag.class).lineIs(42).build();
    SourceSectionFilter line2 = SourceSectionFilter.newBuilder().tagIs(StandardTags.ExpressionTag.class).lineIs(2).build();
    String code = "EXPRESSION(\nEXPRESSION(CONSTANT(0)))";
    // test that input normal filter does not match to any inputs
    EventBinding<?> binding = instrumenter.attachExecutionEventFactory(bogusLine, line2, factory);
    execute(code);
    // no events happening
    binding.dispose();
    assertCleanedUp(code);
    assertAllEventsConsumed();
}
Also used : SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) StandardTags(com.oracle.truffle.api.instrumentation.StandardTags) Test(org.junit.Test)

Example 10 with SourceSectionFilter

use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.

the class InputFilterTest method testHierarchicalInputs.

@Test
public void testHierarchicalInputs() {
    SourceSectionFilter expressionFilter = SourceSectionFilter.newBuilder().tagIs(StandardTags.ExpressionTag.class).build();
    EventBinding<?> binding = instrumenter.attachExecutionEventFactory(expressionFilter, expressionFilter, factory);
    String exp1 = "EXPRESSION(EXPRESSION(CONSTANT(0)), EXPRESSION(CONSTANT(1)))";
    String exp2 = "EXPRESSION(EXPRESSION(CONSTANT(2)))";
    String exp3 = "EXPRESSION(EXPRESSION(CONSTANT(3)), EXPRESSION(EXPRESSION(CONSTANT(4))))";
    String code = "EXPRESSION(" + exp1 + "," + exp2 + "," + exp3 + ")";
    execute(code);
    FrameDescriptor[] descriptor = new FrameDescriptor[1];
    assertOn(ENTER, (e) -> {
        descriptor[0] = e.frame.getFrameDescriptor();
        assertCharacters(e, code);
    });
    // exp1
    assertOn(ENTER, (e) -> {
        assertCharacters(e, exp1);
    });
    assertOn(ENTER, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(0))");
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(0))");
        assertArrayEquals(new Object[] {}, e.inputs);
        assertEquals("(0)", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, exp1);
        assertEquals("(0)", e.inputValue);
    });
    assertOn(ENTER, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(1))");
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(1))");
        assertArrayEquals(new Object[] {}, e.inputs);
        assertEquals("(1)", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, exp1);
        assertEquals("(1)", e.inputValue);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, exp1);
        assertArrayEquals(new Object[] { "(0)", "(1)" }, e.inputs);
        assertEquals("((0)+(1))", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, code);
        assertEquals("((0)+(1))", e.inputValue);
    });
    // exp2
    assertOn(ENTER, (e) -> {
        assertCharacters(e, exp2);
    });
    assertOn(ENTER, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(2))");
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(2))");
        assertArrayEquals(new Object[] {}, e.inputs);
        assertEquals("(2)", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, exp2);
        assertEquals("(2)", e.inputValue);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, exp2);
        assertArrayEquals(new Object[] { "(2)" }, e.inputs);
        assertEquals("((2))", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, code);
        assertEquals("((2))", e.inputValue);
    });
    // exp3
    assertOn(ENTER, (e) -> {
        assertCharacters(e, exp3);
    });
    assertOn(ENTER, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(3))");
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(3))");
        assertEquals("(3)", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, exp3);
        assertEquals("(3)", e.inputValue);
    });
    assertOn(ENTER, (e) -> {
        assertCharacters(e, "EXPRESSION(EXPRESSION(CONSTANT(4)))");
    });
    assertOn(ENTER, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(4))");
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(4))");
        assertArrayEquals(new Object[] {}, e.inputs);
        assertEquals("(4)", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, "EXPRESSION(EXPRESSION(CONSTANT(4)))");
        assertEquals("(4)", e.inputValue);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, "EXPRESSION(EXPRESSION(CONSTANT(4)))");
        assertArrayEquals(new Object[] { "(4)" }, e.inputs);
        assertEquals("((4))", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, exp3);
        assertEquals("((4))", e.inputValue);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, exp3);
        assertArrayEquals(new Object[] { "(3)", "((4))" }, e.inputs);
        assertEquals("((3)+((4)))", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, code);
        assertEquals("((3)+((4)))", e.inputValue);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, code);
        assertArrayEquals(new Object[] { "((0)+(1))", "((2))", "((3)+((4)))" }, e.inputs);
        assertEquals("(((0)+(1))+((2))+((3)+((4))))", e.result);
    });
    // should use maximum four frame slots to save expression values
    assertEquals(4, descriptor[0].getIdentifiers().size());
    binding.dispose();
    assertCleanedUp(code);
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Test(org.junit.Test)

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