Search in sources :

Example 16 with SourceSection

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

the class Profiler method createCountingNode.

private ExecutionEventNode createCountingNode(EventContext context) {
    SourceSection sourceSection = context.getInstrumentedSourceSection();
    Counter counter = counters.get(sourceSection);
    if (counter == null) {
        final RootNode rootNode = context.getInstrumentedNode().getRootNode();
        counter = new Counter(sourceSection, rootNode == null ? "<unknown>>" : rootNode.getName());
        counters.put(sourceSection, counter);
    }
    if (isTiming) {
        return TimedCounterNode.create(this, counter, context);
    } else {
        return new CounterNode(this, counter);
    }
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) SourceSection(com.oracle.truffle.api.source.SourceSection)

Example 17 with SourceSection

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

the class Context method initializeContext.

@Override
protected void initializeContext(Context context) throws Exception {
    super.initializeContext(context);
    Source code = context.initSource;
    if (code != null) {
        SourceSection outer = code.createSection(0, code.getLength());
        BaseNode node = parse(code);
        RootCallTarget rct = Truffle.getRuntime().createCallTarget(new InstrumentationTestRootNode(this, "", outer, node));
        rct.call();
        if (context.runInitAfterExec) {
            context.afterTarget = rct;
        }
    }
}
Also used : SourceSection(com.oracle.truffle.api.source.SourceSection) RootCallTarget(com.oracle.truffle.api.RootCallTarget) Source(com.oracle.truffle.api.source.Source)

Example 18 with SourceSection

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

the class StatementProfilerExampleTest method testLoopHundreds.

@Test
public void testLoopHundreds() throws IOException {
    Source source = lines(// 1
    "LOOP(100", // 2
    ",STATEMENT(", // 3
    "STATEMENT),", /**/
    "STATEMENT)");
    // 4
    Map<SourceSection, Counter> counters = profiler.getCounters();
    for (int i = 0; i < 10; i++) {
        if (i == 0) {
            Assert.assertTrue(counters.isEmpty());
        } else {
            assertLine(counters, 2, i * 100);
            assertLine(counters, 3, i * 100);
            assertLine(counters, 4, i * 100);
        }
        run(source);
    }
}
Also used : Counter(com.oracle.truffle.api.instrumentation.test.examples.StatementProfilerExample.Counter) SourceSection(com.oracle.truffle.api.source.SourceSection) Source(org.graalvm.polyglot.Source) Test(org.junit.Test) AbstractInstrumentationTest(com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)

Example 19 with SourceSection

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

the class DefaultNearestNodeSearch method findNearestNodeAt.

/**
 * We have a source offset (the character index) and a context node given. The offset is in
 * node's source. The context node is an instrumentable node, but may not have any particular
 * tags. We're searching for an instrumentable node tagged with at least one of the given tags,
 * which is nearest to the given offset according to the guest language execution flow. We find
 * the nearest tagged {@link Node node} in following steps:
 * <ul>
 * <li>When the offset is inside the context node, we search for the first tagged parent node
 * and call {@link #findChildTaggedNode(Node, int, Set, boolean)} to find a tagged child. If we
 * find it, we return it, if not, we return the tagged parent.</li>
 * <li>When the offset is behind the context node, we return the last tagged child of the
 * context node.</li>
 * <li>When the offset is before the context node, we return the first tagged child of the
 * context node.</li>
 * </ul>
 */
static Node findNearestNodeAt(int offset, Node contextNode, Set<Class<? extends Tag>> tags) {
    Node node = (Node) ((InstrumentableNode) contextNode).materializeInstrumentableNodes(tags);
    SourceSection section = node.getSourceSection();
    int startIndex = section.getCharIndex();
    int endIndex = getCharEndIndex(section);
    if (startIndex <= offset && offset <= endIndex) {
        Node parent = findParentTaggedNode(node, tags);
        Node ch = findChildTaggedNode(node, offset, tags, parent != null, false);
        if (ch == null) {
            return parent;
        }
        return ch;
    } else if (endIndex < offset) {
        return findLastNode(node, tags);
    } else {
        // offset < o1
        return findFirstNode(node, tags);
    }
}
Also used : WrapperNode(com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode) Node(com.oracle.truffle.api.nodes.Node) SourceSection(com.oracle.truffle.api.source.SourceSection)

Example 20 with SourceSection

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

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