changeset 4363:7462c3600c3a

Draft changes to the graph plotting.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 24 Jan 2012 20:32:23 +0100
parents ed69fd347566
children f33f866a12e5
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/simple/DataFlowAnalysis.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/util/IntervalPrinter.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/InliningUtil.java graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/DebugConfig.java graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugScope.java graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotDebugConfig.java graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/bridge/VMToCompilerImpl.java graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinterDumpHandler.java graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinterObserver.java graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/GraalIntrinsics.java graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/Snippets.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/BoxingEliminationTest.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/DegeneratedLoopsTest.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/EscapeAnalysisTest.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/GraphTest.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/IfBoxingEliminationTest.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/IfCanonicalizerTest.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/NestedLoopTest.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/PhiCreationTests.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/ScalarTypeSystemTest.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/StraighteningTest.java
diffstat 27 files changed, 299 insertions(+), 431 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/simple/DataFlowAnalysis.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/simple/DataFlowAnalysis.java	Tue Jan 24 20:32:23 2012 +0100
@@ -35,7 +35,6 @@
 import com.oracle.max.graal.compiler.lir.*;
 import com.oracle.max.graal.compiler.lir.LIRInstruction.ValueProcedure;
 import com.oracle.max.graal.compiler.schedule.*;
