Search in sources :

Example 41 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class SourceSectionFilterTest method testIndexIn.

@Test
public void testIndexIn() {
    Source sampleSource = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Node root = createNode(sampleSource.createSection(0, 23));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexIn(0, 0).build(), root, createNode(sampleSource.createSection(0, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexIn(0, 1).build(), root, createNode(sampleSource.createSection(0, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexIn(5, 5).build(), root, createNode(sampleSource.createSection(5, 5), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexIn(5, 5).build(), root, createNode(sampleSource.createSection(0, 4), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexIn(5, 5).build(), root, createNode(sampleSource.createSection(0, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexIn(5, 5).build(), root, createNode(sampleSource.createSection(4, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexIn(5, 5).build(), root, createNode(sampleSource.createSection(4, 6), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexIn(5, 5).build(), root, createNode(sampleSource.createSection(5, 5), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexIn(5, 5).build(), root, createNode(sampleSource.createSection(10, 1), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexIn(5, 5).build(), root, createNode(sampleSource.createSection(9, 1), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexIn(5, 5).build(), root, createNode(sampleSource.createSection(9, 5), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexIn(5, 5).build(), root, createNode(sampleSource.createUnavailableSection())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexIn(IndexRange.between(0, 5)).build(), root, createNode(sampleSource.createSection(5, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexIn(IndexRange.between(0, 5), IndexRange.between(5, 6)).build(), root, createNode(sampleSource.createSection(5, 5), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexIn(IndexRange.between(0, 5), IndexRange.between(11, 12)).build(), root, createNode(sampleSource.createSection(5, 5), tags())));
    Assert.assertNotNull(SourceSectionFilter.newBuilder().indexIn(5, 5).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 42 with Source

use of com.oracle.truffle.api.source.Source 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 43 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class SourceSectionFilterTest method testSourceSectionEquals.

@Test
public void testSourceSectionEquals() {
    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();
    Node root1 = createNode(sampleSource1.createSection(0, 23));
    Node root2 = createNode(sampleSource2.createSection(0, 23));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().sourceSectionEquals(sampleSource1.createSection(1, 6)).build(), root1, createNode(sampleSource1.createSection(1, 6), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().sourceSectionEquals(sampleSource1.createSection(1, 6)).build(), root2, createNode(sampleSource2.createSection(1, 6), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().sourceSectionEquals(sampleSource1.createSection(1, 7)).build(), root1, createNode(sampleSource1.createSection(1, 6), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().sourceSectionEquals(sampleSource1.createSection(2, 6)).build(), root1, createNode(sampleSource1.createSection(1, 6), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().sourceSectionEquals(sampleSource1.createSection(2, 6), sampleSource1.createSection(2, 7)).build(), root1, createNode(sampleSource1.createSection(2, 7), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().sourceSectionEquals(sampleSource1.createSection(2, 6), sampleSource1.createSection(2, 7)).build(), root1, createNode(sampleSource1.createSection(2, 8), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().sourceSectionEquals(sampleSource1.createSection(2, 6), sampleSource1.createSection(2, 7)).build(), null, createNode(sampleSource1.createUnavailableSection())));
    Assert.assertNotNull(SourceSectionFilter.newBuilder().sourceSectionEquals(sampleSource1.createSection(1, 6)).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 44 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class InstrumentationHandler method onFirstExecution.

void onFirstExecution(RootNode root) {
    if (!AccessorInstrumentHandler.nodesAccess().isInstrumentable(root)) {
        return;
    }
    assert root.getLanguageInfo() != null;
    if (hasSourceExecutedBindings) {
        final Source[] rootSources;
        synchronized (sourcesExecuted) {
            if (!sourceExecutedBindings.isEmpty()) {
                // we'll add to the sourcesExecutedList, so it needs to be initialized
                lazyInitializeSourcesExecutedList();
                int rootBits = RootNodeBits.get(root);
                if (RootNodeBits.isNoSourceSection(rootBits)) {
                    rootSources = null;
                } else {
                    SourceSection sourceSection = root.getSourceSection();
                    if (RootNodeBits.isSameSource(rootBits) && sourceSection != null) {
                        Source source = sourceSection.getSource();
                        findSourcesExecutedVisitor.adoptSource(source);
                        rootSources = new Source[] { source };
                    } else {
                        if (sourceSection != null) {
                            findSourcesExecutedVisitor.adoptSource(sourceSection.getSource());
                        }
                        visitRoot(root, root, findSourcesExecutedVisitor, false);
                        rootSources = findSourcesExecutedVisitor.getSources();
                    }
                }
            } else {
                hasSourceExecutedBindings = false;
                sourcesExecuted.clear();
                sourcesExecutedListRef.set(null);
                rootSources = null;
            }
        }
        executedRoots.add(root);
        // Do not invoke foreign code while holding a lock to avoid deadlocks.
        if (rootSources != null) {
            for (Source src : rootSources) {
                notifySourceExecutedBindings(sourceExecutedBindings, src);
            }
        }
    } else {
        executedRoots.add(root);
    }
    // fast path no bindings attached
    if (!executionBindings.isEmpty()) {
        visitRoot(root, root, new InsertWrappersVisitor(executionBindings), false);
    }
}
Also used : SourceSection(com.oracle.truffle.api.source.SourceSection) Source(com.oracle.truffle.api.source.Source)

Example 45 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class InstrumentationHandler method lazyInitializeSourcesList.

/**
 * Initializes sources and sourcesList by populating them from loadedRoots.
 */
private void lazyInitializeSourcesList() {
    assert Thread.holdsLock(sources);
    if (sourcesListRef.get() == null) {
        // build the sourcesList, we need it now
        Collection<Source> sourcesList = new WeakAsyncList<>(16);
        sourcesListRef.set(sourcesList);
        for (RootNode root : loadedRoots) {
            int rootBits = RootNodeBits.get(root);
            if (RootNodeBits.isNoSourceSection(rootBits)) {
                continue;
            } else {
                SourceSection sourceSection = root.getSourceSection();
                if (RootNodeBits.isSameSource(rootBits) && sourceSection != null) {
                    Source source = sourceSection.getSource();
                    if (!sources.containsKey(source)) {
                        sources.put(source, null);
                        sourcesList.add(source);
                    }
                } else {
                    if (sourceSection != null) {
                        findSourcesVisitor.adoptSource(sourceSection.getSource());
                    }
                    visitRoot(root, root, findSourcesVisitor, false);
                    for (Source source : findSourcesVisitor.rootSources) {
                        if (!sources.containsKey(source)) {
                            sources.put(source, null);
                            sourcesList.add(source);
                        }
                    }
                    findSourcesVisitor.rootSources.clear();
                }
            }
        }
    }
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) SourceSection(com.oracle.truffle.api.source.SourceSection) Source(com.oracle.truffle.api.source.Source)

Aggregations

Source (com.oracle.truffle.api.source.Source)113 Test (org.junit.Test)65 RootNode (com.oracle.truffle.api.nodes.RootNode)23 File (java.io.File)20 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)16 Node (com.oracle.truffle.api.nodes.Node)16 SourceSection (com.oracle.truffle.api.source.SourceSection)16 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)15 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)11 SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)8 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 CallTarget (com.oracle.truffle.api.CallTarget)5 FileWriter (java.io.FileWriter)5 RootCallTarget (com.oracle.truffle.api.RootCallTarget)4 TruffleContext (com.oracle.truffle.api.TruffleContext)3 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)3 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)3 Script (com.oracle.truffle.tools.chromeinspector.types.Script)3