Search in sources :

Example 21 with AbstractBeginNode

use of org.graalvm.compiler.nodes.AbstractBeginNode in project graal by oracle.

the class LoopEx method nodesInLoopBranch.

public void nodesInLoopBranch(NodeBitMap branchNodes, AbstractBeginNode branch) {
    EconomicSet<AbstractBeginNode> blocks = EconomicSet.create();
    Collection<AbstractBeginNode> exits = new LinkedList<>();
    Queue<Block> work = new LinkedList<>();
    ControlFlowGraph cfg = loopsData().getCFG();
    work.add(cfg.blockFor(branch));
    while (!work.isEmpty()) {
        Block b = work.remove();
        if (loop().getExits().contains(b)) {
            assert !exits.contains(b.getBeginNode());
            exits.add(b.getBeginNode());
        } else if (blocks.add(b.getBeginNode())) {
            Block d = b.getDominatedSibling();
            while (d != null) {
                if (loop.getBlocks().contains(d)) {
                    work.add(d);
                }
                d = d.getDominatedSibling();
            }
        }
    }
    LoopFragment.computeNodes(branchNodes, branch.graph(), blocks, exits);
}
Also used : ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) Block(org.graalvm.compiler.nodes.cfg.Block) LinkedList(java.util.LinkedList) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 22 with AbstractBeginNode

use of org.graalvm.compiler.nodes.AbstractBeginNode in project graal by oracle.

the class GraphKit method startInvokeWithException.

public InvokeWithExceptionNode startInvokeWithException(ResolvedJavaMethod method, InvokeKind invokeKind, FrameStateBuilder frameStateBuilder, int invokeBci, int exceptionEdgeBci, ValueNode... args) {
    assert method.isStatic() == (invokeKind == InvokeKind.Static);
    Signature signature = method.getSignature();
    JavaType returnType = signature.getReturnType(null);
    assert checkArgs(method, args);
    StampPair returnStamp = graphBuilderPlugins.getOverridingStamp(this, returnType, false);
    if (returnStamp == null) {
        returnStamp = StampFactory.forDeclaredType(graph.getAssumptions(), returnType, false);
    }
    ExceptionObjectNode exceptionObject = add(new ExceptionObjectNode(getMetaAccess()));
    if (frameStateBuilder != null) {
        FrameStateBuilder exceptionState = frameStateBuilder.copy();
        exceptionState.clearStack();
        exceptionState.push(JavaKind.Object, exceptionObject);
        exceptionState.setRethrowException(false);
        exceptionObject.setStateAfter(exceptionState.create(exceptionEdgeBci, exceptionObject));
    }
    MethodCallTargetNode callTarget = graph.add(createMethodCallTarget(invokeKind, method, args, returnStamp, invokeBci));
    InvokeWithExceptionNode invoke = append(new InvokeWithExceptionNode(callTarget, exceptionObject, invokeBci));
    AbstractBeginNode noExceptionEdge = graph.add(KillingBeginNode.create(LocationIdentity.any()));
    invoke.setNext(noExceptionEdge);
    if (frameStateBuilder != null) {
        if (invoke.getStackKind() != JavaKind.Void) {
            frameStateBuilder.push(invoke.getStackKind(), invoke);
        }
        invoke.setStateAfter(frameStateBuilder.create(invokeBci, invoke));
        if (invoke.getStackKind() != JavaKind.Void) {
            frameStateBuilder.pop(invoke.getStackKind());
        }
    }
    lastFixedNode = null;
    InvokeWithExceptionStructure s = new InvokeWithExceptionStructure();
    s.state = InvokeWithExceptionStructure.State.INVOKE;
    s.noExceptionEdge = noExceptionEdge;
    s.exceptionEdge = exceptionObject;
    s.exceptionObject = exceptionObject;
    pushStructure(s);
    return invoke;
}
Also used : JavaType(jdk.vm.ci.meta.JavaType) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) Signature(jdk.vm.ci.meta.Signature) StampPair(org.graalvm.compiler.core.common.type.StampPair) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 23 with AbstractBeginNode

use of org.graalvm.compiler.nodes.AbstractBeginNode in project graal by oracle.

the class WriteBarrierVerificationTest method testPredicate.

