Search in sources :

Example 61 with RootNode

use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.

the class TruffleBoundaryInliningTest method runTest.

private void runTest() {
    RootNode n1 = createRootNodeAllowInline();
    RootCallTarget c1 = runtime.createCallTarget(n1);
    StructuredGraph allowInline = partialEval((OptimizedCallTarget) c1, new Object[] {}, StructuredGraph.AllowAssumptions.YES, CompilationIdentifier.INVALID_COMPILATION_ID);
    RootNode n2 = createRootNodeNoInline();
    RootCallTarget c2 = runtime.createCallTarget(n2);
    StructuredGraph noInline = partialEval((OptimizedCallTarget) c2, new Object[] {}, StructuredGraph.AllowAssumptions.YES, CompilationIdentifier.INVALID_COMPILATION_ID);
    checkHasTestMethod(allowInline);
    checkHasTestMethod(noInline);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) RootCallTarget(com.oracle.truffle.api.RootCallTarget)

Example 62 with RootNode

use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.

the class IndirectCallSiteTest method testIndirectCallNodeDoesNotDeopOnFirstCall.

@Test
public void testIndirectCallNodeDoesNotDeopOnFirstCall() {
    final Object[] noArguments = new Object[0];
    final OptimizedCallTarget innerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {

        @Override
        public Object execute(VirtualFrame frame) {
            return null;
        }
    });
    final OptimizedCallTarget uninitializedInnerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {

        @Override
        public Object execute(VirtualFrame frame) {
            return null;
        }
    });
    final OptimizedCallTarget outerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {

        @Child
        OptimizedIndirectCallNode indirectCallNode = (OptimizedIndirectCallNode) runtime.createIndirectCallNode();

        @Override
        public Object execute(VirtualFrame frame) {
            if (frame.getArguments().length == 0) {
                return indirectCallNode.call(innerTarget, noArguments);
            } else {
                return indirectCallNode.call(uninitializedInnerTarget, noArguments);
            }
        }
    });
    final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
    for (int i = 0; i < compilationThreshold; i++) {
        outerTarget.call(noArguments);
    }
    assertCompiled(outerTarget);
    outerTarget.call(new Object[] { null });
    assertCompiled(outerTarget);
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) OptimizedIndirectCallNode(org.graalvm.compiler.truffle.runtime.OptimizedIndirectCallNode) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Test(org.junit.Test)

Example 63 with RootNode

use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.

the class SLGraalRuntimeBuiltin method findCallsTo.

/**
 * Finds all {@link DirectCallNode} instances calling a certain original {@link CallTarget} in
 * the caller function.
 */
@TruffleBoundary
protected static final Set<DirectCallNode> findCallsTo(OptimizedCallTarget originalCallTarget) {
    FrameInstance frame = Truffle.getRuntime().getCallerFrame();
    RootNode root = frame.getCallNode().getRootNode();
    return findCallsTo(root, originalCallTarget);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) FrameInstance(com.oracle.truffle.api.frame.FrameInstance) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 64 with RootNode

use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.

the class SLGraalRuntimeBuiltin method findCallsTo.

/**
 * Finds all {@link DirectCallNode} instances calling a certain original {@link CallTarget} in a
 * given {@link RootNode}.
 */
@TruffleBoundary
protected static final Set<DirectCallNode> findCallsTo(RootNode root, OptimizedCallTarget originalCallTarget) {
    final Set<DirectCallNode> allCallNodes = new HashSet<>();
    root.accept(new NodeVisitor() {

        @Override
        public boolean visit(Node node) {
            if (node instanceof DirectCallNode) {
                DirectCallNode callNode = (DirectCallNode) node;
                if (callNode.getCallTarget() == originalCallTarget || callNode.getClonedCallTarget() == originalCallTarget) {
                    allCallNodes.add(callNode);
                }
            }
            return true;
        }
    });
    return allCallNodes;
}
Also used : Node(com.oracle.truffle.api.nodes.Node) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) SLBuiltinNode(com.oracle.truffle.sl.builtins.SLBuiltinNode) RootNode(com.oracle.truffle.api.nodes.RootNode) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) HashSet(java.util.HashSet) NodeVisitor(com.oracle.truffle.api.nodes.NodeVisitor) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 65 with RootNode

use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.

the class NFILanguageImpl method parse.

@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
    CharSequence library = request.getSource().getCharacters();
    RootNode root;
    NativeLibraryDescriptor descriptor = Parser.parseLibraryDescriptor(library);
    NFIContext ctx = getContextReference().get();
    if (descriptor.isDefaultLibrary()) {
        root = new GetDefaultLibraryNode();
    } else {
        int flags = 0;
        boolean lazyOrNow = false;
        if (descriptor.getFlags() != null) {
            for (String flag : descriptor.getFlags()) {
                switch(flag) {
                    case "RTLD_GLOBAL":
                        flags |= ctx.RTLD_GLOBAL;
                        break;
                    case "RTLD_LOCAL":
                        flags |= ctx.RTLD_LOCAL;
                        break;
                    case "RTLD_LAZY":
                        flags |= ctx.RTLD_LAZY;
                        lazyOrNow = true;
                        break;
                    case "RTLD_NOW":
                        flags |= ctx.RTLD_NOW;
                        lazyOrNow = true;
                        break;
                }
            }
        }
        if (!lazyOrNow) {
            // default to 'RTLD_NOW' if neither 'RTLD_LAZY' nor 'RTLD_NOW' was specified
            flags |= ctx.RTLD_NOW;
        }
        root = new LoadLibraryNode(this, descriptor.getFilename(), flags);
    }
    return Truffle.getRuntime().createCallTarget(root);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) NativeLibraryDescriptor(com.oracle.truffle.nfi.types.NativeLibraryDescriptor)

Aggregations

RootNode (com.oracle.truffle.api.nodes.RootNode)86 Test (org.junit.Test)36 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)24 Node (com.oracle.truffle.api.nodes.Node)23 CallTarget (com.oracle.truffle.api.CallTarget)16 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)16 RootCallTarget (com.oracle.truffle.api.RootCallTarget)12 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)12 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)9 Source (com.oracle.truffle.api.source.Source)8 AbstractTestNode (org.graalvm.compiler.truffle.test.nodes.AbstractTestNode)8 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)7 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)6 SourceSection (com.oracle.truffle.api.source.SourceSection)6 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)5 ArrayList (java.util.ArrayList)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)4 TruffleContext (com.oracle.truffle.api.TruffleContext)3 TruffleException (com.oracle.truffle.api.TruffleException)3 TruffleLanguage (com.oracle.truffle.api.TruffleLanguage)3