changeset 18205:7f63e7683ee7

Truffle: refactor TraceTruffleCompilationAST into a separate class.
author Christian Humer <christian.humer@gmail.com>
date Mon, 27 Oct 2014 17:34:08 +0100
parents a1873eefea65
children 35639ec046d7
files graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallUtils.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/debug/TraceCompilationASTListener.java
diffstat 3 files changed, 74 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallUtils.java	Mon Oct 27 17:07:51 2014 +0100
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallUtils.java	Mon Oct 27 17:34:08 2014 +0100
@@ -36,53 +36,4 @@
         return (int) target.nodeStream(inlined).filter(e -> e != null && !e.getCost().isTrivial()).count();
     }
 
-    public static void printCompactTree(OutputStream out, OptimizedCallTarget target) {
-        printCompactTree(new PrintWriter(out), target);
-    }
-
-    public static void printCompactTree(PrintWriter p, OptimizedCallTarget target) {
-        target.accept(new CallTreeNodeVisitor() {
-
-            public boolean visit(List<TruffleInlining> decisionStack, Node node) {
-                if (node == null) {
-                    return true;
-                }
-                int level = CallTreeNodeVisitor.getNodeDepth(decisionStack, node);
-                for (int i = 0; i < level; i++) {
-                    p.print("  ");
-                }
-                Node parent = node.getParent();
-
-                if (parent == null) {
-                    p.println(node.getClass().getSimpleName());
-                } else {
-                    String fieldName = "unknownField";
-                    NodeField[] fields = NodeClass.get(parent.getClass()).getFields();
-                    for (NodeField field : fields) {
-                        Object value = field.loadValue(parent);
-                        if (value == node) {
-                            fieldName = field.getName();
-                            break;
-                        } else if (value instanceof Node[]) {
-                            int index = 0;
-                            for (Node arrayNode : (Node[]) value) {
-                                if (arrayNode == node) {
-                                    fieldName = field.getName() + "[" + index + "]";
-                                    break;
-                                }
-                                index++;
-                            }
-                        }
-                    }
-                    p.print(fieldName);
-                    p.print(" = ");
-                    p.println(node.getClass().getSimpleName());
-                }
-                p.flush();
-                return true;
-            }
-
-        }, true);
-    }
-
 }
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java	Mon Oct 27 17:07:51 2014 +0100
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java	Mon Oct 27 17:34:08 2014 +0100
@@ -24,7 +24,6 @@
 
 import static com.oracle.graal.api.code.CodeUtil.*;
 import static com.oracle.graal.compiler.GraalCompiler.*;
-import static com.oracle.graal.truffle.TruffleCompilerOptions.*;
 
 import java.util.*;
 
@@ -124,11 +123,7 @@
             }
 
             compilationNotify.notifyCompilationTruffleTierFinished(compilable, graph);
-
             CompilationResult compilationResult = compileMethodHelper(graph, assumptions, compilable.toString(), compilable.getSpeculationLog(), compilable);
-            if (TraceTruffleCompilationAST.getValue()) {
-                OptimizedCallUtils.printCompactTree(OptimizedCallTarget.OUT, compilable);
-            }
             compilationNotify.notifyCompilationSuccess(compilable, graph, compilationResult);
         } catch (Throwable t) {
             compilationNotify.notifyCompilationFailed(compilable, graph, t);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/debug/TraceCompilationASTListener.java	Mon Oct 27 17:34:08 2014 +0100
@@ -0,0 +1,74 @@
+package com.oracle.graal.truffle.debug;
+
+import static com.oracle.graal.truffle.TruffleCompilerOptions.*;
+
+import java.io.*;
+import java.util.*;
+
+import com.oracle.graal.api.code.*;
+import com.oracle.graal.nodes.*;
+import com.oracle.graal.truffle.*;
+import com.oracle.graal.truffle.TruffleInlining.*;
+import com.oracle.truffle.api.nodes.*;
+import com.oracle.truffle.api.nodes.NodeUtil.*;
+
+public class TraceCompilationASTListener extends AbstractDebugCompilationListener {
+
+    public static void install(GraalTruffleRuntime runtime) {
+        if (TraceTruffleCompilationAST.getValue()) {
+            runtime.addCompilationListener(new TraceCompilationASTListener());
+        }
+    }
+
+    @Override
+    public void notifyCompilationSuccess(OptimizedCallTarget target, StructuredGraph graph, CompilationResult result) {
+        log(0, "opt AST", target.toString(), target.getDebugProperties());
+        printCompactTree(new PrintWriter(OUT), target);
+    }
+
+    private static void printCompactTree(PrintWriter p, OptimizedCallTarget target) {
+        target.accept(new CallTreeNodeVisitor() {
+
+            public boolean visit(List<TruffleInlining> decisionStack, Node node) {
+                if (node == null) {
+                    return true;
+                }
+                int level = CallTreeNodeVisitor.getNodeDepth(decisionStack, node);
+                for (int i = 0; i < level; i++) {
+                    p.print("  ");
+                }
+                Node parent = node.getParent();
+
+                if (parent == null) {
+                    p.println(node.getClass().getSimpleName());
+                } else {
+                    String fieldName = "unknownField";
+                    NodeField[] fields = NodeClass.get(parent.getClass()).getFields();
+                    for (NodeField field : fields) {
+                        Object value = field.loadValue(parent);
+                        if (value == node) {
+                            fieldName = field.getName();
+                            break;
+                        } else if (value instanceof Node[]) {
+                            int index = 0;
+                            for (Node arrayNode : (Node[]) value) {
+                                if (arrayNode == node) {
+                                    fieldName = field.getName() + "[" + index + "]";
+                                    break;
+                                }
+                                index++;
+                            }
+                        }
+                    }
+                    p.print(fieldName);
+                    p.print(" = ");
+                    p.println(node.getClass().getSimpleName());
+                }
+                p.flush();
+                return true;
+            }
+
+        }, true);
+    }
+
+}