@SuppressWarnings("try")
private void testPredicate(final String snippet, final GraphPredicate expectedBarriers, final int... removedBarrierIndices) {
    DebugContext debug = getDebugContext();
    try (DebugCloseable d = debug.disableIntercept();
        DebugContext.Scope s = debug.scope("WriteBarrierVerificationTest", new DebugDumpScope(snippet))) {
        final StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES, debug);
        HighTierContext highTierContext = getDefaultHighTierContext();
        new InliningPhase(new CanonicalizerPhase()).apply(graph, highTierContext);
        MidTierContext midTierContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
        new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, highTierContext);
        new GuardLoweringPhase().apply(graph, midTierContext);
        new LoopSafepointInsertionPhase().apply(graph);
        new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, highTierContext);
        new WriteBarrierAdditionPhase(config).apply(graph);
        int barriers = 0;
        // First, the total number of expected barriers is checked.
        if (config.useG1GC) {
            barriers = graph.getNodes().filter(G1PreWriteBarrier.class).count() + graph.getNodes().filter(G1PostWriteBarrier.class).count() + graph.getNodes().filter(G1ArrayRangePreWriteBarrier.class).count() + graph.getNodes().filter(G1ArrayRangePostWriteBarrier.class).count();
            Assert.assertTrue(expectedBarriers.apply(graph) * 2 == barriers);
        } else {
            barriers = graph.getNodes().filter(SerialWriteBarrier.class).count() + graph.getNodes().filter(SerialArrayRangeWriteBarrier.class).count();
            Assert.assertTrue(expectedBarriers.apply(graph) == barriers);
        }
        ResolvedJavaField barrierIndexField = getMetaAccess().lookupJavaField(WriteBarrierVerificationTest.class.getDeclaredField("barrierIndex"));
        LocationIdentity barrierIdentity = new FieldLocationIdentity(barrierIndexField);
        // Iterate over all write nodes and remove barriers according to input indices.
        NodeIteratorClosure<Boolean> closure = new NodeIteratorClosure<Boolean>() {

            @Override
            protected Boolean processNode(FixedNode node, Boolean currentState) {
                if (node instanceof WriteNode) {
                    WriteNode write = (WriteNode) node;
                    LocationIdentity obj = write.getLocationIdentity();
                    if (obj.equals(barrierIdentity)) {
                        /*
                             * A "barrierIndex" variable was found and is checked against the input
                             * barrier array.
                             */
                        if (eliminateBarrier(write.value().asJavaConstant().asInt(), removedBarrierIndices)) {
                            return true;
                        }
                    }
                } else if (node instanceof SerialWriteBarrier || node instanceof G1PostWriteBarrier) {
                    // Remove flagged write barriers.
                    if (currentState) {
                        graph.removeFixed(((FixedWithNextNode) node));
                        return false;
                    }
                }
                return currentState;
            }

            private boolean eliminateBarrier(int index, int[] map) {
                for (int i = 0; i < map.length; i++) {
                    if (map[i] == index) {
                        return true;
                    }
                }
                return false;
            }

            @Override
            protected EconomicMap<LoopExitNode, Boolean> processLoop(LoopBeginNode loop, Boolean initialState) {
                return ReentrantNodeIterator.processLoop(this, loop, initialState).exitStates;
            }

            @Override
            protected Boolean merge(AbstractMergeNode merge, List<Boolean> states) {
                return false;
            }

            @Override
            protected Boolean afterSplit(AbstractBeginNode node, Boolean oldState) {
                return false;
            }
        };
        try (Scope disabled = debug.disable()) {
            ReentrantNodeIterator.apply(closure, graph.start(), false);
            new WriteBarrierVerificationPhase(config).apply(graph);
        } catch (AssertionError error) {
            /*
                 * Catch assertion, test for expected one and re-throw in order to validate unit
                 * test.
                 */
            Assert.assertTrue(error.getMessage().contains("Write barrier must be present"));
            throw error;
        }
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : WriteBarrierVerificationPhase(org.graalvm.compiler.hotspot.phases.WriteBarrierVerificationPhase) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) WriteBarrierAdditionPhase(org.graalvm.compiler.hotspot.phases.WriteBarrierAdditionPhase) FixedNode(org.graalvm.compiler.nodes.FixedNode) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Scope(org.graalvm.compiler.debug.DebugContext.Scope) LocationIdentity(org.graalvm.word.LocationIdentity) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) List(java.util.List) NodeIteratorClosure(org.graalvm.compiler.phases.graph.ReentrantNodeIterator.NodeIteratorClosure) SerialArrayRangeWriteBarrier(org.graalvm.compiler.hotspot.nodes.SerialArrayRangeWriteBarrier) LoopSafepointInsertionPhase(org.graalvm.compiler.phases.common.LoopSafepointInsertionPhase) G1ArrayRangePostWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1ArrayRangePostWriteBarrier) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) G1PreWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier) DebugContext(org.graalvm.compiler.debug.DebugContext) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) SerialWriteBarrier(org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) Scope(org.graalvm.compiler.debug.DebugContext.Scope) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) G1PostWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode)

