use of com.oracle.truffle.api.nodes.RootNode 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();
}
}
}
}
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class ProbeNode method findParentChain.
@SuppressWarnings("deprecation")
private EventChainNode findParentChain(VirtualFrame frame, EventBinding<?> binding) {
Node node = getParent().getParent();
while (node != null) {
// TODO we should avoid materializing the source section here
if (node instanceof com.oracle.truffle.api.instrumentation.InstrumentableFactory.WrapperNode) {
ProbeNode probe = ((com.oracle.truffle.api.instrumentation.InstrumentableFactory.WrapperNode) node).getProbeNode();
EventChainNode c = probe.lazyUpdate(frame);
if (c != null) {
c = c.find(binding);
}
if (c != null) {
return c;
}
} else if (node instanceof RootNode) {
break;
}
node = node.getParent();
}
if (node == null) {
throw new IllegalStateException("The AST node is not yet adopted. ");
}
return null;
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class SLLanguage method parse.
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
Source source = request.getSource();
Map<String, RootCallTarget> functions;
/*
* Parse the provided source. At this point, we do not have a SLContext yet. Registration of
* the functions with the SLContext happens lazily in SLEvalRootNode.
*/
if (request.getArgumentNames().isEmpty()) {
functions = Parser.parseSL(this, source);
} else {
StringBuilder sb = new StringBuilder();
sb.append("function main(");
String sep = "";
for (String argumentName : request.getArgumentNames()) {
sb.append(sep);
sb.append(argumentName);
sep = ",";
}
sb.append(") { return ");
sb.append(request.getSource().getCharacters());
sb.append(";}");
Source decoratedSource = Source.newBuilder(sb.toString()).mimeType(request.getSource().getMimeType()).name(request.getSource().getName()).build();
functions = Parser.parseSL(this, decoratedSource);
}
RootCallTarget main = functions.get("main");
RootNode evalMain;
if (main != null) {
/*
* We have a main function, so "evaluating" the parsed source means invoking that main
* function. However, we need to lazily register functions into the SLContext first, so
* we cannot use the original SLRootNode for the main function. Instead, we create a new
* SLEvalRootNode that does everything we need.
*/
evalMain = new SLEvalRootNode(this, main, functions);
} else {
/*
* Even without a main function, "evaluating" the parsed source needs to register the
* functions into the SLContext.
*/
evalMain = new SLEvalRootNode(this, null, functions);
}
return Truffle.getRuntime().createCallTarget(evalMain);
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class SLStatementNode method getSourceSection.
/*
* The creation of source section can be implemented lazily by looking up the root node source
* and then creating the source section object using the indices stored in the node. This avoids
* the eager creation of source section objects during parsing and creates them only when they
* are needed. Alternatively, if the language uses source sections to implement language
* semantics, then it might be more efficient to eagerly create source sections and store it in
* the AST.
*
* For more details see {@link InstrumentableNode}.
*/
@Override
@TruffleBoundary
public final SourceSection getSourceSection() {
if (sourceCharIndex == NO_SOURCE) {
// AST node without source
return null;
}
RootNode rootNode = getRootNode();
if (rootNode == null) {
// not yet adopted yet
return null;
}
SourceSection rootSourceSection = rootNode.getSourceSection();
if (rootSourceSection == null) {
return null;
}
Source source = rootSourceSection.getSource();
if (sourceCharIndex == UNAVAILABLE_SOURCE) {
return source.createUnavailableSection();
} else {
return source.createSection(sourceCharIndex, sourceLength);
}
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class SimplePartialEvaluationTest method intrinsicHashCode.
@Test
public void intrinsicHashCode() {
/*
* The intrinsic for Object.hashCode() is inlined late during Truffle partial evaluation,
* because we call hashCode() on a value whose exact type Object is only known during
* partial evaluation.
*/
FrameDescriptor fd = new FrameDescriptor();
Object testObject = new Object();
AbstractTestNode result = new ObjectHashCodeNode(testObject);
RootNode rootNode = new RootTestNode(fd, "intrinsicHashCode", result);
OptimizedCallTarget compilable = compileHelper("intrinsicHashCode", rootNode, new Object[0]);
int actual = (Integer) compilable.call(new Object[0]);
int expected = testObject.hashCode();
Assert.assertEquals(expected, actual);
}
Aggregations