use of com.oracle.truffle.api.RootCallTarget in project graal by oracle.
the class DebugStackFrame method findCurrentRoot.
RootNode findCurrentRoot() {
SuspendedContext context = getContext();
if (currentFrame == null) {
return context.getInstrumentedNode().getRootNode();
} else {
Node callNode = currentFrame.getCallNode();
if (callNode != null) {
return callNode.getRootNode();
}
CallTarget target = currentFrame.getCallTarget();
if (target instanceof RootCallTarget) {
return ((RootCallTarget) target).getRootNode();
}
return null;
}
}
use of com.oracle.truffle.api.RootCallTarget in project graal by oracle.
the class TruffleRuntimeTest method testCreateCallTarget.
@Test
public void testCreateCallTarget() {
RootNode rootNode = createTestRootNode(null);
RootCallTarget target = runtime.createCallTarget(rootNode);
assertNotNull(target);
assertEquals(target.call(), 42);
assertSame(rootNode, target.getRootNode());
}
use of com.oracle.truffle.api.RootCallTarget 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.RootCallTarget 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.RootCallTarget in project graal by oracle.
the class OptimizedOSRLoopNodeTest method testNoOSRAfterMinInvocationThreshold.
/*
* Test that if a call target is called a min invocation theshold times it is unlikely that it
* needs OSR at all.
*/
@Theory
public void testNoOSRAfterMinInvocationThreshold(OSRLoopFactory factory) {
TestRootNode rootNode = new TestRootNode(factory, new TestRepeatingNode());
RootCallTarget target = runtime.createCallTarget(rootNode);
int i;
for (i = 0; i < TruffleCompilerOptions.getValue(TruffleMinInvokeThreshold); i++) {
target.call(0);
assertNotCompiled(rootNode.getOSRTarget());
}
target.call(OSR_THRESHOLD);
assertNotCompiled(rootNode.getOSRTarget());
}
Aggregations