comparison graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinterObserver.java @ 2684:ed36daed4c43

Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
author Peter Hofer <peter.hofer@jku.at>
date Mon, 16 May 2011 17:31:53 +0200
parents
children 79590d6b4a7c
comparison
equal deleted inserted replaced
2683:026b21a81651 2684:ed36daed4c43
1 /*
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.sun.c1x.debug;
24
25 import java.io.*;
26
27 import com.oracle.graal.graph.*;
28 import com.sun.c1x.*;
29 import com.sun.c1x.observer.*;
30 import com.sun.c1x.value.*;
31
32 /**
33 * Observes compilation events and uses {@link IdealGraphPrinter} to generate a graph representation that can be
34 * inspected with the <a href="http://kenai.com/projects/igv">Ideal Graph Visualizer</a>.
35 *
36 * @author Peter Hofer
37 */
38 public class IdealGraphPrinterObserver implements CompilationObserver {
39
40 private IdealGraphPrinter printer;
41 private OutputStream stream;
42
43 @Override
44 public void compilationStarted(CompilationEvent event) {
45 assert (stream == null && printer == null);
46
47 if (!TTY.isSuppressed()) {
48 String name = event.getMethod().holder().name();
49 name = name.substring(1, name.length() - 1).replace('/', '.');
50 name = name + "." + event.getMethod().name();
51 String filename = name + ".igv.xml";
52 try {
53 stream = new FileOutputStream(filename);
54 printer = new IdealGraphPrinter(stream);
55
56 if (C1XOptions.OmitDOTFrameStates) {
57 printer.addOmittedClass(FrameState.class);
58 }
59
60 printer.begin(name, name, -1);
61 } catch (IOException e) {
62 e.printStackTrace();
63 }
64 }
65 }
66
67 @Override
68 public void compilationEvent(CompilationEvent event) {
69 if (printer != null && event.getStartBlock() != null) {
70 Graph graph = event.getStartBlock().graph();
71 printer.print(graph, event.getLabel(), true);
72 }
73 }
74
75 @Override
76 public void compilationFinished(CompilationEvent event) {
77 if (printer != null) {
78 try {
79 printer.end();
80 stream.close();
81 } catch (IOException e) {
82 e.printStackTrace();
83 } finally {
84 printer = null;
85 stream = null;
86 }
87 }
88 }
89
90 }