Example 24 with AbstractBeginNode

use of org.graalvm.compiler.nodes.AbstractBeginNode in project graal by oracle.

the class BinaryGraphPrinter method nodeProperties.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void nodeProperties(GraphInfo info, Node node, Map<String, Object> props) {
    node.getDebugProperties((Map) props);
    Graph graph = info.graph;
    ControlFlowGraph cfg = info.cfg;
    NodeMap<Block> nodeToBlocks = info.nodeToBlocks;
    if (cfg != null && DebugOptions.PrintGraphProbabilities.getValue(graph.getOptions()) && node instanceof FixedNode) {
        try {
            props.put("probability", cfg.blockFor(node).probability());
        } catch (Throwable t) {
            props.put("probability", 0.0);
            props.put("probability-exception", t);
        }
    }
    try {
        props.put("NodeCost-Size", node.estimatedNodeSize());
        props.put("NodeCost-Cycles", node.estimatedNodeCycles());
    } catch (Throwable t) {
        props.put("node-cost-exception", t.getMessage());
    }
    if (nodeToBlocks != null) {
        Object block = getBlockForNode(node, nodeToBlocks);
        if (block != null) {
            props.put("node-to-block", block);
        }
    }
    if (node instanceof ControlSinkNode) {
        props.put("category", "controlSink");
    } else if (node instanceof ControlSplitNode) {
        props.put("category", "controlSplit");
    } else if (node instanceof AbstractMergeNode) {
        props.put("category", "merge");
    } else if (node instanceof AbstractBeginNode) {
        props.put("category", "begin");
    } else if (node instanceof AbstractEndNode) {
        props.put("category", "end");
    } else if (node instanceof FixedNode) {
        props.put("category", "fixed");
    } else if (node instanceof VirtualState) {
        props.put("category", "state");
    } else if (node instanceof PhiNode) {
        props.put("category", "phi");
    } else if (node instanceof ProxyNode) {
        props.put("category", "proxy");
    } else {
        if (node instanceof ConstantNode) {
            ConstantNode cn = (ConstantNode) node;
            updateStringPropertiesForConstant((Map) props, cn);
        }
        props.put("category", "floating");
    }
    if (getSnippetReflectionProvider() != null) {
        for (Map.Entry<String, Object> prop : props.entrySet()) {
            if (prop.getValue() instanceof JavaConstantFormattable) {
                props.put(prop.getKey(), ((JavaConstantFormattable) prop.getValue()).format(this));
            }
        }
    }
}
Also used : ProxyNode(org.graalvm.compiler.nodes.ProxyNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) VirtualState(org.graalvm.compiler.nodes.VirtualState) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) Graph(org.graalvm.compiler.graph.Graph) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CachedGraph(org.graalvm.compiler.graph.CachedGraph) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) Block(org.graalvm.compiler.nodes.cfg.Block) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) Map(java.util.Map) NodeMap(org.graalvm.compiler.graph.NodeMap) BlockMap(org.graalvm.compiler.core.common.cfg.BlockMap) JavaConstantFormattable(org.graalvm.compiler.nodes.util.JavaConstantFormattable)

Example 25 with AbstractBeginNode

use of org.graalvm.compiler.nodes.AbstractBeginNode in project graal by oracle.

the class ReentrantNodeIterator method apply.