-import com.oracle.max.graal.debug.*;
 
 public class DataFlowAnalysis {
     private final LIR lir;
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/util/IntervalPrinter.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/util/IntervalPrinter.java	Tue Jan 24 20:32:23 2012 +0100
@@ -30,7 +30,6 @@
 import com.oracle.max.cri.ci.*;
 import com.oracle.max.cri.ri.*;
 import com.oracle.max.graal.alloc.simple.*;
-import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.lir.*;
 import com.oracle.max.graal.compiler.lir.LIRInstruction.OperandFlag;
 import com.oracle.max.graal.compiler.lir.LIRInstruction.OperandMode;
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java	Tue Jan 24 20:32:23 2012 +0100
@@ -126,6 +126,7 @@
         }
 
         if (GraalOptions.Inline && !plan.isPhaseDisabled(InliningPhase.class)) {
+            System.out.println("Inline!");
             new InliningPhase(target, runtime, null, assumptions, plan).apply(graph);
             new DeadCodeEliminationPhase().apply(graph);
             new PhiStampPhase().apply(graph);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java	Tue Jan 24 20:32:23 2012 +0100
@@ -94,7 +94,6 @@
     public static boolean PlotOnError                        = ____;
     public static int     PlotLevel                          = 3;
     public static boolean PlotSnippets                       = ____;
-    public static boolean PrintIdealGraphBytecodes           = true;
     public static int     PrintIdealGraphLevel               = 0;
     public static boolean PrintIdealGraphFile                = ____;
     public static String  PrintIdealGraphAddress             = "127.0.0.1";
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java	Tue Jan 24 20:32:23 2012 +0100
@@ -43,7 +43,6 @@
 import com.oracle.max.graal.compiler.util.*;
 import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
-import com.oracle.max.graal.nodes.*;
 
 /**
  * An implementation of the linear scan register allocator algorithm described
@@ -131,7 +130,7 @@
 
         this.registers = target.arch.registers;
         this.firstVariableNumber = registers.length;
-        this.variables = new ArrayList<>(ir.numVariables() * 3 / 2); throw new NullPointerException();
+        this.variables = new ArrayList<>(ir.numVariables() * 3 / 2);
     }
 
     public static boolean isVariableOrRegister(CiValue value) {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java	Tue Jan 24 20:32:23 2012 +0100
@@ -45,7 +45,12 @@
     }
 
     public final void apply(final StructuredGraph graph) {
-        Debug.scope(name, this, new Runnable() { public void run() { Phase.this.run(graph); }});
+        Debug.scope(name, this, new Runnable() {
+            public void run() {
+                Phase.this.run(graph);
+                Debug.dump(graph, "After phase %s", name);
+            }
+        });
     }
 
     public final String getName() {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/InliningUtil.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/InliningUtil.java	Tue Jan 24 20:32:23 2012 +0100
@@ -24,12 +24,14 @@
 
 import java.lang.reflect.*;
 import java.util.*;
+import java.util.concurrent.*;
 
 import com.oracle.max.cri.ci.*;
 import com.oracle.max.cri.ri.*;
 import com.oracle.max.criutils.*;
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.cri.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 import com.oracle.max.graal.nodes.DeoptimizeNode.DeoptAction;
@@ -108,19 +110,13 @@
         }
 
         @Override
-        public Node inline(StructuredGraph compilerGraph, GraalRuntime runtime, InliningCallback callback) {
-            StructuredGraph graph = null; // TODO: Solve graph caching differently! GraphBuilderPhase.cachedGraphs.get(concrete);
-//            if (graph != null) {
-//                if (GraalOptions.TraceInlining) {
-//                    TTY.println("Reusing graph for %s", methodName(concrete, invoke));
-//                }
-//            } else {
-                if (GraalOptions.TraceInlining) {
-                    TTY.println("Building graph for %s, locals: %d, stack: %d", methodName(concrete, invoke), concrete.maxLocals(), concrete.maxStackSize());
+        public Node inline(StructuredGraph compilerGraph, GraalRuntime runtime, final InliningCallback callback) {
+            StructuredGraph graph = Debug.scope("Inlining", concrete, new Callable<StructuredGraph>() {
+                @Override
+                public StructuredGraph call() throws Exception {
+                    return callback.buildGraph(concrete);
                 }
-                graph = callback.buildGraph(concrete);
-//            }
-
+            });
             return InliningUtil.inline(invoke, graph, true);
         }
 
--- a/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java	Tue Jan 24 20:32:23 2012 +0100
@@ -97,11 +97,14 @@
         }
     }
 
-    public static List<Object> contextSnapshot() {
+    @SuppressWarnings("unchecked")
+    public static <T> List<T> contextSnapshot(Class<T> clazz) {
         if (ENABLED) {
-            List<Object> result = new ArrayList<>();
+            List<T> result = new ArrayList<>();
             for (Object o : context()) {
-                result.add(o);
+                if (clazz.isInstance(o)) {
+                    result.add((T) o);
+                }
             }
             return result;
         } else {
@@ -150,6 +153,11 @@
             public RuntimeException interceptException(RuntimeException e) {
                 return e;
             }
+
+            @Override
+            public Collection< ? extends DebugDumpHandler> dumpHandlers() {
+                return Collections.emptyList();
+            }
         };
     }
 
--- a/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/DebugConfig.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/DebugConfig.java	Tue Jan 24 20:32:23 2012 +0100
@@ -22,6 +22,8 @@
  */
 package com.oracle.max.graal.debug;
 
+import java.util.*;
+
 
 public interface DebugConfig {
     boolean isLogEnabled();
@@ -29,4 +31,5 @@
     boolean isDumpEnabled();
     boolean isTimerEnabled();
     RuntimeException interceptException(RuntimeException e);
+    Collection<? extends DebugDumpHandler> dumpHandlers();
 }
--- a/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugScope.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugScope.java	Tue Jan 24 20:32:23 2012 +0100
@@ -97,10 +97,10 @@
 
     public void dump(Object object, String formatString, Object[] args) {
         if (isDumpEnabled()) {
-            String message = String.format(formatString, args);
-            for (Object o : Debug.context()) {
-                if (o instanceof DebugDumpHandler) {
-                    DebugDumpHandler dumpHandler = (DebugDumpHandler) o;
+            DebugConfig config = getConfig();
+            if (config != null) {
+                String message = String.format(formatString, args);
+                for (DebugDumpHandler dumpHandler : config.dumpHandlers()) {
                     dumpHandler.dump(object, message);
                 }
             }
@@ -119,8 +119,8 @@
         }
         instanceTL.set(newChild);
         T result = null;
-        updateFlags();
-        log("Starting scope %s", newChild.getQualifiedName());
+        newChild.updateFlags();
+        newChild.log("Starting scope %s", newChild.getQualifiedName());
         try {
             if (runnable != null) {
                 runnable.run();
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotDebugConfig.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotDebugConfig.java	Tue Jan 24 20:32:23 2012 +0100
@@ -22,18 +22,22 @@
  */
 package com.oracle.max.graal.hotspot;
 
+import java.util.*;
+
 import com.oracle.max.cri.ri.*;
 import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
+import com.oracle.max.graal.printer.*;
 
 
 public class HotSpotDebugConfig implements DebugConfig {
 
-    public final String logFilter;
-    public final String meterFilter;
-    public final String timerFilter;
-    public final String dumpFilter;
-    public final String methodFilter;
+    private final String logFilter;
+    private final String meterFilter;
+    private final String timerFilter;
+    private final String dumpFilter;
+    private final String methodFilter;
+    private final List<DebugDumpHandler> dumpHandlers = new ArrayList<>();
 
     public HotSpotDebugConfig(String logFilter, String meterFilter, String timerFilter, String dumpFilter, String methodFilter) {
         this.logFilter = logFilter;
@@ -41,6 +45,7 @@
         this.timerFilter = timerFilter;
         this.dumpFilter = dumpFilter;
         this.methodFilter = methodFilter;
+        dumpHandlers.add(new IdealGraphPrinterDumpHandler());
     }
 
     public boolean isLogEnabled() {
@@ -114,4 +119,9 @@
         }
         return e;
     }
+
+    @Override
+    public Collection<? extends DebugDumpHandler> dumpHandlers() {
+        return dumpHandlers;
+    }
 }
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/bridge/VMToCompilerImpl.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/bridge/VMToCompilerImpl.java	Tue Jan 24 20:32:23 2012 +0100
@@ -47,7 +47,6 @@
 
     private final Compiler compiler;
     private int compiledMethodCount;
-    private DebugConfig debugConfig;
 
     public final HotSpotTypePrimitive typeBoolean;
     public final HotSpotTypePrimitive typeChar;
@@ -74,7 +73,11 @@
 
         @Override
         public void run() {
-            Debug.setConfig(debugConfig);
+            if (GraalOptions.Debug) {
+                Debug.enable();
+                HotSpotDebugConfig hotspotDebugConfig = new HotSpotDebugConfig(GraalOptions.Log, GraalOptions.Meter, GraalOptions.Time, GraalOptions.Dump, GraalOptions.MethodFilter);
+                Debug.setConfig(hotspotDebugConfig);
+            }
             super.run();
         }
     }
@@ -102,8 +105,8 @@
         HotSpotRuntime runtime = (HotSpotRuntime) compiler.getCompiler().runtime;
         if (GraalOptions.Intrinsify) {
             GraalIntrinsics.installIntrinsics(runtime, runtime.getCompiler().getTarget(), PhasePlan.DEFAULT);
-            Snippets.install(runtime, runtime.getCompiler().getTarget(), new SystemSnippets(), GraalOptions.PlotSnippets, PhasePlan.DEFAULT);
-            Snippets.install(runtime, runtime.getCompiler().getTarget(), new UnsafeSnippets(), GraalOptions.PlotSnippets, PhasePlan.DEFAULT);
+            Snippets.install(runtime, runtime.getCompiler().getTarget(), new SystemSnippets(), PhasePlan.DEFAULT);
+            Snippets.install(runtime, runtime.getCompiler().getTarget(), new UnsafeSnippets(), PhasePlan.DEFAULT);
         }
 
         // Create compilation queue.
@@ -126,13 +129,6 @@
             t.setDaemon(true);
             t.start();
         }
-
-        if (GraalOptions.Debug) {
-            Debug.enable();
-            HotSpotDebugConfig hotspotDebugConfig = new HotSpotDebugConfig(GraalOptions.Log, GraalOptions.Meter, GraalOptions.Time, GraalOptions.Dump, GraalOptions.MethodFilter);
-            System.out.println(hotspotDebugConfig);
-            this.debugConfig = hotspotDebugConfig;
-        }
     }
 
     /**
--- a/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java	Tue Jan 24 20:32:23 2012 +0100
@@ -27,7 +27,6 @@
 import java.util.Map.Entry;
 
 import com.oracle.max.cri.ri.*;
-import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.schedule.*;
 import com.oracle.max.graal.compiler.util.*;
 import com.oracle.max.graal.compiler.util.LoopUtil.Loop;
@@ -88,7 +87,7 @@
         printer.printProperty("origin", origin);
         printer.endProperties();
         printer.beginMethod(name, shortName, bci);
-        if (GraalOptions.PrintIdealGraphBytecodes && method != null) {
+        if (method != null) {
             printer.beginBytecodes();
             BytecodeStream bytecodes = new BytecodeStream(method.code());
             while (bytecodes.currentBC() != Bytecodes.END) {
@@ -191,51 +190,6 @@
         NodeMap<Set<Entry<String, Integer>>> colors = graph.createNodeMap();
         NodeMap<Set<Entry<String, String>>> colorsToString = graph.createNodeMap();
         NodeMap<Set<String>> bits = graph.createNodeMap();
-// TODO This code was never reachable, since there was no code putting a NodeMap or NodeBitMap into the debugObjects.
-// If you need to reactivate this code, put the mapping from names to values into a helper object and register it in the new debugObjects array.
-//
-//        if (debugObjects != null) {
-//            for (Entry<String, Object> entry : debugObjects.entrySet()) {
-//                String name = entry.getKey();
-//                Object obj = entry.getValue();
-//                if (obj instanceof NodeMap) {
-//                    Map<Object, Integer> colorNumbers = new HashMap<Object, Integer>();
-//                    int nextColor = 0;
-//                    NodeMap<?> map = (NodeMap<?>) obj;
-//                    for (Entry<Node, ?> mapEntry : map.entries()) {
-//                        Node node = mapEntry.getKey();
-//                        Object color = mapEntry.getValue();
-//                        Integer colorNumber = colorNumbers.get(color);
-//                        if (colorNumber == null) {
-//                            colorNumber = nextColor++;
-//                            colorNumbers.put(color, colorNumber);
-//                        }
-//                        Set<Entry<String, Integer>> nodeColors = colors.get(node);
-//                        if (nodeColors == null) {
-//                            nodeColors = new HashSet<Entry<String, Integer>>();
-//                            colors.put(node, nodeColors);
-//                        }
-//                        nodeColors.add(new SimpleImmutableEntry<String, Integer>(name + "Color", colorNumber));
-//                        Set<Entry<String, String>> nodeColorStrings = colorsToString.get(node);
-//                        if (nodeColorStrings == null) {
-//                            nodeColorStrings = new HashSet<Entry<String, String>>();
-//                            colorsToString.put(node, nodeColorStrings);
-//                        }
-//                        nodeColorStrings.add(new SimpleImmutableEntry<String, String>(name, color.toString()));
-//                    }
-//                } else if (obj instanceof NodeBitMap) {
-//                    NodeBitMap bitmap = (NodeBitMap) obj;
-//                    for (Node node : bitmap) {
-//                        Set<String> nodeBits = bits.get(node);
-//                        if (nodeBits == null) {
-//                            nodeBits = new HashSet<String>();
-//                            bits.put(node, nodeBits);
-//                        }
-//                        nodeBits.add(name);
-//                    }
-//                }
-//            }
-//        }
 
         for (Node node : graph.getNodes()) {
             if (omittedClasses.contains(node.getClass())) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinterDumpHandler.java	Tue Jan 24 20:32:23 2012 +0100
@@ -0,0 +1,195 @@
+/*
+ * 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.oracle.max.graal.printer;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import java.util.regex.*;
+
+import com.oracle.max.cri.ri.*;
+import com.oracle.max.graal.debug.*;
+import com.oracle.max.graal.graph.*;
+
+/**
+ * Observes compilation events and uses {@link IdealGraphPrinter} to generate a graph representation that can be
+ * inspected with the <a href="http://kenai.com/projects/igv">Ideal Graph Visualizer</a>.
+ */
+public class IdealGraphPrinterDumpHandler implements DebugDumpHandler {
+
+    private static final Pattern INVALID_CHAR = Pattern.compile("[^A-Za-z0-9_.-]");
+
+    private final String host;
+    private final int port;
+
+    public IdealGraphPrinter printer;
+    private OutputStream stream;
+    private Socket socket;
+
+    /**
+     * Creates a new {@link IdealGraphPrinterDumpHandler} that writes output to a file named after the compiled method.
+     */
+    public IdealGraphPrinterDumpHandler() {
+        this(null, -1);
+    }
+
+    /**
+     * Creates a new {@link IdealGraphPrinterDumpHandler} that sends output to a remote IdealGraphVisualizer instance.
+     */
+    public IdealGraphPrinterDumpHandler(String host, int port) {
+        this.host = host;
+        this.port = port;
+    }
+
+    private IdealGraphPrinter printer() {
+        return printer;
+    }
+
+    private Socket socket() {
+        return socket;
+    }
+
+    private void openPrinter(RiResolvedMethod method) {
+        assert stream == null && printer() == null;
+        String name;
+        if (method != null) {
+            name = method.holder().name();
+            name = name.substring(1, name.length() - 1).replace('/', '.');
+            name = name + "." + method.name();
+        } else {
+            name = "null";
+        }
+
+        openPrinter(name, method);
+    }
+
+    private void openPrinter(String title, RiResolvedMethod method) {
+        assert stream == null && printer() == null;
+        if (host != null) {
+            openNetworkPrinter(title, method);
+        } else {
+            openFilePrinter(title, method);
+        }
+    }
+
+    private void openFilePrinter(String title, RiResolvedMethod method) {
+        String filename = title + ".igv.xml";
+        filename = INVALID_CHAR.matcher(filename).replaceAll("_");
+
+        try {
+            stream = new FileOutputStream(filename);
+            printer = new IdealGraphPrinter(stream);
+            printer().begin();
+            printer().beginGroup(title, title, method, -1, "Graal");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public boolean networkAvailable() {
+        try {
+            Socket s = new Socket(host, port);
+            s.setSoTimeout(10);
+            s.close();
+            return true;
+        } catch (IOException e) {
+            return false;
+        }
+    }
+
+    private void openNetworkPrinter(String title, RiResolvedMethod method) {
+        try {
+            socket = new Socket(host, port);
+            if (socket().getInputStream().read() == 'y') {
+                stream = new BufferedOutputStream(socket().getOutputStream(), 0x4000);
+            } else {
+                // server currently does not accept any input
+                socket().close();
+                socket = null;
+                return;
+            }
+
+
+            printer = new IdealGraphPrinter(stream);
+            printer().begin();
+            printer().beginGroup(title, title, method, -1, "Graal");
+            printer().flush();
+            if (socket().getInputStream().read() != 'y') {
+                // server declines input for this method
+                socket().close();
+                socket = null;
+                stream = null;
+                printer = null;
+            }
+        } catch (IOException e) {
+            System.err.println("Error opening connection to " + host + ":" + port + ": " + e);
+
+            if (socket() != null) {
+                try {
+                    socket().close();
+                } catch (IOException ioe) {
+                }
+                socket = null;
+            }
+            stream = null;
+            printer = null;
+        }
+    }
+
+    private void closePrinter() {
+        assert (printer() != null);
+
+        try {
+            printer().endGroup();
+            printer().end();
+
+            if (socket() != null) {
+                socket().close(); // also closes stream
+            } else {
+                stream.close();
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            printer = null;
+            stream = null;
+            socket = null;
+        }
+    }
+
+    public void compilationStarted(String groupTitle) {
+        openPrinter(groupTitle, null);
+    }
+
+    @Override
+    public void dump(Object object, String message) {
+        if (object instanceof Graph) {
+            Graph graph = (Graph) object;
+            List<RiResolvedMethod> inlineContext = Debug.contextSnapshot(RiResolvedMethod.class);
+            System.out.println("dumping graph");
+            for (RiResolvedMethod m : inlineContext) {
+                System.out.println("m="+m);
+            }
+        }
+    }
+}
--- a/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinterObserver.java	Fri Jan 20 16:26:35 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,262 +0,0 @@
-/*
- * 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.oracle.max.graal.printer;
-
-import java.io.*;
-import java.net.*;
-import java.util.regex.*;
-
-import com.oracle.max.cri.ri.*;
-import com.oracle.max.criutils.*;
-import com.oracle.max.graal.compiler.observer.*;
-import com.oracle.max.graal.compiler.schedule.*;
-import com.oracle.max.graal.graph.*;
-
-/**
- * Observes compilation events and uses {@link IdealGraphPrinter} to generate a graph representation that can be
- * inspected with the <a href="http://kenai.com/projects/igv">Ideal Graph Visualizer</a>.
- */
-public class IdealGraphPrinterObserver implements CompilationObserver {
-
-    private static final Pattern INVALID_CHAR = Pattern.compile("[^A-Za-z0-9_.-]");
-
-    private final String host;
-    private final int port;
-
-    private static class PrintingContext {
-        public IdealGraphPrinter printer;
-        private OutputStream stream;
-        private Socket socket;
-
-    }
-    private final ThreadLocal<PrintingContext> context = new ThreadLocal<PrintingContext>() {
-        @Override
-        protected PrintingContext initialValue() {
-            return new PrintingContext();
-        }
-    };
-
-    /**
-     * 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 remote IdealGraphVisualizer instance.
-     */
-    public IdealGraphPrinterObserver(String host, int port) {
-        this.host = host;
-        this.port = port;
-    }
-
-    private PrintingContext context() {
-        return context.get();
-    }
-
-    private IdealGraphPrinter printer() {
-        return context().printer;
-    }
-
-    private Socket socket() {
-        return context().socket;
-    }
-
-    @Override
-    public void compilationStarted(CompilationEvent event) {
-        openPrinter(event.debugObject(RiResolvedMethod.class), false);
-    }
-
-    private void openPrinter(RiResolvedMethod method, boolean error) {
-        assert (context().stream == null && printer() == null);
-        String name;
-        if (method != null) {
-            name = method.holder().name();
-            name = name.substring(1, name.length() - 1).replace('/', '.');
-            name = name + "." + method.name();
-        } else {
-            name = "null";
-        }
-
-        openPrinter(name, method);
-    }
-
-    private void openPrinter(String title, RiResolvedMethod method) {
-        assert (context().stream == null && printer() == null);
-        if (!TTY.isSuppressed()) {
-            // Use a filter to suppress a recursive attempt to open a printer
-            TTY.Filter filter = new TTY.Filter();
-            try {
-                if (host != null) {
-                    openNetworkPrinter(title, method);
-                } else {
-                    openFilePrinter(title, method);
-                }
-            } finally {
-                filter.remove();
-            }
-        }
-    }
-
-    private void openFilePrinter(String title, RiResolvedMethod method) {
-        String filename = title + ".igv.xml";
-        filename = INVALID_CHAR.matcher(filename).replaceAll("_");
-
-        try {
-            context().stream = new FileOutputStream(filename);
-            context().printer = new IdealGraphPrinter(context().stream);
-            printer().begin();
-            printer().beginGroup(title, title, method, -1, "Graal");
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-    }
-
-    public boolean networkAvailable() {
-        try {
-            Socket s = new Socket(host, port);
-            s.setSoTimeout(10);
-            s.close();
-            return true;
-        } catch (IOException e) {
-            return false;
-        }
-    }
-
-    private void openNetworkPrinter(String title, RiResolvedMethod method) {
-        try {
-            context().socket = new Socket(host, port);
-            if (socket().getInputStream().read() == 'y') {
-                context().stream = new BufferedOutputStream(socket().getOutputStream(), 0x4000);
-            } else {
-                // server currently does not accept any input
-                socket().close();
-                context().socket = null;
-                return;
-            }
-
-            context().printer = new IdealGraphPrinter(context().stream);
-            printer().begin();
-            printer().beginGroup(title, title, method, -1, "Graal");
-            printer().flush();
-            if (socket().getInputStream().read() != 'y') {
-                // server declines input for this method
-                socket().close();
-                context().socket = null;
-                context().stream = null;
-                context().printer = null;
-            }
-        } catch (IOException e) {
-            System.err.println("Error opening connection to " + host + ":" + port + ": " + e);
-
-            if (socket() != null) {
-                try {
-                    socket().close();
-                } catch (IOException ioe) {
-                }
-                context().socket = null;
-            }
-            context().stream = null;
-            context().printer = null;
-        }
-    }
-
-    @Override
-    public void compilationEvent(CompilationEvent event) {
-        boolean lazyStart = false;
-        if (printer() == null && event.hasDebugObject(CompilationEvent.ERROR)) {
-            openPrinter(event.debugObject(RiResolvedMethod.class), true);
-            lazyStart = true;
-        }
-        Graph graph = event.debugObject(Graph.class);
-        if (printer() != null && graph != null) {
-            printer().print(graph, event.label, true, event.debugObject(IdentifyBlocksPhase.class));
-        }
-        if (lazyStart && printer() != null) {
-            closePrinter();
-        }
-    }
-
-    @Override
-    public void compilationFinished(CompilationEvent event) {
-        if (printer() != null) {
-            closePrinter();
-        }
-    }
-
-    private void closePrinter() {
-        assert (printer() != null);
-
-        try {
-            printer().endGroup();
-            printer().end();
-
-            if (socket() != null) {
-                socket().close(); // also closes stream
-            } else {
-                context().stream.close();
-            }
-        } catch (IOException e) {
-            e.printStackTrace();
-        } finally {
-            context().printer = null;
-            context().stream = null;
-            context().socket = null;
-        }
-    }
-
-    public void printGraphs(String groupTitle, Graph... graphs) {
-        openPrinter(groupTitle, null);
-        if (printer() != null) {
-            int i = 0;
-            for (Graph graph : graphs) {
-                printer().print(graph, "Graph " + i, true);
-                i++;
-            }
-            closePrinter();
-        }
-    }
-
-    public void compilationStarted(String groupTitle) {
-        openPrinter(groupTitle, null);
-    }
-
-    public void printGraph(String graphTitle, Graph graph) {
-        if (printer() != null) {
-            printer().print(graph, graphTitle, true);
-        }
-    }
-
-    public void printSingleGraph(String title, Graph graph) {
-        printSingleGraph(title, title, graph);
-    }
-
-    public void printSingleGraph(String groupTitle, String graphTitle, Graph graph) {
-        openPrinter(groupTitle, null);
-        if (printer() != null) {
-            printer().print(graph, graphTitle, true);
-            closePrinter();
-        }
-    }
-}
--- a/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/GraalIntrinsics.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/GraalIntrinsics.java	Tue Jan 24 20:32:23 2012 +0100
@@ -34,11 +34,11 @@
 public class GraalIntrinsics {
     public static void installIntrinsics(GraalRuntime runtime, CiTarget target, PhasePlan plan) {
         if (GraalOptions.Intrinsify) {
-            Snippets.install(runtime, target, new MathSnippetsX86(), GraalOptions.PlotSnippets, plan);
-            Snippets.install(runtime, target, new DoubleSnippets(), GraalOptions.PlotSnippets, plan);
-            Snippets.install(runtime, target, new FloatSnippets(), GraalOptions.PlotSnippets, plan);
-            Snippets.install(runtime, target, new NodeClassSnippets(), GraalOptions.PlotSnippets, plan);
-            Snippets.install(runtime, target, new ArrayCopySnippets(), GraalOptions.PlotSnippets, plan);
+            Snippets.install(runtime, target, new MathSnippetsX86(), plan);
+            Snippets.install(runtime, target, new DoubleSnippets(), plan);
+            Snippets.install(runtime, target, new FloatSnippets(), plan);
+            Snippets.install(runtime, target, new NodeClassSnippets(), plan);
+            Snippets.install(runtime, target, new ArrayCopySnippets(), plan);
             plan.addPhase(PhasePosition.HIGH_LEVEL, new IntrinsifyArrayCopyPhase(runtime));
         }
     }
--- a/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/Snippets.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/Snippets.java	Tue Jan 24 20:32:23 2012 +0100
@@ -26,33 +26,32 @@
 
 import com.oracle.max.cri.ci.*;
 import com.oracle.max.cri.ri.*;
-import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.phases.*;
 import com.oracle.max.graal.compiler.util.*;
 import com.oracle.max.graal.cri.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.java.*;
 import com.oracle.max.graal.nodes.*;
 import com.oracle.max.graal.nodes.extended.*;
 import com.oracle.max.graal.nodes.java.*;
-import com.oracle.max.graal.printer.*;
 
 /**
  * Utilities for snippet installation and management.
  */
 public class Snippets {
 
-    public static void install(GraalRuntime runtime, CiTarget target, SnippetsInterface obj, boolean plotGraphs, PhasePlan plan) {
+    public static void install(GraalRuntime runtime, CiTarget target, SnippetsInterface obj, PhasePlan plan) {
         Class<? extends SnippetsInterface> clazz = obj.getClass();
         BoxingMethodPool pool = new BoxingMethodPool(runtime);
         if (clazz.isAnnotationPresent(ClassSubstitution.class)) {
-            installSubstitution(runtime, target, plotGraphs, plan, clazz, pool, clazz.getAnnotation(ClassSubstitution.class).value());
+            installSubstitution(runtime, target, plan, clazz, pool, clazz.getAnnotation(ClassSubstitution.class).value());
         } else {
-            installSnippets(runtime, target, plotGraphs, plan, clazz, pool);
+            installSnippets(runtime, target, plan, clazz, pool);
         }
     }
 
-    private static void installSnippets(GraalRuntime runtime, CiTarget target, boolean plotGraphs, PhasePlan plan, Class< ? extends SnippetsInterface> clazz,
+    private static void installSnippets(GraalRuntime runtime, CiTarget target, PhasePlan plan, Class< ? extends SnippetsInterface> clazz,
                     BoxingMethodPool pool) {
         for (Method snippet : clazz.getDeclaredMethods()) {
             int modifiers = snippet.getModifiers();
@@ -61,12 +60,12 @@
             }
             RiResolvedMethod snippetRiMethod = runtime.getRiMethod(snippet);
             if (snippetRiMethod.compilerStorage().get(Graph.class) == null) {
-                buildSnippetGraph(snippetRiMethod, runtime, target, pool, plotGraphs, plan);
+                buildSnippetGraph(snippetRiMethod, runtime, target, pool, plan);
             }
         }
     }
 
-    private static void installSubstitution(GraalRuntime runtime, CiTarget target, boolean plotGraphs, PhasePlan plan, Class< ? extends SnippetsInterface> clazz,
+    private static void installSubstitution(GraalRuntime runtime, CiTarget target, PhasePlan plan, Class< ? extends SnippetsInterface> clazz,
                     BoxingMethodPool pool, Class<?> original) throws GraalInternalError {
         for (Method snippet : clazz.getDeclaredMethods()) {
             try {
@@ -79,7 +78,7 @@
                     throw new RuntimeException("Snippet must not be abstract or native");
                 }
                 RiResolvedMethod snippetRiMethod = runtime.getRiMethod(snippet);
-                StructuredGraph graph = buildSnippetGraph(snippetRiMethod, runtime, target, pool, plotGraphs, plan);
+                StructuredGraph graph = buildSnippetGraph(snippetRiMethod, runtime, target, pool, plan);
                 runtime.getRiMethod(method).compilerStorage().put(Graph.class, graph);
             } catch (NoSuchMethodException e) {
                 throw new RuntimeException("Could not resolve method to substitute with: " + snippet.getName(), e);
@@ -87,29 +86,14 @@
         }
     }
 
-    private static StructuredGraph buildSnippetGraph(RiResolvedMethod snippetRiMethod, GraalRuntime runtime, CiTarget target, BoxingMethodPool pool, boolean plotGraphs, PhasePlan plan) {
-        IdealGraphPrinterObserver observer = null;
-        if (plotGraphs) {
-            observer = new IdealGraphPrinterObserver(GraalOptions.PrintIdealGraphAddress, GraalOptions.PrintIdealGraphPort);
-            observer.compilationStarted(CiUtil.format("snippet:%h.%n(%p)", snippetRiMethod));
-        }
-        StructuredGraph graph = buildSnippetGraph(snippetRiMethod, runtime, target, pool, plan, observer);
-        if (observer != null) {
-            observer.compilationFinished(null);
-        }
-        return graph;
-    }
-
-    private static StructuredGraph buildSnippetGraph(RiResolvedMethod snippetRiMethod, GraalRuntime runtime, CiTarget target, BoxingMethodPool pool, PhasePlan plan, IdealGraphPrinterObserver observer) {
+    private static StructuredGraph buildSnippetGraph(RiResolvedMethod snippetRiMethod, GraalRuntime runtime, CiTarget target, BoxingMethodPool pool, PhasePlan plan) {
 
         GraphBuilderConfiguration config = GraphBuilderConfiguration.getDeoptFreeDefault();
         GraphBuilderPhase graphBuilder = new GraphBuilderPhase(runtime, config);
         StructuredGraph graph = new StructuredGraph(snippetRiMethod);
         graphBuilder.apply(graph);
 
-        if (observer != null) {
-            observer.printGraph(snippetRiMethod.name() + ":" + GraphBuilderPhase.class.getSimpleName(), graph);
-        }
+        Debug.dump(graph, "%s: %s", snippetRiMethod.name(), GraphBuilderPhase.class.getSimpleName());
 
         new SnippetIntrinsificationPhase(runtime, pool).apply(graph);
 
@@ -120,7 +104,7 @@
             if (holder.isSubtypeOf(runtime.getType(SnippetsInterface.class))) {
                 StructuredGraph targetGraph = (StructuredGraph) targetMethod.compilerStorage().get(Graph.class);
                 if (targetGraph == null) {
-                    targetGraph = buildSnippetGraph(targetMethod, runtime, target, pool, plan, observer);
+                    targetGraph = buildSnippetGraph(targetMethod, runtime, target, pool, plan);
                 }
                 InliningUtil.inline(invoke, targetGraph, true);
                 new CanonicalizerPhase(target, runtime, null).apply(graph);
@@ -129,9 +113,7 @@
 
         new SnippetIntrinsificationPhase(runtime, pool).apply(graph);
 
-        if (observer != null) {
-            observer.printGraph(snippetRiMethod.name() + ":" + SnippetIntrinsificationPhase.class.getSimpleName(), graph);
-        }
+        Debug.dump(graph, "%s: %s", snippetRiMethod.name(), GraphBuilderPhase.class.getSimpleName());
         new DeadCodeEliminationPhase().apply(graph);
         new CanonicalizerPhase(target, runtime, null).apply(graph);
 
@@ -140,9 +122,7 @@
             end.setSafepointPolling(false);
         }
 
-        if (observer != null) {
-            observer.printGraph(snippetRiMethod.name() + ":" + "Final", graph);
-        }
+        Debug.dump(graph, "%s: Final", snippetRiMethod.name());
 
         snippetRiMethod.compilerStorage().put(Graph.class, graph);
 
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/BoxingEliminationTest.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/BoxingEliminationTest.java	Tue Jan 24 20:32:23 2012 +0100
@@ -28,6 +28,7 @@
 
 import com.oracle.max.graal.compiler.phases.*;
 import com.oracle.max.graal.compiler.phases.PhasePlan.PhasePosition;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 import com.oracle.max.graal.nodes.extended.*;
@@ -109,9 +110,9 @@
         }
         new InliningPhase(null, runtime(), hints, null, phasePlan).apply(graph);
         new CanonicalizerPhase(null, runtime(), null).apply(graph);
-        print(graph);
+        Debug.dump(graph, "Graph");
         new BoxingEliminationPhase().apply(graph);
-        print(graph);
+        Debug.dump(graph, "Graph");
         new ExpandBoxingNodesPhase(pool).apply(graph);
         new CanonicalizerPhase(null, runtime(), null).apply(graph);
         new DeadCodeEliminationPhase().apply(graph);
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/DegeneratedLoopsTest.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/DegeneratedLoopsTest.java	Tue Jan 24 20:32:23 2012 +0100
@@ -27,6 +27,7 @@
 import org.junit.*;
 
 import com.oracle.max.graal.compiler.phases.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 
@@ -80,7 +81,7 @@
 
     private void test(String snippet) {
         StructuredGraph graph = parse(snippet);
-        print(graph);
+        Debug.dump(graph, "Graph");
         LocalNode local = graph.getNodes(LocalNode.class).iterator().next();
         ConstantNode constant = ConstantNode.forInt(0, graph);
         for (Node n : local.usages().snapshot()) {
@@ -94,7 +95,7 @@
             invoke.intrinsify(null);
         }
         new CanonicalizerPhase(null, runtime(), null).apply(graph);
-        StructuredGraph referenceGraph = parse(REFERENCE_SNIPPET); print(referenceGraph);
+        StructuredGraph referenceGraph = parse(REFERENCE_SNIPPET); Debug.dump(referenceGraph, "Graph");
         assertEquals(referenceGraph, graph);
     }
 }
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/EscapeAnalysisTest.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/EscapeAnalysisTest.java	Tue Jan 24 20:32:23 2012 +0100
@@ -28,6 +28,7 @@
 
 import com.oracle.max.cri.ci.*;
 import com.oracle.max.graal.compiler.phases.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.nodes.*;
 import com.oracle.max.graal.nodes.java.*;
 
@@ -122,9 +123,9 @@
 
         new InliningPhase(null, runtime(), null, null, getDefaultPhasePlan()).apply(graph);
         new DeadCodeEliminationPhase().apply(graph);
-        print(graph);
+        Debug.dump(graph, "Graph");
         new EscapeAnalysisPhase(null, runtime(), null, getDefaultPhasePlan()).apply(graph);
-        print(graph);
+        Debug.dump(graph, "Graph");
         int retCount = 0;
         for (ReturnNode ret : graph.getNodes(ReturnNode.class)) {
             Assert.assertTrue(ret.result().isConstant());
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/GraphTest.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/GraphTest.java	Tue Jan 24 20:32:23 2012 +0100
@@ -24,18 +24,15 @@
 
 import java.lang.reflect.*;
 
-import org.junit.*;
-
 import junit.framework.Assert;
 
 import com.oracle.max.cri.ri.*;
-import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.phases.*;
 import com.oracle.max.graal.compiler.phases.PhasePlan.*;
 import com.oracle.max.graal.cri.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.java.*;
 import com.oracle.max.graal.nodes.*;
-import com.oracle.max.graal.printer.*;
 
 /**
  * Base class for Graal compiler unit tests. These are white box tests
@@ -56,23 +53,15 @@
 public abstract class GraphTest {
 
     protected final GraalRuntime runtime;
-    private static IdealGraphPrinterObserver observer;
 
     public GraphTest() {
         this.runtime = GraalRuntimeAccess.getGraalRuntime();
     }
 
-    @BeforeClass
-    public static void init() {
-        IdealGraphPrinterObserver o = new IdealGraphPrinterObserver(GraalOptions.PrintIdealGraphAddress, GraalOptions.PrintIdealGraphPort);
-        if (o.networkAvailable()) {
-            observer = o;
-        }
-    }
-
     protected void assertEquals(StructuredGraph expected, StructuredGraph graph) {
         if (expected.getNodeCount() != graph.getNodeCount()) {
-            print("Node count not matching", expected, graph);
+            Debug.dump(expected, "Node count not matching - expected");
+            Debug.dump(graph, "Node count not matching - actual");
             Assert.fail("Graphs do not have the same number of nodes");
         }
     }
@@ -112,16 +101,4 @@
         plan.addPhase(PhasePosition.AFTER_PARSING, new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getDeoptFreeDefault()));
         return plan;
     }
-
-    protected void print(String title, StructuredGraph... graphs) {
-        if (observer != null) {
-            observer.printGraphs(getClass().getSimpleName() + ": " + title, graphs);
-        }
-    }
-
-    protected void print(StructuredGraph graph) {
-        if (observer != null) {
-            observer.printSingleGraph(getClass().getSimpleName(), graph);
-        }
-    }
 }
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/IfBoxingEliminationTest.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/IfBoxingEliminationTest.java	Tue Jan 24 20:32:23 2012 +0100
@@ -28,6 +28,7 @@
 
 import com.oracle.max.graal.compiler.phases.*;
 import com.oracle.max.graal.compiler.phases.PhasePlan.PhasePosition;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.nodes.*;
 import com.oracle.max.graal.nodes.extended.*;
 
@@ -84,9 +85,9 @@
         new CanonicalizerPhase(null, runtime(), null).apply(graph);
         new PhiStampPhase().apply(graph);
         new CanonicalizerPhase(null, runtime(), null).apply(graph);
-        print(graph);
+        Debug.dump(graph, "Graph");
         new BoxingEliminationPhase().apply(graph);
-        print(graph);
+        Debug.dump(graph, "Graph");
         new ExpandBoxingNodesPhase(pool).apply(graph);
         new CanonicalizerPhase(null, runtime(), null).apply(graph);
         new DeadCodeEliminationPhase().apply(graph);
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/IfCanonicalizerTest.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/IfCanonicalizerTest.java	Tue Jan 24 20:32:23 2012 +0100
@@ -25,6 +25,7 @@
 import org.junit.*;
 
 import com.oracle.max.graal.compiler.phases.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 
@@ -143,7 +144,7 @@
                 n.replaceFirstInput(local, constant);
             }
         }
-        print(graph);
+        Debug.dump(graph, "Graph");
         new CanonicalizerPhase(null, runtime(), null).apply(graph);
         StructuredGraph referenceGraph = parse(REFERENCE_SNIPPET);
         assertEquals(referenceGraph, graph);
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/NestedLoopTest.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/NestedLoopTest.java	Tue Jan 24 20:32:23 2012 +0100
@@ -25,6 +25,7 @@
 import org.junit.*;
 
 import com.oracle.max.graal.compiler.loop.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.nodes.*;
 
 /**
@@ -147,7 +148,7 @@
 
     private void test(String snippet) {
         StructuredGraph graph = parse(snippet);
-        print(graph);
+        Debug.dump(graph, "Graph");
         LoopInfo loopInfo = LoopUtil.computeLoopInfo(graph);
         loopInfo.print();
         Loop rootLoop = loopInfo.rootLoops().get(0);
@@ -161,6 +162,6 @@
         Assert.assertTrue(nestedLoop.localContainsFixed((FixedNode) b));
         Assert.assertTrue(innerMostLoop.localContainsFixed((FixedNode) c));
         Assert.assertTrue(innerMostLoop.localContainsFixed((FixedNode) d));
-        print(graph);
+        Debug.dump(graph, "Graph");
     }
 }
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/PhiCreationTests.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/PhiCreationTests.java	Tue Jan 24 20:32:23 2012 +0100
@@ -24,6 +24,7 @@
 
 import org.junit.*;
 
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.nodes.*;
 
 /**
@@ -66,7 +67,7 @@
     @Test
     public void test3() {
         StructuredGraph graph = parse("test3Snippet");
-        print(graph);
+        Debug.dump(graph, "Graph");
         Assert.assertFalse(graph.getNodes(PhiNode.class).iterator().hasNext());
     }
 
@@ -82,7 +83,7 @@
     @Test
     public void test4() {
         StructuredGraph graph = parse("test4Snippet");
-        print(graph);
+        Debug.dump(graph, "Graph");
         Assert.assertFalse(graph.getNodes(PhiNode.class).iterator().hasNext());
     }
 
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/ScalarTypeSystemTest.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/ScalarTypeSystemTest.java	Tue Jan 24 20:32:23 2012 +0100
@@ -27,6 +27,7 @@
 import org.junit.*;
 
 import com.oracle.max.graal.compiler.phases.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.nodes.*;
 
 /**
@@ -162,7 +163,7 @@
 
     private void test(String snippet, String referenceSnippet) {
         StructuredGraph graph = parse(snippet);
-        print(graph);
+        Debug.dump(graph, "Graph");
         new CanonicalizerPhase(null, runtime(), null).apply(graph);
         StructuredGraph referenceGraph = parse(referenceSnippet);
         assertEquals(referenceGraph, graph);
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/StraighteningTest.java	Fri Jan 20 16:26:35 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/StraighteningTest.java	Tue Jan 24 20:32:23 2012 +0100
@@ -27,6 +27,7 @@
 import org.junit.*;
 
 import com.oracle.max.graal.compiler.phases.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.nodes.*;
 
 public class StraighteningTest extends GraphTest {
@@ -87,7 +88,7 @@
 
     private void test(String snippet) {
         StructuredGraph graph = parse(snippet);
-        print(graph);
+        Debug.dump(graph, "Graph");
         new CanonicalizerPhase(null, runtime(), null).apply(graph);
         StructuredGraph referenceGraph = parse(REFERENCE_SNIPPET);
         assertEquals(referenceGraph, graph);