Search in sources :

Example 21 with SourceSection

use of com.oracle.truffle.api.source.SourceSection 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)

Example 22 with SourceSection

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

the class InstrumentationHandler method createBindings.

EventChainNode createBindings(VirtualFrame frame, ProbeNode probeNodeImpl) {
    EventContext context = probeNodeImpl.getContext();
    SourceSection sourceSection = context.getInstrumentedSourceSection();
    if (TRACE) {
        trace("BEGIN: Lazy update for %s%n", sourceSection);
    }
    RootNode rootNode;
    Node parentInstrumentable = null;
    SourceSection parentInstrumentableSourceSection = null;
    Node parentNode = probeNodeImpl.getParent();
    while (parentNode != null && parentNode.getParent() != null) {
        if (parentInstrumentable == null) {
            SourceSection parentSourceSection = parentNode.getSourceSection();
            if (isInstrumentableNode(parentNode, parentSourceSection)) {
                parentInstrumentable = parentNode;
                parentInstrumentableSourceSection = parentSourceSection;
            }
        }
        parentNode = parentNode.getParent();
    }
    if (parentNode instanceof RootNode) {
        rootNode = (RootNode) parentNode;
    } else {
        throw new AssertionError();
    }
    Node instrumentedNode = probeNodeImpl.getContext().getInstrumentedNode();
    Set<Class<?>> providedTags = getProvidedTags(rootNode);
    EventChainNode root = null;
    EventChainNode parent = null;
    for (EventBinding.Source<?> binding : executionBindings) {
        if (binding.isChildInstrumentedFull(providedTags, rootNode, parentInstrumentable, parentInstrumentableSourceSection, instrumentedNode, sourceSection)) {
            if (TRACE) {
                trace("  Found input value binding %s, %s%n", binding.getInputFilter(), System.identityHashCode(binding));
            }
            EventChainNode next = probeNodeImpl.createParentEventChainCallback(frame, binding, rootNode, providedTags);
            if (next == null) {
                // inconsistent AST
                continue;
            }
            if (root == null) {
                root = next;
            } else {
                assert parent != null;
                parent.setNext(next);
            }
            parent = next;
        }
        if (binding.isInstrumentedFull(providedTags, rootNode, instrumentedNode, sourceSection)) {
            if (TRACE) {
                trace("  Found binding %s, %s%n", binding.getFilter(), binding.getElement());
            }
            EventChainNode next = probeNodeImpl.createEventChainCallback(frame, binding, rootNode, providedTags, instrumentedNode, sourceSection);
            if (next == null) {
                continue;
            }
            if (root == null) {
                root = next;
            } else {
                assert parent != null;
                parent.setNext(next);
            }
            parent = next;
        }
    }
    if (TRACE) {
        trace("END: Lazy updated for %s%n", sourceSection);
    }
    return root;
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) EventChainNode(com.oracle.truffle.api.instrumentation.ProbeNode.EventChainNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) EventChainNode(com.oracle.truffle.api.instrumentation.ProbeNode.EventChainNode) SourceSection(com.oracle.truffle.api.source.SourceSection)

Example 23 with SourceSection

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

the class InstrumentationHandler method lazyInitializeSourcesExecutedList.

/**
 * Initializes sourcesExecuted and sourcesExecutedList by populating them from executedRoots.
 */
private void lazyInitializeSourcesExecutedList() {
    assert Thread.holdsLock(sourcesExecuted);
    if (sourcesExecutedListRef.get() == null) {
        // build the sourcesExecutedList, we need it now
        Collection<Source> sourcesExecutedList = new WeakAsyncList<>(16);
        sourcesExecutedListRef.set(sourcesExecutedList);
        for (RootNode root : executedRoots) {
            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 (!sourcesExecuted.containsKey(source)) {
                        sourcesExecuted.put(source, null);
                        sourcesExecutedList.add(source);
                    }
                } else {
                    if (sourceSection != null) {
                        findSourcesExecutedVisitor.adoptSource(sourceSection.getSource());
                    }
                    visitRoot(root, root, findSourcesExecutedVisitor, false);
                    for (Source source : findSourcesExecutedVisitor.rootSources) {
                        if (!sourcesExecuted.containsKey(source)) {
                            sourcesExecuted.put(source, null);
                            sourcesExecutedList.add(source);
                        }
                    }
                    findSourcesExecutedVisitor.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)

Example 24 with SourceSection

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

the class SourceSectionTest method testSourceSections.

@Theory
public void testSourceSections(int value0, int value1, int value2) {
    TestRootNode<MutableSourceSectionNode> root = createRoot(SourceSectionTestFactory.MutableSourceSectionNodeFactory.getInstance());
    SourceSection section = Source.newBuilder("").name("a").mimeType("").build().createUnavailableSection();
    root.getNode().changeSourceSection(section);
    expectSourceSection(root.getNode(), section);
    assertThat((int) executeWith(root, value0), is(value0));
    expectSourceSection(root.getNode(), section);
    assertThat((int) executeWith(root, value1), is(value1));
    expectSourceSection(root.getNode(), section);
    assertThat((int) executeWith(root, value2), is(value2));
    expectSourceSection(root.getNode(), section);
}
Also used : SourceSection(com.oracle.truffle.api.source.SourceSection) Theory(org.junit.experimental.theories.Theory)

Example 25 with SourceSection

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

the class SourceSectionTest method testCreateCast.

@Test
public void testCreateCast() {
    SourceSection section = Source.newBuilder("").name("a").mimeType("").build().createUnavailableSection();
    TestRootNode<NodeWithFixedSourceSection> root = createRootPrefix(SourceSectionTestFactory.NodeWithFixedSourceSectionFactory.getInstance(), true, section);
    expectSourceSection(root.getNode(), section);
    assertThat((int) executeWith(root, 1), is(1));
    expectSourceSection(root.getNode(), section);
}
Also used : SourceSection(com.oracle.truffle.api.source.SourceSection) Test(org.junit.Test)

Aggregations

SourceSection (com.oracle.truffle.api.source.SourceSection)68 Test (org.junit.Test)23 Source (com.oracle.truffle.api.source.Source)15 Source (org.graalvm.polyglot.Source)12 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)11 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)8 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)8 AbstractInstrumentationTest (com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)6 Node (com.oracle.truffle.api.nodes.Node)6 RootNode (com.oracle.truffle.api.nodes.RootNode)6 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)5 DebugValue (com.oracle.truffle.api.debug.DebugValue)5 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)3 DebugScope (com.oracle.truffle.api.debug.DebugScope)3 Counter (com.oracle.truffle.api.instrumentation.test.examples.StatementProfilerExample.Counter)3 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)3 RootCallTarget (com.oracle.truffle.api.RootCallTarget)2 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)2 WrapperNode (com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode)2 SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)2