Search in sources :

Example 16 with SourceSectionFilter

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

the class InputFilterTest method testFilterChildren2.

@Test
public void testFilterChildren2() {
    SourceSectionFilter line1 = SourceSectionFilter.newBuilder().tagIs(StandardTags.ExpressionTag.class).lineStartsIn(IndexRange.between(1, 2)).build();
    String code = "EXPRESSION(\nEXPRESSION(CONSTANT(0)))";
    // test that input filter does not match to any inputs
    EventBinding<?> binding = instrumenter.attachExecutionEventFactory(line1, line1, factory);
    execute(code);
    assertOn(ENTER, (e) -> {
        assertCharacters(e, code);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, code);
        assertArrayEquals(new Object[] {}, e.inputs);
        assertEquals("((0))", e.result);
    });
    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 17 with SourceSectionFilter

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

the class InputFilterTest method testInnerFrames.

@Test
public void testInnerFrames() {
    SourceSectionFilter expressionFilter = SourceSectionFilter.newBuilder().tagIs(StandardTags.ExpressionTag.class).build();
    String code = "EXPRESSION(INNER_FRAME(EXPRESSION(INNER_FRAME(EXPRESSION))))";
    EventBinding<?> binding1 = instrumenter.attachExecutionEventFactory(expressionFilter, expressionFilter, factory);
    execute(code);
    assertOn(ENTER);
    assertOn(ENTER);
    assertOn(ENTER);
    assertOn(RETURN_VALUE, (e) -> {
        assertEquals("()", e.result);
        assertArrayEquals(new Object[] {}, e.inputs);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertEquals(0, e.inputValueIndex);
        assertEquals("()", e.inputValue);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertEquals("(())", e.result);
        // the expression value is not recoverable for inner frames.
        assertArrayEquals(new Object[] { null }, e.inputs);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertEquals(0, e.inputValueIndex);
        assertEquals("(())", e.inputValue);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertEquals("((()))", e.result);
        assertArrayEquals(new Object[] { null }, e.inputs);
    });
    binding1.dispose();
    assertCleanedUp(code);
}
Also used : SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Test(org.junit.Test)

Example 18 with SourceSectionFilter

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

the class InputFilterTest method testCleanupFrameDescriptor.

@Test
public void testCleanupFrameDescriptor() {
    SourceSectionFilter expressionFilter = SourceSectionFilter.newBuilder().tagIs(StandardTags.ExpressionTag.class).build();
    String code = "EXPRESSION(INTERNAL(EXPRESSION))";
    assertCleanedUp(code);
    EventBinding<?> binding = instrumenter.attachExecutionEventFactory(expressionFilter, expressionFilter, factory);
    // lazy initialize
    execute(code);
    assertOn(ENTER);
    assertOn(ENTER);
    assertOn(RETURN_VALUE, (e) -> {
        assertEquals("()", e.result);
        assertArrayEquals(new Object[] {}, e.inputs);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertEquals(0, e.inputValueIndex);
        assertEquals("()", e.inputValue);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertEquals("(())", e.result);
        assertArrayEquals(new Object[] { "()" }, e.inputs);
    });
    binding.dispose();
    assertCleanedUp(code);
}
Also used : SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Test(org.junit.Test)

Example 19 with SourceSectionFilter

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

the class InputFilterTest method testSameInputFilter.

@Test
public void testSameInputFilter() {
    SourceSectionFilter expressionFilter = SourceSectionFilter.newBuilder().tagIs(StandardTags.ExpressionTag.class).build();
    EventBinding<?> binding = instrumenter.attachExecutionEventFactory(expressionFilter, expressionFilter, factory);
    String code = "ROOT(EXPRESSION(" + "INTERNAL(INTERNAL(EXPRESSION), INTERNAL)," + "STATEMENT(CONSTANT(42))," + "EXPRESSION)" + ")";
    execute(code);
    assertOn(ENTER);
    assertOn(ENTER);
    assertOn(RETURN_VALUE, (e) -> {
        assertEquals("()", e.result);
        assertArrayEquals(new Object[] {}, e.inputs);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertEquals(0, e.inputValueIndex);
        assertEquals("()", e.inputValue);
    });
    assertOn(ENTER);
    assertOn(RETURN_VALUE, (e) -> {
        assertEquals("()", e.result);
        assertArrayEquals(new Object[] {}, e.inputs);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertEquals(1, e.inputValueIndex);
        assertEquals("()", e.inputValue);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertEquals("(()+42+())", e.result);
        assertArrayEquals(new Object[] { "()", "()" }, e.inputs);
    });
    binding.dispose();
    assertCleanedUp(code);
}
Also used : SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Test(org.junit.Test)

Example 20 with SourceSectionFilter

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

the class InputFilterTest method testMultipleFactories.

@Test
public void testMultipleFactories() {
    SourceSectionFilter expressionFilter = SourceSectionFilter.newBuilder().tagIs(StandardTags.ExpressionTag.class).build();
    String code = "EXPRESSION(INTERNAL(EXPRESSION))";
    EventBinding<?> binding1 = instrumenter.attachExecutionEventFactory(expressionFilter, expressionFilter, factory);
    EventBinding<?> binding2 = instrumenter.attachExecutionEventFactory(expressionFilter, expressionFilter, factory);
    EventBinding<?> binding3 = instrumenter.attachExecutionEventFactory(expressionFilter, expressionFilter, factory);
    // lazy initialize
    execute(code);
    assertOn(ENTER);
    assertOn(ENTER);
    assertOn(ENTER);
    assertOn(ENTER);
    assertOn(ENTER);
    assertOn(ENTER);
    assertOn(RETURN_VALUE, (e) -> {
        assertEquals("()", e.result);
        assertArrayEquals(new Object[] {}, e.inputs);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertEquals(0, e.inputValueIndex);
        assertEquals("()", e.inputValue);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertEquals("()", e.result);
        assertArrayEquals(new Object[] {}, e.inputs);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertEquals(0, e.inputValueIndex);
        assertEquals("()", e.inputValue);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertEquals("()", e.result);
        assertArrayEquals(new Object[] {}, e.inputs);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertEquals(0, e.inputValueIndex);
        assertEquals("()", e.inputValue);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertEquals("(())", e.result);
        assertArrayEquals(new Object[] { "()" }, e.inputs);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertEquals("(())", e.result);
        assertArrayEquals(new Object[] { "()" }, e.inputs);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertEquals("(())", e.result);
        assertArrayEquals(new Object[] { "()" }, e.inputs);
    });
    binding1.dispose();
    binding2.dispose();
    binding3.dispose();
    assertCleanedUp(code);
}
Also used : 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