# HG changeset patch # User Michael Haupt # Date 1409133395 -7200 # Node ID 818844f7224dc1e62348420ebc8cc9336f9cf1e8 # Parent e92bc7d8e2ddbe42b562e0f28d35050179cc3813 extract TypedNodeIterator to separate file and rename (workaround for javac bug) diff -r e92bc7d8e2dd -r 818844f7224d graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java --- 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 implements Iterator { - - 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 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; } diff -r e92bc7d8e2dd -r 818844f7224d graal/com.oracle.graal.graph/src/com/oracle/graal/graph/TypedGraphNodeIterator.java --- /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 implements Iterator { + + 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