Search in sources :

Example 1 with NodeCost

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

the class TraceCompilationPolymorphismListener method onCompilationSuccess.

@Override
public void onCompilationSuccess(OptimizedCallTarget target, TruffleInlining inliningDecision, GraphInfo graph, CompilationResultInfo result) {
    for (Node node : target.nodeIterable(inliningDecision)) {
        if (node != null && (node.getCost() == NodeCost.MEGAMORPHIC || node.getCost() == NodeCost.POLYMORPHIC)) {
            NodeCost cost = node.getCost();
            Map<String, Object> props = new LinkedHashMap<>();
            props.put("simpleName", node.getClass().getSimpleName());
            props.put("subtree", "\n" + NodeUtil.printCompactTreeToString(node));
            String msg = cost == NodeCost.MEGAMORPHIC ? "megamorphic" : "polymorphic";
            runtime.logEvent(0, msg, node.toString(), props);
        }
    }
}
Also used : Node(com.oracle.truffle.api.nodes.Node) NodeCost(com.oracle.truffle.api.nodes.NodeCost) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with NodeCost

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

the class SplittingStrategyTest method testDefaultStrategyStabilises.

@Test
@SuppressWarnings("try")
public void testDefaultStrategyStabilises() {
    try (TruffleCompilerOptions.TruffleOptionsOverrideScope s = TruffleCompilerOptions.overrideOptions(TruffleCompilerOptions.TruffleSplittingMaxNumberOfSplitNodes, fallbackSplitInfo.getSplitLimit() + 1000)) {
        createDummyTargetsToBoostGrowingSplitLimit();
        class InnerRootNode extends SplittableRootNode {

            OptimizedCallTarget target;

            @Child
            private DirectCallNode callNode1;

            @Child
            private Node polymorphic = new Node() {

                @Override
                public NodeCost getCost() {
                    return NodeCost.POLYMORPHIC;
                }
            };

            protected InnerRootNode() {
                super();
            }

            @Override
            public Object execute(VirtualFrame frame) {
                CompilerDirectives.transferToInterpreterAndInvalidate();
                if (callNode1 == null) {
                    callNode1 = runtime.createDirectCallNode(target);
                    adoptChildren();
                }
                if (frame.getArguments().length > 0) {
                    if ((Integer) frame.getArguments()[0] < 100) {
                        callNode1.call(frame.getArguments());
                    }
                }
                return null;
            }

            @Override
            public String toString() {
                return "INNER";
            }
        }
        final InnerRootNode innerRootNode = new InnerRootNode();
        final OptimizedCallTarget inner = (OptimizedCallTarget) runtime.createCallTarget(innerRootNode);
        final OptimizedCallTarget mid = (OptimizedCallTarget) runtime.createCallTarget(new SplittableRootNode() {

            @Child
            private DirectCallNode callNode = null;

            @Child
            private Node polymorphic = new Node() {

                @Override
                public NodeCost getCost() {
                    return NodeCost.POLYMORPHIC;
                }
            };

            @Override
            public Object execute(VirtualFrame frame) {
                CompilerDirectives.transferToInterpreterAndInvalidate();
                if (callNode == null) {
                    callNode = runtime.createDirectCallNode(inner);
                    adoptChildren();
                }
                Object[] arguments = frame.getArguments();
                if ((Integer) arguments[0] < 100) {
                    callNode.call(new Object[] { ((Integer) arguments[0]) + 1 });
                }
                return null;
            }

            @Override
            public String toString() {
                return "MID";
            }
        });
        OptimizedCallTarget outside = (OptimizedCallTarget) runtime.createCallTarget(new SplittableRootNode() {

            // runtime.createDirectCallNode(mid);
            @Child
            private DirectCallNode outsideCallNode = null;

            @Override
            public Object execute(VirtualFrame frame) {
                CompilerDirectives.transferToInterpreterAndInvalidate();
                // Emulates builtin i.e. Split immediately
                if (outsideCallNode == null) {
                    outsideCallNode = runtime.createDirectCallNode(mid);
                    adoptChildren();
                    outsideCallNode.cloneCallTarget();
                }
                return outsideCallNode.call(frame.getArguments());
            }

            @Override
            public String toString() {
                return "OUTSIDE";
            }
        });
        innerRootNode.target = outside;
        createDummyTargetsToBoostGrowingSplitLimit();
        final int baseSplitCount = listener.splitCount;
        outside.call(1);
        // Expected 14
        // OUTSIDE MID
        // MID <split> INNER
        // INNER <split> OUTSIDE
        // OUTSIDE <split> MID
        // INNER OUTSIDE
        // OUTSIDE <split> MID
        // MID <split> INNER
        // MID <split> INNER
        // INNER <split> OUTSIDE
        // OUTSIDE <split> MID
        // INNER <split> OUTSIDE
        // OUTSIDE <split> MID
        // MID <split> INNER
        Assert.assertEquals("Not the right number of splits.", baseSplitCount + 13, listener.splitCount);
    }
}
Also used : Node(com.oracle.truffle.api.nodes.Node) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) RootNode(com.oracle.truffle.api.nodes.RootNode) OptimizedDirectCallNode(org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) NodeCost(com.oracle.truffle.api.nodes.NodeCost) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) TruffleCompilerOptions(org.graalvm.compiler.truffle.common.TruffleCompilerOptions) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) OptimizedDirectCallNode(org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode) Test(org.junit.Test)

Aggregations

Node (com.oracle.truffle.api.nodes.Node)2 NodeCost (com.oracle.truffle.api.nodes.NodeCost)2 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)1 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1 LinkedHashMap (java.util.LinkedHashMap)1 TruffleCompilerOptions (org.graalvm.compiler.truffle.common.TruffleCompilerOptions)1 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)1 OptimizedDirectCallNode (org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode)1 Test (org.junit.Test)1