changeset 2654:616c6e74b69a

Merge.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 11 May 2011 15:11:58 +0200
parents 7c8ad40c1f88 (current diff) d456b679b6de (diff)
children df5de2a207ca
files graal/GraalCompiler/src/com/sun/c1x/C1XOptions.java
diffstat 3 files changed, 76 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/C1XCompiler.java	Wed May 11 15:11:33 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/C1XCompiler.java	Wed May 11 15:11:58 2011 +0200
@@ -22,11 +22,8 @@
  */
 package com.sun.c1x;
 
-import java.io.*;
 import java.util.*;
 
-import com.oracle.graal.graph.*;
-import com.oracle.graal.graph.vis.*;
 import com.sun.c1x.debug.*;
 import com.sun.c1x.globalstub.*;
 import com.sun.c1x.observer.*;
@@ -128,46 +125,8 @@
         if (C1XOptions.PrintCFGToFile) {
             addCompilationObserver(new CFGPrinterObserver());
         }
-        String dot = System.getProperty("c1x.dot");
-        if (dot != null && !dot.isEmpty()) {
-            if (!dot.endsWith("$")) {
-                dot = dot + ".*";
-            }
-            if (!dot.startsWith("^")) {
-                dot = ".*" + dot;
-            }
-            final String dotPattern = dot;
-            addCompilationObserver(new CompilationObserver() {
-                private Graph graph;
-                private int n;
-                public void compilationStarted(CompilationEvent event) {
-                    n = 0;
-                }
-                public void compilationFinished(CompilationEvent event) {
-                }
-                public void compilationEvent(CompilationEvent event) {
-                    if (event.getStartBlock() != null) {
-                        graph = event.getStartBlock().graph();
-                        String name = event.getMethod().holder().name();
-                        name = name.substring(1, name.length() - 1).replace('/', '.');
-                        name = name + "." + event.getMethod().name();
-                        if (name.matches(dotPattern)) {
-                            ByteArrayOutputStream out = new ByteArrayOutputStream();
-                            GraphvizPrinter printer = new GraphvizPrinter(out);
-                            printer.begin(name);
-                            printer.print(graph, true);
-                            printer.end();
-
-                            try {
-                                GraphvizRunner.process(GraphvizRunner.DOT_LAYOUT, new ByteArrayInputStream(out.toByteArray()),
-                                                new FileOutputStream(name + "_" + (n++) + event.getLabel() + ".pdf"), "pdf");
-                            } catch (Exception e) {
-                                e.printStackTrace();
-                            }
-                        }
-                    }
-                }
-            });
+        if (C1XOptions.PrintDOTGraphToFile) {
+            addCompilationObserver(new GraphvizPrinterObserver());
         }
     }
 
--- a/graal/GraalCompiler/src/com/sun/c1x/C1XOptions.java	Wed May 11 15:11:33 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/C1XOptions.java	Wed May 11 15:11:58 2011 +0200
@@ -66,6 +66,7 @@
     public static boolean PrintInliningFailures              = ____;
     public static boolean PrintLIR                           = ____;
     public static boolean PrintCFGToFile                     = ____;
+    public static boolean PrintDOTGraphToFile                = ____;
     public static boolean PrintMetrics                       = ____;
     public static boolean PrintTimers                        = ____;
     public static boolean PrintCompilation                   = ____;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/GraalCompiler/src/com/sun/c1x/debug/GraphvizPrinterObserver.java	Wed May 11 15:11:58 2011 +0200
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.c1x.debug;
+
+import java.io.*;
+
+import com.oracle.graal.graph.*;
+import com.oracle.graal.graph.vis.*;
+import com.sun.c1x.observer.*;
+
+/**
+ * Observes compilation events and uses {@link GraphvizPrinter} to produce a control flow graph in the DOT language
+ * which can be visualized with Graphviz.
+ *
+ * @author Peter Hofer
+ */
+public class GraphvizPrinterObserver implements CompilationObserver {
+
+    private int n;
+
+    public GraphvizPrinterObserver() {
+    }
+
+    public void compilationStarted(CompilationEvent event) {
+        n = 0;
+    }
+
+    public void compilationFinished(CompilationEvent event) {
+    }
+
+    public void compilationEvent(CompilationEvent event) {
+        if (event.getStartBlock() != null && !TTY.isSuppressed()) {
+            Graph graph = event.getStartBlock().graph();
+
+            String name = event.getMethod().holder().name();
+            name = name.substring(1, name.length() - 1).replace('/', '.');
+            name = name + "." + event.getMethod().name();
+            try {
+                FileOutputStream stream = new FileOutputStream(name + "_" + n + "_" + event.getLabel() + ".gv");
+                n++;
+
+                GraphvizPrinter printer = new GraphvizPrinter(stream);
+                printer.begin(name);
+                printer.print(graph, true);
+                printer.end();
+
+                stream.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+}