comparison graal/GraalCompiler/src/com/sun/c1x/C1XCompiler.java @ 2648:d456b679b6de

Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
author Peter Hofer <peter.hofer@jku.at>
date Wed, 11 May 2011 14:45:32 +0200
parents 3558ca7088c0
children 6ab73784566a
comparison
equal deleted inserted replaced
2647:0bf54306c139 2648:d456b679b6de
20 * or visit www.oracle.com if you need additional information or have any 20 * or visit www.oracle.com if you need additional information or have any
21 * questions. 21 * questions.
22 */ 22 */
23 package com.sun.c1x; 23 package com.sun.c1x;
24 24
25 import java.io.*;
26 import java.util.*; 25 import java.util.*;
27 26
28 import com.oracle.graal.graph.*;
29 import com.oracle.graal.graph.vis.*;
30 import com.sun.c1x.debug.*; 27 import com.sun.c1x.debug.*;
31 import com.sun.c1x.globalstub.*; 28 import com.sun.c1x.globalstub.*;
32 import com.sun.c1x.observer.*; 29 import com.sun.c1x.observer.*;
33 import com.sun.c1x.target.*; 30 import com.sun.c1x.target.*;
34 import com.sun.cri.ci.*; 31 import com.sun.cri.ci.*;
126 } 123 }
127 124
128 if (C1XOptions.PrintCFGToFile) { 125 if (C1XOptions.PrintCFGToFile) {
129 addCompilationObserver(new CFGPrinterObserver()); 126 addCompilationObserver(new CFGPrinterObserver());
130 } 127 }
131 String dot = System.getProperty("c1x.dot"); 128 if (C1XOptions.PrintDOTGraphToFile) {
132 if (dot != null && !dot.isEmpty()) { 129 addCompilationObserver(new GraphvizPrinterObserver());
133 if (!dot.endsWith("$")) {
134 dot = dot + ".*";
135 }
136 if (!dot.startsWith("^")) {
137 dot = ".*" + dot;
138 }
139 final String dotPattern = dot;
140 addCompilationObserver(new CompilationObserver() {
141 private Graph graph;
142 private int n;
143 public void compilationStarted(CompilationEvent event) {
144 n = 0;
145 }
146 public void compilationFinished(CompilationEvent event) {
147 }
148 public void compilationEvent(CompilationEvent event) {
149 if (event.getStartBlock() != null) {
150 graph = event.getStartBlock().graph();
151 String name = event.getMethod().holder().name();
152 name = name.substring(1, name.length() - 1).replace('/', '.');
153 name = name + "." + event.getMethod().name();
154 if (name.matches(dotPattern)) {
155 ByteArrayOutputStream out = new ByteArrayOutputStream();
156 GraphvizPrinter printer = new GraphvizPrinter(out);
157 printer.begin(name);
158 printer.print(graph, true);
159 printer.end();
160
161 try {
162 GraphvizRunner.process(GraphvizRunner.DOT_LAYOUT, new ByteArrayInputStream(out.toByteArray()),
163 new FileOutputStream(name + "_" + (n++) + event.getLabel() + ".pdf"), "pdf");
164 } catch (Exception e) {
165 e.printStackTrace();
166 }
167 }
168 }
169 }
170 });
171 } 130 }
172 } 131 }
173 132
174 public GlobalStub lookupGlobalStub(GlobalStub.Id id) { 133 public GlobalStub lookupGlobalStub(GlobalStub.Id id) {
175 GlobalStub globalStub = stubs.get(id); 134 GlobalStub globalStub = stubs.get(id);