Mercurial > hg > graal-compiler
diff graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java @ 12686:ca8ab182026f
abstracted a graph mark as a Mark object (hiding the node index)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 05 Nov 2013 19:54:32 +0100 |
parents | 2c4aa758ee18 |
children | 43301f080126 |
line wrap: on
line diff
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java Tue Nov 05 19:44:09 2013 +0100 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java Tue Nov 05 19:54:32 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2013, 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 @@ -394,15 +394,55 @@ } } - public boolean isNew(int mark, Node node) { - return node.id >= mark; + public boolean isNew(Mark mark, Node node) { + return node.id >= mark.getValue(); } /** - * Gets a mark that can be used with {@link #getNewNodes(int)}. + * A snapshot of the {@linkplain Graph#getNodeCount() live node count} in a graph. */ - public int getMark() { - return nodeIdCount(); + public static class Mark { + private final int value; + + Mark(Graph graph) { + this.value = graph.nodeIdCount(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof Mark) { + Mark other = (Mark) obj; + return other.getValue() == getValue(); + } + return false; + } + + @Override + public int hashCode() { + return value; + } + + /** + * Determines if this mark is positioned at the first live node in the graph. + */ + public boolean isStart() { + return value == 0; + } + + /** + * Gets the {@linkplain Graph#getNodeCount() live node count} of the associated graph when + * this object was created. + */ + int getValue() { + return value; + } + } + + /** + * Gets a mark that can be used with {@link #getNewNodes}. + */ + public Mark getMark() { + return new Mark(this); } private class NodeIterator implements Iterator<Node> { @@ -459,8 +499,8 @@ * Returns an {@link Iterable} providing all nodes added since the last {@link Graph#getMark() * mark}. */ - public NodeIterable<Node> getNewNodes(int mark) { - final int index = mark; + public NodeIterable<Node> getNewNodes(Mark mark) { + final int index = mark.getValue(); return new AbstractNodeIterable<Node>() { @Override