annotate graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java @ 9331:199c77760850

Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Fri, 26 Apr 2013 18:40:17 +0200
parents e24fb475bdec
children 18906f4dfe77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2011, 2011, Oracle and/or its affiliates. All rights reserved.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
23 package com.oracle.graal.graph;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import java.util.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
27 import com.oracle.graal.graph.GraphEvent.NodeEvent;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
28 import com.oracle.graal.graph.Node.IterableNodeType;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
29 import com.oracle.graal.graph.Node.ValueNumberable;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
30 import com.oracle.graal.graph.iterators.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33 * This class is a graph container, it contains the set of nodes that belong to this graph.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 public class Graph {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
37 public final String name;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 private static final boolean TIME_TRAVEL = false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41 private final ArrayList<Node> nodes;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 // these two arrays contain one entry for each NodeClass, indexed by NodeClass.iterableId.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 // they contain the first and last pointer to a linked list of all nodes with this type.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 private final ArrayList<Node> nodeCacheFirst;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 private final ArrayList<Node> nodeCacheLast;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 private int deletedNodeCount;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 private GraphEventLog eventLog;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49
9331
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8327
diff changeset
50 NodeChangedListener inputChanged;
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8327
diff changeset
51 NodeChangedListener usagesDroppedZero;
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
52 private final HashMap<CacheEntry, Node> cachedNodes = new HashMap<>();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 private static final class CacheEntry {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 private final Node node;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 public CacheEntry(Node node) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 this.node = node;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 public int hashCode() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
64 return node.getNodeClass().valueNumber(node);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 public boolean equals(Object obj) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69 if (obj == this) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
72 if (obj instanceof CacheEntry) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
73 CacheEntry other = (CacheEntry) obj;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
74 NodeClass nodeClass = node.getNodeClass();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75 if (other.node.getNodeClass() == nodeClass) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
76 return nodeClass.valueNumberable() && nodeClass.valueEqual(node, other.node) && nodeClass.edgesEqual(node, other.node);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
77 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
78 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
79 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
80 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
81 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
82
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
83 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
84 * Creates an empty Graph with no name.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
85 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
86 public Graph() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
87 this(null);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
88 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
90 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
91 * Creates an empty Graph with a given name.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
92 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
93 * @param name the name of the graph, used for debugging purposes
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
94 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
95 public Graph(String name) {
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
96 nodes = new ArrayList<>(32);
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
97 nodeCacheFirst = new ArrayList<>(NodeClass.cacheSize());
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
98 nodeCacheLast = new ArrayList<>(NodeClass.cacheSize());
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
99 this.name = name;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
100 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
101
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
102 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
103 * Creates a copy of this graph.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
104 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
105 public Graph copy() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
106 return copy(name);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
107 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
108
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
109 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
110 * Creates a copy of this graph.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
111 *
5711
4d7175cf3526 enabled Eclipse/JDT javadoc checking and fixed resulting warnings
Doug Simon <doug.simon@oracle.com>
parents: 5608
diff changeset
112 * @param newName the name of the copy, used for debugging purposes (can be null)
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
113 */
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
114 public Graph copy(String newName) {
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
115 Graph copy = new Graph(newName);
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
116 Map<Node, Node> emptyMap = Collections.emptyMap();
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
117 copy.addDuplicates(getNodes(), emptyMap);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
118 return copy;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
119 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
120
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
121 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
122 public String toString() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
123 return name == null ? super.toString() : "Graph " + name;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
124 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
125
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
126 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
127 * Gets the number of live nodes in this graph. That is the number of nodes which have been
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
128 * added to the graph minus the number of deleted nodes.
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
129 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
130 * @return the number of live nodes in this graph
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
131 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
132 public int getNodeCount() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
133 return nodes.size() - getDeletedNodeCount();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
134 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
135
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
136 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
137 * Gets the number of node which have been deleted from this graph.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
138 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
139 * @return the number of node which have been deleted from this graph
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
140 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
141 public int getDeletedNodeCount() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
142 return deletedNodeCount;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
143 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
144
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
145 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
146 * Adds a new node to the graph.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
147 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
148 * @param node the node to be added
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
149 * @return the node which was added to the graph
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
150 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
151 public <T extends Node> T add(T node) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
152 node.initialize(this);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
153 return node;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
154 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
155
9331
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8327
diff changeset
156 public interface NodeChangedListener {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
157
9331
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8327
diff changeset
158 void nodeChanged(Node node);
5419
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
159 }
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
160
9331
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8327
diff changeset
161 public void trackInputChange(NodeChangedListener inputChangedListener) {
5419
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
162 this.inputChanged = inputChangedListener;
4614
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4411
diff changeset
163 }
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4411
diff changeset
164
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4411
diff changeset
165 public void stopTrackingInputChange() {
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4411
diff changeset
166 inputChanged = null;
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4411
diff changeset
167 }
a3882fd1ae61 Make it possible to have multiple LoopEnds per LoopBegin
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4411
diff changeset
168
9331
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8327
diff changeset
169 public void trackUsagesDroppedZero(NodeChangedListener usagesDroppedZeroListener) {
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8327
diff changeset
170 this.usagesDroppedZero = usagesDroppedZeroListener;
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8327
diff changeset
171 }
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8327
diff changeset
172
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8327
diff changeset
173 public void stopTrackingUsagesDroppedZero() {
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8327
diff changeset
174 usagesDroppedZero = null;
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8327
diff changeset
175 }
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8327
diff changeset
176
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
177 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
178 * Adds a new node to the graph, if a <i>similar</i> node already exists in the graph, the
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
179 * provided node will not be added to the graph but the <i>similar</i> node will be returned
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
180 * instead.
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
181 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
182 * @param node
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
183 * @return the node which was added to the graph or a <i>similar</i> which was already in the
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
184 * graph.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
185 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
186 @SuppressWarnings("unchecked")
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
187 public <T extends Node & ValueNumberable> T unique(T node) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
188 assert checkValueNumberable(node);
4646
75dcf829cfdc experimental: "next" successor on all nodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 4614
diff changeset
189
75dcf829cfdc experimental: "next" successor on all nodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 4614
diff changeset
190 for (Node input : node.inputs()) {
75dcf829cfdc experimental: "next" successor on all nodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 4614
diff changeset
191 if (input != null) {
75dcf829cfdc experimental: "next" successor on all nodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 4614
diff changeset
192 for (Node usage : input.usages()) {
75dcf829cfdc experimental: "next" successor on all nodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 4614
diff changeset
193 if (usage != node && node.getNodeClass().valueEqual(node, usage) && node.getNodeClass().edgesEqual(node, usage)) {
75dcf829cfdc experimental: "next" successor on all nodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 4614
diff changeset
194 return (T) usage;
75dcf829cfdc experimental: "next" successor on all nodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 4614
diff changeset
195 }
75dcf829cfdc experimental: "next" successor on all nodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 4614
diff changeset
196 }
75dcf829cfdc experimental: "next" successor on all nodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 4614
diff changeset
197 return add(node);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
198 }
4646
75dcf829cfdc experimental: "next" successor on all nodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 4614
diff changeset
199 }
75dcf829cfdc experimental: "next" successor on all nodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 4614
diff changeset
200 Node cachedNode = cachedNodes.get(new CacheEntry(node));
75dcf829cfdc experimental: "next" successor on all nodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 4614
diff changeset
201 if (cachedNode != null && cachedNode.isAlive()) {
75dcf829cfdc experimental: "next" successor on all nodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 4614
diff changeset
202 return (T) cachedNode;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
203 } else {
4646
75dcf829cfdc experimental: "next" successor on all nodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 4614
diff changeset
204 Node result = add(node);
75dcf829cfdc experimental: "next" successor on all nodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 4614
diff changeset
205 cachedNodes.put(new CacheEntry(node), result);
75dcf829cfdc experimental: "next" successor on all nodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 4614
diff changeset
206 return (T) result;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
207 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
208 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
209
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
210 public Node findDuplicate(Node node) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
211 if (node.getNodeClass().valueNumberable()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
212 for (Node input : node.inputs()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
213 if (input != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
214 for (Node usage : input.usages()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
215 if (usage != node && node.getNodeClass().valueEqual(node, usage) && node.getNodeClass().edgesEqual(node, usage)) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
216 return usage;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
217 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
218 }
5446
fafab5f0507d Fix findDuplicate for nodes with no inputs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5427
diff changeset
219 return null;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
220 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
221 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
222 }
5446
fafab5f0507d Fix findDuplicate for nodes with no inputs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5427
diff changeset
223 CacheEntry key = new CacheEntry(node);
fafab5f0507d Fix findDuplicate for nodes with no inputs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5427
diff changeset
224 Node cachedNode = cachedNodes.get(key);
fafab5f0507d Fix findDuplicate for nodes with no inputs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5427
diff changeset
225 if (cachedNode != null) {
fafab5f0507d Fix findDuplicate for nodes with no inputs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5427
diff changeset
226 if (!cachedNode.isAlive()) {
fafab5f0507d Fix findDuplicate for nodes with no inputs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5427
diff changeset
227 cachedNodes.remove(key);
fafab5f0507d Fix findDuplicate for nodes with no inputs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5427
diff changeset
228 return null;
fafab5f0507d Fix findDuplicate for nodes with no inputs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5427
diff changeset
229 }
fafab5f0507d Fix findDuplicate for nodes with no inputs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5427
diff changeset
230 return cachedNode != node ? cachedNode : null;
fafab5f0507d Fix findDuplicate for nodes with no inputs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5427
diff changeset
231 } else {
fafab5f0507d Fix findDuplicate for nodes with no inputs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5427
diff changeset
232 cachedNodes.put(key, node);
fafab5f0507d Fix findDuplicate for nodes with no inputs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5427
diff changeset
233 return null;
fafab5f0507d Fix findDuplicate for nodes with no inputs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5427
diff changeset
234 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
235 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
236
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
237 private static boolean checkValueNumberable(Node node) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
238 if (!node.getNodeClass().valueNumberable()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
239 throw new VerificationError("node is not valueNumberable").addContext(node);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
240 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
241 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
242 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
243
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
244 /**
5711
4d7175cf3526 enabled Eclipse/JDT javadoc checking and fixed resulting warnings
Doug Simon <doug.simon@oracle.com>
parents: 5608
diff changeset
245 * Gets a mark that can be used with {@link #getNewNodes(int)}.
5361
dec5a35ddbe2 lowering checkcasts with Java snippets (incomplete)
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
246 */
5380
8be0c73cf118 made graph marking stateless (in the graph) to ensure recursive marking is safe
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
247 public int getMark() {
8be0c73cf118 made graph marking stateless (in the graph) to ensure recursive marking is safe
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
248 return nodeIdCount();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
249 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
250
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
251 private class NodeIterator implements Iterator<Node> {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
252
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
253 private int index;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
254
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
255 public NodeIterator() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
256 this(0);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
257 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
258
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
259 public NodeIterator(int index) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
260 this.index = index - 1;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
261 forward();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
262 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
263
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
264 private void forward() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
265 if (index < nodes.size()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
266 do {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
267 index++;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
268 } while (index < nodes.size() && nodes.get(index) == null);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
269 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
270 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
271
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
272 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
273 public boolean hasNext() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
274 checkForDeletedNode();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
275 return index < nodes.size();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
276 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
277
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
278 private void checkForDeletedNode() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
279 if (index < nodes.size()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
280 while (index < nodes.size() && nodes.get(index) == null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
281 index++;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
282 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
283 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
284 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
285
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
286 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
287 public Node next() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
288 try {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
289 return nodes.get(index);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
290 } finally {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
291 forward();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
292 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
293 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
294
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
295 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
296 public void remove() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
297 throw new UnsupportedOperationException();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
298 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
299 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
300
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
301 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
302 * Returns an {@link Iterable} providing all nodes added since the last {@link Graph#getMark()
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
303 * mark}.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
304 */
5380
8be0c73cf118 made graph marking stateless (in the graph) to ensure recursive marking is safe
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
305 public NodeIterable<Node> getNewNodes(int mark) {
8be0c73cf118 made graph marking stateless (in the graph) to ensure recursive marking is safe
Doug Simon <doug.simon@oracle.com>
parents: 5361
diff changeset
306 final int index = mark;
5608
3bc48971a1bf Make NodeIterable an interface and create AbstractNodeIterable,
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5488
diff changeset
307 return new AbstractNodeIterable<Node>() {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
308
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
309 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
310 public Iterator<Node> iterator() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
311 return new NodeIterator(index);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
312 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
313 };
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
314 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
315
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
316 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
317 * Returns an {@link Iterable} providing all the live nodes.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
318 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
319 * @return an {@link Iterable} providing all the live nodes.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
320 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
321 public NodeIterable<Node> getNodes() {
5608
3bc48971a1bf Make NodeIterable an interface and create AbstractNodeIterable,
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5488
diff changeset
322 return new AbstractNodeIterable<Node>() {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
323
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
324 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
325 public Iterator<Node> iterator() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
326 return new NodeIterator();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
327 }
5488
21cab9000931 .filter() on Graph.getNode now tries to use the fast node iterator if possible
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5478
diff changeset
328
5810
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5806
diff changeset
329 @Override
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5806
diff changeset
330 public int count() {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5806
diff changeset
331 return getNodeCount();
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5806
diff changeset
332 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
333 };
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
334 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
335
8327
e24fb475bdec Remove PlaceHolderNode class definition.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
336 private static final Node PLACE_HOLDER = new Node() {
e24fb475bdec Remove PlaceHolderNode class definition.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
337 };
7332
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
338
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
339 private class TypedNodeIterator<T extends IterableNodeType> implements Iterator<T> {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
340
7332
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
341 private final int[] ids;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
342 private final Node[] current;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
343
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
344 private int currentIdIndex;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
345 private boolean needsForward;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
346
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
347 public TypedNodeIterator(NodeClass clazz) {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
348 ids = clazz.iterableIds();
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
349 currentIdIndex = 0;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
350 current = new Node[ids.length];
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
351 Arrays.fill(current, PLACE_HOLDER);
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
352 needsForward = true;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
353 }
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
354
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
355 private Node findNext() {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
356 if (needsForward) {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
357 forward();
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
358 } else {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
359 Node c = current();
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
360 Node afterDeleted = skipDeleted(c);
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
361 if (afterDeleted == null) {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
362 needsForward = true;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
363 } else if (c != afterDeleted) {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
364 setCurrent(afterDeleted);
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
365 }
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
366 }
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
367 if (needsForward) {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
368 return null;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
369 }
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
370 return current();
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
371 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
372
7332
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
373 private Node skipDeleted(Node node) {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
374 Node n = node;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
375 while (n != null && n.isDeleted()) {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
376 n = n.typeCacheNext;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
377 }
7332
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
378 return n;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
379 }
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
380
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
381 private void forward() {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
382 needsForward = false;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
383 int startIdx = currentIdIndex;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
384 while (true) {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
385 Node next;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
386 if (current() == PLACE_HOLDER) {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
387 next = getStartNode(ids[currentIdIndex]);
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
388 } else {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
389 next = current().typeCacheNext;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
390 }
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
391 next = skipDeleted(next);
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
392 if (next == null) {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
393 currentIdIndex++;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
394 if (currentIdIndex >= ids.length) {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
395 currentIdIndex = 0;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
396 }
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
397 if (currentIdIndex == startIdx) {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
398 needsForward = true;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
399 return;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
400 }
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
401 } else {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
402 setCurrent(next);
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
403 break;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
404 }
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
405 }
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
406 }
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
407
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
408 private Node current() {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
409 return current[currentIdIndex];
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
410 }
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
411
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
412 private void setCurrent(Node n) {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
413 current[currentIdIndex] = n;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
414 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
415
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
416 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
417 public boolean hasNext() {
7332
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
418 return findNext() != null;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
419 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
420
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
421 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
422 @SuppressWarnings("unchecked")
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
423 public T next() {
7332
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
424 Node result = findNext();
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
425 if (result == null) {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
426 throw new NoSuchElementException();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
427 }
7332
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
428 needsForward = true;
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
429 return (T) result;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
430 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
431
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
432 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
433 public void remove() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
434 throw new UnsupportedOperationException();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
435 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
436 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
437
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
438 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
439 * Returns an {@link Iterable} providing all the live nodes whose type is compatible with
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
440 * {@code type}.
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
441 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
442 * @param type the type of node to return
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
443 * @return an {@link Iterable} providing all the matching nodes.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
444 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
445 public <T extends Node & IterableNodeType> NodeIterable<T> getNodes(final Class<T> type) {
7332
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
446 final NodeClass nodeClass = NodeClass.get(type);
5608
3bc48971a1bf Make NodeIterable an interface and create AbstractNodeIterable,
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5488
diff changeset
447 return new AbstractNodeIterable<T>() {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
448
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
449 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
450 public Iterator<T> iterator() {
7332
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
451 return new TypedNodeIterator<>(nodeClass);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
452 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
453 };
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
454 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
455
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
456 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
457 * Returns whether the graph contains at least one node of the given type.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
458 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
459 * @param type the type of node that is checked for occurrence
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
460 * @return whether there is at least one such node
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
461 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
462 public <T extends Node & IterableNodeType> boolean hasNode(final Class<T> type) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
463 return getNodes(type).iterator().hasNext();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
464 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
465
7332
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
466 private Node getStartNode(int iterableId) {
c5a9bcd9493d Support sub-types for typed node iterators
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7124
diff changeset
467 Node start = nodeCacheFirst.size() <= iterableId ? null : nodeCacheFirst.get(iterableId);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
468 return start;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
469 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
470
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
471 public NodeBitMap createNodeBitMap() {
5419
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
472 return createNodeBitMap(false);
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
473 }
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
474
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
475 public NodeBitMap createNodeBitMap(boolean autoGrow) {
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
476 return new NodeBitMap(this, autoGrow);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
477 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
478
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
479 public <T> NodeMap<T> createNodeMap() {
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
480 return new NodeMap<>(this);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
481 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
482
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
483 public NodeFlood createNodeFlood() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
484 return new NodeFlood(this);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
485 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
486
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
487 public NodeWorkList createNodeWorkList() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
488 return new NodeWorkList(this);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
489 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
490
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
491 public NodeWorkList createNodeWorkList(boolean fill, int iterationLimitPerNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
492 return new NodeWorkList(this, fill, iterationLimitPerNode);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
493 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
494
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
495 void register(Node node) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
496 assert node.id() == Node.INITIAL_ID;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
497 int id = nodes.size();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
498 nodes.add(id, node);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
499
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
500 int nodeClassId = node.getNodeClass().iterableId();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
501 if (nodeClassId != NodeClass.NOT_ITERABLE) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
502 while (nodeCacheFirst.size() <= nodeClassId) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
503 nodeCacheFirst.add(null);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
504 nodeCacheLast.add(null);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
505 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
506 Node prev = nodeCacheLast.get(nodeClassId);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
507 if (prev != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
508 prev.typeCacheNext = node;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
509 } else {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
510 nodeCacheFirst.set(nodeClassId, node);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
511 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
512 nodeCacheLast.set(nodeClassId, node);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
513 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
514
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
515 node.id = id;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
516 logNodeAdded(node);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
517 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
518
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
519 void logNodeAdded(Node node) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
520 if (TIME_TRAVEL) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
521 log(new GraphEvent.NodeEvent(node, GraphEvent.NodeEvent.Type.ADDED));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
522 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
523 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
524
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
525 void logNodeDeleted(Node node) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
526 if (TIME_TRAVEL) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
527 log(new GraphEvent.NodeEvent(node, GraphEvent.NodeEvent.Type.DELETED));
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
528 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
529 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
530
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
531 private void log(NodeEvent nodeEvent) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
532 if (eventLog == null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
533 eventLog = new GraphEventLog();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
534 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
535 eventLog.add(nodeEvent);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
536 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
537
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
538 public GraphEventLog getEventLog() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
539 return eventLog;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
540 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
541
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
542 void unregister(Node node) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
543 assert !node.isDeleted() : "cannot delete a node twice! node=" + node;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
544 logNodeDeleted(node);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
545 nodes.set(node.id(), null);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
546 deletedNodeCount++;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
547
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
548 // nodes aren't removed from the type cache here - they will be removed during iteration
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
549 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
550
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
551 public boolean verify() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
552 for (Node node : getNodes()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
553 try {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
554 try {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
555 assert node.verify();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
556 } catch (AssertionError t) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
557 throw new GraalInternalError(t);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
558 } catch (RuntimeException t) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
559 throw new GraalInternalError(t);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
560 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
561 } catch (GraalInternalError e) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
562 throw e.addContext(node).addContext(this);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
563 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
564 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
565 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
566 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
567
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
568 Node getNode(int i) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
569 return nodes.get(i);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
570 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
571
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
572 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
573 * Returns the number of node ids generated so far.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
574 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
575 * @return the number of node ids generated so far
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
576 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
577 int nodeIdCount() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
578 return nodes.size();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
579 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
580
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
581 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
582 * Adds duplicates of the nodes in {@code nodes} to this graph. This will recreate any edges
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
583 * between the duplicate nodes. The {@code replacement} map can be used to replace a node from
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
584 * the source graph by a given node (which must already be in this graph). Edges between
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
585 * duplicate and replacement nodes will also be recreated so care should be taken regarding the
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
586 * matching of node types in the replacement map.
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
587 *
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
588 * @param newNodes the nodes to be duplicated
5711
4d7175cf3526 enabled Eclipse/JDT javadoc checking and fixed resulting warnings
Doug Simon <doug.simon@oracle.com>
parents: 5608
diff changeset
589 * @param replacementsMap the replacement map (can be null if no replacement is to be performed)
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
590 * @return a map which associates the original nodes from {@code nodes} to their duplicates
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
591 */
5478
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
592 public Map<Node, Node> addDuplicates(Iterable<Node> newNodes, Map<Node, Node> replacementsMap) {
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
593 DuplicationReplacement replacements;
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
594 if (replacementsMap == null) {
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
595 replacements = null;
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
596 } else {
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
597 replacements = new MapReplacement(replacementsMap);
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
598 }
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
599 return addDuplicates(newNodes, replacements);
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
600 }
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
601
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
602 public interface DuplicationReplacement {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
603
5478
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
604 Node replacement(Node original);
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
605 }
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
606
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
607 private static final class MapReplacement implements DuplicationReplacement {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
608
5478
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
609 private final Map<Node, Node> map;
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
610
5478
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
611 public MapReplacement(Map<Node, Node> map) {
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
612 this.map = map;
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
613 }
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
614
5478
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
615 @Override
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
616 public Node replacement(Node original) {
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
617 Node replacement = map.get(original);
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
618 return replacement != null ? replacement : original;
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
619 }
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
620
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
621 }
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
622
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
623 private static final DuplicationReplacement NO_REPLACEMENT = new DuplicationReplacement() {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7332
diff changeset
624
5478
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
625 @Override
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
626 public Node replacement(Node original) {
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
627 return original;
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
628 }
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
629 };
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
630
5427
441cf24df453 correctly handle null for replacements parameter in Graph.addDuplicates()
Doug Simon <doug.simon@oracle.com>
parents: 5419
diff changeset
631 @SuppressWarnings("all")
5478
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
632 public Map<Node, Node> addDuplicates(Iterable<Node> newNodes, DuplicationReplacement replacements) {
5427
441cf24df453 correctly handle null for replacements parameter in Graph.addDuplicates()
Doug Simon <doug.simon@oracle.com>
parents: 5419
diff changeset
633 if (replacements == null) {
5478
4a99bfc329f0 Add posibility to provide a replacement function instead of map for duplication.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5446
diff changeset
634 replacements = NO_REPLACEMENT;
5427
441cf24df453 correctly handle null for replacements parameter in Graph.addDuplicates()
Doug Simon <doug.simon@oracle.com>
parents: 5419
diff changeset
635 }
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
636 return NodeClass.addGraphDuplicate(this, newNodes, replacements);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
637 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
638 }