private static <StateT> EconomicMap<FixedNode, StateT> apply(NodeIteratorClosure<StateT> closure, FixedNode start, StateT initialState, LoopBeginNode boundary) {
    assert start != null;
    Deque<AbstractBeginNode> nodeQueue = new ArrayDeque<>();
    EconomicMap<FixedNode, StateT> blockEndStates = EconomicMap.create(Equivalence.IDENTITY);
    StateT state = initialState;
    FixedNode current = start;
    do {
        while (current instanceof FixedWithNextNode) {
            if (boundary != null && current instanceof LoopExitNode && ((LoopExitNode) current).loopBegin() == boundary) {
                blockEndStates.put(current, state);
                current = null;
            } else {
                FixedNode next = ((FixedWithNextNode) current).next();
                state = closure.processNode(current, state);
                current = closure.continueIteration(state) ? next : null;
            }
        }
        if (current != null) {
            state = closure.processNode(current, state);
            if (closure.continueIteration(state)) {
                Iterator<Node> successors = current.successors().iterator();
                if (!successors.hasNext()) {
                    if (current instanceof LoopEndNode) {
                        blockEndStates.put(current, state);
                    } else if (current instanceof EndNode) {
                        // add the end node and see if the merge is ready for processing
                        AbstractMergeNode merge = ((EndNode) current).merge();
                        if (merge instanceof LoopBeginNode) {
                            EconomicMap<LoopExitNode, StateT> loopExitState = closure.processLoop((LoopBeginNode) merge, state);
                            MapCursor<LoopExitNode, StateT> entry = loopExitState.getEntries();
                            while (entry.advance()) {
                                blockEndStates.put(entry.getKey(), entry.getValue());
                                nodeQueue.add(entry.getKey());
                            }
                        } else {
                            boolean endsVisited = true;
                            for (AbstractEndNode forwardEnd : merge.forwardEnds()) {
                                if (forwardEnd != current && !blockEndStates.containsKey(forwardEnd)) {
                                    endsVisited = false;
                                    break;
                                }
                            }
                            if (endsVisited) {
                                ArrayList<StateT> states = new ArrayList<>(merge.forwardEndCount());
                                for (int i = 0; i < merge.forwardEndCount(); i++) {
                                    AbstractEndNode forwardEnd = merge.forwardEndAt(i);
                                    assert forwardEnd == current || blockEndStates.containsKey(forwardEnd);
                                    StateT other = forwardEnd == current ? state : blockEndStates.removeKey(forwardEnd);
                                    states.add(other);
                                }
                                state = closure.merge(merge, states);
                                current = closure.continueIteration(state) ? merge : null;
                                continue;
                            } else {
                                assert !blockEndStates.containsKey(current);
                                blockEndStates.put(current, state);
                            }
                        }
                    }
                } else {
                    FixedNode firstSuccessor = (FixedNode) successors.next();
                    if (!successors.hasNext()) {
                        current = firstSuccessor;
                        continue;
                    } else {
                        do {
                            AbstractBeginNode successor = (AbstractBeginNode) successors.next();
                            StateT successorState = closure.afterSplit(successor, state);
                            if (closure.continueIteration(successorState)) {
                                blockEndStates.put(successor, successorState);
                                nodeQueue.add(successor);
                            }
                        } while (successors.hasNext());
                        state = closure.afterSplit((AbstractBeginNode) firstSuccessor, state);
                        current = closure.continueIteration(state) ? firstSuccessor : null;
                        continue;
                    }
                }
            }
        }
        // get next queued block
        if (nodeQueue.isEmpty()) {
            return blockEndStates;
        } else {
            current = nodeQueue.removeFirst();
            assert blockEndStates.containsKey(current);
            state = blockEndStates.removeKey(current);
            assert !(current instanceof AbstractMergeNode) && current instanceof AbstractBeginNode;
        }
    } while (true);
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) EconomicMap(org.graalvm.collections.EconomicMap) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ArrayList(java.util.ArrayList) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) ArrayDeque(java.util.ArrayDeque) MapCursor(org.graalvm.collections.MapCursor) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) EndNode(org.graalvm.compiler.nodes.EndNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode)

Aggregations

AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)63 FixedNode (org.graalvm.compiler.nodes.FixedNode)32 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)31 Node (org.graalvm.compiler.graph.Node)24 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)23 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)23 EndNode (org.graalvm.compiler.nodes.EndNode)22 BeginNode (org.graalvm.compiler.nodes.BeginNode)21 ValueNode (org.graalvm.compiler.nodes.ValueNode)20 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)16 IfNode (org.graalvm.compiler.nodes.IfNode)16 ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)15 MergeNode (org.graalvm.compiler.nodes.MergeNode)15 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)15 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)14 PhiNode (org.graalvm.compiler.nodes.PhiNode)14 LoopEndNode (org.graalvm.compiler.nodes.LoopEndNode)13 LogicNode (org.graalvm.compiler.nodes.LogicNode)12 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)11 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)11