# HG changeset patch # User Gilles Duboscq # Date 1327932993 -3600 # Node ID c8de52cc672a3fc4d83b9c2a249ea5afa05952b2 # Parent ccbdd90bf35610a69ec9de35de93fd2bacd0f0ff# Parent 9f8e4aeec1a9b7095721d940bf1d7e929cacfb9a Merge diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java Mon Jan 30 15:16:33 2012 +0100 @@ -392,7 +392,7 @@ } if (block.numberOfSux() >= 1 && !block.endsWithJump()) { NodeSuccessorsIterable successors = block.lastNode().successors(); - assert successors.explicitCount() >= 1 : "should have at least one successor : " + block.lastNode(); + assert successors.count() >= 1 : "should have at least one successor : " + block.lastNode(); emitJump(getLIRBlock((FixedNode) successors.first()), null); } diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/BoxingEliminationPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/BoxingEliminationPhase.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/BoxingEliminationPhase.java Mon Jan 30 15:16:33 2012 +0100 @@ -22,11 +22,14 @@ */ package com.oracle.max.graal.compiler.phases; +import static com.oracle.max.graal.graph.iterators.NodePredicates.*; + import java.util.*; import com.oracle.max.cri.ci.*; import com.oracle.max.cri.ri.*; import com.oracle.max.graal.graph.*; +import com.oracle.max.graal.graph.iterators.*; import com.oracle.max.graal.nodes.*; import com.oracle.max.graal.nodes.PhiNode.*; import com.oracle.max.graal.nodes.extended.*; @@ -106,11 +109,9 @@ virtualizeUsages(boxNode, boxNode.source(), boxNode.exactType()); - for (Node n : boxNode.usages()) { - if (!(n instanceof FrameState) && !(n instanceof VirtualObjectFieldNode)) { - // Elimination failed, because boxing object escapes. - return; - } + if (boxNode.usages().filter(isNotA(FrameState.class).nor(VirtualObjectFieldNode.class)).isNotEmpty()) { + // Elimination failed, because boxing object escapes. + return; } // TODO(ls) this seems weird: there might still be references to boxNode, yet it is deleted... @@ -125,7 +126,7 @@ private static void virtualizeUsages(ValueNode boxNode, ValueNode replacement, RiResolvedType exactType) { ValueNode virtualValueNode = null; VirtualObjectNode virtualObjectNode = null; - for (Node n : boxNode.usages().filter(FrameState.class).or(VirtualObjectFieldNode.class).snapshot()) { + for (Node n : boxNode.usages().filter(NodePredicates.isA(FrameState.class).or(VirtualObjectFieldNode.class)).snapshot()) { if (virtualValueNode == null) { virtualObjectNode = n.graph().unique(new BoxedVirtualObjectNode(exactType, replacement)); } diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/CanonicalizerPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/CanonicalizerPhase.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/CanonicalizerPhase.java Mon Jan 30 15:16:33 2012 +0100 @@ -22,6 +22,8 @@ */ package com.oracle.max.graal.compiler.phases; +import static com.oracle.max.graal.graph.iterators.NodePredicates.*; + import com.oracle.max.cri.ci.*; import com.oracle.max.cri.ri.*; import com.oracle.max.graal.debug.*; @@ -232,8 +234,8 @@ if (node instanceof PhiNode) { node.replaceFirstInput(input, null); } else { - for (Node usage : node.usages().snapshot()) { - if ((usage instanceof FloatingNode || usage instanceof CallTargetNode) && !usage.isDeleted()) { + for (Node usage : node.usages().filter(isA(FloatingNode.class).or(CallTargetNode.class)).snapshot()) { + if (!usage.isDeleted()) { killNonCFG(usage, node); } } diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/EscapeAnalysisPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/EscapeAnalysisPhase.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/EscapeAnalysisPhase.java Mon Jan 30 15:16:33 2012 +0100 @@ -306,7 +306,7 @@ private static Node escape(EscapeRecord record, Node usage) { final Node node = record.node; if (usage instanceof FrameState) { - assert ((FrameState) usage).inputs().contains(node); + assert usage.inputs().contains(node); return null; } else { if (usage instanceof FixedNode) { diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java Mon Jan 30 15:16:33 2012 +0100 @@ -125,11 +125,8 @@ Invoke invoke = (Invoke) node; scanInvoke(invoke, level); } - for (Node usage : node.usages().snapshot()) { - if (usage instanceof Invoke) { - Invoke invoke = (Invoke) usage; - scanInvoke(invoke, level); - } + for (Node usage : node.usages().filterInterface(Invoke.class).snapshot()) { + scanInvoke((Invoke) usage, level); } } } diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/PhiStampPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/PhiStampPhase.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/PhiStampPhase.java Mon Jan 30 15:16:33 2012 +0100 @@ -22,7 +22,6 @@ */ package com.oracle.max.graal.compiler.phases; -import com.oracle.max.graal.graph.*; import com.oracle.max.graal.nodes.*; public class PhiStampPhase extends Phase { @@ -45,22 +44,16 @@ private void iterativeInferPhi(PhiNode phi) { if (phi.inferStamp()) { - for (Node n : phi.usages()) { - if (n instanceof PhiNode) { - PhiNode phiUsage = (PhiNode) n; - iterativeInferPhi(phiUsage); - } + for (PhiNode phiUsage : phi.usages().filter(PhiNode.class)) { + iterativeInferPhi(phiUsage); } } } private void inferPhi(PhiNode phi) { - for (ValueNode v : phi.values()) { - if (v instanceof PhiNode) { - PhiNode phiInput = (PhiNode) v; - if (!phiInput.isLoopPhi()) { - inferPhi(phiInput); - } + for (PhiNode phiInput : phi.values().filter(PhiNode.class)) { + if (!phiInput.isLoopPhi()) { + inferPhi(phiInput); } } phi.inferStamp(); diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SafepointPollingEliminationPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SafepointPollingEliminationPhase.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SafepointPollingEliminationPhase.java Mon Jan 30 15:16:33 2012 +0100 @@ -22,9 +22,9 @@ */ package com.oracle.max.graal.compiler.phases; -import com.oracle.max.graal.compiler.util.*; import com.oracle.max.graal.graph.iterators.*; import com.oracle.max.graal.nodes.*; +import com.oracle.max.graal.util.*; public class SafepointPollingEliminationPhase extends Phase { diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SnippetIntrinsificationPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SnippetIntrinsificationPhase.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SnippetIntrinsificationPhase.java Mon Jan 30 15:16:33 2012 +0100 @@ -169,36 +169,33 @@ public void cleanUpReturnCheckCast(Node newInstance) { if (newInstance instanceof ValueNode && ((ValueNode) newInstance).kind() != CiKind.Object) { StructuredGraph graph = (StructuredGraph) newInstance.graph(); - for (Node usage : newInstance.usages().snapshot()) { - if (usage instanceof CheckCastNode) { - CheckCastNode checkCastNode = (CheckCastNode) usage; - for (Node checkCastUsage : checkCastNode.usages().snapshot()) { - if (checkCastUsage instanceof ValueAnchorNode) { - ValueAnchorNode valueAnchorNode = (ValueAnchorNode) checkCastUsage; - graph.removeFixed(valueAnchorNode); - } else if (checkCastUsage instanceof MethodCallTargetNode) { - MethodCallTargetNode checkCastCallTarget = (MethodCallTargetNode) checkCastUsage; - assert pool.isUnboxingMethod(checkCastCallTarget.targetMethod()); - Invoke invokeNode = checkCastCallTarget.invoke(); - invokeNode.node().replaceAtUsages(newInstance); - if (invokeNode instanceof InvokeWithExceptionNode) { - // Destroy exception edge & clear stateAfter. - InvokeWithExceptionNode invokeWithExceptionNode = (InvokeWithExceptionNode) invokeNode; + for (CheckCastNode checkCastNode : newInstance.usages().filter(CheckCastNode.class).snapshot()) { + for (Node checkCastUsage : checkCastNode.usages().snapshot()) { + if (checkCastUsage instanceof ValueAnchorNode) { + ValueAnchorNode valueAnchorNode = (ValueAnchorNode) checkCastUsage; + graph.removeFixed(valueAnchorNode); + } else if (checkCastUsage instanceof MethodCallTargetNode) { + MethodCallTargetNode checkCastCallTarget = (MethodCallTargetNode) checkCastUsage; + assert pool.isUnboxingMethod(checkCastCallTarget.targetMethod()); + Invoke invokeNode = checkCastCallTarget.invoke(); + invokeNode.node().replaceAtUsages(newInstance); + if (invokeNode instanceof InvokeWithExceptionNode) { + // Destroy exception edge & clear stateAfter. + InvokeWithExceptionNode invokeWithExceptionNode = (InvokeWithExceptionNode) invokeNode; - invokeWithExceptionNode.killExceptionEdge(); - graph.removeSplit(invokeWithExceptionNode, InvokeWithExceptionNode.NORMAL_EDGE); - } else { - graph.removeFixed((InvokeNode) invokeNode); - } - checkCastCallTarget.safeDelete(); - } else if (checkCastUsage instanceof FrameState) { - checkCastUsage.replaceFirstInput(checkCastNode, null); + invokeWithExceptionNode.killExceptionEdge(); + graph.removeSplit(invokeWithExceptionNode, InvokeWithExceptionNode.NORMAL_EDGE); } else { - assert false : "unexpected checkcast usage: " + checkCastUsage; + graph.removeFixed((InvokeNode) invokeNode); } + checkCastCallTarget.safeDelete(); + } else if (checkCastUsage instanceof FrameState) { + checkCastUsage.replaceFirstInput(checkCastNode, null); + } else { + assert false : "unexpected checkcast usage: " + checkCastUsage; } - checkCastNode.safeDelete(); } + checkCastNode.safeDelete(); } } } diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/schedule/IdentifyBlocksPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/schedule/IdentifyBlocksPhase.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/schedule/IdentifyBlocksPhase.java Mon Jan 30 15:16:33 2012 +0100 @@ -179,10 +179,8 @@ } if (n instanceof MergeNode) { - for (Node usage : n.usages()) { - if (usage instanceof PhiNode) { - nodeToBlock.set(usage, b); - } + for (PhiNode phi : ((MergeNode) n).phis()) { + nodeToBlock.set(phi, b); } } if (n instanceof EndNode) { diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/InliningUtil.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/InliningUtil.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/InliningUtil.java Mon Jan 30 15:16:33 2012 +0100 @@ -371,7 +371,7 @@ InvokeWithExceptionNode invokeWithException = ((InvokeWithExceptionNode) invoke); if (unwindNode != null) { assert unwindNode.predecessor() != null; - assert invokeWithException.exceptionEdge().successors().explicitCount() == 1; + assert invokeWithException.exceptionEdge().successors().count() == 1; ExceptionObjectNode obj = (ExceptionObjectNode) invokeWithException.exceptionEdge().next(); stateAtExceptionEdge = obj.stateAfter(); UnwindNode unwindDuplicate = (UnwindNode) duplicates.get(unwindNode); diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/NodeIterators.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/NodeIterators.java Sun Jan 29 11:40:04 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2011, 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.max.graal.compiler.util; - -import java.util.*; - -import com.oracle.max.graal.graph.iterators.*; -import com.oracle.max.graal.nodes.*; -import com.oracle.max.graal.util.*; - -public class NodeIterators { - - public static NodeIterable dominators(final FixedNode n) { - return new NodeIterable() { - @Override - public Iterator iterator() { - return new NodeIterator(until){ - FixedNode p = n; - @Override - protected void forward() { - if (current == null) { - if (p instanceof MergeNode) { - current = new ComputeImmediateDominator((MergeNode) p).compute(); - } else { - current = (FixedNode) p.predecessor(); - } - p = current; - } - } - }; - } - }; - } -} diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Graph.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Graph.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Graph.java Mon Jan 30 15:16:33 2012 +0100 @@ -265,9 +265,9 @@ * Returns an {@link Iterable} providing all nodes added since the last {@link Graph#mark() mark}. * @return an {@link Iterable} providing the new nodes */ - public Iterable getNewNodes() { + public NodeIterable getNewNodes() { final int index = this.mark; - return new Iterable() { + return new NodeIterable() { @Override public Iterator iterator() { return new NodeIterator(index); diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeInputsIterable.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeInputsIterable.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeInputsIterable.java Mon Jan 30 15:16:33 2012 +0100 @@ -26,9 +26,6 @@ import com.oracle.max.graal.graph.iterators.*; public abstract class NodeInputsIterable extends NodeIterable { - - public abstract boolean contains(Node node); - @Override public abstract NodeClassIterator iterator(); } diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeList.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeList.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeList.java Mon Jan 30 15:16:33 2012 +0100 @@ -27,7 +27,9 @@ import java.util.List; import java.util.ListIterator; -public abstract class NodeList implements Iterable, List { +import com.oracle.max.graal.graph.iterators.*; + +public abstract class NodeList extends NodeIterable implements List { protected static final Node[] EMPTY_NODE_ARRAY = new Node[0]; @@ -74,6 +76,16 @@ return size == 0; } + @Override + public boolean isNotEmpty() { + return size > 0; + } + + @Override + public int count() { + return size; + } + protected final void incModCount() { modCount++; } @@ -214,6 +226,7 @@ }; } + @Override public boolean contains(T other) { for (int i = 0; i < size; i++) { if (nodes[i] == other) { @@ -223,33 +236,10 @@ return false; } - public Iterable snapshot() { - return new Iterable() { - - @Override - public Iterator iterator() { - return new Iterator() { - private Node[] nodesCopy = Arrays.copyOf(NodeList.this.nodes, NodeList.this.size); - private int index = 0; - - @Override - public boolean hasNext() { - return index < nodesCopy.length; - } - - @SuppressWarnings("unchecked") - @Override - public T next() { - return (T) nodesCopy[index++]; - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - }; - } - }; + @SuppressWarnings("unchecked") + @Override + public List snapshot() { + return (List) Arrays.asList(Arrays.copyOf(this.nodes, this.size)); } @SuppressWarnings("unchecked") diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeSuccessorsIterable.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeSuccessorsIterable.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeSuccessorsIterable.java Mon Jan 30 15:16:33 2012 +0100 @@ -26,17 +26,6 @@ import com.oracle.max.graal.graph.iterators.*; public abstract class NodeSuccessorsIterable extends NodeIterable { - - public int explicitCount() { - int count = 0; - for (@SuppressWarnings("unused") Node node : this) { - count++; - } - return count; - } - - public abstract boolean contains(Node node); - @Override public abstract NodeClassIterator iterator(); } diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeUsagesList.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeUsagesList.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeUsagesList.java Mon Jan 30 15:16:33 2012 +0100 @@ -58,6 +58,11 @@ return size > 0; } + @Override + public int count() { + return size; + } + protected void incModCount() { modCount++; } @@ -140,6 +145,7 @@ }; } + @Override public boolean contains(Node other) { for (int i = 0; i < size; i++) { if (nodes[i] == other) { diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/FilteredNodeIterable.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/FilteredNodeIterable.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/FilteredNodeIterable.java Mon Jan 30 15:16:33 2012 +0100 @@ -28,20 +28,10 @@ public class FilteredNodeIterable extends NodeIterable { private final NodeIterable nodeIterable; - private NodePredicate predicate = NodePredicate.TAUTOLOGY; + private NodePredicate predicate = NodePredicates.alwaysTrue(); + private NodePredicate until = NodePredicates.isNull(); public FilteredNodeIterable(NodeIterable nodeIterable) { this.nodeIterable = nodeIterable; - this.until = nodeIterable.until; - } - @SuppressWarnings("unchecked") - public FilteredNodeIterable and(Class clazz) { - this.predicate = predicate.and(new TypePredicate(clazz)); - return (FilteredNodeIterable) this; - } - @SuppressWarnings("unchecked") - public FilteredNodeIterable or(Class clazz) { - this.predicate = predicate.or(new TypePredicate(clazz)); - return (FilteredNodeIterable) this; } public FilteredNodeIterable and(NodePredicate nodePredicate) { this.predicate = this.predicate.and(nodePredicate); @@ -52,8 +42,34 @@ return this; } @Override + public NodeIterable until(final T u) { + until = until.or(NodePredicates.equals(u)); + return this; + } + @Override + public NodeIterable until(final Class clazz) { + until = until.or(NodePredicates.isA(clazz)); + return this; + } + @Override public Iterator iterator() { final Iterator iterator = nodeIterable.iterator(); return new PredicatedProxyNodeIterator<>(until, iterator, predicate); } + + @SuppressWarnings("unchecked") + @Override + public FilteredNodeIterable filter(Class clazz) { + return (FilteredNodeIterable) this.and(NodePredicates.isA(clazz)); + } + + @Override + public FilteredNodeIterable filter(NodePredicate p) { + return this.and(p); + } + + @Override + public FilteredNodeIterable filterInterface(Class< ? > iface) { + return this.and(NodePredicates.isAInterface(iface)); + } } diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodeIterable.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodeIterable.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodeIterable.java Mon Jan 30 15:16:33 2012 +0100 @@ -27,17 +27,18 @@ import com.oracle.max.graal.graph.*; public abstract class NodeIterable implements Iterable { - protected NodePredicate until = NodePredicate.IS_NULL; public NodeIterable until(final T u) { - until = until.or(NodePredicate.equals(u)); - return this; + return new FilteredNodeIterable<>(this).until(u); } public NodeIterable until(final Class clazz) { - until = until.or(new TypePredicate(clazz)); - return this; + return new FilteredNodeIterable<>(this).until(clazz); } + @SuppressWarnings("unchecked") public FilteredNodeIterable filter(Class clazz) { - return new FilteredNodeIterable<>(this).and(clazz); + return (FilteredNodeIterable) new FilteredNodeIterable<>(this).and(NodePredicates.isA(clazz)); + } + public FilteredNodeIterable filterInterface(Class iface) { + return new FilteredNodeIterable<>(this).and(NodePredicates.isAInterface(iface)); } public FilteredNodeIterable filter(NodePredicate predicate) { return new FilteredNodeIterable<>(this).and(predicate); @@ -71,4 +72,7 @@ public boolean isNotEmpty() { return iterator().hasNext(); } + public boolean contains(T node) { + return this.filter(NodePredicates.equals(node)).isNotEmpty(); + } } diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodeIterator.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodeIterator.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodeIterator.java Mon Jan 30 15:16:33 2012 +0100 @@ -28,21 +28,17 @@ public abstract class NodeIterator implements Iterator{ protected T current; - protected final NodePredicate until; - public NodeIterator(NodePredicate until) { - this.until = until; - } protected abstract void forward(); @Override public boolean hasNext() { forward(); - return current != null && !until.apply(current); + return current != null; } @Override public T next() { forward(); T ret = current; - if (current == null || until.apply(current)) { + if (current == null) { throw new NoSuchElementException(); } current = null; diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodePredicate.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodePredicate.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodePredicate.java Mon Jan 30 15:16:33 2012 +0100 @@ -25,78 +25,18 @@ import com.oracle.max.graal.graph.*; public abstract class NodePredicate { - public static final TautologyPredicate TAUTOLOGY = new TautologyPredicate(); - - public static final IsNullPredicate IS_NULL = new IsNullPredicate(); - - public static final class TautologyPredicate extends NodePredicate { - @Override - public boolean apply(Node n) { - return true; - } - } - - public static final class AndPredicate extends NodePredicate { - private final NodePredicate a; - private final NodePredicate b; - private AndPredicate(NodePredicate np, NodePredicate thiz) { - this.a = np; - this.b = thiz; - } - @Override - public boolean apply(Node n) { - return b.apply(n) && a.apply(n); - } - } - - public static final class OrPredicate extends NodePredicate { - private final NodePredicate a; - private final NodePredicate b; - private OrPredicate(NodePredicate np, NodePredicate thiz) { - this.a = np; - this.b = thiz; - } - @Override - public boolean apply(Node n) { - return b.apply(n) || a.apply(n); - } - } - - public static final class IsNullPredicate extends NodePredicate { - @Override - public boolean apply(Node n) { - return n == null; - } - } - - public static final class EqualsPredicate extends NodePredicate { - private final T u; - public EqualsPredicate(T u) { - this.u = u; - } - @Override - public boolean apply(Node n) { - return u == n; - } - } public abstract boolean apply(Node n); - public NodePredicate and(final NodePredicate np) { - if (this instanceof TautologyPredicate) { - return np; - } - return new AndPredicate(this, np); + public NodePredicate and(NodePredicate np) { + return NodePredicates.and(this, np); } - public NodePredicate or(final NodePredicate np) { - if (this instanceof TautologyPredicate) { - return this; - } - return new OrPredicate(this, np); + public NodePredicate or(NodePredicate np) { + return NodePredicates.or(this, np); } - public static EqualsPredicate equals(T u) { - return new EqualsPredicate<>(u); + public NodePredicate negate() { + return NodePredicates.not(this); } } diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodePredicates.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodePredicates.java Mon Jan 30 15:16:33 2012 +0100 @@ -0,0 +1,266 @@ +/* + * Copyright (c) 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.max.graal.graph.iterators; + +import com.oracle.max.graal.graph.*; + +public abstract class NodePredicates { + private static final TautologyPredicate TAUTOLOGY = new TautologyPredicate(); + private static final FalsePredicate FALSE = new FalsePredicate(); + private static final IsNullPredicate IS_NULL = new IsNullPredicate(); + private static final IsNotNullPredicate IS_NOT_NULL = new IsNotNullPredicate(); + + public static NodePredicate alwaysTrue() { + return TAUTOLOGY; + } + + public static NodePredicate alwaysFalse() { + return FALSE; + } + + public static NodePredicate isNull() { + return IS_NULL; + } + + public static NodePredicate isNotNull() { + return IS_NOT_NULL; + } + + public static NodePredicate equals(Node n) { + return new EqualsPredicate(n); + } + + public static NodePredicate not(NodePredicate a) { + if (a == TAUTOLOGY) { + return FALSE; + } + if (a == FALSE) { + return TAUTOLOGY; + } + if (a == IS_NULL) { + return IS_NOT_NULL; + } + if (a == IS_NOT_NULL) { + return IS_NULL; + } + if (a instanceof NotPredicate) { + return ((NotPredicate) a).a; + } + if (a instanceof PositiveTypePredicate) { + return new NegativeTypePredicate((PositiveTypePredicate) a); + } + if (a instanceof NegativeTypePredicate) { + return new PositiveTypePredicate((NegativeTypePredicate) a); + } + if (a instanceof EqualsPredicate) { + return new NotEqualsPredicate(((EqualsPredicate) a).u); + } + if (a instanceof NotEqualsPredicate) { + return new EqualsPredicate(((NotEqualsPredicate) a).u); + } + return new NotPredicate(a); + } + + public static NodePredicate and(NodePredicate a, NodePredicate b) { + if (a == TAUTOLOGY) { + return b; + } + if (b == TAUTOLOGY) { + return a; + } + if (a == FALSE || b == FALSE) { + return FALSE; + } + return new AndPredicate(a, b); + } + + public static NodePredicate or(NodePredicate a, NodePredicate b) { + if (a == FALSE) { + return b; + } + if (b == FALSE) { + return a; + } + if (a == TAUTOLOGY || b == TAUTOLOGY) { + return TAUTOLOGY; + } + return new OrPredicate(a, b); + } + + public static NegativeTypePredicate isNotA(Class clazz) { + return new NegativeTypePredicate(clazz); + } + + public static PositiveTypePredicate isA(Class clazz) { + return new PositiveTypePredicate(clazz); + } + + public static NodePredicate isAInterface(Class iface) { + assert iface.isInterface(); + return new PositiveTypePredicate(iface); + } + + public static NodePredicate isNotAInterface(Class iface) { + assert iface.isInterface(); + return new NegativeTypePredicate(iface); + } + + private static final class TautologyPredicate extends NodePredicate { + @Override + public boolean apply(Node n) { + return true; + } + } + + private static final class FalsePredicate extends NodePredicate { + @Override + public boolean apply(Node n) { + return false; + } + } + + private static final class AndPredicate extends NodePredicate { + private final NodePredicate a; + private final NodePredicate b; + private AndPredicate(NodePredicate pa, NodePredicate pb) { + this.a = pa; + this.b = pb; + } + @Override + public boolean apply(Node n) { + return b.apply(n) && a.apply(n); + } + } + + private static final class NotPredicate extends NodePredicate { + private final NodePredicate a; + private NotPredicate(NodePredicate n) { + this.a = n; + } + @Override + public boolean apply(Node n) { + return !a.apply(n); + } + } + + private static final class OrPredicate extends NodePredicate { + private final NodePredicate a; + private final NodePredicate b; + private OrPredicate(NodePredicate np, NodePredicate thiz) { + this.a = np; + this.b = thiz; + } + @Override + public boolean apply(Node n) { + return b.apply(n) || a.apply(n); + } + } + + private static final class IsNullPredicate extends NodePredicate { + @Override + public boolean apply(Node n) { + return n == null; + } + } + + private static final class IsNotNullPredicate extends NodePredicate { + @Override + public boolean apply(Node n) { + return n != null; + } + } + + private static final class EqualsPredicate extends NodePredicate { + private final Node u; + public EqualsPredicate(Node u) { + this.u = u; + } + @Override + public boolean apply(Node n) { + return u == n; + } + } + + private static final class NotEqualsPredicate extends NodePredicate { + private final Node u; + public NotEqualsPredicate(Node u) { + this.u = u; + } + @Override + public boolean apply(Node n) { + return u != n; + } + } + + public static final class PositiveTypePredicate extends NodePredicate { + private final Class type; + private PositiveTypePredicate or; + public PositiveTypePredicate(Class type) { + this.type = type; + } + public PositiveTypePredicate(NegativeTypePredicate a) { + type = a.type; + if (a.nor != null) { + or = new PositiveTypePredicate(a.nor); + } + } + @Override + public boolean apply(Node n) { + return type.isInstance(n) || (or != null && or.apply(n)); + } + public PositiveTypePredicate or(Class clazz) { + if (or == null) { + or = new PositiveTypePredicate(clazz); + } else { + or.or(clazz); + } + return this; + } + } + + public static final class NegativeTypePredicate extends NodePredicate { + private final Class type; + private NegativeTypePredicate nor; + public NegativeTypePredicate(Class type) { + this.type = type; + } + public NegativeTypePredicate(PositiveTypePredicate a) { + type = a.type; + if (a.or != null) { + nor = new NegativeTypePredicate(a.or); + } + } + @Override + public boolean apply(Node n) { + return !type.isInstance(n) && (nor == null || nor.apply(n)); + } + public NegativeTypePredicate nor(Class clazz) { + if (nor == null) { + nor = new NegativeTypePredicate(clazz); + } else { + nor.nor(clazz); + } + return this; + } + } +} diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/PredicatedProxyNodeIterator.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/PredicatedProxyNodeIterator.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/PredicatedProxyNodeIterator.java Mon Jan 30 15:16:33 2012 +0100 @@ -29,8 +29,9 @@ public final class PredicatedProxyNodeIterator extends NodeIterator { private final Iterator iterator; private final NodePredicate predicate; + private final NodePredicate until; public PredicatedProxyNodeIterator(NodePredicate until, Iterator iterator, NodePredicate predicate) { - super(until); + this.until = until; this.iterator = iterator; this.predicate = predicate; } @@ -39,7 +40,7 @@ while ((current == null || !current.isAlive() || !predicate.apply(current)) && iterator.hasNext()) { current = iterator.next(); } - if (current != null && (!current.isAlive() || !predicate.apply(current))) { + if (current != null && (!current.isAlive() || !predicate.apply(current) || until.apply(current))) { current = null; } } diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/TypePredicate.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/TypePredicate.java Sun Jan 29 11:40:04 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2011, 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.max.graal.graph.iterators; - -import com.oracle.max.graal.graph.*; - -public final class TypePredicate extends NodePredicate { - private final Class type; - public TypePredicate(Class< ? extends Node> type) { - this.type = type; - } - @Override - public boolean apply(Node n) { - return type.isInstance(n); - } -} diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/EndNode.java --- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/EndNode.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/EndNode.java Mon Jan 30 15:16:33 2012 +0100 @@ -40,12 +40,7 @@ } public MergeNode merge() { - if (usages().size() == 0) { - return null; - } else { - assert usages().size() == 1; - return (MergeNode) usages().iterator().next(); - } + return (MergeNode) usages().first(); } @Override diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/FrameState.java --- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/FrameState.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/FrameState.java Mon Jan 30 15:16:33 2012 +0100 @@ -27,6 +27,7 @@ import com.oracle.max.cri.ci.*; import com.oracle.max.cri.ri.*; import com.oracle.max.graal.graph.*; +import com.oracle.max.graal.graph.iterators.*; import com.oracle.max.graal.nodes.PhiNode.PhiType; import com.oracle.max.graal.nodes.spi.*; import com.oracle.max.graal.nodes.virtual.*; @@ -455,9 +456,8 @@ public void deleteRedundantPhi(PhiNode redundantPhi, ValueNode phiValue) { Collection phiUsages = redundantPhi.usages().filter(PhiNode.class).snapshot(); ((StructuredGraph) graph()).replaceFloating(redundantPhi, phiValue); - for (Node n : phiUsages) { - PhiNode phiNode = (PhiNode) n; - checkRedundantPhi(phiNode); + for (PhiNode phi : phiUsages) { + checkRedundantPhi(phi); } } @@ -488,48 +488,11 @@ } public StateSplit stateSplit() { - for (Node n : usages()) { - if (n instanceof StateSplit) { - return (StateSplit) n; - } - } - return null; + return (StateSplit) usages().filterInterface(StateSplit.class).first(); } - public Iterable innerFrameStates() { - final Iterator iterator = usages().iterator(); - return new Iterable() { - @Override - public Iterator iterator() { - return new Iterator() { - private Node next; - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - @Override - public FrameState next() { - forward(); - if (!hasNext()) { - throw new NoSuchElementException(); - } - FrameState res = (FrameState) next; - next = null; - return res; - } - @Override - public boolean hasNext() { - forward(); - return next != null; - } - private void forward() { - while (!(next instanceof FrameState) && iterator.hasNext()) { - next = iterator.next(); - } - } - }; - } - }; + public NodeIterable innerFrameStates() { + return usages().filter(FrameState.class); } /** diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/LoopBeginNode.java --- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/LoopBeginNode.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/LoopBeginNode.java Mon Jan 30 15:16:33 2012 +0100 @@ -45,12 +45,7 @@ } public LoopEndNode loopEnd() { - for (LoopEndNode end : usages().filter(LoopEndNode.class)) { - if (end.loopBegin() == this) { - return end; - } - } - return null; + return usages().filter(LoopEndNode.class).first(); } @Override @@ -83,11 +78,6 @@ throw ValueUtil.shouldNotReachHere(); } - @Override - public Iterable phiPredecessors() { - return Arrays.asList(new Node[]{this.forwardEdge(), this.loopEnd()}); - } - public EndNode forwardEdge() { return this.endAt(0); } @@ -96,7 +86,7 @@ public boolean verify() { assertTrue(loopEnd() != null, "missing loopEnd"); assertTrue(forwardEdge() != null, "missing forwardEdge"); - assertTrue(usages().filter(LoopEndNode.class).snapshot().size() == 1, "multiple loop ends"); + assertTrue(usages().filter(LoopEndNode.class).count() == 1, "multiple loop ends"); return super.verify(); } diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/MergeNode.java --- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/MergeNode.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/MergeNode.java Mon Jan 30 15:16:33 2012 +0100 @@ -59,12 +59,8 @@ return ends.get(index); } - public Iterable phiPredecessors() { - return ends; - } - @Override - public Iterable cfgPredecessors() { + public NodeIterable cfgPredecessors() { return ends; } diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/java/MethodCallTargetNode.java --- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/java/MethodCallTargetNode.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/java/MethodCallTargetNode.java Mon Jan 30 15:16:33 2012 +0100 @@ -106,10 +106,7 @@ } public Invoke invoke() { - if (this.usages().size() == 0) { - return null; - } - return (Invoke) this.usages().iterator().next(); + return (Invoke) this.usages().first(); } diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/spi/EscapeOp.java --- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/spi/EscapeOp.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/spi/EscapeOp.java Mon Jan 30 15:16:33 2012 +0100 @@ -44,7 +44,7 @@ assert ((IsTypeNode) usage).object() == node; return false; } else if (usage instanceof FrameState) { - assert ((FrameState) usage).inputs().contains(node); + assert usage.inputs().contains(node); return true; } else if (usage instanceof AccessMonitorNode) { assert ((AccessMonitorNode) usage).object() == node; diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/util/NodeIterators.java --- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/util/NodeIterators.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/util/NodeIterators.java Mon Jan 30 15:16:33 2012 +0100 @@ -33,7 +33,7 @@ return new NodeIterable() { @Override public Iterator iterator() { - return new NodeIterator(until){ + return new NodeIterator(){ FixedNode p = n; @Override protected void forward() { diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java --- a/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java Mon Jan 30 15:16:33 2012 +0100 @@ -27,6 +27,7 @@ import java.util.Map.Entry; import com.oracle.max.cri.ri.*; +import com.oracle.max.graal.compiler.*; import com.oracle.max.graal.compiler.schedule.*; import com.oracle.max.graal.graph.*; import com.oracle.max.graal.graph.Node.Verbosity; @@ -34,30 +35,58 @@ import com.oracle.max.graal.graph.NodeClass.Position; import com.oracle.max.graal.java.*; import com.oracle.max.graal.nodes.*; +import com.oracle.max.graal.printer.BasicIdealGraphPrinter.Edge; /** * Generates a representation of {@link Graph Graphs} that can be visualized and inspected with the Ideal Graph Visualizer. */ -class IdealGraphPrinter extends BasicIdealGraphPrinter { +class IdealGraphPrinter { + + private final BasicIdealGraphPrinter printer; + private final HashSet> omittedClasses = new HashSet<>(); + private final Set noBlockNodes = new HashSet<>(); + /** * Creates a new {@link IdealGraphPrinter} that writes to the specified output stream. */ public IdealGraphPrinter(OutputStream stream) { - super(stream); + this.printer = new BasicIdealGraphPrinter(stream); + } + + /** + * Adds a node class that is omitted in the output. + */ + public void addOmittedClass(Class clazz) { + omittedClasses.add(clazz); + } + + /** + * Flushes any buffered output. + */ + public void flush() { + printer.flush(); + } + + /** + * Starts a new graph document. + */ + public void begin() { + printer.begin(); } /** * Starts a new group of graphs with the given name, short name and method byte code index (BCI) as properties. */ - public void beginGroup(String name, String shortName, RiResolvedMethod method, int bci) { - beginGroup(); - beginProperties(); - printProperty("name", name); - endProperties(); - beginMethod(name, shortName, bci); - if (method != null) { - beginBytecodes(); + public void beginGroup(String name, String shortName, RiResolvedMethod method, int bci, String origin) { + printer.beginGroup(); + printer.beginProperties(); + printer.printProperty("name", name); + printer.printProperty("origin", origin); + printer.endProperties(); + printer.beginMethod(name, shortName, bci); + if (GraalOptions.PrintIdealGraphBytecodes && method != null) { + printer.beginBytecodes(); BytecodeStream bytecodes = new BytecodeStream(method.code()); while (bytecodes.currentBC() != Bytecodes.END) { int startBCI = bytecodes.currentBCI(); @@ -69,84 +98,151 @@ extra[i] = bytecodes.readUByte(startBCI + 1 + i); } } - printBytecode(startBCI, mnemonic, extra); + printer.printBytecode(startBCI, mnemonic, extra); bytecodes.next(); } - endBytecodes(); + printer.endBytecodes(); } - endMethod(); + printer.endMethod(); } - public void print(Graph graph, String title) { - print(graph, title, null); + /** + * Ends the current group. + */ + public void endGroup() { + printer.endGroup(); + } + + /** + * Finishes the graph document and flushes the output stream. + */ + public void end() { + printer.end(); + } + + public void print(Graph graph, String title, boolean shortNames) { + print(graph, title, shortNames, null); } /** * Prints an entire {@link Graph} with the specified title, optionally using short names for nodes. */ - public void print(Graph graph, String title, IdentifyBlocksPhase predefinedSchedule) { - beginGraph(title); - Set noBlockNodes = new HashSet<>(); + public void print(Graph graph, String title, boolean shortNames, IdentifyBlocksPhase predefinedSchedule) { + printer.beginGraph(title); + noBlockNodes.clear(); IdentifyBlocksPhase schedule = predefinedSchedule; if (schedule == null) { try { schedule = new IdentifyBlocksPhase(true); - schedule.apply((StructuredGraph) graph); + schedule.apply((StructuredGraph) graph, false); } catch (Throwable t) { // nothing to do here... } } - beginNodes(); - List edges = printNodes(graph, schedule == null ? null : schedule.getNodeToBlock(), noBlockNodes); - endNodes(); + printer.beginNodes(); + List edges = printNodes(graph, shortNames, schedule == null ? null : schedule.getNodeToBlock()); + printer.endNodes(); - beginEdges(); + printer.beginEdges(); for (Edge edge : edges) { - printEdge(edge); + printer.printEdge(edge); } - endEdges(); + printer.endEdges(); if (schedule != null) { - beginControlFlow(); + printer.beginControlFlow(); for (Block block : schedule.getBlocks()) { printBlock(graph, block, schedule.getNodeToBlock()); } - printNoBlock(noBlockNodes); - endControlFlow(); + printNoBlock(); + printer.endControlFlow(); } - endGraph(); + printer.endGraph(); flush(); } - private List printNodes(Graph graph, NodeMap nodeToBlock, Set noBlockNodes) { + private List printNodes(Graph graph, boolean shortNames, NodeMap nodeToBlock) { ArrayList edges = new ArrayList<>(); NodeMap>> colors = graph.createNodeMap(); NodeMap>> colorsToString = graph.createNodeMap(); NodeMap> bits = graph.createNodeMap(); +// TODO This code was never reachable, since there was no code putting a NodeMap or NodeBitMap into the debugObjects. +// If you need to reactivate this code, put the mapping from names to values into a helper object and register it in the new debugObjects array. +// +// if (debugObjects != null) { +// for (Entry entry : debugObjects.entrySet()) { +// String name = entry.getKey(); +// Object obj = entry.getValue(); +// if (obj instanceof NodeMap) { +// Map colorNumbers = new HashMap(); +// int nextColor = 0; +// NodeMap map = (NodeMap) obj; +// for (Entry mapEntry : map.entries()) { +// Node node = mapEntry.getKey(); +// Object color = mapEntry.getValue(); +// Integer colorNumber = colorNumbers.get(color); +// if (colorNumber == null) { +// colorNumber = nextColor++; +// colorNumbers.put(color, colorNumber); +// } +// Set> nodeColors = colors.get(node); +// if (nodeColors == null) { +// nodeColors = new HashSet>(); +// colors.put(node, nodeColors); +// } +// nodeColors.add(new SimpleImmutableEntry(name + "Color", colorNumber)); +// Set> nodeColorStrings = colorsToString.get(node); +// if (nodeColorStrings == null) { +// nodeColorStrings = new HashSet>(); +// colorsToString.put(node, nodeColorStrings); +// } +// nodeColorStrings.add(new SimpleImmutableEntry(name, color.toString())); +// } +// } else if (obj instanceof NodeBitMap) { +// NodeBitMap bitmap = (NodeBitMap) obj; +// for (Node node : bitmap) { +// Set nodeBits = bits.get(node); +// if (nodeBits == null) { +// nodeBits = new HashSet(); +// bits.put(node, nodeBits); +// } +// nodeBits.add(name); +// } +// } +// } +// } for (Node node : graph.getNodes()) { + if (omittedClasses.contains(node.getClass())) { + continue; + } - beginNode(node.toString(Verbosity.Id)); - beginProperties(); - printProperty("idx", node.toString(Verbosity.Id)); + printer.beginNode(node.toString(Verbosity.Id)); + printer.beginProperties(); + printer.printProperty("idx", node.toString(Verbosity.Id)); Map props = node.getDebugProperties(); if (!props.containsKey("name") || props.get("name").toString().trim().length() == 0) { - String name = node.toString(Verbosity.Name); - printProperty("name", name); + String name; + if (shortNames) { + name = node.toString(Verbosity.Name); + } else { + name = node.toString(); + } + printer.printProperty("name", name); } - printProperty("class", node.getClass().getSimpleName()); + printer.printProperty("class", node.getClass().getSimpleName()); Block block = nodeToBlock == null ? null : nodeToBlock.get(node); if (block != null) { - printProperty("block", Integer.toString(block.blockID())); + printer.printProperty("block", Integer.toString(block.blockID())); if (!(node instanceof PhiNode || node instanceof FrameState || node instanceof LocalNode) && !block.getInstructions().contains(node)) { - printProperty("notInOwnBlock", "true"); + printer.printProperty("notInOwnBlock", "true"); } } else { - printProperty("block", "noBlock"); + printer.printProperty("block", "noBlock"); noBlockNodes.add(node); } @@ -155,7 +251,7 @@ for (Entry color : nodeColors) { String name = color.getKey(); Integer value = color.getValue(); - printProperty(name, Integer.toString(value)); + printer.printProperty(name, Integer.toString(value)); } } Set> nodeColorStrings = colorsToString.get(node); @@ -163,24 +259,24 @@ for (Entry color : nodeColorStrings) { String name = color.getKey(); String value = color.getValue(); - printProperty(name, value); + printer.printProperty(name, value); } } Set nodeBits = bits.get(node); if (nodeBits != null) { for (String bit : nodeBits) { - printProperty(bit, "true"); + printer.printProperty(bit, "true"); } } for (Entry entry : props.entrySet()) { String key = entry.getKey().toString(); String value = entry.getValue() == null ? "null" : entry.getValue().toString(); - printProperty(key, value); + printer.printProperty(key, value); } - endProperties(); - endNode(); + printer.endProperties(); + printer.endNode(); // successors int fromIndex = 0; @@ -188,7 +284,7 @@ while (succIter.hasNext()) { Position position = succIter.nextPosition(); Node successor = node.getNodeClass().get(node, position); - if (successor != null) { + if (successor != null && !omittedClasses.contains(successor.getClass())) { edges.add(new Edge(node.toString(Verbosity.Id), fromIndex, successor.toString(Verbosity.Id), 0, node.getNodeClass().getName(position))); } fromIndex++; @@ -200,8 +296,8 @@ while (inputIter.hasNext()) { Position position = inputIter.nextPosition(); Node input = node.getNodeClass().get(node, position); - if (input != null) { - edges.add(new Edge(input.toString(Verbosity.Id), input.successors().explicitCount(), node.toString(Verbosity.Id), toIndex, node.getNodeClass().getName(position))); + if (input != null && !omittedClasses.contains(input.getClass())) { + edges.add(new Edge(input.toString(Verbosity.Id), input.successors().count(), node.toString(Verbosity.Id), toIndex, node.getNodeClass().getName(position))); } toIndex++; } @@ -211,15 +307,15 @@ } private void printBlock(Graph graph, Block block, NodeMap nodeToBlock) { - beginBlock(Integer.toString(block.blockID())); - beginSuccessors(); + printer.beginBlock(Integer.toString(block.blockID())); + printer.beginSuccessors(); for (Block sux : block.getSuccessors()) { if (sux != null) { - printSuccessor(Integer.toString(sux.blockID())); + printer.printSuccessor(Integer.toString(sux.blockID())); } } - endSuccessors(); - beginBlockNodes(); + printer.endSuccessors(); + printer.beginBlockNodes(); Set nodes = new HashSet<>(block.getInstructions()); @@ -255,22 +351,25 @@ } for (Node node : nodes) { - printBlockNode(node.toString(Verbosity.Id)); + if (!omittedClasses.contains(node.getClass())) { + printer.printBlockNode(node.toString(Verbosity.Id)); + } } } - endBlockNodes(); - endBlock(); + printer.endBlockNodes(); + printer.endBlock(); } - private void printNoBlock(Set noBlockNodes) { + private void printNoBlock() { if (!noBlockNodes.isEmpty()) { - beginBlock("noBlock"); - beginBlockNodes(); + printer.beginBlock("noBlock"); + printer.beginBlockNodes(); for (Node node : noBlockNodes) { - printBlockNode(node.toString(Verbosity.Id)); + printer.printBlockNode(node.toString(Verbosity.Id)); } - endBlockNodes(); - endBlock(); + printer.endBlockNodes(); + printer.endBlock(); } } + } diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/ArrayCopySnippets.java --- a/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/ArrayCopySnippets.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/ArrayCopySnippets.java Mon Jan 30 15:16:33 2012 +0100 @@ -154,6 +154,29 @@ } @Snippet + public static void arraycopy(float[] src, int srcPos, float[] dest, int destPos, int length) { + if (src == null || dest == null) { + throw new NullPointerException(); + } + if (srcPos < 0 || destPos < 0 || length < 0 || srcPos + length > src.length || destPos + length > dest.length) { + throw new IndexOutOfBoundsException(); + } + if (src == dest && srcPos < destPos) { // bad aliased case + if ((length & 0x01) == 0) { + copyLongsDown(src, srcPos * 4L, dest, destPos * 4L, length >> 1); + } else { + copyIntsDown(src, srcPos * 4L, dest, destPos * 4L, length); + } + } else { + if ((length & 0x01) == 0) { + copyLongsUp(src, srcPos * 4L, dest, destPos * 4L, length >> 1); + } else { + copyIntsUp(src, srcPos * 4L, dest, destPos * 4L, length); + } + } + } + + @Snippet public static void arraycopy(long[] src, int srcPos, long[] dest, int destPos, int length) { if (src == null || dest == null) { throw new NullPointerException(); @@ -169,6 +192,37 @@ } @Snippet + public static void arraycopy(double[] src, int srcPos, double[] dest, int destPos, int length) { + if (src == null || dest == null) { + throw new NullPointerException(); + } + if (srcPos < 0 || destPos < 0 || length < 0 || srcPos + length > src.length || destPos + length > dest.length) { + throw new IndexOutOfBoundsException(); + } + if (src == dest && srcPos < destPos) { // bad aliased case + copyLongsDown(src, srcPos * 8L, dest, destPos * 8L, length); + } else { + copyLongsUp(src, srcPos * 8L, dest, destPos * 8L, length); + } + } + + // Does NOT perform store checks + @Snippet + public static void arraycopy(Object[] src, int srcPos, Object[] dest, int destPos, int length) { + if (src == null || dest == null) { + throw new NullPointerException(); + } + if (srcPos < 0 || destPos < 0 || length < 0 || srcPos + length > src.length || destPos + length > dest.length) { + throw new IndexOutOfBoundsException(); + } + if (src == dest && srcPos < destPos) { // bad aliased case + copyObjectsDown(src, srcPos * 8L, dest, destPos * 8L, length); + } else { + copyObjectsUp(src, srcPos * 8L, dest, destPos * 8L, length); + } + } + + @Snippet public static void copyBytesDown(Object src, int srcPos, Object dest, int destPos, int length) { long header = ArrayHeaderSizeNode.sizeFor(CiKind.Byte); for (long i = length - 1; i >= 0; i--) { @@ -204,6 +258,16 @@ } } + // Does NOT perform store checks + @Snippet + public static void copyObjectsDown(Object src, long srcOffset, Object dest, long destOffset, int length) { + long header = ArrayHeaderSizeNode.sizeFor(CiKind.Object); + for (long i = (length - 1) * 8; i >= 0; i -= 8) { + Object a = UnsafeLoadNode.load(src, i + (srcOffset + header), CiKind.Object); + UnsafeStoreNode.store(dest, i + (destOffset + header), a, CiKind.Object); + } + } + /** * Copies {@code length} bytes from {@code src} starting at {@code srcPos} to {@code dest} starting at {@code destPos}. * @param src source object @@ -255,4 +319,14 @@ UnsafeStoreNode.store(dest, i + (destOffset + header), a.longValue(), CiKind.Long); } } + + // Does NOT perform store checks + @Snippet + public static void copyObjectsUp(Object src, long srcOffset, Object dest, long destOffset, int length) { + long header = ArrayHeaderSizeNode.sizeFor(CiKind.Object); + for (long i = 0; i < length * 8L; i += 8) { + Object a = UnsafeLoadNode.load(src, i + (srcOffset + header), CiKind.Object); + UnsafeStoreNode.store(dest, i + (destOffset + header), a, CiKind.Object); + } + } } diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/IntrinsifyArrayCopyPhase.java --- a/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/IntrinsifyArrayCopyPhase.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/IntrinsifyArrayCopyPhase.java Mon Jan 30 15:16:33 2012 +0100 @@ -24,6 +24,7 @@ import java.lang.reflect.*; +import com.oracle.max.cri.ci.*; import com.oracle.max.cri.ri.*; import com.oracle.max.graal.compiler.phases.*; import com.oracle.max.graal.compiler.util.*; @@ -40,6 +41,9 @@ private RiResolvedMethod charArrayCopy; private RiResolvedMethod intArrayCopy; private RiResolvedMethod longArrayCopy; + private RiResolvedMethod floatArrayCopy; + private RiResolvedMethod doubleArrayCopy; + private RiResolvedMethod objectArrayCopy; public IntrinsifyArrayCopyPhase(GraalRuntime runtime) { this.runtime = runtime; @@ -49,6 +53,9 @@ shortArrayCopy = getArrayCopySnippet(runtime, short.class); intArrayCopy = getArrayCopySnippet(runtime, int.class); longArrayCopy = getArrayCopySnippet(runtime, long.class); + floatArrayCopy = getArrayCopySnippet(runtime, float.class); + doubleArrayCopy = getArrayCopySnippet(runtime, double.class); + objectArrayCopy = getArrayCopySnippet(runtime, Object.class); arrayCopy = runtime.getRiMethod(System.class.getDeclaredMethod("arraycopy", Object.class, int.class, Object.class, int.class, int.class)); } catch (SecurityException e) { e.printStackTrace(); @@ -78,19 +85,29 @@ if (srcDeclaredType != null && srcDeclaredType.isArrayClass() && destDeclaredType != null - && destDeclaredType.isArrayClass() - && srcDeclaredType.componentType() == destDeclaredType.componentType()) { - Class componentType = srcDeclaredType.componentType().toJava(); - if (componentType.equals(int.class)) { - snippetMethod = intArrayCopy; - } else if (componentType.equals(char.class)) { - snippetMethod = charArrayCopy; - } else if (componentType.equals(long.class)) { - snippetMethod = longArrayCopy; - } else if (componentType.equals(byte.class)) { - snippetMethod = byteArrayCopy; - } else if (componentType.equals(short.class)) { - snippetMethod = shortArrayCopy; + && destDeclaredType.isArrayClass()) { + CiKind componentKind = srcDeclaredType.componentType().kind(false); + if (srcDeclaredType.componentType() == destDeclaredType.componentType()) { + if (componentKind == CiKind.Int) { + snippetMethod = intArrayCopy; + } else if (componentKind == CiKind.Char) { + snippetMethod = charArrayCopy; + } else if (componentKind == CiKind.Long) { + snippetMethod = longArrayCopy; + } else if (componentKind == CiKind.Byte) { + snippetMethod = byteArrayCopy; + } else if (componentKind == CiKind.Short) { + snippetMethod = shortArrayCopy; + } else if (componentKind == CiKind.Float) { + snippetMethod = floatArrayCopy; + } else if (componentKind == CiKind.Double) { + snippetMethod = doubleArrayCopy; + } else if (componentKind == CiKind.Object) { + snippetMethod = objectArrayCopy; + } + } else if (componentKind == CiKind.Object + && srcDeclaredType.componentType().isSubtypeOf(destDeclaredType.componentType())) { + snippetMethod = objectArrayCopy; } } } diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/BoxingEliminationTest.java --- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/BoxingEliminationTest.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/BoxingEliminationTest.java Mon Jan 30 15:16:33 2012 +0100 @@ -22,6 +22,8 @@ */ package com.oracle.max.graal.compiler.tests; +import static com.oracle.max.graal.graph.iterators.NodePredicates.*; + import java.util.*; import org.junit.*; @@ -97,12 +99,8 @@ identifyBoxingPhase.apply(graph); LocalNode local = graph.getNodes(LocalNode.class).iterator().next(); ConstantNode constant = ConstantNode.forInt(0, graph); - for (Node n : local.usages().snapshot()) { - if (n instanceof FrameState) { - // Do not replace. - } else { - n.replaceFirstInput(local, constant); - } + for (Node n : local.usages().filter(isNotA(FrameState.class)).snapshot()) { + n.replaceFirstInput(local, constant); } Collection hints = new ArrayList<>(); for (Invoke invoke : graph.getInvokes()) { diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/DegeneratedLoopsTest.java --- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/DegeneratedLoopsTest.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/DegeneratedLoopsTest.java Mon Jan 30 15:16:33 2012 +0100 @@ -22,9 +22,10 @@ */ package com.oracle.max.graal.compiler.tests; -import junit.framework.AssertionFailedError; +import static com.oracle.max.graal.graph.iterators.NodePredicates.*; +import junit.framework.*; -import org.junit.*; +import org.junit.Test; import com.oracle.max.graal.compiler.phases.*; import com.oracle.max.graal.debug.*; @@ -84,12 +85,8 @@ Debug.dump(graph, "Graph"); LocalNode local = graph.getNodes(LocalNode.class).iterator().next(); ConstantNode constant = ConstantNode.forInt(0, graph); - for (Node n : local.usages().snapshot()) { - if (n instanceof FrameState) { - // Do not replace. - } else { - n.replaceFirstInput(local, constant); - } + for (Node n : local.usages().filter(isNotA(FrameState.class)).snapshot()) { + n.replaceFirstInput(local, constant); } for (Invoke invoke : graph.getInvokes()) { invoke.intrinsify(null); diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/IfCanonicalizerTest.java --- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/IfCanonicalizerTest.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/IfCanonicalizerTest.java Mon Jan 30 15:16:33 2012 +0100 @@ -22,6 +22,8 @@ */ package com.oracle.max.graal.compiler.tests; +import static com.oracle.max.graal.graph.iterators.NodePredicates.*; + import org.junit.*; import com.oracle.max.graal.compiler.phases.*; @@ -137,12 +139,8 @@ StructuredGraph graph = parse(snippet); LocalNode local = graph.getNodes(LocalNode.class).iterator().next(); ConstantNode constant = ConstantNode.forInt(0, graph); - for (Node n : local.usages().snapshot()) { - if (n instanceof FrameState) { - // Do not replace. - } else { - n.replaceFirstInput(local, constant); - } + for (Node n : local.usages().filter(isNotA(FrameState.class)).snapshot()) { + n.replaceFirstInput(local, constant); } Debug.dump(graph, "Graph"); new CanonicalizerPhase(null, runtime(), null).apply(graph); diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/InvokeTest.java --- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/InvokeTest.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/InvokeTest.java Mon Jan 30 15:16:33 2012 +0100 @@ -22,6 +22,8 @@ */ package com.oracle.max.graal.compiler.tests; +import static com.oracle.max.graal.graph.iterators.NodePredicates.*; + import java.util.*; import org.junit.*; @@ -72,12 +74,8 @@ StructuredGraph graph = parse(snippet); LocalNode local = graph.getNodes(LocalNode.class).iterator().next(); ConstantNode constant = ConstantNode.forInt(0, graph); - for (Node n : local.usages().snapshot()) { - if (n instanceof FrameState) { - // Do not replace. - } else { - n.replaceFirstInput(local, constant); - } + for (Node n : local.usages().filter(isNotA(FrameState.class)).snapshot()) { + n.replaceFirstInput(local, constant); } Collection hints = new ArrayList<>(); for (Invoke invoke : graph.getInvokes()) { diff -r 9f8e4aeec1a9 -r c8de52cc672a graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/MonitorTest.java --- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/MonitorTest.java Sun Jan 29 11:40:04 2012 +0100 +++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/MonitorTest.java Mon Jan 30 15:16:33 2012 +0100 @@ -22,6 +22,8 @@ */ package com.oracle.max.graal.compiler.tests; +import static com.oracle.max.graal.graph.iterators.NodePredicates.*; + import java.util.*; import junit.framework.AssertionFailedError; @@ -30,6 +32,7 @@ import com.oracle.max.graal.compiler.phases.*; import com.oracle.max.graal.graph.*; +import com.oracle.max.graal.graph.iterators.*; import com.oracle.max.graal.nodes.*; import com.oracle.max.graal.nodes.java.*; @@ -64,10 +67,9 @@ @Test public void test2() { StructuredGraph graph = parseAndProcess("test2Snippet"); - Collection monitors = graph.getNodes(MonitorExitNode.class).snapshot(); - Assert.assertEquals(1, monitors.size()); - MonitorExitNode monitor = monitors.iterator().next(); - Assert.assertEquals(monitor.stateAfter().bci, 3); + NodeIterable monitors = graph.getNodes(MonitorExitNode.class); + Assert.assertEquals(1, monitors.count()); + Assert.assertEquals(monitors.first().stateAfter().bci, 3); } @SuppressWarnings("all") @@ -81,14 +83,10 @@ private StructuredGraph parseAndProcess(String snippet) { StructuredGraph graph = parse(snippet); - LocalNode local = graph.getNodes(LocalNode.class).iterator().next(); + LocalNode local = graph.getNodes(LocalNode.class).first(); ConstantNode constant = ConstantNode.forInt(0, graph); - for (Node n : local.usages().snapshot()) { - if (n instanceof FrameState) { - // Do not replace. - } else { - n.replaceFirstInput(local, constant); - } + for (Node n : local.usages().filter(isNotA(FrameState.class)).snapshot()) { + n.replaceFirstInput(local, constant); } Collection hints = new ArrayList<>(); for (Invoke invoke : graph.getInvokes()) {