# HG changeset patch # User Gilles Duboscq # Date 1397485873 -7200 # Node ID 65efd2eeea1ba67f243b1e931cc61093e73ddb0e # Parent df2ef5204f2bd082c9bc1743291b803d428f3076 Remove AbstractNodeIterable, move its methods to default methods on NodeIterable. This allows to remove a number of duplicated methods in NodeList NodeClassIterable is also interface instead of an abstract class. diff -r df2ef5204f2b -r 65efd2eeea1b 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 Mon Apr 14 15:21:27 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java Mon Apr 14 16:31:13 2014 +0200 @@ -525,7 +525,7 @@ */ public NodeIterable getNewNodes(Mark mark) { final int index = mark.getValue(); - return new AbstractNodeIterable() { + return new NodeIterable() { @Override public Iterator iterator() { @@ -540,7 +540,7 @@ * @return an {@link Iterable} providing all the live nodes. */ public NodeIterable getNodes() { - return new AbstractNodeIterable() { + return new NodeIterable() { @Override public Iterator iterator() { @@ -714,7 +714,7 @@ */ public NodeIterable getNodes(final Class type) { final NodeClass nodeClass = NodeClass.get(type); - return new AbstractNodeIterable() { + return new NodeIterable() { @Override public Iterator iterator() { diff -r df2ef5204f2b -r 65efd2eeea1b graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java Mon Apr 14 15:21:27 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java Mon Apr 14 16:31:13 2014 +0200 @@ -228,7 +228,7 @@ } } - class NodeUsageIterable extends AbstractNodeIterable { + class NodeUsageIterable implements NodeIterable { public NodeUsageIterator iterator() { return new NodeUsageIterator(); diff -r df2ef5204f2b -r 65efd2eeea1b graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeBitMap.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeBitMap.java Mon Apr 14 15:21:27 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeBitMap.java Mon Apr 14 16:31:13 2014 +0200 @@ -26,7 +26,7 @@ import com.oracle.graal.graph.iterators.*; -public final class NodeBitMap extends AbstractNodeIterable { +public final class NodeBitMap implements NodeIterable { private final boolean autoGrow; private final BitSet bitMap; diff -r df2ef5204f2b -r 65efd2eeea1b graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClassIterable.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClassIterable.java Mon Apr 14 15:21:27 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClassIterable.java Mon Apr 14 16:31:13 2014 +0200 @@ -30,7 +30,7 @@ * The iterator returned by this iterable can be used to access {@link Position Positions} during * iteration using {@link NodeClassIterator#nextPosition()}. */ -public abstract class NodeClassIterable extends AbstractNodeIterable { +public interface NodeClassIterable extends NodeIterable { @Override public abstract NodeClassIterator iterator(); diff -r df2ef5204f2b -r 65efd2eeea1b graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeList.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeList.java Mon Apr 14 15:21:27 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeList.java Mon Apr 14 16:31:13 2014 +0200 @@ -348,42 +348,6 @@ } @Override - public NodeIterable until(final T u) { - return new FilteredNodeIterable<>(this).until(u); - } - - @Override - public NodeIterable until(final Class clazz) { - return new FilteredNodeIterable<>(this).until(clazz); - } - - @Override - @SuppressWarnings("unchecked") - public NodeIterable filter(Class clazz) { - return (NodeIterable) new FilteredNodeIterable<>(this).and(NodePredicates.isA(clazz)); - } - - @Override - public NodeIterable filterInterface(Class iface) { - return new FilteredNodeIterable<>(this).and(NodePredicates.isAInterface(iface)); - } - - @Override - public FilteredNodeIterable filter(NodePredicate predicate) { - return new FilteredNodeIterable<>(this).and(predicate); - } - - @Override - public FilteredNodeIterable nonNull() { - return new FilteredNodeIterable<>(this).and(NodePredicates.isNotNull()); - } - - @Override - public NodeIterable distinct() { - return new FilteredNodeIterable<>(this).distinct(); - } - - @Override public T first() { if (size() > 0) { return get(0); diff -r df2ef5204f2b -r 65efd2eeea1b graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/AbstractNodeIterable.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/AbstractNodeIterable.java Mon Apr 14 15:21:27 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.graph.iterators; - -import java.util.*; - -import com.oracle.graal.graph.*; - -public abstract class AbstractNodeIterable implements NodeIterable { - - @Override - public NodeIterable until(final T u) { - return new FilteredNodeIterable<>(this).until(u); - } - - @Override - public NodeIterable until(final Class clazz) { - return new FilteredNodeIterable<>(this).until(clazz); - } - - @Override - @SuppressWarnings("unchecked") - public NodeIterable filter(Class clazz) { - return (NodeIterable) new FilteredNodeIterable<>(this).and(NodePredicates.isA(clazz)); - } - - @Override - public NodeIterable filterInterface(Class iface) { - return new FilteredNodeIterable<>(this).and(NodePredicates.isAInterface(iface)); - } - - @Override - public FilteredNodeIterable filter(NodePredicate predicate) { - return new FilteredNodeIterable<>(this).and(predicate); - } - - @Override - public FilteredNodeIterable nonNull() { - return new FilteredNodeIterable<>(this).and(NodePredicates.isNotNull()); - } - - @Override - public NodeIterable distinct() { - return new FilteredNodeIterable<>(this).distinct(); - } - - @Override - public List snapshot() { - ArrayList list = new ArrayList<>(); - for (T n : this) { - list.add(n); - } - return list; - } - - @Override - public void snapshotTo(Collection to) { - for (T n : this) { - to.add(n); - } - } - - @Override - public T first() { - Iterator iterator = iterator(); - if (iterator.hasNext()) { - return iterator.next(); - } - return null; - } - - @Override - public int count() { - int count = 0; - Iterator iterator = iterator(); - while (iterator.hasNext()) { - iterator.next(); - count++; - } - return count; - } - - @Override - public boolean isEmpty() { - return !iterator().hasNext(); - } - - @Override - public boolean isNotEmpty() { - return iterator().hasNext(); - } - - @Override - public boolean contains(T node) { - return this.filter(NodePredicates.equals(node)).isNotEmpty(); - } -} diff -r df2ef5204f2b -r 65efd2eeea1b graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/FilteredNodeIterable.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/FilteredNodeIterable.java Mon Apr 14 15:21:27 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/FilteredNodeIterable.java Mon Apr 14 16:31:13 2014 +0200 @@ -26,7 +26,7 @@ import com.oracle.graal.graph.*; -public class FilteredNodeIterable extends AbstractNodeIterable { +public class FilteredNodeIterable implements NodeIterable { protected final NodeIterable nodeIterable; protected NodePredicate predicate = NodePredicates.alwaysTrue(); diff -r df2ef5204f2b -r 65efd2eeea1b graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/NodeIterable.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/NodeIterable.java Mon Apr 14 15:21:27 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/NodeIterable.java Mon Apr 14 16:31:13 2014 +0200 @@ -28,32 +28,74 @@ public interface NodeIterable extends Iterable { - NodeIterable until(T u); + default NodeIterable until(final T u) { + return new FilteredNodeIterable<>(this).until(u); + } + + default NodeIterable until(final Class clazz) { + return new FilteredNodeIterable<>(this).until(clazz); + } - NodeIterable until(Class clazz); + @SuppressWarnings("unchecked") + default NodeIterable filter(Class clazz) { + return (NodeIterable) new FilteredNodeIterable<>(this).and(NodePredicates.isA(clazz)); + } - NodeIterable filter(Class clazz); + default NodeIterable filterInterface(Class iface) { + return new FilteredNodeIterable<>(this).and(NodePredicates.isAInterface(iface)); + } - NodeIterable filterInterface(Class iface); + default FilteredNodeIterable filter(NodePredicate predicate) { + return new FilteredNodeIterable<>(this).and(predicate); + } - FilteredNodeIterable filter(NodePredicate predicate); + default FilteredNodeIterable nonNull() { + return new FilteredNodeIterable<>(this).and(NodePredicates.isNotNull()); + } - FilteredNodeIterable nonNull(); + default NodeIterable distinct() { + return new FilteredNodeIterable<>(this).distinct(); + } - NodeIterable distinct(); + default List snapshot() { + ArrayList list = new ArrayList<>(); + snapshotTo(list); + return list; + } - List snapshot(); - - void snapshotTo(Collection to); + default void snapshotTo(Collection to) { + for (T n : this) { + to.add(n); + } + } - T first(); - - int count(); + default T first() { + Iterator iterator = iterator(); + if (iterator.hasNext()) { + return iterator.next(); + } + return null; + } - boolean isEmpty(); - - boolean isNotEmpty(); + default int count() { + int count = 0; + Iterator iterator = iterator(); + while (iterator.hasNext()) { + iterator.next(); + count++; + } + return count; + } - boolean contains(T node); + default boolean isEmpty() { + return !iterator().hasNext(); + } + default boolean isNotEmpty() { + return iterator().hasNext(); + } + + default boolean contains(T node) { + return this.filter(NodePredicates.equals(node)).isNotEmpty(); + } } diff -r df2ef5204f2b -r 65efd2eeea1b graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopFragment.java --- a/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopFragment.java Mon Apr 14 15:21:27 2014 +0200 +++ b/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopFragment.java Mon Apr 14 16:31:13 2014 +0200 @@ -254,7 +254,7 @@ } public static NodeIterable toHirBlocks(final Iterable blocks) { - return new AbstractNodeIterable() { + return new NodeIterable() { public Iterator iterator() { final Iterator it = blocks.iterator(); @@ -279,7 +279,7 @@ } public static NodeIterable toHirExits(final Iterable blocks) { - return new AbstractNodeIterable() { + return new NodeIterable() { public Iterator iterator() { final Iterator it = blocks.iterator(); @@ -341,7 +341,7 @@ * VirtualState nodes contained in the old exit's state may be shared by other * dominated VirtualStates. Those dominated virtual states need to see the * proxy->phi update that are applied below. - * + * * We now update the original fragment's nodes accordingly: */ state.applyToVirtual(new VirtualClosure() { diff -r df2ef5204f2b -r 65efd2eeea1b graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/BeginNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/BeginNode.java Mon Apr 14 15:21:27 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/BeginNode.java Mon Apr 14 16:31:13 2014 +0200 @@ -130,7 +130,7 @@ } public NodeIterable getBlockNodes() { - return new AbstractNodeIterable() { + return new NodeIterable() { @Override public Iterator iterator() { diff -r df2ef5204f2b -r 65efd2eeea1b graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/NodeIterators.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/NodeIterators.java Mon Apr 14 15:21:27 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/NodeIterators.java Mon Apr 14 16:31:13 2014 +0200 @@ -30,7 +30,7 @@ public class NodeIterators { public static NodeIterable dominators(final FixedNode n) { - return new AbstractNodeIterable() { + return new NodeIterable() { @Override public Iterator iterator() {