# HG changeset patch # User Christian Humer # Date 1404493014 -7200 # Node ID 9575add7149c931d62cfe1fff733f575c51f3995 # Parent ed91068c8af5ca34f04fe8ad73810bc79705ea80 Truffle: new option TraceTruffleCompilationCallTree which prints the inlined call tree just before compilation. diff -r ed91068c8af5 -r 9575add7149c CHANGELOG.md --- a/CHANGELOG.md Fri Jul 04 16:06:44 2014 +0200 +++ b/CHANGELOG.md Fri Jul 04 18:56:54 2014 +0200 @@ -10,6 +10,7 @@ * Enabled use of separate class loader (via -XX:+UseGraalClassLoader) for classes loaded from graal.jar to hide them from application classes. ### Truffle +* New flag -G:+TraceTruffleCompilationCallTree to print the tree of inlined calls before compilation. * `truffle.jar`: strip out build-time only dependency into a seperated JAR file (`truffle-dsl-processor.jar`) * New flag -G:+TraceTruffleCompilationAST to print the AST before compilation. * ... diff -r ed91068c8af5 -r 9575add7149c graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTargetLog.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTargetLog.java Fri Jul 04 16:06:44 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTargetLog.java Fri Jul 04 18:56:54 2014 +0200 @@ -76,6 +76,34 @@ } } + public static void logTruffleCalls(OptimizedCallTarget compilable) { + compilable.getRootNode().accept(new NodeVisitor() { + + int depth = 1; + + public boolean visit(Node node) { + if (node instanceof OptimizedDirectCallNode) { + OptimizedDirectCallNode callNode = ((OptimizedDirectCallNode) node); + String dispatched = !callNode.isInlined() ? " " : ""; + Map properties = new LinkedHashMap<>(); + addASTSizeProperty(callNode.getCurrentCallTarget(), properties); + properties.putAll(callNode.getCurrentCallTarget().getDebugProperties()); + + log((depth * 2), "call", callNode.getCurrentCallTarget().toString() + dispatched, properties); + + if (callNode.isInlined()) { + depth++; + callNode.getCurrentRootNode().accept(this); + depth--; + } + } else if (node instanceof OptimizedIndirectCallNode) { + log((depth * 2), "call", "", new LinkedHashMap()); + } + return true; + } + }); + } + private static List searchCallNodes(final OptimizedCallTarget target) { final List callNodes = new ArrayList<>(); target.getRootNode().accept(new NodeVisitor() { diff -r ed91068c8af5 -r 9575add7149c graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallUtils.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallUtils.java Fri Jul 04 16:06:44 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallUtils.java Fri Jul 04 18:56:54 2014 +0200 @@ -22,8 +22,12 @@ */ package com.oracle.graal.truffle; +import java.io.*; + import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.api.nodes.NodeUtil.NodeClass; import com.oracle.truffle.api.nodes.NodeUtil.NodeCountFilter; +import com.oracle.truffle.api.nodes.NodeUtil.NodeField; class OptimizedCallUtils { @@ -54,4 +58,54 @@ } }, inlined); } + + public static void printCompactTree(OutputStream out, Node node) { + printCompactTree(new PrintWriter(out), null, node, 1); + } + + private static void printCompactTree(PrintWriter p, Node parent, Node node, int level) { + if (node == null) { + return; + } + for (int i = 0; i < level; i++) { + p.print(" "); + } + 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()); + } + + for (Node child : node.getChildren()) { + printCompactTree(p, node, child, level + 1); + } + if (node instanceof OptimizedDirectCallNode) { + OptimizedDirectCallNode callNode = (OptimizedDirectCallNode) node; + if (callNode.isInlined()) { + printCompactTree(p, node, callNode.getCurrentRootNode(), level + 1); + } + } + p.flush(); + } + } diff -r ed91068c8af5 -r 9575add7149c graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java Fri Jul 04 16:06:44 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java Fri Jul 04 18:56:54 2014 +0200 @@ -114,9 +114,13 @@ if (TraceTruffleCompilation.getValue() || TraceTruffleCompilationAST.getValue()) { OptimizedCallTargetLog.logOptimizingStart(compilable); if (TraceTruffleCompilationAST.getValue()) { - NodeUtil.printCompactTree(OptimizedCallTarget.OUT, compilable.getRootNode()); + OptimizedCallUtils.printCompactTree(OptimizedCallTarget.OUT, compilable.getRootNode()); } } + if (TraceTruffleCompilationCallTree.getValue()) { + OptimizedCallTargetLog.log(0, "opt call tree", compilable.toString(), compilable.getDebugProperties()); + OptimizedCallTargetLog.logTruffleCalls(compilable); + } long timeCompilationStarted = System.nanoTime(); Assumptions assumptions = new Assumptions(true); @@ -134,6 +138,10 @@ long timeCompilationFinished = System.nanoTime(); int nodeCountLowered = graph.getNodeCount(); + if (Thread.currentThread().isInterrupted()) { + return; + } + if (TraceTruffleCompilation.getValue()) { int calls = OptimizedCallUtils.countCalls(compilable); int inlinedCalls = OptimizedCallUtils.countCallsInlined(compilable); diff -r ed91068c8af5 -r 9575add7149c graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java Fri Jul 04 16:06:44 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java Fri Jul 04 18:56:54 2014 +0200 @@ -89,6 +89,8 @@ public static final OptionValue TraceTruffleCompilationPolymorphism = new OptionValue<>(false); @Option(help = "Prints out all polymorphic and generic nodes after compilation.") public static final OptionValue TraceTruffleCompilationAST = new OptionValue<>(false); + @Option(help = "Prints out all calls of a compiled method.") + public static final OptionValue TraceTruffleCompilationCallTree = new OptionValue<>(false); @Option(help = "") public static final OptionValue TraceTruffleExpansion = new OptionValue<>(false); @Option(help = "")