Mercurial > hg > truffle
annotate graal/GraalCompiler/src/com/sun/c1x/debug/GraphvizPrinterObserver.java @ 2694:773189811d10
Removed dominator calculation.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 18 May 2011 14:40:29 +0200 |
parents | 6ab73784566a |
children | 4149feada801 |
rev | line source |
---|---|
2648
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
1 /* |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
4 * |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
8 * |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
14 * |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
18 * |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
21 * questions. |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
22 */ |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
23 package com.sun.c1x.debug; |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
24 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
25 import java.io.*; |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
26 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
27 import com.oracle.graal.graph.*; |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
28 import com.oracle.graal.graph.vis.*; |
2674
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
29 import com.sun.c1x.*; |
2648
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
30 import com.sun.c1x.observer.*; |
2674
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
31 import com.sun.c1x.value.*; |
2648
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
32 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
33 /** |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
34 * Observes compilation events and uses {@link GraphvizPrinter} to produce a control flow graph in the DOT language |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
35 * which can be visualized with Graphviz. |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
36 * |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
37 * @author Peter Hofer |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
38 */ |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
39 public class GraphvizPrinterObserver implements CompilationObserver { |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
40 |
2674
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
41 private final boolean pdf; |
2648
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
42 private int n; |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
43 |
2674
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
44 public GraphvizPrinterObserver(boolean pdf) { |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
45 this.pdf = pdf; |
2648
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
46 } |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
47 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
48 public void compilationStarted(CompilationEvent event) { |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
49 n = 0; |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
50 } |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
51 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
52 public void compilationFinished(CompilationEvent event) { |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
53 } |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
54 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
55 public void compilationEvent(CompilationEvent event) { |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
56 if (event.getStartBlock() != null && !TTY.isSuppressed()) { |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
57 Graph graph = event.getStartBlock().graph(); |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
58 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
59 String name = event.getMethod().holder().name(); |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
60 name = name.substring(1, name.length() - 1).replace('/', '.'); |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
61 name = name + "." + event.getMethod().name(); |
2674
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
62 String filename = name + "_" + (n++) + "_" + event.getLabel(); |
2648
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
63 try { |
2674
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
64 if (pdf) { |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
65 ByteArrayOutputStream out = new ByteArrayOutputStream(); |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
66 GraphvizPrinter printer = new GraphvizPrinter(out); |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
67 if (C1XOptions.OmitDOTFrameStates) { |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
68 printer.addOmittedClass(FrameState.class); |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
69 } |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
70 printer.begin(name); |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
71 printer.print(graph, true); |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
72 printer.end(); |
2648
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
73 |
2674
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
74 FileOutputStream output = new FileOutputStream(filename + ".pdf"); |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
75 GraphvizRunner.process(GraphvizRunner.DOT_LAYOUT, new ByteArrayInputStream(out.toByteArray()), output, "pdf"); |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
76 output.close(); |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
77 } else { |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
78 final FileOutputStream stream = new FileOutputStream(filename + ".gv"); |
2648
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
79 |
2674
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
80 GraphvizPrinter printer = new GraphvizPrinter(stream); |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
81 if (C1XOptions.OmitDOTFrameStates) { |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
82 printer.addOmittedClass(FrameState.class); |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
83 } |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
84 printer.begin(name); |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
85 printer.print(graph, true); |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
86 printer.end(); |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
87 |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
88 stream.close(); |
6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
Lukas Stadler <lukas.stadler@jku.at>
parents:
2648
diff
changeset
|
89 } |
2648
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
90 } catch (IOException e) { |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
91 e.printStackTrace(); |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
92 } |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
93 } |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
94 } |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
95 } |