changeset 2701:2186ca5c2dab

Merge.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 18 May 2011 16:09:55 +0200
parents d06cff53b77e (current diff) a51ef0310dad (diff)
children 618f545fcac5
files
diffstat 4 files changed, 106 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/C1XCompiler.java	Wed May 18 16:09:31 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/C1XCompiler.java	Wed May 18 16:09:55 2011 +0200
@@ -131,8 +131,14 @@
         if (C1XOptions.PrintDOTGraphToPdf) {
             addCompilationObserver(new GraphvizPrinterObserver(true));
         }
-        if (C1XOptions.PrintIdealGraphToFile) {
-            addCompilationObserver(new IdealGraphPrinterObserver());
+        if (C1XOptions.PrintIdealGraphLevel != 0) {
+            CompilationObserver observer;
+            if (C1XOptions.PrintIdealGraphFile) {
+                observer = new IdealGraphPrinterObserver();
+            } else {
+                observer = new IdealGraphPrinterObserver(C1XOptions.PrintIdealGraphAddress, C1XOptions.PrintIdealGraphPort);
+            }
+            addCompilationObserver(observer);
         }
     }
 
--- a/graal/GraalCompiler/src/com/sun/c1x/C1XOptions.java	Wed May 18 16:09:31 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/C1XOptions.java	Wed May 18 16:09:55 2011 +0200
@@ -69,7 +69,10 @@
     public static boolean PrintCFGToFile                     = ____;
     public static boolean PrintDOTGraphToFile                = ____;
     public static boolean PrintDOTGraphToPdf                 = ____;
-    public static boolean PrintIdealGraphToFile              = ____;
+    public static int     PrintIdealGraphLevel               = 0;
+    public static boolean PrintIdealGraphFile                = ____;
+    public static String  PrintIdealGraphAddress             = "127.0.0.1";
+    public static int     PrintIdealGraphPort                = 4444;
     public static boolean OmitDOTFrameStates                 = true;
     public static boolean PrintMetrics                       = ____;
     public static boolean PrintTimers                        = ____;
--- a/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java	Wed May 18 16:09:31 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java	Wed May 18 16:09:55 2011 +0200
@@ -63,6 +63,13 @@
     }
 
     /**
+     * Flushes any buffered output.
+     */
+    public void flush() {
+        stream.flush();
+    }
+
+    /**
      * Starts a new graph document.
      */
     public void begin() {
@@ -90,7 +97,7 @@
      */
     public void end() {
         stream.println("</graphDocument>");
-        stream.flush();
+        flush();
     }
 
     /**
--- a/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinterObserver.java	Wed May 18 16:09:31 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinterObserver.java	Wed May 18 16:09:55 2011 +0200
@@ -23,6 +23,7 @@
 package com.sun.c1x.debug;
 
 import java.io.*;
+import java.net.*;
 import java.util.regex.*;
 
 import com.oracle.graal.graph.*;
@@ -40,8 +41,27 @@
 
     private static final Pattern INVALID_CHAR = Pattern.compile("[^A-Za-z0-9_.-]");
 
+    private final String host;
+    private final int port;
+
     private IdealGraphPrinter printer;
     private OutputStream stream;
+    private Socket socket;
+
+    /**
+     * Creates a new {@link IdealGraphPrinterObserver} that writes output to a file named after the compiled method.
+     */
+    public IdealGraphPrinterObserver() {
+        this(null, -1);
+    }
+
+    /**
+     * Creates a new {@link IdealGraphPrinterObserver} that sends output to a remove IdealGraphVisualizer instance.
+     */
+    public IdealGraphPrinterObserver(String host, int port) {
+        this.host = host;
+        this.port = port;
+    }
 
     @Override
     public void compilationStarted(CompilationEvent event) {
@@ -52,22 +72,69 @@
             name = name.substring(1, name.length() - 1).replace('/', '.');
             name = name + "." + event.getMethod().name();
 
-            String filename = name + ".igv.xml";
-            filename = INVALID_CHAR.matcher(filename).replaceAll("_");
+            if (host != null) {
+                openNetworkPrinter(name);
+            } else {
+                openFilePrinter(name);
+            }
+        }
+    }
+
+    private void openFilePrinter(String name) {
+        String filename = name + ".igv.xml";
+        filename = INVALID_CHAR.matcher(filename).replaceAll("_");
 
-            try {
-                stream = new FileOutputStream(filename);
-                printer = new IdealGraphPrinter(stream);
+        try {
+            stream = new FileOutputStream(filename);
+            printer = new IdealGraphPrinter(stream);
+            if (C1XOptions.OmitDOTFrameStates) {
+                printer.addOmittedClass(FrameState.class);
+            }
+            printer.begin();
+            printer.beginGroup(name, name, -1);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 
-                if (C1XOptions.OmitDOTFrameStates) {
-                    printer.addOmittedClass(FrameState.class);
-                }
+    private void openNetworkPrinter(String name) {
+        try {
+            socket = new Socket(host, port);
+            if (socket.getInputStream().read() == 'y') {
+                stream = socket.getOutputStream();
+            } else {
+                // server currently does not accept any input
+                socket.close();
+                socket = null;
+                return;
+            }
 
-                printer.begin();
-                printer.beginGroup(name, name, -1);
-            } catch (IOException e) {
-                e.printStackTrace();
+            printer = new IdealGraphPrinter(stream);
+            if (C1XOptions.OmitDOTFrameStates) {
+                printer.addOmittedClass(FrameState.class);
             }
+            printer.begin();
+            printer.beginGroup(name, name, -1);
+            printer.flush();
+            if (socket.getInputStream().read() != 'y') {
+                // server declines input for this method
+                socket.close();
+                socket = null;
+                stream = null;
+                printer = null;
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+
+            if (socket != null) {
+                try {
+                    socket.close();
+                } catch (IOException ioe) {
+                }
+                socket = null;
+            }
+            stream = null;
+            printer = null;
         }
     }
 
@@ -85,12 +152,18 @@
             try {
                 printer.endGroup();
                 printer.end();
-                stream.close();
+
+                if (socket != null) {
+                    socket.close(); // also closes stream
+                } else {
+                    stream.close();
+                }
             } catch (IOException e) {
                 e.printStackTrace();
             } finally {
                 printer = null;
                 stream = null;
+                socket = null;
             }
         }
     }