changeset 3084:05dcd49a2df2

Added -G:+PlotOnError option to print graph to IGV even without -G:+Plot on error condition (verification failure or AssertionError/RuntimeException in a Phase)
author Gilles Duboscq <gilles.duboscq@oracle.com>
date Tue, 28 Jun 2011 17:08:45 +0200
parents 25b5ec0568e6
children 1ddf16c7271d
files 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/debug/IdealGraphPrinter.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/debug/IdealGraphPrinterObserver.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/CompilationEvent.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java
diffstat 6 files changed, 54 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java	Tue Jun 28 16:45:48 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java	Tue Jun 28 17:08:45 2011 +0200
@@ -72,7 +72,7 @@
         Graph.verificationListeners.add(new VerificationListener() {
             @Override
             public void verificationFailed(Node n, String message) {
-                GraalCompiler.this.fireCompilationEvent(new CompilationEvent(currentCompilation, "Verification Error on Node " + n.id(), currentCompilation.graph, true, false));
+                GraalCompiler.this.fireCompilationEvent(new CompilationEvent(currentCompilation, "Verification Error on Node " + n.id(), currentCompilation.graph, true, false, true));
                 for (Node p : n.predecessors()) {
                     TTY.println("predecessor: " + p);
                 }
@@ -142,7 +142,7 @@
         if (GraalOptions.PrintDOTGraphToPdf) {
             addCompilationObserver(new GraphvizPrinterObserver(true));
         }
-        if (GraalOptions.PrintIdealGraphLevel != 0 || GraalOptions.Plot) {
+        if (GraalOptions.PrintIdealGraphLevel != 0 || GraalOptions.Plot || GraalOptions.PlotOnError) {
             CompilationObserver observer;
             if (GraalOptions.PrintIdealGraphFile) {
                 observer = new IdealGraphPrinterObserver();
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java	Tue Jun 28 16:45:48 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java	Tue Jun 28 17:08:45 2011 +0200
@@ -80,6 +80,7 @@
 
     // Ideal graph visualizer output settings
     public static boolean Plot                               = ____;
+    public static boolean PlotOnError                        = ____;
     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/debug/IdealGraphPrinter.java	Tue Jun 28 16:45:48 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/debug/IdealGraphPrinter.java	Tue Jun 28 17:08:45 2011 +0200
@@ -128,7 +128,12 @@
             // nothing to do here...
             //t.printStackTrace();
         }
-        List<Loop> loops = LoopUtil.computeLoops(graph);
+        List<Loop> loops = null;
+        try {
+            LoopUtil.computeLoops(graph);
+        } catch (Throwable t) {
+
+        }
 
         stream.println("  <nodes>");
         List<Edge> edges = printNodes(graph, shortNames, schedule == null ? null : schedule.getNodeToBlock(), loops, debugObjects);
@@ -156,8 +161,10 @@
     private List<Edge> printNodes(Graph graph, boolean shortNames, NodeMap<Block> nodeToBlock, List<Loop> loops, Map<String, Object> debugObjects) {
         ArrayList<Edge> edges = new ArrayList<Edge>();
         NodeBitMap loopExits = graph.createNodeBitMap();
-        for (Loop loop : loops) {
-            loopExits.setUnion(loop.exits());
+        if (loops != null) {
+            for (Loop loop : loops) {
+                loopExits.setUnion(loop.exits());
+            }
         }
 
         Map<Node, Set<Entry<String, Integer>>> colors = new HashMap<Node, Set<Entry<String, Integer>>>();
@@ -232,12 +239,14 @@
                 stream.printf("    <p name='loopExit'>true</p>%n");
             }
             StringBuilder sb = new StringBuilder();
-            for (Loop loop : loops) {
-                if (loop.nodes().isMarked(node)) {
-                    if (sb.length() > 0) {
-                        sb.append(", ");
+            if (loops != null) {
+                for (Loop loop : loops) {
+                    if (loop.nodes().isMarked(node)) {
+                        if (sb.length() > 0) {
+                            sb.append(", ");
+                        }
+                        sb.append(loop.loopBegin().id());
                     }
-                    sb.append(loop.loopBegin().id());
                 }
             }
             if (sb.length() > 0) {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/debug/IdealGraphPrinterObserver.java	Tue Jun 28 16:45:48 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/debug/IdealGraphPrinterObserver.java	Tue Jun 28 17:08:45 2011 +0200
@@ -67,7 +67,7 @@
     public void compilationStarted(CompilationEvent event) {
         assert (stream == null && printer == null);
 
-        if (!TTY.isSuppressed()) {
+        if ((!TTY.isSuppressed() && GraalOptions.Plot) || (GraalOptions.PlotOnError && event.isErrorEvent())) {
             String name = event.getMethod().holder().name();
             name = name.substring(1, name.length() - 1).replace('/', '.');
             name = name + "." + event.getMethod().name();
@@ -140,6 +140,9 @@
 
     @Override
     public void compilationEvent(CompilationEvent event) {
+        if (printer == null && event.isErrorEvent()) {
+            this.compilationStarted(event); // lazy start
+        }
         if (printer != null && event.getGraph() != null && event.isHIRValid()) {
             Graph graph = event.getGraph();
             printer.print(graph, event.getLabel(), true, event.getDebugObjects());
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/CompilationEvent.java	Tue Jun 28 16:45:48 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/CompilationEvent.java	Tue Jun 28 17:08:45 2011 +0200
@@ -52,11 +52,12 @@
     private CiTargetMethod targetMethod;
     private boolean hirValid = false;
     private boolean lirValid = false;
+    private boolean errorEvent;
+    private Map<String, Object> debugObjects;
 
     private Interval[] intervals;
     private int intervalsSize;
     private Interval[] intervalsCopy = null;
-    Map<String, Object> debugObjects;
 
     public CompilationEvent(GraalCompilation compilation) {
         this(compilation, null);
@@ -69,18 +70,23 @@
     }
 
     public CompilationEvent(GraalCompilation compilation, String label, Graph graph, boolean hirValid, boolean lirValid) {
-        this(compilation, label);
-        this.graph = graph;
-        this.hirValid = hirValid;
-        this.lirValid = lirValid;
+        this(compilation, label, graph, hirValid, lirValid, false, (Map<String, Object>) null);
+    }
+    public CompilationEvent(GraalCompilation compilation, String label, Graph graph, boolean hirValid, boolean lirValid, boolean error) {
+        this(compilation, label, graph, hirValid, lirValid, error, (Map<String, Object>) null);
     }
 
     public CompilationEvent(GraalCompilation compilation, String label, Graph graph, boolean hirValid, boolean lirValid, Map<String, Object> debugObjects) {
+        this(compilation, label, graph, hirValid, lirValid, false, debugObjects);
+    }
+
+    public CompilationEvent(GraalCompilation compilation, String label, Graph graph, boolean hirValid, boolean lirValid, boolean error, Map<String, Object> debugObjects) {
         this(compilation, label);
         this.graph = graph;
         this.hirValid = hirValid;
         this.lirValid = lirValid;
         this.debugObjects = debugObjects;
+        this.errorEvent = error;
     }
 
     public CompilationEvent(GraalCompilation compilation, String label, Graph graph, boolean hirValid, boolean lirValid, CiTargetMethod targetMethod) {
@@ -137,6 +143,10 @@
         return lirValid;
     }
 
+    public boolean isErrorEvent() {
+        return errorEvent;
+    }
+
     public Interval[] getIntervals() {
         if (intervalsCopy == null && intervals != null) {
             // deferred copy of the valid range of the intervals array
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java	Tue Jun 28 16:45:48 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java	Tue Jun 28 17:08:45 2011 +0200
@@ -62,7 +62,21 @@
             GraalTimers.get(getName()).start();
         }
         //System.out.println("Starting Phase " + getName());
-        run(graph);
+        try {
+            run(graph);
+        } catch (AssertionError t) {
+            GraalCompilation compilation = GraalCompilation.compilation();
+            if (compilation.compiler.isObserved() && this.getClass() != IdentifyBlocksPhase.class) {
+                compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, "AssertionError in " + getName(), graph, true, false, true));
+            }
+            throw t;
+        } catch (RuntimeException t) {
+            GraalCompilation compilation = GraalCompilation.compilation();
+            if (compilation.compiler.isObserved() && this.getClass() != IdentifyBlocksPhase.class) {
+                compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, "RuntimeException in " + getName(), graph, true, false, true));
+            }
+            throw t;
+        }
         //System.out.println("Finished Phase " + getName());
         if (GraalOptions.Time) {
             GraalTimers.get(getName()).stop();