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();
}
}
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);
}
}
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;
}
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);
}
}
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;
}
Aggregations