Search in sources :

Example 36 with Node

use of com.oracle.truffle.api.nodes.Node in project graal by oracle.

the class InstrumentationUpdateTest method assertExecuted.

private void assertExecuted(Node... children) {
    Iterator<EventContext> executeIterator = executionEvents.iterator();
    for (Node loadedChild : children) {
        Assert.assertTrue(executeIterator.hasNext());
        Assert.assertSame(loadedChild, executeIterator.next().getInstrumentedNode());
    }
    Assert.assertFalse(executeIterator.hasNext());
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) WrapperNode(com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode)

Example 37 with Node

use of com.oracle.truffle.api.nodes.Node in project graal by oracle.

the class SourceListenerTest method testNoRootSectionImpl.

private void testNoRootSectionImpl(TestLoadExecuteSource impl) throws Exception {
    com.oracle.truffle.api.source.Source source1 = com.oracle.truffle.api.source.Source.newBuilder("line1\nline2").mimeType("mime").name("NoName1").build();
    com.oracle.truffle.api.source.Source source2 = com.oracle.truffle.api.source.Source.newBuilder("line3\nline4").mimeType("mime").name("NoName2").build();
    com.oracle.truffle.api.source.Source source3 = com.oracle.truffle.api.source.Source.newBuilder("line5\nline6").mimeType("mime").name("NoName3").build();
    Node node1 = new SourceSectionFilterTest.SourceSectionNode(source1.createSection(1));
    RootNode rootA = SourceSectionFilterTest.createRootNode(engine, null, Boolean.FALSE, node1);
    assertEvents(impl.allEvents);
    Truffle.getRuntime().createCallTarget(rootA).call();
    assertEvents(impl.allEvents, source1);
    Node node2 = new SourceSectionFilterTest.SourceSectionNode(source2.createSection(2));
    Node node3 = new SourceSectionFilterTest.SourceSectionNode(source3.createSection(2));
    RootNode rootB = SourceSectionFilterTest.createRootNode(engine, null, Boolean.FALSE, node2, node3);
    assertEvents(impl.allEvents, source1);
    Truffle.getRuntime().createCallTarget(rootB).call();
    assertEvents(impl.allEvents, source1, source2, source3);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode)

Example 38 with Node

use of com.oracle.truffle.api.nodes.Node in project graal by oracle.

the class SourceListenerTest method testBindingDisposalImpl.

private void testBindingDisposalImpl(boolean load) throws Exception {
    Instrument instrument = engine.getInstruments().get("testBindingDisposal");
    TestBindingDisposal impl = instrument.lookup(TestBindingDisposal.class);
    impl.doAttach(load);
    Source source1 = lines("STATEMENT");
    run(source1);
    assertEvents(impl.onlyNewEvents, source1);
    assertEvents(impl.allEvents, source1);
    impl.onlyNewBinding.dispose();
    impl.allBinding.dispose();
    // No new events received after bindings are disposed
    com.oracle.truffle.api.source.Source source2a = com.oracle.truffle.api.source.Source.newBuilder("line2a").mimeType("mime").name("NoName2a").build();
    com.oracle.truffle.api.source.Source source2b = com.oracle.truffle.api.source.Source.newBuilder("line2b").mimeType("mime").name("NoName2b").build();
    Node node2a = new SourceSectionFilterTest.SourceSectionNode(source2a.createSection(1));
    Node node2b = new SourceSectionFilterTest.SourceSectionNode(source2b.createSection(1));
    RootNode root2 = SourceSectionFilterTest.createRootNode(engine, null, Boolean.FALSE, node2a, node2b);
    Truffle.getRuntime().createCallTarget(root2).call();
    assertEvents(impl.onlyNewEvents, source1);
    assertEvents(impl.allEvents, source1);
    // Clear and reattach
    impl.onlyNewEvents.clear();
    impl.allEvents.clear();
    impl.doAttach(load);
    Source source3 = lines("VARIABLE(a, 10)");
    run(source3);
    assertEvents(impl.onlyNewEvents, source3);
    assertEvents(impl.allEvents, getSourceImpl(source1), source2a, source2b, getSourceImpl(source3));
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) Instrument(org.graalvm.polyglot.Instrument) TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) Source(org.graalvm.polyglot.Source)

Example 39 with Node

use of com.oracle.truffle.api.nodes.Node in project graal by oracle.

the class SourceSectionFilterTest method testSourceIn.

@Test
public void testSourceIn() {
    Source sampleSource1 = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Source sampleSource2 = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Source sampleSource3 = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Node root1 = createNode(sampleSource1.createSection(0, 23));
    Node root2 = createNode(sampleSource2.createSection(0, 23));
    Node root3 = createNode(sampleSource3.createSection(0, 23));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().sourceIs(sampleSource1).build(), root1, createNode(sampleSource1.createSection(0, 5), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().sourceIs(sampleSource1).build(), null, createNode(sampleSource2.createUnavailableSection())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().sourceIs(sampleSource1).build(), root2, createNode(sampleSource2.createSection(0, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().sourceIs(sampleSource1, sampleSource2).build(), root2, createNode(sampleSource2.createSection(0, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().sourceIs(sampleSource1, sampleSource2).build(), root1, createNode(sampleSource1.createSection(0, 5), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().sourceIs(sampleSource1, sampleSource2).build(), root3, createNode(sampleSource3.createSection(0, 5), tags())));
    Assert.assertNotNull(SourceSectionFilter.newBuilder().sourceIs(sampleSource1, sampleSource2).build().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) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 40 with Node

use of com.oracle.truffle.api.nodes.Node in project graal by oracle.

the class SourceSectionFilterTest method testLineStartIn.

@Test
public void testLineStartIn() {
    Source sampleSource = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Node root = createNode(sampleSource.createSection(0, 23));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineStartsIn(IndexRange.byLength(2, 1)).build(), root, createNode(sampleSource.createSection(6, 15))));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineStartsIn(IndexRange.byLength(2, 1)).build(), root, createNode(sampleSource.createSection(0, 15))));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineStartsIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(0, 15))));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineStartsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(0, 15))));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineStartsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(6, 15))));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineStartsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(12, 6))));
}
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) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Aggregations

Node (com.oracle.truffle.api.nodes.Node)101 RootNode (com.oracle.truffle.api.nodes.RootNode)65 Test (org.junit.Test)46 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)21 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)21 Source (com.oracle.truffle.api.source.Source)16 NodeVisitor (com.oracle.truffle.api.nodes.NodeVisitor)11 CallTarget (com.oracle.truffle.api.CallTarget)9 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)9 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)8 WrapperNode (com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode)7 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)6 SourceSection (com.oracle.truffle.api.source.SourceSection)6 TestHelper.createNode (com.oracle.truffle.api.dsl.test.TestHelper.createNode)5 ValueNode (com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode)5 SLEvalRootNode (com.oracle.truffle.sl.nodes.SLEvalRootNode)5 SLStatementNode (com.oracle.truffle.sl.nodes.SLStatementNode)5 SLBlockNode (com.oracle.truffle.sl.nodes.controlflow.SLBlockNode)5 LinkedHashMap (java.util.LinkedHashMap)5 TruffleInstrument (com.oracle.truffle.api.instrumentation.TruffleInstrument)4