--- old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/GraphPrinter.java 2017-07-07 09:31:38.000000000 -0700 +++ new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/GraphPrinter.java 2017-07-07 09:31:38.000000000 -0700 @@ -30,8 +30,12 @@ import java.util.Map; import org.graalvm.compiler.api.replacements.SnippetReflectionProvider; +import org.graalvm.compiler.debug.DebugContext; +import org.graalvm.compiler.debug.DebugContext.Scope; import org.graalvm.compiler.graph.Graph; import org.graalvm.compiler.nodes.ConstantNode; +import org.graalvm.compiler.nodes.StructuredGraph; +import org.graalvm.compiler.phases.schedule.SchedulePhase; import org.graalvm.compiler.serviceprovider.JDK9Method; import jdk.vm.ci.meta.JavaConstant; @@ -48,18 +52,16 @@ * Starts a new group of graphs with the given name, short name and method byte code index (BCI) * as properties. */ - void beginGroup(String name, String shortName, ResolvedJavaMethod method, int bci, Map properties) throws IOException; + void beginGroup(DebugContext debug, String name, String shortName, ResolvedJavaMethod method, int bci, Map properties) throws IOException; /** * Prints an entire {@link Graph} with the specified title, optionally using short names for * nodes. */ - void print(Graph graph, Map properties, int id, String format, Object... args) throws IOException; + void print(DebugContext debug, Graph graph, Map properties, int id, String format, Object... args) throws IOException; SnippetReflectionProvider getSnippetReflectionProvider(); - void setSnippetReflectionProvider(SnippetReflectionProvider snippetReflection); - /** * Ends the current group. */ @@ -142,20 +144,30 @@ } } - default String formatTitle(int id, String format, Object... args) { - /* - * If an argument is a Class, replace it with the simple name. - */ - Object[] newArgs = new Object[args.length]; - for (int i = 0; i < newArgs.length; i++) { + /** + * Replaces all {@link JavaType} elements in {@code args} with the result of + * {@link JavaType#getUnqualifiedName()}. + * + * @return a copy of {@code args} with the above mentioned substitutions or {@code args} if no + * substitutions were performed + */ + default Object[] simplifyClassArgs(Object... args) { + Object[] res = args; + for (int i = 0; i < args.length; i++) { Object arg = args[i]; if (arg instanceof JavaType) { - newArgs[i] = ((JavaType) arg).getUnqualifiedName(); + if (args == res) { + res = new Object[args.length]; + for (int a = 0; a < i; a++) { + res[a] = args[a]; + } + } + res[i] = ((JavaType) arg).getUnqualifiedName(); } else { - newArgs[i] = arg; + res[i] = arg; } } - return id + ": " + String.format(format, newArgs); + return res; } static String truncate(String s) { @@ -198,4 +210,23 @@ } return buf.append('}').toString(); } + + @SuppressWarnings("try") + static StructuredGraph.ScheduleResult getScheduleOrNull(Graph graph) { + if (graph instanceof StructuredGraph) { + StructuredGraph sgraph = (StructuredGraph) graph; + StructuredGraph.ScheduleResult scheduleResult = sgraph.getLastSchedule(); + if (scheduleResult == null) { + DebugContext debug = graph.getDebug(); + try (Scope scope = debug.disable()) { + SchedulePhase schedule = new SchedulePhase(graph.getOptions()); + schedule.apply(sgraph); + scheduleResult = sgraph.getLastSchedule(); + } catch (Throwable t) { + } + } + return scheduleResult; + } + return null; + } }