annotate graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/GraphChangeMonitoringPhase.java @ 19583:4eb793cfec27

Filter LogicConstantNode when detecting changes in GraphChangeMonitoringPhase
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Wed, 18 Feb 2015 10:37:08 -0800
parents 7d805868d01d
children fe76bf3867f3
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
19583
4eb793cfec27 Filter LogicConstantNode when detecting changes in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 19060
diff changeset
25 import java.util.*;
18945
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
26 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
27
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.*;
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
29 import com.oracle.graal.debug.Debug.Scope;
19060
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
30 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
31 import com.oracle.graal.graph.Graph.NodeEventScope;
19583
4eb793cfec27 Filter LogicConstantNode when detecting changes in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 19060
diff changeset
32 import com.oracle.graal.graph.Node;
18945
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.nodes.*;
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.*;
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
35 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
36 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
37
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
38 /**
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
39 * 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
40 * 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
41 * 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
42 * 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
43 * 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
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 * @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
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 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
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 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
50
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
51 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
52 super();
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
53 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
54 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
55 }
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
56
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
57 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
58 super();
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
59 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
60 }
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
61
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
62 @Override
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
63 protected void run(StructuredGraph graph, C context) {
19060
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
64 /*
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
65 * 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
66 * having their inputs change are the main interesting differences.
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
67 */
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
68 HashSetNodeEventListener listener = new HashSetNodeEventListener().exclude(NodeEvent.NODE_ADDED);
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
69 StructuredGraph graphCopy = graph.copy();
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
70 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
71 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
72 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
73 } 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
74 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
75 }
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
76 }
19583
4eb793cfec27 Filter LogicConstantNode when detecting changes in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 19060
diff changeset
77 /*
4eb793cfec27 Filter LogicConstantNode when detecting changes in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 19060
diff changeset
78 * Ignore LogicConstantNode since those are sometimes created and deleted as part of running
4eb793cfec27 Filter LogicConstantNode when detecting changes in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 19060
diff changeset
79 * a phase.
4eb793cfec27 Filter LogicConstantNode when detecting changes in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 19060
diff changeset
80 */
4eb793cfec27 Filter LogicConstantNode when detecting changes in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 19060
diff changeset
81 if (listener.getNodes().stream().filter(e -> !(e instanceof LogicConstantNode)).findFirst().get() != null) {
19060
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
82 /* 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
83 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
84 try (NodeEventScope s = graph.trackNodeEvents(listener)) {
19060
7d805868d01d Fix criteria in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18945
diff changeset
85 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
86 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
87 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
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 super.run(graph, context);
19583
4eb793cfec27 Filter LogicConstantNode when detecting changes in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 19060
diff changeset
90 Set<Node> collect = listener.getNodes().stream().filter(e -> !e.isAlive()).filter(e -> !(e instanceof LogicConstantNode)).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
91 if (Debug.isDumpEnabled(BasePhase.PHASE_DUMP_LEVEL)) {
19583
4eb793cfec27 Filter LogicConstantNode when detecting changes in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 19060
diff changeset
92 Debug.dump(BasePhase.PHASE_DUMP_LEVEL, graph, "*** After phase %s %s", getName(), collect);
18945
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
93 }
19583
4eb793cfec27 Filter LogicConstantNode when detecting changes in GraphChangeMonitoringPhase
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 19060
diff changeset
94 Debug.log("*** %s %s %s\n", message, graph, collect);
18945
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
95 }
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
96 }
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
97 } else {
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
98 // 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
99 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
100 }
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
101 }
7e08e0de79a9 Add utility phase to dump more information when another phase changes the graph
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
102 }