annotate graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/GraphChangeMonitoringPhase.java @ 19060:7d805868d01d

Fix criteria in GraphChangeMonitoringPhase
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Fri, 30 Jan 2015 11:33:32 -0800
parents 7e08e0de79a9
children 4eb793cfec27
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18945
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
1 /*
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
4 *
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
8 *
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
13 * accompanied this code).
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
14 *
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
18 *
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
21 * questions.
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
22 */
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.compiler.phases;
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
24
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
25 import java.util.stream.*;
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
26
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
27 import com.oracle.graal.debug.*;
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
28 import com.oracle.graal.debug.Debug.Scope;
19060
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
29 import com.oracle.graal.graph.Graph.NodeEvent;
18945
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.graph.Graph.NodeEventScope;
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.nodes.*;
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.phases.*;
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.phases.common.util.*;
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.phases.tiers.*;
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
35
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
36 /**
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
37 * A utility phase for detecting when a phase would change the graph and reporting extra information
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
38 * about the effects. The phase is first run on a copy of the graph and if a change in that graph is
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
39 * detected then it's rerun on the original graph inside a new debug scope under
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
40 * GraphChangeMonitoringPhase. The message argument can be used to distinguish between the same
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
41 * phase run at different points.
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
42 *
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
43 * @param <C>
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
44 */
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
45 public class GraphChangeMonitoringPhase<C extends PhaseContext> extends PhaseSuite<C> {
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
46
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
47 private final String message;
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
48
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
49 public GraphChangeMonitoringPhase(String message, BasePhase<C> phase) {
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
50 super();
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
51 this.message = message;
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
52 appendPhase(phase);
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
53 }
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
54
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
55 public GraphChangeMonitoringPhase(String message) {
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
56 super();
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
57 this.message = message;
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
58 }
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
59
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
60 @Override
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
61 protected void run(StructuredGraph graph, C context) {
19060
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
62 /*
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
63 * Phase may add nodes but not end up using them so ignore additions. Nodes going dead and
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
64 * having their inputs change are the main interesting differences.
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
65 */
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
66 HashSetNodeEventListener listener = new HashSetNodeEventListener().exclude(NodeEvent.NODE_ADDED);
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
67 StructuredGraph graphCopy = graph.copy();
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
68 try (NodeEventScope s = graphCopy.trackNodeEvents(listener)) {
18945
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
69 try (Scope s2 = Debug.sandbox("WithoutMonitoring", null)) {
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
70 super.run(graphCopy, context);
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
71 } catch (Throwable t) {
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
72 Debug.handle(t);
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
73 }
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
74 }
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
75 if (!listener.getNodes().isEmpty()) {
19060
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
76 /* rerun it on the real graph in a new Debug scope so Dump and Log can find it. */
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
77 listener = new HashSetNodeEventListener();
18945
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
78 try (NodeEventScope s = graph.trackNodeEvents(listener)) {
19060
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
79 try (Scope s2 = Debug.scope("WithGraphChangeMonitoring." + getName() + "-" + message)) {
18945
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
80 if (Debug.isDumpEnabled(BasePhase.PHASE_DUMP_LEVEL)) {
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
81 Debug.dump(BasePhase.PHASE_DUMP_LEVEL, graph, "*** Before phase %s", getName());
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
82 }
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
83 super.run(graph, context);
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
84 if (Debug.isDumpEnabled(BasePhase.PHASE_DUMP_LEVEL)) {
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
85 Debug.dump(BasePhase.PHASE_DUMP_LEVEL, graph, "*** After phase %s", getName());
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
86 }
19060
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
87 Debug.log("*** %s %s %s\n", message, graph, listener.getNodes().stream().filter(e -> !e.isAlive()).collect(Collectors.toSet()));
18945
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
88 }
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
89 }
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
90 } else {
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
91 // Go ahead and run it normally even though it should have no effect
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
92 super.run(graph, context);
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
93 }
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
94 }
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
95 }