Search in sources :

Example 66 with Source

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

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

the class SourceSectionFilterTest method testColumnStartIn.

@Test
public void testColumnStartIn() {
    Source sampleSource = Source.newBuilder("123456789\n123456789").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Node root = createNode(sampleSource.createSection(0, 19));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(2, 1)).build(), root, createNode(sampleSource.createSection(1, 1))));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(2, 1)).build(), root, createNode(sampleSource.createSection(0, 2))));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(0, 2))));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(0, 2))));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(1, 2))));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(2, 1))));
}
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 68 with Source

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

the class SourceSectionFilterTest method testColumnIn.

@Test
public void testColumnIn() {
    Source sampleSource = Source.newBuilder("123456789\n123456789").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Node root = createNode(sampleSource.createSection(0, 19));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 1).build(), root, createNode(sampleSource.createSection(1, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(1, 2).build(), root, createNode(sampleSource.createSection(0, 1), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnIn(1, 1).build(), root, createNode(sampleSource.createSection(1, 1), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 2).build(), root, createNode(sampleSource.createSection(4, 1), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 2).build(), root, createNode(sampleSource.createSection(1, 1), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 2).build(), root, createNode(sampleSource.createSection(1, 5), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 2).build(), root, createNode(sampleSource.createSection(0, 1), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 2).build(), root, createNode(sampleSource.createSection(0, 2), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 2).build(), root, createNode(sampleSource.createSection(1, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 2).build(), root, createNode(sampleSource.createSection(1, 1), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(2, 2).build(), root, createNode(sampleSource.createSection(0, 5), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnIn(1, 1).build(), root, createNode(sampleSource.createUnavailableSection())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnIn(IndexRange.byLength(1, 1)).build(), root, createNode(sampleSource.createSection(1, 1), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnIn(IndexRange.byLength(1, 1), IndexRange.between(2, 3), IndexRange.byLength(3, 1)).build(), root, createNode(sampleSource.createSection(1, 1), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnIn(IndexRange.byLength(1, 1), IndexRange.byLength(3, 1)).build(), root, createNode(sampleSource.createSection(1, 1), tags())));
    Assert.assertNotNull(SourceSectionFilter.newBuilder().columnIn(2, 2).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 69 with Source

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

the class InstrumentationHandler method addSourceExecutionBinding.

<T> EventBinding<T> addSourceExecutionBinding(EventBinding.Source<T> binding, boolean notifyLoaded) {
    if (TRACE) {
        trace("BEGIN: Adding source execution binding %s, %s%n", binding.getFilter(), binding.getElement());
    }
    this.sourceExecutedBindings.add(binding);
    this.hasSourceExecutedBindings = true;
    if (notifyLoaded) {
        synchronized (sourcesExecuted) {
            lazyInitializeSourcesExecutedList();
        }
        for (Source source : sourcesExecutedListRef.get()) {
            notifySourceExecutedBinding(binding, source);
        }
    }
    if (TRACE) {
        trace("END: Added source execution binding %s, %s%n", binding.getFilter(), binding.getElement());
    }
    return binding;
}
Also used : Source(com.oracle.truffle.api.source.Source)

Example 70 with Source

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

the class InstrumentationHandler method onLoad.

void onLoad(RootNode root) {
    if (!AccessorInstrumentHandler.nodesAccess().isInstrumentable(root)) {
        return;
    }
    assert root.getLanguageInfo() != null;
    if (hasSourceBindings) {
        final Source[] rootSources;
        synchronized (sources) {
            if (!sourceBindings.isEmpty()) {
                // we'll add to the sourcesList, so it needs to be initialized
                lazyInitializeSourcesList();
                SourceSection sourceSection = root.getSourceSection();
                if (sourceSection != null) {
                    findSourcesVisitor.adoptSource(sourceSection.getSource());
                }
                visitRoot(root, root, findSourcesVisitor, false);
                rootSources = findSourcesVisitor.getSources();
            } else {
                hasSourceBindings = false;
                sources.clear();
                sourcesListRef.set(null);
                rootSources = null;
            }
        }
        loadedRoots.add(root);
        // Do not invoke foreign code while holding a lock to avoid deadlocks.
        if (rootSources != null) {
            for (Source src : rootSources) {
                notifySourceBindingsLoaded(sourceBindings, src);
            }
        }
    } else {
        loadedRoots.add(root);
    }
    // fast path no bindings attached
    if (!sourceSectionBindings.isEmpty()) {
        visitRoot(root, root, new NotifyLoadedListenerVisitor(sourceSectionBindings), false);
    }
}
Also used : 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