# HG changeset patch # User Peter Hofer # Date 1305723703 -7200 # Node ID b179be22a3dbd7de76b511a4844851fadd03ecd8 # Parent bd4c3be86fb723c496e3b794b4b42daeeb567694 Allow to submit graphs to IdealGraphVisualizer remotely with new options named after their counterparts in C2 diff -r bd4c3be86fb7 -r b179be22a3db graal/GraalCompiler/src/com/sun/c1x/C1XCompiler.java --- a/graal/GraalCompiler/src/com/sun/c1x/C1XCompiler.java Wed May 18 15:14:55 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/C1XCompiler.java Wed May 18 15:01:43 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); } } diff -r bd4c3be86fb7 -r b179be22a3db graal/GraalCompiler/src/com/sun/c1x/C1XOptions.java --- a/graal/GraalCompiler/src/com/sun/c1x/C1XOptions.java Wed May 18 15:14:55 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/C1XOptions.java Wed May 18 15:01:43 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 = ____; diff -r bd4c3be86fb7 -r b179be22a3db graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java --- a/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java Wed May 18 15:14:55 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java Wed May 18 15:01:43 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(""); - stream.flush(); + flush(); } /** diff -r bd4c3be86fb7 -r b179be22a3db graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinterObserver.java --- a/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinterObserver.java Wed May 18 15:14:55 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinterObserver.java Wed May 18 15:01:43 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,21 @@ 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; + + public IdealGraphPrinterObserver() { + this(null, -1); + } + + public IdealGraphPrinterObserver(String host, int port) { + this.host = host; + this.port = port; + } @Override public void compilationStarted(CompilationEvent event) { @@ -52,22 +66,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 +146,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; } } }