changeset 15647:84cf47e9c9f3

[single-pass-iter] owner-is-mutator access protocol for queued states
author Miguel Garcia <miguel.m.garcia@oracle.com>
date Wed, 14 May 2014 16:52:45 +0200
parents 2bc323b43467
children 9c9bb06a6b83
files graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/SinglePassNodeIterator.java
diffstat 1 files changed, 23 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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)}).
+     *
+     * <p>
+     * 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).
+     * </p>
+     */
     private void queueSuccessors(FixedNode x) {
-        for (Node node : x.successors()) {
-            if (node != null) {
-                nodeQueue.addFirst(new PathStart<>((BeginNode) node, state));
-            }
+        Iterator<Node> 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;
         }