changeset 9623:76c40c3f6bb7

let ReentrantNodeIterator.processNode return the next state
author Lukas Stadler <lukas.stadler@jku.at>
date Wed, 08 May 2013 15:30:06 +0200
parents c0d76a2ef720
children 87eafaddf9d9
files graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/WriteBarrierVerificationTest.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ReentrantNodeIterator.java graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetFrameStateCleanupPhase.java
diffstat 4 files changed, 38 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/WriteBarrierVerificationTest.java	Wed May 08 13:42:14 2013 +0200
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/WriteBarrierVerificationTest.java	Wed May 08 15:30:06 2013 +0200
@@ -634,17 +634,11 @@
                 final int barriers = graph.getNodes(SerialWriteBarrier.class).count();
                 Assert.assertTrue(expectedBarriers == barriers);
 
-                class State {
-
-                    boolean removeBarrier = false;
-
-                }
-
                 // Iterate over all write nodes and remove barriers according to input indices.
-                NodeIteratorClosure<State> closure = new NodeIteratorClosure<State>() {
+                NodeIteratorClosure<Boolean> closure = new NodeIteratorClosure<Boolean>() {
 
                     @Override
-                    protected void processNode(FixedNode node, State currentState) {
+                    protected Boolean processNode(FixedNode node, Boolean currentState) {
                         if (node instanceof WriteNode) {
                             WriteNode write = (WriteNode) node;
                             LocationIdentity obj = write.getLocationIdentities()[0];
@@ -655,17 +649,18 @@
                                      * the input barrier array.
                                      */
                                     if (eliminateBarrier(write.value().asConstant().asInt(), removedBarrierIndices)) {
-                                        currentState.removeBarrier = true;
+                                        return true;
                                     }
                                 }
                             }
                         } else if (node instanceof SerialWriteBarrier) {
                             // Remove flagged write barriers.
-                            if (currentState.removeBarrier) {
+                            if (currentState) {
                                 graph.removeFixed(((SerialWriteBarrier) node));
-                                currentState.removeBarrier = false;
+                                return false;
                             }
                         }
+                        return currentState;
                     }
 
                     private boolean eliminateBarrier(int index, int[] map) {
@@ -678,24 +673,24 @@
                     }
 
                     @Override
-                    protected Map<LoopExitNode, State> processLoop(LoopBeginNode loop, State initialState) {
+                    protected Map<LoopExitNode, Boolean> processLoop(LoopBeginNode loop, Boolean initialState) {
                         return ReentrantNodeIterator.processLoop(this, loop, initialState).exitStates;
                     }
 
                     @Override
-                    protected State merge(MergeNode merge, List<State> states) {
-                        return new State();
+                    protected Boolean merge(MergeNode merge, List<Boolean> states) {
+                        return false;
                     }
 
                     @Override
-                    protected State afterSplit(AbstractBeginNode node, State oldState) {
-                        return new State();
+                    protected Boolean afterSplit(AbstractBeginNode node, Boolean oldState) {
+                        return false;
                     }
                 };
 
                 DebugConfig config = DebugScope.getConfig();
                 try {
-                    ReentrantNodeIterator.apply(closure, graph.start(), new State(), null);
+                    ReentrantNodeIterator.apply(closure, graph.start(), false, null);
                     Debug.setConfig(Debug.fixedConfig(false, false, false, false, config.dumpHandlers(), config.output()));
                     new WriteBarrierVerificationPhase().apply(graph);
                 } catch (AssertionError error) {
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java	Wed May 08 13:42:14 2013 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java	Wed May 08 15:30:06 2013 +0200
@@ -88,12 +88,13 @@
         }
 
         @Override
-        protected void processNode(FixedNode node, Set<LocationIdentity> currentState) {
+        protected Set<LocationIdentity> processNode(FixedNode node, Set<LocationIdentity> currentState) {
             if (node instanceof MemoryCheckpoint) {
                 for (LocationIdentity identity : ((MemoryCheckpoint) node).getLocationIdentities()) {
                     currentState.add(identity);
                 }
             }
+            return currentState;
         }
 
         @Override
@@ -137,12 +138,13 @@
         }
 
         @Override
-        protected void processNode(FixedNode node, MemoryMap state) {
+        protected MemoryMap processNode(FixedNode node, MemoryMap state) {
             if (node instanceof FloatableAccessNode) {
                 processFloatable((FloatableAccessNode) node, state);
             } else if (node instanceof MemoryCheckpoint) {
                 processCheckpoint((MemoryCheckpoint) node, state);
             }
+            return state;
         }
 
         private static void processCheckpoint(MemoryCheckpoint checkpoint, MemoryMap state) {
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ReentrantNodeIterator.java	Wed May 08 13:42:14 2013 +0200
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ReentrantNodeIterator.java	Wed May 08 15:30:06 2013 +0200
@@ -37,7 +37,7 @@
 
     public abstract static class NodeIteratorClosure<StateT> {
 
-        protected abstract void processNode(FixedNode node, StateT currentState);
+        protected abstract StateT processNode(FixedNode node, StateT currentState);
 
         protected abstract StateT merge(MergeNode merge, List<StateT> states);
 
@@ -82,13 +82,13 @@
                     current = null;
                 } else {
                     FixedNode next = ((FixedWithNextNode) current).next();
-                    closure.processNode(current, state);
+                    state = closure.processNode(current, state);
                     current = next;
                 }
             }
 
             if (current != null) {
-                closure.processNode(current, state);
+                state = closure.processNode(current, state);
 
                 NodeClassIterator successors = current.successors().iterator();
                 if (!successors.hasNext()) {
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetFrameStateCleanupPhase.java	Wed May 08 13:42:14 2013 +0200
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetFrameStateCleanupPhase.java	Wed May 08 15:30:06 2013 +0200
@@ -45,33 +45,24 @@
 
     @Override
     protected void run(StructuredGraph graph) {
-        ReentrantNodeIterator.apply(new SnippetFrameStateCleanupClosure(), graph.start(), new CleanupState(false), null);
-    }
-
-    private static class CleanupState {
-
-        public boolean containsFrameState;
-
-        public CleanupState(boolean containsFrameState) {
-            this.containsFrameState = containsFrameState;
-        }
+        ReentrantNodeIterator.apply(new SnippetFrameStateCleanupClosure(), graph.start(), false, null);
     }
 
     /**
      * A proper (loop-aware) iteration over the graph is used to detect loops that contain invalid
      * frame states, so that they can be marked with an invalid frame state.
      */
-    private static class SnippetFrameStateCleanupClosure extends NodeIteratorClosure<CleanupState> {
+    private static class SnippetFrameStateCleanupClosure extends NodeIteratorClosure<Boolean> {
 
         @Override
-        protected void processNode(FixedNode node, CleanupState currentState) {
+        protected Boolean processNode(FixedNode node, Boolean currentState) {
             if (node instanceof StateSplit) {
                 StateSplit stateSplit = (StateSplit) node;
                 FrameState frameState = stateSplit.stateAfter();
                 if (frameState != null) {
                     if (stateSplit.hasSideEffect()) {
-                        currentState.containsFrameState = true;
                         stateSplit.setStateAfter(node.graph().add(new FrameState(FrameState.INVALID_FRAMESTATE_BCI)));
+                        return true;
                     } else {
                         stateSplit.setStateAfter(null);
                     }
@@ -80,36 +71,37 @@
                     }
                 }
             }
+            return currentState;
         }
 
         @Override
-        protected CleanupState merge(MergeNode merge, List<CleanupState> states) {
-            for (CleanupState state : states) {
-                if (state.containsFrameState) {
-                    return new CleanupState(true);
+        protected Boolean merge(MergeNode merge, List<Boolean> states) {
+            for (boolean state : states) {
+                if (state) {
+                    return true;
                 }
             }
-            return new CleanupState(false);
+            return false;
         }
 
         @Override
-        protected CleanupState afterSplit(AbstractBeginNode node, CleanupState oldState) {
-            return new CleanupState(oldState.containsFrameState);
+        protected Boolean afterSplit(AbstractBeginNode node, Boolean oldState) {
+            return oldState;
         }
 
         @Override
-        protected Map<LoopExitNode, CleanupState> processLoop(LoopBeginNode loop, CleanupState initialState) {
-            LoopInfo<CleanupState> info = ReentrantNodeIterator.processLoop(this, loop, new CleanupState(false));
+        protected Map<LoopExitNode, Boolean> processLoop(LoopBeginNode loop, Boolean initialState) {
+            LoopInfo<Boolean> info = ReentrantNodeIterator.processLoop(this, loop, false);
             boolean containsFrameState = false;
-            for (CleanupState state : info.endStates.values()) {
-                containsFrameState |= state.containsFrameState;
+            for (Boolean state : info.endStates.values()) {
+                containsFrameState |= state;
             }
             if (containsFrameState) {
                 loop.setStateAfter(loop.graph().add(new FrameState(FrameState.INVALID_FRAMESTATE_BCI)));
             }
-            if (containsFrameState || initialState.containsFrameState) {
-                for (CleanupState state : info.exitStates.values()) {
-                    state.containsFrameState = true;
+            if (containsFrameState || initialState) {
+                for (Map.Entry<?, Boolean> entry : info.exitStates.entrySet()) {
+                    entry.setValue(true);
                 }
             }
             return info.exitStates;