# HG changeset patch # User Doug Simon # Date 1336738316 -7200 # Node ID 8be0c73cf1184f4bac45b557150d6020b9a406b4 # Parent c862951e769dd4cb43bf32376a2341d2c0b9cbec made graph marking stateless (in the graph) to ensure recursive marking is safe diff -r c862951e769d -r 8be0c73cf118 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Fri May 11 12:20:36 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Fri May 11 14:11:56 2012 +0200 @@ -168,9 +168,9 @@ new GlobalValueNumberingPhase().apply(graph); } - graph.mark(); + int mark = graph.getMark(); new LoweringPhase(runtime, assumptions).apply(graph); - new CanonicalizerPhase(target, runtime, assumptions, true, null).apply(graph); + new CanonicalizerPhase(target, runtime, assumptions, mark, null).apply(graph); if (GraalOptions.Lower) { new FloatingReadPhase().apply(graph); diff -r c862951e769d -r 8be0c73cf118 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/CanonicalizerPhase.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/CanonicalizerPhase.java Fri May 11 12:20:36 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/CanonicalizerPhase.java Fri May 11 14:11:56 2012 +0200 @@ -37,18 +37,22 @@ private static final DebugMetric METRIC_CANONICALIZATION_CONSIDERED_NODES = Debug.metric("CanonicalizationConsideredNodes"); private static final DebugMetric METRIC_SIMPLIFICATION_CONSIDERED_NODES = Debug.metric("SimplificationConsideredNodes"); - private boolean newNodes; + private int newNodesMark; private final CiTarget target; private final CiAssumptions assumptions; private final RiRuntime runtime; private final IsImmutablePredicate immutabilityPredicate; public CanonicalizerPhase(CiTarget target, RiRuntime runtime, CiAssumptions assumptions) { - this(target, runtime, assumptions, false, null); + this(target, runtime, assumptions, -1, null); } - public CanonicalizerPhase(CiTarget target, RiRuntime runtime, CiAssumptions assumptions, boolean newNodes, IsImmutablePredicate immutabilityPredicate) { - this.newNodes = newNodes; + /** + * @param newNodesMark if non-negative, then only the {@linkplain Graph#getNewNodes(int) new nodes} specified by + * this mark are processed otherwise all nodes in the graph are processed + */ + public CanonicalizerPhase(CiTarget target, RiRuntime runtime, CiAssumptions assumptions, int newNodesMark, IsImmutablePredicate immutabilityPredicate) { + this.newNodesMark = newNodesMark; this.target = target; this.assumptions = assumptions; this.runtime = runtime; @@ -57,9 +61,10 @@ @Override protected void run(StructuredGraph graph) { + boolean newNodes = newNodesMark >= 0; NodeWorkList nodeWorkList = graph.createNodeWorkList(!newNodes, MAX_ITERATION_PER_NODE); if (newNodes) { - nodeWorkList.addAll(graph.getNewNodes()); + nodeWorkList.addAll(graph.getNewNodes(newNodesMark)); } canonicalize(graph, nodeWorkList, runtime, target, assumptions, immutabilityPredicate); @@ -80,7 +85,7 @@ METRIC_PROCESSED_NODES.increment(); if (node instanceof Canonicalizable) { METRIC_CANONICALIZATION_CONSIDERED_NODES.increment(); - graph.mark(); + int mark = graph.getMark(); ValueNode canonical = ((Canonicalizable) node).canonical(tool); // cases: original node: // |Floating|Fixed-unconnected|Fixed-connected| @@ -132,7 +137,7 @@ } } } - nodeWorkList.addAll(graph.getNewNodes()); + nodeWorkList.addAll(graph.getNewNodes(mark)); } } else if (node instanceof Simplifiable) { Debug.log("Canonicalizer: simplifying %s", node); diff -r c862951e769d -r 8be0c73cf118 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/InliningPhase.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/InliningPhase.java Fri May 11 12:20:36 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/InliningPhase.java Fri May 11 14:11:56 2012 +0200 @@ -84,10 +84,10 @@ graph.createNodeMap(); if (hints != null) { - scanInvokes((Iterable) Util.uncheckedCast(this.hints), -1, graph); + scanInvokes((Iterable) Util.uncheckedCast(this.hints), -1); } else { - scanInvokes(graph.getNodes(InvokeNode.class), 0, graph); - scanInvokes(graph.getNodes(InvokeWithExceptionNode.class), 0, graph); + scanInvokes(graph.getNodes(InvokeNode.class), 0); + scanInvokes(graph.getNodes(InvokeWithExceptionNode.class), 0); } while (!inlineCandidates.isEmpty() && graph.getNodeCount() < GraalOptions.MaximumDesiredSize) { @@ -101,14 +101,14 @@ }); if (inline) { + int mark = graph.getMark(); Iterable newNodes = null; try { info.inline(graph, runtime, this); Debug.dump(graph, "after %s", info); - // get the new nodes here, the canonicalizer phase will reset the mark - newNodes = graph.getNewNodes(); + newNodes = graph.getNewNodes(mark); if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(target, runtime, assumptions, true, null).apply(graph); + new CanonicalizerPhase(target, runtime, assumptions, mark, null).apply(graph); } // if (GraalOptions.Intrinsify) { // new IntrinsificationPhase(runtime).apply(graph); @@ -126,7 +126,7 @@ } if (newNodes != null && info.level < GraalOptions.MaximumInlineLevel) { - scanInvokes(newNodes, info.level + 1, graph); + scanInvokes(newNodes, info.level + 1); } } } @@ -144,11 +144,10 @@ } } - private void scanInvokes(final Iterable newNodes, final int level, final StructuredGraph graph) { + private void scanInvokes(final Iterable nodes, final int level) { Debug.scope("InliningDecisions", new Runnable() { public void run() { - graph.mark(); - for (Node node : newNodes) { + for (Node node : nodes) { if (node != null) { if (node instanceof Invoke) { Invoke invoke = (Invoke) node; diff -r c862951e769d -r 8be0c73cf118 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/util/InliningUtil.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/util/InliningUtil.java Fri May 11 12:20:36 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/util/InliningUtil.java Fri May 11 14:11:56 2012 +0200 @@ -962,7 +962,7 @@ assert localCount == args.length : "snippet argument count mismatch"; snippetCopy.addDuplicates(snippetGraph.getNodes(), replacements); if (!replacements.isEmpty()) { - new CanonicalizerPhase(null, runtime, null, false, immutabilityPredicate).apply(snippetCopy); + new CanonicalizerPhase(null, runtime, null, -1, immutabilityPredicate).apply(snippetCopy); } // Explode all loops in the snippet if requested @@ -974,10 +974,10 @@ Debug.dump(snippetCopy, "Before exploding loop %s", loopBegin); int peel = 0; while (!loopBegin.isDeleted()) { - snippetCopy.mark(); + int mark = snippetCopy.getMark(); LoopTransformUtil.peel(loop, wholeLoop); Debug.dump(snippetCopy, "After peel %d", peel); - new CanonicalizerPhase(null, runtime, null, true, immutabilityPredicate).apply(snippetCopy); + new CanonicalizerPhase(null, runtime, null, mark, immutabilityPredicate).apply(snippetCopy); peel++; } Debug.dump(snippetCopy, "After exploding loop %s", loopBegin); @@ -1012,7 +1012,7 @@ // Inline the gathered snippet nodes StructuredGraph graph = (StructuredGraph) replacee.graph(); - graph.mark(); + int mark = graph.getMark(); Map duplicates = graph.addDuplicates(nodes, replacements); Debug.dump(graph, "After inlining snippet %s", snippetCopy.method()); @@ -1032,7 +1032,7 @@ } } - for (Node node : graph.getNewNodes()) { + for (Node node : graph.getNewNodes(mark)) { if (node instanceof StateSplit) { StateSplit stateSplit = (StateSplit) node; FrameState frameState = stateSplit.stateAfter(); diff -r c862951e769d -r 8be0c73cf118 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java Fri May 11 12:20:36 2012 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java Fri May 11 14:11:56 2012 +0200 @@ -45,7 +45,6 @@ private final ArrayList nodeCacheFirst; private final ArrayList nodeCacheLast; private int deletedNodeCount; - private int mark; private GraphEventLog eventLog; ArrayList usagesDropped = new ArrayList<>(); @@ -221,10 +220,10 @@ } /** - * @see #getNewNodes() + * Gets a mark that can be used with {@link #getNewNodes()}. */ - public void mark() { - this.mark = nodeIdCount(); + public int getMark() { + return nodeIdCount(); } private class NodeIterator implements Iterator { @@ -277,11 +276,10 @@ } /** - * Returns an {@link Iterable} providing all nodes added since the last {@link Graph#mark() mark}. - * @return an {@link Iterable} providing the new nodes + * Returns an {@link Iterable} providing all nodes added since the last {@link Graph#getMark() mark}. */ - public NodeIterable getNewNodes() { - final int index = this.mark; + public NodeIterable getNewNodes(int mark) { + final int index = mark; return new NodeIterable() { @Override public Iterator iterator() {