src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/GraphPrinterDumpHandler.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File
*** old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/GraphPrinterDumpHandler.java	Fri Jul  7 09:31:39 2017
--- new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/GraphPrinterDumpHandler.java	Fri Jul  7 09:31:39 2017

*** 20,30 **** --- 20,30 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ package org.graalvm.compiler.printer; - import static org.graalvm.compiler.debug.GraalDebugConfig.asJavaMethod; import java.io.IOException; import java.lang.management.ManagementFactory; import java.nio.channels.ClosedByInterruptException; import java.util.ArrayList;
*** 34,84 **** --- 34,78 ---- import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.WeakHashMap; ! import org.graalvm.compiler.api.replacements.SnippetReflectionProvider; import org.graalvm.compiler.debug.Debug; import org.graalvm.compiler.debug.Debug.Scope; import org.graalvm.compiler.debug.DebugConfig; ! import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.debug.DebugDumpHandler; import org.graalvm.compiler.debug.DebugDumpScope; ! import org.graalvm.compiler.debug.GraalDebugConfig; import org.graalvm.compiler.debug.GraalDebugConfig.Options; ! import org.graalvm.compiler.debug.DebugOptions; import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.debug.TTY; import org.graalvm.compiler.debug.internal.DebugScope; import org.graalvm.compiler.graph.Graph; import org.graalvm.compiler.nodes.StructuredGraph; + import org.graalvm.compiler.options.OptionValues; import org.graalvm.compiler.phases.contract.NodeCostUtil; import jdk.vm.ci.meta.JavaMethod; import jdk.vm.ci.meta.ResolvedJavaMethod; //JaCoCo Exclude /** * 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> * . ! * that can be inspected with the Graph Visualizer. */ public class GraphPrinterDumpHandler implements DebugDumpHandler { private static final int FAILURE_LIMIT = 8; private final GraphPrinterSupplier printerSupplier; protected GraphPrinter printer; private SnippetReflectionProvider snippetReflection; private List<String> previousInlineContext; private int[] dumpIds = {}; private int failuresCount; private Map<Graph, List<String>> inlineContextMap; private final String jvmArguments; private final String sunJavaCommand; @FunctionalInterface public interface GraphPrinterSupplier { ! GraphPrinter get(Graph graph) throws IOException; } /** * Creates a new {@link GraphPrinterDumpHandler}. *
*** 90,113 **** --- 84,105 ---- /* Add the JVM and Java arguments to the graph properties to help identify it. */ this.jvmArguments = String.join(" ", ManagementFactory.getRuntimeMXBean().getInputArguments()); this.sunJavaCommand = System.getProperty("sun.java.command"); } ! private void ensureInitialized(Graph graph) { if (printer == null) { if (failuresCount >= FAILURE_LIMIT) { return; } previousInlineContext = new ArrayList<>(); inlineContextMap = new WeakHashMap<>(); + DebugContext debug = graph.getDebug(); try { ! printer = printerSupplier.get(graph); if (snippetReflection != null) { printer.setSnippetReflectionProvider(snippetReflection); } } catch (IOException e) { ! handleException(debug, e); } } } private int nextDumpId() {
*** 118,202 **** --- 110,193 ---- return dumpIds[depth - 1]++; } @Override @SuppressWarnings("try") ! public void dump(DebugContext debug, Object object, final String format, Object... arguments) { if (object instanceof Graph && Options.PrintGraph.getValue(DebugScope.getConfig().getOptions())) { ensureInitialized(); + OptionValues options = debug.getOptions(); + if (object instanceof Graph && DebugOptions.PrintGraph.getValue(options)) { + final Graph graph = (Graph) object; + ensureInitialized(graph); if (printer == null) { return; } final Graph graph = (Graph) object; // Get all current JavaMethod instances in the context. List<String> inlineContext = getInlineContext(graph); if (inlineContext != previousInlineContext) { Map<Object, Object> properties = new HashMap<>(); properties.put("graph", graph.toString()); addCompilationId(properties, graph); addCFGFileName(properties); if (inlineContext.equals(previousInlineContext)) { /* * two different graphs have the same inline context, so make sure they appear * in different folders by closing and reopening the top scope. */ int inlineDepth = previousInlineContext.size() - 1; ! closeScope(debug, inlineDepth); ! openScope(inlineContext.get(inlineDepth), inlineDepth, properties); ! openScope(debug, inlineContext.get(inlineDepth), inlineDepth, properties); } else { // Check for method scopes that must be closed since the previous dump. for (int i = 0; i < previousInlineContext.size(); ++i) { if (i >= inlineContext.size() || !inlineContext.get(i).equals(previousInlineContext.get(i))) { for (int inlineDepth = previousInlineContext.size() - 1; inlineDepth >= i; --inlineDepth) { ! closeScope(debug, inlineDepth); } break; } } // Check for method scopes that must be opened since the previous dump. for (int i = 0; i < inlineContext.size(); ++i) { if (i >= previousInlineContext.size() || !inlineContext.get(i).equals(previousInlineContext.get(i))) { for (int inlineDepth = i; inlineDepth < inlineContext.size(); ++inlineDepth) { ! openScope(debug, inlineContext.get(inlineDepth), inlineDepth, inlineDepth == inlineContext.size() - 1 ? properties : null); } break; } } } } // Save inline context for next dump. previousInlineContext = inlineContext; ! try (Scope s = Debug.sandbox("PrintingGraph", null)) { ! try (DebugContext.Scope s = debug.sandbox("PrintingGraph", null)) { // Finally, output the graph. Map<Object, Object> properties = new HashMap<>(); properties.put("graph", graph.toString()); ! properties.put("scope", Debug.currentScope()); ! properties.put("scope", debug.getCurrentScopeName()); if (graph instanceof StructuredGraph) { properties.put("compilationIdentifier", ((StructuredGraph) graph).compilationId()); try { int size = NodeCostUtil.computeGraphSize((StructuredGraph) graph); properties.put("node-cost graph size", size); } catch (Throwable t) { properties.put("node-cost-exception", t.getMessage()); } } ! addCFGFileName(properties); printer.print(graph, properties, nextDumpId(), format, arguments); ! printer.print(debug, graph, properties, nextDumpId(), format, arguments); } catch (IOException e) { ! handleException(debug, e); } catch (Throwable e) { ! throw Debug.handle(e); ! throw debug.handle(e); } } } ! void handleException(DebugContext debug, IOException e) { ! if (GraalDebugConfig.Options.DumpingErrorsAreFatal.getValue(DebugScope.getConfig().getOptions())) { ! if (debug != null && DebugOptions.DumpingErrorsAreFatal.getValue(debug.getOptions())) { throw new GraalError(e); } if (e instanceof ClosedByInterruptException) { /* * The current dumping was aborted by an interrupt so treat this as a transient failure.
*** 204,250 **** --- 195,224 ---- failuresCount = 0; } else { failuresCount++; } printer = null; if (failuresCount > FAILURE_LIMIT) { e.printStackTrace(TTY.out); + if (failuresCount > FAILURE_LIMIT) { TTY.println("Too many failures with dumping. Disabling dump in thread " + Thread.currentThread()); } else { TTY.println(e.getMessage()); } } private static void addCompilationId(Map<Object, Object> properties, final Graph graph) { if (graph instanceof StructuredGraph) { properties.put("compilationId", ((StructuredGraph) graph).compilationId()); } } private static void addCFGFileName(Map<Object, Object> properties) { DebugConfig config = DebugScope.getConfig(); if (config != null) { for (DebugDumpHandler dumpHandler : config.dumpHandlers()) { if (dumpHandler instanceof CFGPrinterObserver) { CFGPrinterObserver cfg = (CFGPrinterObserver) dumpHandler; String path = cfg.getDumpPath(); if (path != null) { properties.put("PrintCFGFileName", path); } return; } } } } private List<String> getInlineContext(Graph graph) { List<String> result = inlineContextMap.get(graph); if (result == null) { result = new ArrayList<>(); Object lastMethodOrGraph = null; boolean graphSeen = false; for (Object o : Debug.context()) { + DebugContext debug = graph.getDebug(); + for (Object o : debug.context()) { if (o == graph) { graphSeen = true; } if (o instanceof DebugDumpScope) {
*** 305,315 **** --- 279,289 ---- */ } } } ! private void openScope(DebugContext debug, String name, int inlineDepth, Map<Object, Object> properties) { try { Map<Object, Object> props = properties; if (inlineDepth == 0) { /* Include some VM specific properties at the root. */ if (props == null) {
*** 319,361 **** --- 293,327 ---- if (sunJavaCommand != null) { props.put("sun.java.command", sunJavaCommand); } props.put("date", new Date().toString()); } ! printer.beginGroup(name, name, Debug.contextLookup(ResolvedJavaMethod.class), -1, props); ! printer.beginGroup(debug, name, name, debug.contextLookup(ResolvedJavaMethod.class), -1, props); } catch (IOException e) { ! handleException(debug, e); } } ! private void closeScope(DebugContext debug, int inlineDepth) { dumpIds[inlineDepth] = 0; try { + if (printer != null) { printer.endGroup(); + } } catch (IOException e) { ! handleException(debug, e); } } @Override public void close() { if (previousInlineContext != null) { for (int inlineDepth = 0; inlineDepth < previousInlineContext.size(); inlineDepth++) { ! closeScope(null, inlineDepth); } } if (printer != null) { printer.close(); printer = null; } } @Override public void addCapability(Object capability) { if (capability instanceof SnippetReflectionProvider) { snippetReflection = (SnippetReflectionProvider) capability; if (printer != null && printer.getSnippetReflectionProvider() == null) { printer.setSnippetReflectionProvider(snippetReflection); } } } }

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/GraphPrinterDumpHandler.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File