annotate graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java @ 18665:96861e3f8cc5

made CFGPrinterObserver reset (upon close) properly
author Doug Simon <doug.simon@oracle.com>
date Thu, 11 Dec 2014 22:14:30 +0100
parents 133d5a98c547
children d80301977c5e
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 /*
5011
5d0af6520f26 Do not use SchedulePhase in CFG printer
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4612
diff changeset
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3733
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.printer;
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.io.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26 import java.util.*;
5763
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
27 import java.util.concurrent.atomic.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28
5510
426c605c9d3c Move cri.ci to api.code.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
29 import com.oracle.graal.api.code.*;
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5506
diff changeset
30 import com.oracle.graal.api.meta.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
31 import com.oracle.graal.compiler.alloc.*;
15193
96bb07a5d667 Spit up and move GraalInternalError.
Josef Eisl <josef.eisl@jku.at>
parents: 15025
diff changeset
32 import com.oracle.graal.compiler.common.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
33 import com.oracle.graal.compiler.gen.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
34 import com.oracle.graal.debug.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
35 import com.oracle.graal.graph.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
36 import com.oracle.graal.java.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
37 import com.oracle.graal.lir.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
38 import com.oracle.graal.nodes.*;
6529
2e96dc4eb8e2 renamed package: com.oracle.graal.lir.cfg -> com.oracle.graal.nodes.cfg
Doug Simon <doug.simon@oracle.com>
parents: 6526
diff changeset
39 import com.oracle.graal.nodes.cfg.*;
14594
3eda945af90a dump final HIR schedule to c1visualizer
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14145
diff changeset
40 import com.oracle.graal.phases.schedule.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7032
diff changeset
43 * Observes compilation events and uses {@link CFGPrinter} to produce a control flow graph for the
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7032
diff changeset
44 * <a href="http://java.net/projects/c1visualizer/">C1 Visualizer</a>.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 */
4522
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
46 public class CFGPrinterObserver implements DebugDumpHandler {
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
47
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
48 private CFGPrinter cfgPrinter;
5763
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
49 private File cfgFile;
9658
d64083db3c11 changed CFGPrinterObserver to use JavaMethod instead of ResolvedJavaMethod for method scope
Doug Simon <doug.simon@oracle.com>
parents: 9234
diff changeset
50 private JavaMethod curMethod;
5432
50598118cd0a added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method
Doug Simon <doug.simon@oracle.com>
parents: 5275
diff changeset
51 private List<String> curDecorators = Collections.emptyList();
11379
0942e34b6c7d added PrintBackendCFG option (default is true) for controlling if backend output is dumped to the C1Visualizer
Doug Simon <doug.simon@oracle.com>
parents: 9658
diff changeset
52 private final boolean dumpFrontend;
0942e34b6c7d added PrintBackendCFG option (default is true) for controlling if backend output is dumped to the C1Visualizer
Doug Simon <doug.simon@oracle.com>
parents: 9658
diff changeset
53
0942e34b6c7d added PrintBackendCFG option (default is true) for controlling if backend output is dumped to the C1Visualizer
Doug Simon <doug.simon@oracle.com>
parents: 9658
diff changeset
54 public CFGPrinterObserver(boolean dumpFrontend) {
0942e34b6c7d added PrintBackendCFG option (default is true) for controlling if backend output is dumped to the C1Visualizer
Doug Simon <doug.simon@oracle.com>
parents: 9658
diff changeset
55 this.dumpFrontend = dumpFrontend;
0942e34b6c7d added PrintBackendCFG option (default is true) for controlling if backend output is dumped to the C1Visualizer
Doug Simon <doug.simon@oracle.com>
parents: 9658
diff changeset
56 }
3733
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 @Override
5011
5d0af6520f26 Do not use SchedulePhase in CFG printer
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4612
diff changeset
59 public void dump(Object object, String message) {
5029
74f47ef37394 Fix and enable liveness analysis to prune unnecessary frame state entries
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5011
diff changeset
60 try {
74f47ef37394 Fix and enable liveness analysis to prune unnecessary frame state entries
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5011
diff changeset
61 dumpSandboxed(object, message);
74f47ef37394 Fix and enable liveness analysis to prune unnecessary frame state entries
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5011
diff changeset
62 } catch (Throwable ex) {
74f47ef37394 Fix and enable liveness analysis to prune unnecessary frame state entries
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5011
diff changeset
63 TTY.println("CFGPrinter: Exception during output of " + message + ": " + ex);
8150
b66f831ac5ab Fix CFG printer output. Clean up after making the compiler class all-static.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7835
diff changeset
64 ex.printStackTrace();
5029
74f47ef37394 Fix and enable liveness analysis to prune unnecessary frame state entries
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5011
diff changeset
65 }
74f47ef37394 Fix and enable liveness analysis to prune unnecessary frame state entries
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5011
diff changeset
66 }
74f47ef37394 Fix and enable liveness analysis to prune unnecessary frame state entries
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5011
diff changeset
67
5432
50598118cd0a added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method
Doug Simon <doug.simon@oracle.com>
parents: 5275
diff changeset
68 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7032
diff changeset
69 * Looks for the outer most method and its {@link DebugDumpScope#decorator}s in the current
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7032
diff changeset
70 * debug scope and opens a new compilation scope if this pair does not match the current method
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7032
diff changeset
71 * and decorator pair.
5432
50598118cd0a added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method
Doug Simon <doug.simon@oracle.com>
parents: 5275
diff changeset
72 */
5763
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
73 private boolean checkMethodScope() {
9658
d64083db3c11 changed CFGPrinterObserver to use JavaMethod instead of ResolvedJavaMethod for method scope
Doug Simon <doug.simon@oracle.com>
parents: 9234
diff changeset
74 JavaMethod method = null;
5432
50598118cd0a added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method
Doug Simon <doug.simon@oracle.com>
parents: 5275
diff changeset
75 ArrayList<String> decorators = new ArrayList<>();
50598118cd0a added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method
Doug Simon <doug.simon@oracle.com>
parents: 5275
diff changeset
76 for (Object o : Debug.context()) {
9658
d64083db3c11 changed CFGPrinterObserver to use JavaMethod instead of ResolvedJavaMethod for method scope
Doug Simon <doug.simon@oracle.com>
parents: 9234
diff changeset
77 if (o instanceof JavaMethod) {
d64083db3c11 changed CFGPrinterObserver to use JavaMethod instead of ResolvedJavaMethod for method scope
Doug Simon <doug.simon@oracle.com>
parents: 9234
diff changeset
78 method = (JavaMethod) o;
5432
50598118cd0a added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method
Doug Simon <doug.simon@oracle.com>
parents: 5275
diff changeset
79 decorators.clear();
50598118cd0a added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method
Doug Simon <doug.simon@oracle.com>
parents: 5275
diff changeset
80 } else if (o instanceof StructuredGraph) {
50598118cd0a added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method
Doug Simon <doug.simon@oracle.com>
parents: 5275
diff changeset
81 StructuredGraph graph = (StructuredGraph) o;
9658
d64083db3c11 changed CFGPrinterObserver to use JavaMethod instead of ResolvedJavaMethod for method scope
Doug Simon <doug.simon@oracle.com>
parents: 9234
diff changeset
82 if (graph.method() != null) {
d64083db3c11 changed CFGPrinterObserver to use JavaMethod instead of ResolvedJavaMethod for method scope
Doug Simon <doug.simon@oracle.com>
parents: 9234
diff changeset
83 method = graph.method();
d64083db3c11 changed CFGPrinterObserver to use JavaMethod instead of ResolvedJavaMethod for method scope
Doug Simon <doug.simon@oracle.com>
parents: 9234
diff changeset
84 decorators.clear();
d64083db3c11 changed CFGPrinterObserver to use JavaMethod instead of ResolvedJavaMethod for method scope
Doug Simon <doug.simon@oracle.com>
parents: 9234
diff changeset
85 }
5432
50598118cd0a added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method
Doug Simon <doug.simon@oracle.com>
parents: 5275
diff changeset
86 } else if (o instanceof DebugDumpScope) {
50598118cd0a added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method
Doug Simon <doug.simon@oracle.com>
parents: 5275
diff changeset
87 DebugDumpScope debugDumpScope = (DebugDumpScope) o;
50598118cd0a added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method
Doug Simon <doug.simon@oracle.com>
parents: 5275
diff changeset
88 if (debugDumpScope.decorator) {
50598118cd0a added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method
Doug Simon <doug.simon@oracle.com>
parents: 5275
diff changeset
89 decorators.add(debugDumpScope.name);
50598118cd0a added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method
Doug Simon <doug.simon@oracle.com>
parents: 5275
diff changeset
90 }
50598118cd0a added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method
Doug Simon <doug.simon@oracle.com>
parents: 5275
diff changeset
91 }
5275
290b3025b66f added support for disassembling code after installation (so that the result of patching and relocation can be seen)
Doug Simon <doug.simon@oracle.com>
parents: 5249
diff changeset
92 }
5432
50598118cd0a added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method
Doug Simon <doug.simon@oracle.com>
parents: 5275
diff changeset
93
5763
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
94 if (method == null) {
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
95 return false;
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
96 }
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
97
12570
af39ea2dc39d made ConstantNodes (optionally) not record their usages (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12045
diff changeset
98 if (!method.equals(curMethod) || !curDecorators.equals(decorators)) {
5432
50598118cd0a added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method
Doug Simon <doug.simon@oracle.com>
parents: 5275
diff changeset
99 cfgPrinter.printCompilation(method);
5763
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
100 TTY.println("CFGPrinter: Dumping method %s to %s", method, cfgFile);
5432
50598118cd0a added support for decorator dump scopes so that the visualizers can distinguish between multiple compilations of the same method
Doug Simon <doug.simon@oracle.com>
parents: 5275
diff changeset
101 }
18642
133d5a98c547 generalized semantics of DebugDumpHandler.close() to mean reset so that closing a handler flushes and releases all its resources but leaves it operational (i.e. subsequent uses will (re)create and (re)open the required resources)
Doug Simon <doug.simon@oracle.com>
parents: 16950
diff changeset
102 curMethod = method;
133d5a98c547 generalized semantics of DebugDumpHandler.close() to mean reset so that closing a handler flushes and releases all its resources but leaves it operational (i.e. subsequent uses will (re)create and (re)open the required resources)
Doug Simon <doug.simon@oracle.com>
parents: 16950
diff changeset
103 curDecorators = decorators;
5763
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
104 return true;
5275
290b3025b66f added support for disassembling code after installation (so that the result of patching and relocation can be seen)
Doug Simon <doug.simon@oracle.com>
parents: 5249
diff changeset
105 }
290b3025b66f added support for disassembling code after installation (so that the result of patching and relocation can be seen)
Doug Simon <doug.simon@oracle.com>
parents: 5249
diff changeset
106
5763
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
107 private static final long timestamp = System.currentTimeMillis();
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
108 private static final AtomicInteger uniqueId = new AtomicInteger();
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
109
11379
0942e34b6c7d added PrintBackendCFG option (default is true) for controlling if backend output is dumped to the C1Visualizer
Doug Simon <doug.simon@oracle.com>
parents: 9658
diff changeset
110 private static boolean isFrontendObject(Object object) {
0942e34b6c7d added PrintBackendCFG option (default is true) for controlling if backend output is dumped to the C1Visualizer
Doug Simon <doug.simon@oracle.com>
parents: 9658
diff changeset
111 return object instanceof Graph || object instanceof BciBlockMapping;
0942e34b6c7d added PrintBackendCFG option (default is true) for controlling if backend output is dumped to the C1Visualizer
Doug Simon <doug.simon@oracle.com>
parents: 9658
diff changeset
112 }
0942e34b6c7d added PrintBackendCFG option (default is true) for controlling if backend output is dumped to the C1Visualizer
Doug Simon <doug.simon@oracle.com>
parents: 9658
diff changeset
113
5029
74f47ef37394 Fix and enable liveness analysis to prune unnecessary frame state entries
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 5011
diff changeset
114 public void dumpSandboxed(Object object, String message) {
4535
10f300ba182f Make CFGObserver handle the case without GraalCompiler silently without NPE.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4525
diff changeset
115
11379
0942e34b6c7d added PrintBackendCFG option (default is true) for controlling if backend output is dumped to the C1Visualizer
Doug Simon <doug.simon@oracle.com>
parents: 9658
diff changeset
116 if (!dumpFrontend && isFrontendObject(object)) {
0942e34b6c7d added PrintBackendCFG option (default is true) for controlling if backend output is dumped to the C1Visualizer
Doug Simon <doug.simon@oracle.com>
parents: 9658
diff changeset
117 return;
0942e34b6c7d added PrintBackendCFG option (default is true) for controlling if backend output is dumped to the C1Visualizer
Doug Simon <doug.simon@oracle.com>
parents: 9658
diff changeset
118 }
0942e34b6c7d added PrintBackendCFG option (default is true) for controlling if backend output is dumped to the C1Visualizer
Doug Simon <doug.simon@oracle.com>
parents: 9658
diff changeset
119
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
120 if (cfgPrinter == null) {
5763
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
121 cfgFile = new File("compilations-" + timestamp + "_" + uniqueId.incrementAndGet() + ".cfg");
4522
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
122 try {
5763
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
123 OutputStream out = new BufferedOutputStream(new FileOutputStream(cfgFile));
5011
5d0af6520f26 Do not use SchedulePhase in CFG printer
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4612
diff changeset
124 cfgPrinter = new CFGPrinter(out);
4522
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
125 } catch (FileNotFoundException e) {
5763
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
126 throw new GraalInternalError("Could not open " + cfgFile.getAbsolutePath());
4522
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
127 }
5763
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
128 TTY.println("CFGPrinter: Output to file %s", cfgFile);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
129 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
130
5763
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
131 if (!checkMethodScope()) {
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
132 return;
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
133 }
15025
292353f2645c CFGPrinter: workaround for bytecode dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 14888
diff changeset
134 if (curMethod instanceof ResolvedJavaMethod) {
292353f2645c CFGPrinter: workaround for bytecode dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 14888
diff changeset
135 cfgPrinter.method = (ResolvedJavaMethod) curMethod;
292353f2645c CFGPrinter: workaround for bytecode dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 14888
diff changeset
136 }
4522
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
137
5011
5d0af6520f26 Do not use SchedulePhase in CFG printer
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4612
diff changeset
138 if (object instanceof LIR) {
5d0af6520f26 Do not use SchedulePhase in CFG printer
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4612
diff changeset
139 cfgPrinter.lir = (LIR) object;
5d0af6520f26 Do not use SchedulePhase in CFG printer
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4612
diff changeset
140 } else {
5d0af6520f26 Do not use SchedulePhase in CFG printer
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4612
diff changeset
141 cfgPrinter.lir = Debug.contextLookup(LIR.class);
5d0af6520f26 Do not use SchedulePhase in CFG printer
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4612
diff changeset
142 }
14888
f6630873316b Rename NodeLIRGenerator (and related classes and interfaces) to NodeLIRBuilder.
Josef Eisl <josef.eisl@jku.at>
parents: 14842
diff changeset
143 cfgPrinter.nodeLirGenerator = Debug.contextLookup(NodeLIRBuilder.class);
14842
f2e61bf2a2d8 Removed nodeOperands from LIRGenerator.
Josef Eisl <josef.eisl@jku.at>
parents: 14826
diff changeset
144 if (cfgPrinter.nodeLirGenerator != null) {
f2e61bf2a2d8 Removed nodeOperands from LIRGenerator.
Josef Eisl <josef.eisl@jku.at>
parents: 14826
diff changeset
145 cfgPrinter.target = cfgPrinter.nodeLirGenerator.getLIRGeneratorTool().target();
8150
b66f831ac5ab Fix CFG printer output. Clean up after making the compiler class all-static.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7835
diff changeset
146 }
14814
f200eb890729 Handle AbstractBlock in CFGPrinter.
Josef Eisl <josef.eisl@jku.at>
parents: 14791
diff changeset
147 if (cfgPrinter.lir != null && cfgPrinter.lir.getControlFlowGraph() instanceof ControlFlowGraph) {
14791
be2be30c653d Introduce AbstractControlFlowGraph.
Josef Eisl <josef.eisl@jku.at>
parents: 14788
diff changeset
148 cfgPrinter.cfg = (ControlFlowGraph) cfgPrinter.lir.getControlFlowGraph();
5011
5d0af6520f26 Do not use SchedulePhase in CFG printer
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4612
diff changeset
149 }
4522
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
150
12045
0fc653a9e019 made GraalCodeCacheProvider independent of CodeCacheProvider and renamed the former to LoweringProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11379
diff changeset
151 CodeCacheProvider codeCache = Debug.contextLookup(CodeCacheProvider.class);
0fc653a9e019 made GraalCodeCacheProvider independent of CodeCacheProvider and renamed the former to LoweringProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11379
diff changeset
152 if (codeCache != null) {
0fc653a9e019 made GraalCodeCacheProvider independent of CodeCacheProvider and renamed the former to LoweringProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11379
diff changeset
153 cfgPrinter.target = codeCache.getTarget();
8150
b66f831ac5ab Fix CFG printer output. Clean up after making the compiler class all-static.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7835
diff changeset
154 }
5011
5d0af6520f26 Do not use SchedulePhase in CFG printer
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4612
diff changeset
155
5d0af6520f26 Do not use SchedulePhase in CFG printer
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4612
diff changeset
156 if (object instanceof BciBlockMapping) {
4522
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
157 BciBlockMapping blockMap = (BciBlockMapping) object;
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
158 cfgPrinter.printCFG(message, blockMap);
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6529
diff changeset
159 if (blockMap.method.getCode() != null) {
5763
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
160 cfgPrinter.printBytecodes(new BytecodeDisassembler(false).disassemble(blockMap.method));
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5557
diff changeset
161 }
4522
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
162
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
163 } else if (object instanceof LIR) {
16950
559ab93c1ad6 CFGPrinter: do not print empty HIR cfgs.
Josef Eisl <josef.eisl@jku.at>
parents: 15537
diff changeset
164 // Currently no node printing for lir
559ab93c1ad6 CFGPrinter: do not print empty HIR cfgs.
Josef Eisl <josef.eisl@jku.at>
parents: 15537
diff changeset
165 cfgPrinter.printCFG(message, cfgPrinter.lir.codeEmittingOrder(), false);
4522
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
166
14594
3eda945af90a dump final HIR schedule to c1visualizer
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14145
diff changeset
167 } else if (object instanceof SchedulePhase) {
3eda945af90a dump final HIR schedule to c1visualizer
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14145
diff changeset
168 cfgPrinter.printSchedule(message, (SchedulePhase) object);
4522
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
169 } else if (object instanceof StructuredGraph) {
5011
5d0af6520f26 Do not use SchedulePhase in CFG printer
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4612
diff changeset
170 if (cfgPrinter.cfg == null) {
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8349
diff changeset
171 StructuredGraph graph = (StructuredGraph) object;
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents: 8349
diff changeset
172 cfgPrinter.cfg = ControlFlowGraph.compute(graph, true, true, true, false);
4522
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
173 }
15537
8117e9cadb48 Use List instead of an array in AbstractControlFlowGraph.
Josef Eisl <josef.eisl@jku.at>
parents: 15193
diff changeset
174 cfgPrinter.printCFG(message, cfgPrinter.cfg.getBlocks(), true);
4522
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
175
5546
e42c0df7212a Rename CiTargetMethod => CompilationResult.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
176 } else if (object instanceof CompilationResult) {
8349
8d6ea1915d42 merged CodeInfo into InstalledCode (GRAAL-156)
Doug Simon <doug.simon@oracle.com>
parents: 8150
diff changeset
177 final CompilationResult compResult = (CompilationResult) object;
12045
0fc653a9e019 made GraalCodeCacheProvider independent of CodeCacheProvider and renamed the former to LoweringProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11379
diff changeset
178 cfgPrinter.printMachineCode(codeCache.disassemble(compResult, null), message);
8349
8d6ea1915d42 merged CodeInfo into InstalledCode (GRAAL-156)
Doug Simon <doug.simon@oracle.com>
parents: 8150
diff changeset
179 } else if (isCompilationResultAndInstalledCode(object)) {
5557
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
180 Object[] tuple = (Object[]) object;
12045
0fc653a9e019 made GraalCodeCacheProvider independent of CodeCacheProvider and renamed the former to LoweringProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11379
diff changeset
181 cfgPrinter.printMachineCode(codeCache.disassemble((CompilationResult) tuple[0], (InstalledCode) tuple[1]), message);
4522
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
182 } else if (object instanceof Interval[]) {
cf13124efdd9 Restructure phi functions in LIR; Re-enabled C1Visualizer output
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4435
diff changeset
183 cfgPrinter.printIntervals(message, (Interval[]) object);
5011
5d0af6520f26 Do not use SchedulePhase in CFG printer
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4612
diff changeset
184
4278
b49981617b10 Fixes after removal of GraalCompilation
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4265
diff changeset
185 }
b49981617b10 Fixes after removal of GraalCompilation
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4265
diff changeset
186
5011
5d0af6520f26 Do not use SchedulePhase in CFG printer
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4612
diff changeset
187 cfgPrinter.target = null;
5d0af6520f26 Do not use SchedulePhase in CFG printer
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4612
diff changeset
188 cfgPrinter.lir = null;
14842
f2e61bf2a2d8 Removed nodeOperands from LIRGenerator.
Josef Eisl <josef.eisl@jku.at>
parents: 14826
diff changeset
189 cfgPrinter.nodeLirGenerator = null;
5011
5d0af6520f26 Do not use SchedulePhase in CFG printer
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4612
diff changeset
190 cfgPrinter.cfg = null;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
191 cfgPrinter.flush();
11379
0942e34b6c7d added PrintBackendCFG option (default is true) for controlling if backend output is dumped to the C1Visualizer
Doug Simon <doug.simon@oracle.com>
parents: 9658
diff changeset
192
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
193 }
5557
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
194
8349
8d6ea1915d42 merged CodeInfo into InstalledCode (GRAAL-156)
Doug Simon <doug.simon@oracle.com>
parents: 8150
diff changeset
195 private static boolean isCompilationResultAndInstalledCode(Object object) {
5557
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
196 if (object instanceof Object[]) {
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
197 Object[] tuple = (Object[]) object;
8349
8d6ea1915d42 merged CodeInfo into InstalledCode (GRAAL-156)
Doug Simon <doug.simon@oracle.com>
parents: 8150
diff changeset
198 if (tuple.length == 2 && tuple[0] instanceof CompilationResult && tuple[1] instanceof InstalledCode) {
5557
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
199 return true;
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
200 }
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
201 }
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
202 return false;
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
203 }
5819
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5763
diff changeset
204
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5763
diff changeset
205 @Override
7032
5a1f6e96e163 close() method for dump handlers should not throw IOException
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6960
diff changeset
206 public void close() {
5819
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5763
diff changeset
207 if (cfgPrinter != null) {
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5763
diff changeset
208 cfgPrinter.close();
18642
133d5a98c547 generalized semantics of DebugDumpHandler.close() to mean reset so that closing a handler flushes and releases all its resources but leaves it operational (i.e. subsequent uses will (re)create and (re)open the required resources)
Doug Simon <doug.simon@oracle.com>
parents: 16950
diff changeset
209 cfgPrinter = null;
18665
96861e3f8cc5 made CFGPrinterObserver reset (upon close) properly
Doug Simon <doug.simon@oracle.com>
parents: 18642
diff changeset
210 curDecorators = Collections.emptyList();
96861e3f8cc5 made CFGPrinterObserver reset (upon close) properly
Doug Simon <doug.simon@oracle.com>
parents: 18642
diff changeset
211 curMethod = null;
5819
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5763
diff changeset
212 }
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5763
diff changeset
213 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
214 }