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