Search in sources :

Example 46 with SourceSection

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

the class InstrumentationHandler method invalidateWrapperImpl.

@SuppressWarnings("deprecation")
private static void invalidateWrapperImpl(com.oracle.truffle.api.instrumentation.InstrumentableFactory.WrapperNode parent, Node node) {
    ProbeNode probeNode = parent.getProbeNode();
    if (TRACE) {
        SourceSection section = probeNode.getContext().getInstrumentedSourceSection();
        trace("Invalidate wrapper for %s, section %s %n", node, section);
    }
    if (probeNode != null) {
        probeNode.invalidate();
    }
}
Also used : SourceSection(com.oracle.truffle.api.source.SourceSection)

Example 47 with SourceSection

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

Example 48 with SourceSection

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

the class TruffleInlining method getPosition.

@Override
public SourceLanguagePosition getPosition(JavaConstant node) {
    SnippetReflectionProvider snippetReflection = runtime().getGraalRuntime().getRequiredCapability(SnippetReflectionProvider.class);
    Node truffleNode = snippetReflection.asObject(Node.class, node);
    if (truffleNode == null) {
        return null;
    }
    SourceSection section = null;
    if (truffleNode instanceof DirectCallNode) {
        section = ((DirectCallNode) truffleNode).getCurrentRootNode().getSourceSection();
    }
    if (section == null) {
        section = truffleNode.getSourceSection();
    }
    if (section == null) {
        Node cur = truffleNode.getParent();
        while (cur != null) {
            section = cur.getSourceSection();
            if (section != null) {
                break;
            }
            cur = cur.getParent();
        }
    }
    if (section != null) {
        return new TruffleSourceLanguagePosition(section);
    }
    return null;
}
Also used : SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) Node(com.oracle.truffle.api.nodes.Node) SourceSection(com.oracle.truffle.api.source.SourceSection) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode)

Example 49 with SourceSection

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

the class BreakpointSnippets method install.

private void install() {
    assert Thread.holdsLock(this);
    if (sourceBinding == null) {
        SourceFilter filter = locationKey.createSourceFilter();
        final boolean[] sourceResolved = new boolean[] { false };
        sourceBinding = debugger.getInstrumenter().attachExecuteSourceListener(filter, new ExecuteSourceListener() {

            @Override
            public void onExecute(ExecuteSourceEvent event) {
                if (sourceResolved[0]) {
                    return;
                }
                sourceResolved[0] = true;
                synchronized (Breakpoint.this) {
                    if (sourceBinding != null) {
                        sourceBinding.dispose();
                    }
                }
                Source source = event.getSource();
                SourceSection location = locationKey.adjustLocation(source, debugger.getEnv(), suspendAnchor);
                if (location != null) {
                    resolveBreakpoint(location);
                }
                SourceSectionFilter locationFilter = locationKey.createLocationFilter(source, suspendAnchor);
                breakpointBinding = createBinding(locationFilter);
            }
        }, true);
        if (sourceResolved[0]) {
            sourceBinding.dispose();
        }
    } else if (breakpointBinding == null && sourceBinding.isDisposed()) {
        // re-installing breakpoint
        SourceSectionFilter locationFilter = locationKey.createLocationFilter(null, suspendAnchor);
        breakpointBinding = createBinding(locationFilter);
    }
}
Also used : SourceFilter(com.oracle.truffle.api.instrumentation.SourceFilter) ExecuteSourceEvent(com.oracle.truffle.api.instrumentation.ExecuteSourceEvent) ExecuteSourceListener(com.oracle.truffle.api.instrumentation.ExecuteSourceListener) SourceSection(com.oracle.truffle.api.source.SourceSection) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Source(com.oracle.truffle.api.source.Source)

Example 50 with SourceSection

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

the class BreakpointLocation method adjustLocation.

SourceSection adjustLocation(Source source, TruffleInstrument.Env env, SuspendAnchor suspendAnchor) {
    if (sourceSection != null) {
        return sourceSection;
    }
    if (key == null) {
        return null;
    }
    boolean hasColumn = column > 0;
    SourceSection location = SuspendableLocationFinder.findNearest(source, sourceElements, line, column, suspendAnchor, env);
    if (location != null) {
        switch(suspendAnchor) {
            case BEFORE:
                line = location.getStartLine();
                if (hasColumn) {
                    column = location.getStartColumn();
                }
                break;
            case AFTER:
                line = location.getEndLine();
                if (hasColumn) {
                    column = location.getEndColumn();
                }
                break;
            default:
                throw new IllegalArgumentException("Unknown suspend anchor: " + suspendAnchor);
        }
    }
    return location;
}
Also used : SourceSection(com.oracle.truffle.api.source.SourceSection)

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