Search in sources :

Example 76 with CallTarget

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());
}
Also used : RootCallTarget(com.oracle.truffle.api.RootCallTarget) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Theory(org.junit.experimental.theories.Theory)

Example 77 with CallTarget

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();
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Source(com.oracle.truffle.api.source.Source) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 78 with CallTarget

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));
}
Also used : NativeSource(com.oracle.truffle.nfi.types.NativeSource) CallTarget(com.oracle.truffle.api.CallTarget) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) Source(com.oracle.truffle.api.source.Source) NativeSource(com.oracle.truffle.nfi.types.NativeSource)

Example 79 with CallTarget

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);
                }
            }
        }
    }
}
Also used : RootCallTarget(com.oracle.truffle.api.RootCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) RootCallTarget(com.oracle.truffle.api.RootCallTarget)

Example 80 with CallTarget

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);
    }
}
Also used : LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) CallTarget(com.oracle.truffle.api.CallTarget) IOException(java.io.IOException)

Aggregations

CallTarget (com.oracle.truffle.api.CallTarget)128 Test (org.junit.Test)102 TestHelper.createCallTarget (com.oracle.truffle.api.dsl.test.TestHelper.createCallTarget)50 RootCallTarget (com.oracle.truffle.api.RootCallTarget)26 RootNode (com.oracle.truffle.api.nodes.RootNode)17 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)15 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)10 UnsupportedSpecializationException (com.oracle.truffle.api.dsl.UnsupportedSpecializationException)9 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)9 Node (com.oracle.truffle.api.nodes.Node)9 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)9 TruffleContext (com.oracle.truffle.api.TruffleContext)6 LanguageContext (com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext)6 Context (org.graalvm.polyglot.Context)6 Theory (org.junit.experimental.theories.Theory)6 TruffleException (com.oracle.truffle.api.TruffleException)5 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)5 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)5 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)5 Source (com.oracle.truffle.api.source.Source)5