--- old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugContext.java 2017-11-03 23:56:21.207317682 -0700 +++ new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/DebugContext.java 2017-11-03 23:56:20.669293606 -0700 @@ -29,9 +29,11 @@ import static org.graalvm.compiler.debug.DebugOptions.Dump; import static org.graalvm.compiler.debug.DebugOptions.DumpOnError; import static org.graalvm.compiler.debug.DebugOptions.DumpOnPhaseChange; +import static org.graalvm.compiler.debug.DebugOptions.DumpPath; import static org.graalvm.compiler.debug.DebugOptions.ListMetrics; import static org.graalvm.compiler.debug.DebugOptions.Log; import static org.graalvm.compiler.debug.DebugOptions.MemUseTrackers; +import static org.graalvm.compiler.debug.DebugOptions.ShowDumpFiles; import static org.graalvm.compiler.debug.DebugOptions.Time; import static org.graalvm.compiler.debug.DebugOptions.Timers; import static org.graalvm.compiler.debug.DebugOptions.TrackMemUse; @@ -56,6 +58,7 @@ import org.graalvm.compiler.options.OptionKey; import org.graalvm.compiler.options.OptionValues; +import org.graalvm.graphio.GraphOutput; import org.graalvm.util.EconomicMap; import org.graalvm.util.EconomicSet; import org.graalvm.util.Pair; @@ -98,6 +101,8 @@ CloseableCounter currentMemUseTracker; Scope lastClosedScope; Throwable lastExceptionThrown; + private IgvDumpChannel sharedChannel; + private GraphOutput parentOutput; /** * Stores the {@link MetricKey} values. @@ -111,6 +116,19 @@ return immutable.scopesEnabled; } + public GraphOutput buildOutput(GraphOutput.Builder builder) throws IOException { + if (parentOutput != null) { + return builder.build(parentOutput); + } else { + if (sharedChannel == null) { + sharedChannel = new IgvDumpChannel(() -> getDumpPath(".bgv", false), immutable.options); + } + final GraphOutput output = builder.build(sharedChannel); + parentOutput = output; + return output; + } + } + /** * The immutable configuration that can be shared between {@link DebugContext} objects. */ @@ -323,6 +341,14 @@ String compilableName = compilable instanceof JavaMethod ? ((JavaMethod) compilable).format("%H.%n(%p)%R") : String.valueOf(compilable); return identifier + ":" + compilableName; } + + final String getLabel() { + if (compilable instanceof JavaMethod) { + JavaMethod method = (JavaMethod) compilable; + return method.format("%h.%n(%p)%r"); + } + return String.valueOf(compilable); + } } private final Description description; @@ -394,6 +420,20 @@ } } + public Path getDumpPath(String extension, boolean directory) { + try { + String id = description == null ? null : description.identifier; + String label = description == null ? null : description.getLabel(); + Path result = PathUtilities.createUnique(immutable.options, DumpPath, id, label, extension, directory); + if (ShowDumpFiles.getValue(immutable.options)) { + TTY.println("Dumping debug output to %s", result.toAbsolutePath().toString()); + } + return result; + } catch (IOException ex) { + throw rethrowSilently(RuntimeException.class, ex); + } + } + /** * A special dump level that indicates the dumping machinery is enabled but no dumps will be * produced except through other options. @@ -2043,4 +2083,9 @@ } out.println(); } + + @SuppressWarnings({"unused", "unchecked"}) + private static E rethrowSilently(Class type, Throwable ex) throws E { + throw (E) ex; + } }