26
27 import static org.graalvm.compiler.debug.DebugConfig.asJavaMethod;
28
29 import java.io.IOException;
30 import java.nio.channels.ClosedByInterruptException;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.Collections;
34 import java.util.Date;
35 import java.util.HashMap;
36 import java.util.List;
37 import java.util.Map;
38 import java.util.WeakHashMap;
39
40 import org.graalvm.compiler.debug.DebugContext;
41 import org.graalvm.compiler.debug.DebugDumpHandler;
42 import org.graalvm.compiler.debug.DebugDumpScope;
43 import org.graalvm.compiler.debug.DebugOptions;
44 import org.graalvm.compiler.debug.GraalError;
45 import org.graalvm.compiler.debug.TTY;
46 import org.graalvm.compiler.graph.Graph;
47 import org.graalvm.compiler.nodes.StructuredGraph;
48 import org.graalvm.compiler.options.OptionValues;
49 import org.graalvm.compiler.phases.contract.NodeCostUtil;
50 import org.graalvm.compiler.serviceprovider.GraalServices;
51
52 import jdk.vm.ci.meta.JavaMethod;
53 import jdk.vm.ci.meta.ResolvedJavaMethod;
54
55 //JaCoCo Exclude
56
57 /**
58 * Observes compilation events and uses {@link BinaryGraphPrinter} to generate a graph
59 * representation that can be inspected with the Graph Visualizer.
60 */
61 public class GraphPrinterDumpHandler implements DebugDumpHandler {
62
63 private static final int FAILURE_LIMIT = 8;
64 private final GraphPrinterSupplier printerSupplier;
65 protected GraphPrinter printer;
107 try {
108 printer = printerSupplier.get(ctx, graph);
109 } catch (IOException e) {
110 handleException(debug, e);
111 }
112 }
113 }
114
115 private int nextDumpId() {
116 int depth = previousInlineContext.size();
117 if (dumpIds.length < depth) {
118 dumpIds = Arrays.copyOf(dumpIds, depth);
119 }
120 return dumpIds[depth - 1]++;
121 }
122
123 @Override
124 @SuppressWarnings("try")
125 public void dump(DebugContext debug, Object object, final String format, Object... arguments) {
126 OptionValues options = debug.getOptions();
127 if (object instanceof Graph && DebugOptions.PrintGraph.getValue(options)) {
128 final Graph graph = (Graph) object;
129 ensureInitialized(debug, graph);
130 if (printer == null) {
131 return;
132 }
133
134 // Get all current JavaMethod instances in the context.
135 List<String> inlineContext = getInlineContext(graph);
136
137 if (inlineContext != previousInlineContext) {
138 Map<Object, Object> properties = new HashMap<>();
139 properties.put("graph", graph.toString());
140 addCompilationId(properties, graph);
141 if (inlineContext.equals(previousInlineContext)) {
142 /*
143 * two different graphs have the same inline context, so make sure they appear
144 * in different folders by closing and reopening the top scope.
145 */
146 int inlineDepth = previousInlineContext.size() - 1;
147 closeScope(debug, inlineDepth);
|
26
27 import static org.graalvm.compiler.debug.DebugConfig.asJavaMethod;
28
29 import java.io.IOException;
30 import java.nio.channels.ClosedByInterruptException;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.Collections;
34 import java.util.Date;
35 import java.util.HashMap;
36 import java.util.List;
37 import java.util.Map;
38 import java.util.WeakHashMap;
39
40 import org.graalvm.compiler.debug.DebugContext;
41 import org.graalvm.compiler.debug.DebugDumpHandler;
42 import org.graalvm.compiler.debug.DebugDumpScope;
43 import org.graalvm.compiler.debug.DebugOptions;
44 import org.graalvm.compiler.debug.GraalError;
45 import org.graalvm.compiler.debug.TTY;
46 import org.graalvm.compiler.debug.DebugOptions.PrintGraphTarget;
47 import org.graalvm.compiler.graph.Graph;
48 import org.graalvm.compiler.nodes.StructuredGraph;
49 import org.graalvm.compiler.options.OptionValues;
50 import org.graalvm.compiler.phases.contract.NodeCostUtil;
51 import org.graalvm.compiler.serviceprovider.GraalServices;
52
53 import jdk.vm.ci.meta.JavaMethod;
54 import jdk.vm.ci.meta.ResolvedJavaMethod;
55
56 //JaCoCo Exclude
57
58 /**
59 * Observes compilation events and uses {@link BinaryGraphPrinter} to generate a graph
60 * representation that can be inspected with the Graph Visualizer.
61 */
62 public class GraphPrinterDumpHandler implements DebugDumpHandler {
63
64 private static final int FAILURE_LIMIT = 8;
65 private final GraphPrinterSupplier printerSupplier;
66 protected GraphPrinter printer;
108 try {
109 printer = printerSupplier.get(ctx, graph);
110 } catch (IOException e) {
111 handleException(debug, e);
112 }
113 }
114 }
115
116 private int nextDumpId() {
117 int depth = previousInlineContext.size();
118 if (dumpIds.length < depth) {
119 dumpIds = Arrays.copyOf(dumpIds, depth);
120 }
121 return dumpIds[depth - 1]++;
122 }
123
124 @Override
125 @SuppressWarnings("try")
126 public void dump(DebugContext debug, Object object, final String format, Object... arguments) {
127 OptionValues options = debug.getOptions();
128 if (object instanceof Graph && DebugOptions.PrintGraph.getValue(options) != PrintGraphTarget.Disable) {
129 final Graph graph = (Graph) object;
130 ensureInitialized(debug, graph);
131 if (printer == null) {
132 return;
133 }
134
135 // Get all current JavaMethod instances in the context.
136 List<String> inlineContext = getInlineContext(graph);
137
138 if (inlineContext != previousInlineContext) {
139 Map<Object, Object> properties = new HashMap<>();
140 properties.put("graph", graph.toString());
141 addCompilationId(properties, graph);
142 if (inlineContext.equals(previousInlineContext)) {
143 /*
144 * two different graphs have the same inline context, so make sure they appear
145 * in different folders by closing and reopening the top scope.
146 */
147 int inlineDepth = previousInlineContext.size() - 1;
148 closeScope(debug, inlineDepth);
|