# HG changeset patch # User Miguel Garcia # Date 1400079165 -7200 # Node ID 84cf47e9c9f3eb4b5233f1476ddd46ef480e69a9 # Parent 2bc323b434676ae413bc04662c7d7244e6e7f6da [single-pass-iter] owner-is-mutator access protocol for queued states diff -r 2bc323b43467 -r 84cf47e9c9f3 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/SinglePassNodeIterator.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/SinglePassNodeIterator.java Wed May 14 16:13:44 2014 +0200 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/SinglePassNodeIterator.java Wed May 14 16:52:45 2014 +0200 @@ -191,11 +191,29 @@ finished(); } + /** + * Two methods enqueue items in {@link #nodeQueue}. Of them, only this method enqueues items + * with non-null state (the other method being {@link #queueMerge(EndNode)}). + * + *

+ * A space optimization is made: the state is cloned for all successors except the first. Given + * that right after invoking this method, {@link #nextQueuedNode()} is invoked, that single + * non-cloned state instance is in effect "handed over" to its next owner (thus realizing an + * owner-is-mutator access protocol). + *

+ */ private void queueSuccessors(FixedNode x) { - for (Node node : x.successors()) { - if (node != null) { - nodeQueue.addFirst(new PathStart<>((BeginNode) node, state)); - } + Iterator iter = x.successors().nonNull().iterator(); + if (iter.hasNext()) { + BeginNode begin = (BeginNode) iter.next(); + // the current state isn't cloned for the first successor + // conceptually, the state is handed over to it + nodeQueue.addFirst(new PathStart<>(begin, state)); + } + while (iter.hasNext()) { + BeginNode begin = (BeginNode) iter.next(); + // for all other successors it is cloned + nodeQueue.addFirst(new PathStart<>(begin, state.clone())); } } @@ -228,7 +246,7 @@ } else { BeginNode begin = elem.node; assert begin.predecessor() != null; - state = elem.stateOnEntry.clone(); + state = elem.stateOnEntry; state.afterSplit(begin); return begin; }