changeset 16970:818844f7224d

extract TypedNodeIterator to separate file and rename (workaround for javac bug)
author Michael Haupt <michael.haupt@oracle.com>
date Wed, 27 Aug 2014 11:56:35 +0200
parents e92bc7d8e2dd
children 7bb9b9f56799
files graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java graal/com.oracle.graal.graph/src/com/oracle/graal/graph/TypedGraphNodeIterator.java
diffstat 2 files changed, 107 insertions(+), 104 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java	Wed Aug 27 09:14:19 2014 +0200
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java	Wed Aug 27 11:56:35 2014 +0200
@@ -608,7 +608,7 @@
         }
     }
 
-    private static final Node PLACE_HOLDER = USE_GENERATED_NODES ? new Graph_PlaceHolderNodeGen() : new PlaceHolderNode();
+    static final Node PLACE_HOLDER = USE_GENERATED_NODES ? new Graph_PlaceHolderNodeGen() : new PlaceHolderNode();
 
     /**
      * When the percent of live nodes in {@link #nodes} fall below this number, a call to
@@ -659,107 +659,6 @@
         return true;
     }
 
-    private static class TypedNodeIterator<T extends IterableNodeType> implements Iterator<T> {
-
-        private final Graph graph;
-        private final int[] ids;
-        private final Node[] current;
-
-        private int currentIdIndex;
-        private boolean needsForward;
-
-        public TypedNodeIterator(NodeClass clazz, Graph graph) {
-            this.graph = graph;
-            ids = clazz.iterableIds();
-            currentIdIndex = 0;
-            current = new Node[ids.length];
-            Arrays.fill(current, PLACE_HOLDER);
-            needsForward = true;
-        }
-
-        private Node findNext() {
-            if (needsForward) {
-                forward();
-            } else {
-                Node c = current();
-                Node afterDeleted = skipDeleted(c);
-                if (afterDeleted == null) {
-                    needsForward = true;
-                } else if (c != afterDeleted) {
-                    setCurrent(afterDeleted);
-                }
-            }
-            if (needsForward) {
-                return null;
-            }
-            return current();
-        }
-
-        private static Node skipDeleted(Node node) {
-            Node n = node;
-            while (n != null && n.isDeleted()) {
-                n = n.typeCacheNext;
-            }
-            return n;
-        }
-
-        private void forward() {
-            needsForward = false;
-            int startIdx = currentIdIndex;
-            while (true) {
-                Node next;
-                if (current() == PLACE_HOLDER) {
-                    next = graph.getStartNode(ids[currentIdIndex]);
-                } else {
-                    next = current().typeCacheNext;
-                }
-                next = skipDeleted(next);
-                if (next == null) {
-                    currentIdIndex++;
-                    if (currentIdIndex >= ids.length) {
-                        currentIdIndex = 0;
-                    }
-                    if (currentIdIndex == startIdx) {
-                        needsForward = true;
-                        return;
-                    }
-                } else {
-                    setCurrent(next);
-                    break;
-                }
-            }
-        }
-
-        private Node current() {
-            return current[currentIdIndex];
-        }
-
-        private void setCurrent(Node n) {
-            current[currentIdIndex] = n;
-        }
-
-        @Override
-        public boolean hasNext() {
-            return findNext() != null;
-        }
-
-        @Override
-        @SuppressWarnings("unchecked")
-        public T next() {
-            Node result = findNext();
-            if (result == null) {
-                throw new NoSuchElementException();
-            }
-            needsForward = true;
-            return (T) result;
-        }
-
-        @Override
-        public void remove() {
-            throw new UnsupportedOperationException();
-        }
-    }
-
     /**
      * Returns an {@link Iterable} providing all the live nodes whose type is compatible with
      * {@code type}.
@@ -773,7 +672,7 @@
 
             @Override
             public Iterator<T> iterator() {
-                return new TypedNodeIterator<>(nodeClass, Graph.this);
+                return new TypedGraphNodeIterator<>(nodeClass, Graph.this);
             }
         };
     }
@@ -788,7 +687,7 @@
         return getNodes(type).iterator().hasNext();
     }
 
-    private Node getStartNode(int iterableId) {
+    Node getStartNode(int iterableId) {
         Node start = nodeCacheFirst.size() <= iterableId ? null : nodeCacheFirst.get(iterableId);
         return start;
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/TypedGraphNodeIterator.java	Wed Aug 27 11:56:35 2014 +0200
@@ -0,0 +1,104 @@
+package com.oracle.graal.graph;
+
+import java.util.*;
+
+class TypedGraphNodeIterator<T extends IterableNodeType> implements Iterator<T> {
+
+    private final Graph graph;
+    private final int[] ids;
+    private final Node[] current;
+
+    private int currentIdIndex;
+    private boolean needsForward;
+
+    public TypedGraphNodeIterator(NodeClass clazz, Graph graph) {
+        this.graph = graph;
+        ids = clazz.iterableIds();
+        currentIdIndex = 0;
+        current = new Node[ids.length];
+        Arrays.fill(current, Graph.PLACE_HOLDER);
+        needsForward = true;
+    }
+
+    private Node findNext() {
+        if (needsForward) {
+            forward();
+        } else {
+            Node c = current();
+            Node afterDeleted = skipDeleted(c);
+            if (afterDeleted == null) {
+                needsForward = true;
+            } else if (c != afterDeleted) {
+                setCurrent(afterDeleted);
+            }
+        }
+        if (needsForward) {
+            return null;
+        }
+        return current();
+    }
+
+    private static Node skipDeleted(Node node) {
+        Node n = node;
+        while (n != null && n.isDeleted()) {
+            n = n.typeCacheNext;
+        }
+        return n;
+    }
+
+    private void forward() {
+        needsForward = false;
+        int startIdx = currentIdIndex;
+        while (true) {
+            Node next;
+            if (current() == Graph.PLACE_HOLDER) {
+                next = graph.getStartNode(ids[currentIdIndex]);
+            } else {
+                next = current().typeCacheNext;
+            }
+            next = skipDeleted(next);
+            if (next == null) {
+                currentIdIndex++;
+                if (currentIdIndex >= ids.length) {
+                    currentIdIndex = 0;
+                }
+                if (currentIdIndex == startIdx) {
+                    needsForward = true;
+                    return;
+                }
+            } else {
+                setCurrent(next);
+                break;
+            }
+        }
+    }
+
+    private Node current() {
+        return current[currentIdIndex];
+    }
+
+    private void setCurrent(Node n) {
+        current[currentIdIndex] = n;
+    }
+
+    @Override
+    public boolean hasNext() {
+        return findNext() != null;
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public T next() {
+        Node result = findNext();
+        if (result == null) {
+            throw new NoSuchElementException();
+        }
+        needsForward = true;
+        return (T) result;
+    }
+
+    @Override
+    public void remove() {
+        throw new UnsupportedOperationException();
+    }
+}
\ No newline at end of file