use of com.oracle.truffle.api.CallTarget in project graal by oracle.
the class OptimizedOSRLoopNodeTest method testInternalInvalidations.
/*
* Test behavior of OSR compile loops if the invalidate internally during loop execution. Also
* test that it respects the invalidation reprofile count.
*/
@Theory
public void testInternalInvalidations(OSRLoopFactory factory) {
TestRepeatingNode repeating = new TestRepeatingNode();
TestRootNode rootNode = new TestRootNode(factory, repeating);
CallTarget target = runtime.createCallTarget(rootNode);
target.call(OSR_THRESHOLD + 1);
assertCompiled(rootNode.getOSRTarget());
repeating.invalidationCounter = 5;
target.call(4);
assertCompiled(rootNode.getOSRTarget());
// should trigger invalidation
target.call(2);
assertNotCompiled(rootNode.getOSRTarget());
}
use of com.oracle.truffle.api.CallTarget in project graal by oracle.
the class NFITest method loadLibrary.
private static TruffleObject loadLibrary(String lib) {
String testBackend = System.getProperty("native.test.backend");
String sourceString;
if (testBackend != null) {
sourceString = String.format("with %s %s", testBackend, lib);
} else {
sourceString = lib;
}
Source source = Source.newBuilder(sourceString).name("loadLibrary").mimeType("application/x-native").build();
CallTarget target = runWithPolyglot.getTruffleTestEnv().parse(source);
return (TruffleObject) target.call();
}
use of com.oracle.truffle.api.CallTarget in project graal by oracle.
the class NFILanguage method parse.
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
CharSequence nfiSource = request.getSource().getCharacters();
NativeSource source = Parser.parseNFISource(nfiSource);
String backendId;
if (source.isDefaultBackend()) {
backendId = "native";
} else {
backendId = source.getNFIBackendId();
}
Source backendSource = Source.newBuilder(source.getLibraryDescriptor()).mimeType("trufflenfi/" + backendId).name("<nfi-impl>").build();
CallTarget backendTarget = getContextReference().get().env.parse(backendSource);
DirectCallNode loadLibrary = DirectCallNode.create(backendTarget);
return Truffle.getRuntime().createCallTarget(new NFIRootNode(this, loadLibrary, source));
}
use of com.oracle.truffle.api.CallTarget in project graal by oracle.
the class TruffleTreeDumpHandler method dumpInlinedTrees.
private static void dumpInlinedTrees(GraphOutput<AST, ?> output, final RootCallTarget callTarget, TruffleInlining inlining, List<RootCallTarget> dumped) throws IOException {
for (DirectCallNode callNode : NodeUtil.findAllNodeInstances(callTarget.getRootNode(), DirectCallNode.class)) {
CallTarget inlinedCallTarget = callNode.getCurrentCallTarget();
if (inlinedCallTarget instanceof RootCallTarget && callNode instanceof OptimizedDirectCallNode) {
TruffleInliningDecision decision = inlining.findByCall((OptimizedDirectCallNode) callNode);
if (decision != null && decision.shouldInline()) {
final RootCallTarget rootCallTarget = (RootCallTarget) inlinedCallTarget;
if (!dumped.contains(rootCallTarget)) {
AST ast = new AST(rootCallTarget);
output.beginGroup(ast, inlinedCallTarget.toString(), rootCallTarget.getRootNode().getName(), null, 0, DebugContext.addVersionProperties(null));
output.print(ast, Collections.emptyMap(), 0, AFTER_PROFILING);
output.endGroup();
dumped.add(rootCallTarget);
dumpInlinedTrees(output, (OptimizedCallTarget) inlinedCallTarget, decision, dumped);
}
}
}
}
}
use of com.oracle.truffle.api.CallTarget in project graal by oracle.
the class DebugContext method evaluate.
/**
* Evaluate the given code in this context.
*
* @param code the code to evaluate
* @param languageId the language to evaluate the code in
* @return result of the evaluation
* @since 0.30
*/
public DebugValue evaluate(String code, String languageId) {
assert code != null;
Object prevContext = context.enter();
try {
Debugger debugger = executionLifecycle.getDebugger();
CallTarget target = debugger.getEnv().parse(Source.newBuilder(code).language(languageId).name("eval").build());
Object result = target.call();
LanguageInfo languageInfo = debugger.getEnv().getLanguages().get(languageId);
return new DebugValue.HeapValue(debugger, languageInfo, null, result);
} catch (IOException ex) {
throw new RuntimeException(ex);
} finally {
context.leave(prevContext);
}
}
Aggregations