changeset 9625:bce1c7759d9d

Merge
author Lukas Stadler <lukas.stadler@jku.at>
date Thu, 09 May 2013 11:32:08 +0200
parents 87eafaddf9d9 (diff) ac96c2062de4 (current diff)
children 29abc1e22280
files
diffstat 8 files changed, 88 insertions(+), 128 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/WriteBarrierVerificationTest.java	Wed May 08 22:56:34 2013 +0200
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/WriteBarrierVerificationTest.java	Thu May 09 11:32:08 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 22:56:34 2013 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java	Thu May 09 11:32:08 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.common/src/com/oracle/graal/phases/common/FrameStateAssignmentPhase.java	Wed May 08 22:56:34 2013 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FrameStateAssignmentPhase.java	Thu May 09 11:32:08 2013 +0200
@@ -27,84 +27,53 @@
 import com.oracle.graal.graph.*;
 import com.oracle.graal.graph.iterators.*;
 import com.oracle.graal.nodes.*;
-import com.oracle.graal.nodes.cfg.*;
 import com.oracle.graal.nodes.util.*;
 import com.oracle.graal.phases.*;
 import com.oracle.graal.phases.graph.*;
-import com.oracle.graal.phases.graph.ReentrantBlockIterator.BlockIteratorClosure;
+import com.oracle.graal.phases.graph.ReentrantNodeIterator.NodeIteratorClosure;
 
 public class FrameStateAssignmentPhase extends Phase {
 
-    private static class FrameStateAssignmentState {
-
-        private FrameState framestate;
+    private static class FrameStateAssignementClosure extends NodeIteratorClosure<FrameState> {
 
-        public FrameStateAssignmentState(FrameState framestate) {
-            this.framestate = framestate;
-        }
+        @Override
+        protected FrameState processNode(FixedNode node, FrameState currentState) {
+            if (node instanceof DeoptimizingNode) {
+                DeoptimizingNode deopt = (DeoptimizingNode) node;
+                if (deopt.canDeoptimize() && deopt.getDeoptimizationState() == null) {
+                    deopt.setDeoptimizationState(currentState);
+                }
+            }
 
-        public FrameState getFramestate() {
-            return framestate;
-        }
-
-        public void setFramestate(FrameState framestate) {
-            assert framestate != null;
-            this.framestate = framestate;
+            if (node instanceof StateSplit) {
+                StateSplit stateSplit = (StateSplit) node;
+                if (stateSplit.stateAfter() != null) {
+                    try {
+                        return stateSplit.stateAfter();
+                    } finally {
+                        stateSplit.setStateAfter(null);
+                    }
+                }
+            }
+            return currentState;
         }
 
         @Override
-        public String toString() {
-            return "FrameStateAssignementState: " + framestate;
-        }
-    }
-
-    private static class FrameStateAssignementClosure extends BlockIteratorClosure<FrameStateAssignmentState> {
-
-        @Override
-        protected void processBlock(Block block, FrameStateAssignmentState currentState) {
-            FixedNode node = block.getBeginNode();
-            while (node != null) {
-                if (node instanceof DeoptimizingNode) {
-                    DeoptimizingNode deopt = (DeoptimizingNode) node;
-                    if (deopt.canDeoptimize() && deopt.getDeoptimizationState() == null) {
-                        FrameState state = currentState.getFramestate();
-                        deopt.setDeoptimizationState(state);
-                    }
-                }
-
-                if (node instanceof StateSplit) {
-                    StateSplit stateSplit = (StateSplit) node;
-                    if (stateSplit.stateAfter() != null) {
-                        currentState.setFramestate(stateSplit.stateAfter());
-                        stateSplit.setStateAfter(null);
-                    }
-                }
-
-                if (node instanceof FixedWithNextNode) {
-                    node = ((FixedWithNextNode) node).next();
-                } else {
-                    node = null;
-                }
+        protected FrameState merge(MergeNode merge, List<FrameState> states) {
+            if (merge.stateAfter() != null) {
+                return merge.stateAfter();
             }
+            return singleFrameState(merge, states);
         }
 
         @Override
-        protected FrameStateAssignmentState merge(Block mergeBlock, List<FrameStateAssignmentState> states) {
-            MergeNode merge = (MergeNode) mergeBlock.getBeginNode();
-            if (merge.stateAfter() != null) {
-                return new FrameStateAssignmentState(merge.stateAfter());
-            }
-            return new FrameStateAssignmentState(singleFrameState(merge, states));
+        protected FrameState afterSplit(AbstractBeginNode node, FrameState oldState) {
+            return oldState;
         }
 
         @Override
-        protected FrameStateAssignmentState cloneState(FrameStateAssignmentState oldState) {
-            return new FrameStateAssignmentState(oldState.getFramestate());
-        }
-
-        @Override
-        protected List<FrameStateAssignmentState> processLoop(Loop loop, FrameStateAssignmentState initialState) {
-            return ReentrantBlockIterator.processLoop(this, loop, initialState).exitStates;
+        protected Map<LoopExitNode, FrameState> processLoop(LoopBeginNode loop, FrameState initialState) {
+            return ReentrantNodeIterator.processLoop(this, loop, initialState).exitStates;
         }
 
     }
@@ -112,8 +81,7 @@
     @Override
     protected void run(StructuredGraph graph) {
         assert checkFixedDeopts(graph);
-        ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, false, false);
-        ReentrantBlockIterator.apply(new FrameStateAssignementClosure(), cfg.getStartBlock(), new FrameStateAssignmentState(null), null);
+        ReentrantNodeIterator.apply(new FrameStateAssignementClosure(), graph.start(), null, null);
     }
 
     private static boolean checkFixedDeopts(StructuredGraph graph) {
@@ -126,18 +94,18 @@
         return true;
     }
 
-    private static FrameState singleFrameState(@SuppressWarnings("unused") MergeNode merge, List<FrameStateAssignmentState> states) {
+    private static FrameState singleFrameState(@SuppressWarnings("unused") MergeNode merge, List<FrameState> states) {
         if (states.size() == 0) {
             return null;
         }
-        FrameState firstState = states.get(0).getFramestate();
+        FrameState firstState = states.get(0);
         FrameState singleState = firstState;
         if (singleState == null) {
             return null;
         }
         int singleBci = singleState.bci;
         for (int i = 1; i < states.size(); ++i) {
-            FrameState cur = states.get(i).getFramestate();
+            FrameState cur = states.get(i);
             if (cur == null) {
                 return null;
             }
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ReentrantBlockIterator.java	Wed May 08 22:56:34 2013 +0200
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ReentrantBlockIterator.java	Thu May 09 11:32:08 2013 +0200
@@ -37,7 +37,7 @@
 
     public abstract static class BlockIteratorClosure<StateT> {
 
-        protected abstract void processBlock(Block block, StateT currentState);
+        protected abstract StateT processBlock(Block block, StateT currentState);
 
         protected abstract StateT merge(Block merge, List<StateT> states);
 
@@ -62,8 +62,8 @@
         }
         for (Block loopExit : loop.exits) {
             assert loopExit.getPredecessorCount() == 1;
+            assert blockEndStates.containsKey(loopExit.getBeginNode());
             StateT exitState = blockEndStates.get(loopExit.getBeginNode());
-            assert exitState != null;
             // make sure all exit states are unique objects
             info.exitStates.add(closure.cloneState(exitState));
         }
@@ -82,7 +82,7 @@
 
         while (true) {
             if (boundary == null || boundary.contains(current)) {
-                closure.processBlock(current, state);
+                state = closure.processBlock(current, state);
 
                 if (current.getSuccessors().isEmpty()) {
                     // nothing to do...
@@ -156,6 +156,7 @@
             } else {
                 current = blockQueue.removeFirst();
                 if (current.getPredecessors().size() == 1) {
+                    assert states.containsKey(current.getBeginNode());
                     state = states.get(current.getBeginNode());
                 } else {
                     assert current.getPredecessors().size() > 1;
@@ -167,7 +168,6 @@
                     }
                     state = closure.merge(current, mergedStates);
                 }
-                assert state != null;
             }
         }
     }
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ReentrantNodeIterator.java	Wed May 08 22:56:34 2013 +0200
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ReentrantNodeIterator.java	Thu May 09 11:32:08 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.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java	Wed May 08 22:56:34 2013 +0200
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java	Thu May 09 11:32:08 2013 +0200
@@ -84,7 +84,7 @@
     private class MemoryScheduleClosure extends BlockIteratorClosure<HashSet<FloatingReadNode>> {
 
         @Override
-        protected void processBlock(Block block, HashSet<FloatingReadNode> currentState) {
+        protected HashSet<FloatingReadNode> processBlock(Block block, HashSet<FloatingReadNode> currentState) {
             for (Node node : getBlockToNodesMap().get(block)) {
                 if (node instanceof FloatingReadNode) {
                     currentState.add((FloatingReadNode) node);
@@ -100,6 +100,7 @@
                     }
                 }
             }
+            return currentState;
         }
 
         public void addPhantomReference(FloatingReadNode read, FixedNode fixed) {
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetFrameStateCleanupPhase.java	Wed May 08 22:56:34 2013 +0200
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetFrameStateCleanupPhase.java	Thu May 09 11:32:08 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;
--- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java	Wed May 08 22:56:34 2013 +0200
+++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java	Thu May 09 11:32:08 2013 +0200
@@ -92,7 +92,7 @@
 
     public List<Node> applyEffects(final StructuredGraph graph) {
         final ArrayList<Node> obsoleteNodes = new ArrayList<>();
-        BlockIteratorClosure<Object> closure = new BlockIteratorClosure<Object>() {
+        BlockIteratorClosure<Void> closure = new BlockIteratorClosure<Void>() {
 
             private void apply(GraphEffectList effects, Object context) {
                 if (!effects.isEmpty()) {
@@ -107,28 +107,29 @@
             }
 
             @Override
-            protected void processBlock(Block block, Object currentState) {
+            protected Void processBlock(Block block, Void currentState) {
                 apply(blockEffects.get(block), block);
+                return currentState;
             }
 
             @Override
-            protected Object merge(Block merge, List<Object> states) {
-                return new Object();
+            protected Void merge(Block merge, List<Void> states) {
+                return null;
             }
 
             @Override
-            protected Object cloneState(Object oldState) {
+            protected Void cloneState(Void oldState) {
                 return oldState;
             }
 
             @Override
-            protected List<Object> processLoop(Loop loop, Object initialState) {
-                LoopInfo<Object> info = ReentrantBlockIterator.processLoop(this, loop, initialState);
+            protected List<Void> processLoop(Loop loop, Void initialState) {
+                LoopInfo<Void> info = ReentrantBlockIterator.processLoop(this, loop, initialState);
                 apply(loopMergeEffects.get(loop), loop);
                 return info.exitStates;
             }
         };
-        ReentrantBlockIterator.apply(closure, schedule.getCFG().getStartBlock(), new Object(), null);
+        ReentrantBlockIterator.apply(closure, schedule.getCFG().getStartBlock(), null, null);
         return obsoleteNodes;
     }
 
@@ -137,7 +138,7 @@
     }
 
     @Override
-    protected void processBlock(Block block, BlockState state) {
+    protected BlockState processBlock(Block block, BlockState state) {
         GraphEffectList effects = blockEffects.get(block);
         tool.setEffects(effects);
 
@@ -194,6 +195,7 @@
             }
         }
         trace(")\n    end state: %s\n", state);
+        return state;
     }
 
     private boolean processNode(final ValueNode node, FixedNode insertBefore, final BlockState state, final GraphEffectList effects) {