43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
package org.graalvm.compiler.virtual.phases.ea;
|
|
24 |
|
|
25 |
import static org.graalvm.compiler.core.common.GraalOptions.TraceEscapeAnalysis;
|
|
26 |
|
|
27 |
import java.util.List;
|
|
28 |
|
48861
|
29 |
import org.graalvm.collections.EconomicMap;
|
|
30 |
import org.graalvm.collections.Equivalence;
|
46640
|
31 |
import org.graalvm.compiler.debug.DebugContext;
|
43972
|
32 |
import org.graalvm.compiler.debug.GraalError;
|
|
33 |
import org.graalvm.compiler.debug.TTY;
|
|
34 |
import org.graalvm.compiler.graph.Node;
|
|
35 |
import org.graalvm.compiler.graph.NodeFlood;
|
|
36 |
import org.graalvm.compiler.nodes.AbstractEndNode;
|
|
37 |
import org.graalvm.compiler.nodes.FixedNode;
|
|
38 |
import org.graalvm.compiler.nodes.StructuredGraph;
|
46344
|
39 |
import org.graalvm.compiler.options.OptionValues;
|
43972
|
40 |
|
|
41 |
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
42 |
|
|
43 |
public final class VirtualUtil {
|
|
44 |
|
|
45 |
private VirtualUtil() {
|
|
46 |
GraalError.shouldNotReachHere();
|
|
47 |
}
|
|
48 |
|
|
49 |
public static boolean assertNonReachable(StructuredGraph graph, List<Node> obsoleteNodes) {
|
46344
|
50 |
// Helper code that determines the paths that keep obsolete nodes alive.
|
|
51 |
// Nodes with support for GVN can be kept alive by GVN and are therefore not part of the
|
|
52 |
// assertion.
|
43972
|
53 |
|
46640
|
54 |
DebugContext debug = graph.getDebug();
|
43972
|
55 |
NodeFlood flood = graph.createNodeFlood();
|
46344
|
56 |
EconomicMap<Node, Node> path = EconomicMap.create(Equivalence.IDENTITY);
|
43972
|
57 |
flood.add(graph.start());
|
|
58 |
for (Node current : flood) {
|
|
59 |
if (current instanceof AbstractEndNode) {
|
|
60 |
AbstractEndNode end = (AbstractEndNode) current;
|
|
61 |
flood.add(end.merge());
|
|
62 |
if (!path.containsKey(end.merge())) {
|
|
63 |
path.put(end.merge(), end);
|
|
64 |
}
|
|
65 |
} else {
|
|
66 |
for (Node successor : current.successors()) {
|
|
67 |
flood.add(successor);
|
|
68 |
if (!path.containsKey(successor)) {
|
|
69 |
path.put(successor, current);
|
|
70 |
}
|
|
71 |
}
|
|
72 |
}
|
|
73 |
}
|
|
74 |
|
|
75 |
for (Node node : obsoleteNodes) {
|
|
76 |
if (node instanceof FixedNode && !node.isDeleted()) {
|
|
77 |
assert !flood.isMarked(node) : node;
|
|
78 |
}
|
|
79 |
}
|
|
80 |
|
|
81 |
for (Node node : graph.getNodes()) {
|
|
82 |
if (flood.isMarked(node)) {
|
|
83 |
for (Node input : node.inputs()) {
|
|
84 |
flood.add(input);
|
|
85 |
if (!path.containsKey(input)) {
|
|
86 |
path.put(input, node);
|
|
87 |
}
|
|
88 |
}
|
|
89 |
}
|
|
90 |
}
|
|
91 |
for (Node current : flood) {
|
|
92 |
for (Node input : current.inputs()) {
|
|
93 |
flood.add(input);
|
|
94 |
if (!path.containsKey(input)) {
|
|
95 |
path.put(input, current);
|
|
96 |
}
|
|
97 |
}
|
|
98 |
}
|
|
99 |
boolean success = true;
|
|
100 |
for (Node node : obsoleteNodes) {
|
46344
|
101 |
if (!node.isDeleted() && flood.isMarked(node) && !node.getNodeClass().valueNumberable()) {
|
43972
|
102 |
TTY.println("offending node path:");
|
|
103 |
Node current = node;
|
|
104 |
TTY.print(current.toString());
|
|
105 |
while (true) {
|
|
106 |
current = path.get(current);
|
|
107 |
if (current != null) {
|
|
108 |
TTY.print(" -> " + current.toString());
|
|
109 |
if (current instanceof FixedNode && !obsoleteNodes.contains(current)) {
|
|
110 |
break;
|
|
111 |
}
|
|
112 |
}
|
|
113 |
}
|
|
114 |
success = false;
|
|
115 |
}
|
|
116 |
}
|
|
117 |
if (!success) {
|
|
118 |
TTY.println();
|
46640
|
119 |
debug.forceDump(graph, "assertNonReachable");
|
43972
|
120 |
}
|
|
121 |
return success;
|
|
122 |
}
|
|
123 |
|
46640
|
124 |
public static void trace(OptionValues options, DebugContext debug, String msg) {
|
|
125 |
if (debug.areScopesEnabled() && TraceEscapeAnalysis.getValue(options) && debug.isLogEnabled()) {
|
|
126 |
debug.log(msg);
|
43972
|
127 |
}
|
|
128 |
}
|
|
129 |
|
46640
|
130 |
public static void trace(OptionValues options, DebugContext debug, String format, Object obj) {
|
|
131 |
if (debug.areScopesEnabled() && TraceEscapeAnalysis.getValue(options) && debug.isLogEnabled()) {
|
|
132 |
debug.logv(format, obj);
|
43972
|
133 |
}
|
|
134 |
}
|
|
135 |
|
46640
|
136 |
public static void trace(OptionValues options, DebugContext debug, String format, Object obj, Object obj2) {
|
|
137 |
if (debug.areScopesEnabled() && TraceEscapeAnalysis.getValue(options) && debug.isLogEnabled()) {
|
|
138 |
debug.logv(format, obj, obj2);
|
43972
|
139 |
}
|
|
140 |
}
|
|
141 |
|
46640
|
142 |
public static void trace(OptionValues options, DebugContext debug, String format, Object obj, Object obj2, Object obj3) {
|
|
143 |
if (debug.areScopesEnabled() && TraceEscapeAnalysis.getValue(options) && debug.isLogEnabled()) {
|
|
144 |
debug.logv(format, obj, obj2, obj3);
|
43972
|
145 |
}
|
|
146 |
}
|
|
147 |
|
46640
|
148 |
public static void trace(OptionValues options, DebugContext debug, String format, Object obj, Object obj2, Object obj3, Object obj4) {
|
|
149 |
if (debug.areScopesEnabled() && TraceEscapeAnalysis.getValue(options) && debug.isLogEnabled()) {
|
|
150 |
debug.logv(format, obj, obj2, obj3, obj4);
|
43972
|
151 |
}
|
|
152 |
}
|
|
153 |
|
|
154 |
public static boolean matches(StructuredGraph graph, String filter) {
|
|
155 |
if (filter != null) {
|
|
156 |
return matchesHelper(graph, filter);
|
|
157 |
}
|
|
158 |
return true;
|
|
159 |
}
|
|
160 |
|
|
161 |
private static boolean matchesHelper(StructuredGraph graph, String filter) {
|
|
162 |
if (filter.startsWith("~")) {
|
|
163 |
ResolvedJavaMethod method = graph.method();
|
|
164 |
return method == null || !method.format("%H.%n").contains(filter.substring(1));
|
|
165 |
} else {
|
|
166 |
ResolvedJavaMethod method = graph.method();
|
|
167 |
return method != null && method.format("%H.%n").contains(filter);
|
|
168 |
}
|
|
169 |
}
|
|
170 |
}
|