Skip to content

Commit 48837f5

Browse files
committed
report hot code phase: reporting fixes
1 parent 689a9fb commit 48837f5

File tree

1 file changed

+47
-24
lines changed

1 file changed

+47
-24
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/common/ReportHotCodePhase.java

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.List;
3030
import java.util.Optional;
3131

32-
import jdk.graal.compiler.debug.DebugContext;
3332
import jdk.graal.compiler.debug.TTY;
3433
import jdk.graal.compiler.graph.Node;
3534
import jdk.graal.compiler.nodes.FixedGuardNode;
@@ -72,6 +71,8 @@ public static class Options {
7271
//@formatter:off
7372
@Option(help = "", type = OptionType.Debug)
7473
public static final OptionKey<Boolean> ReportHotCodePartsToIGV = new OptionKey<>(false);
74+
@Option(help = "", type = OptionType.Debug)
75+
public static final OptionKey<Integer> ReportHotCodIGVLevel = new OptionKey<>(1);
7576
//@formatter:on
7677
}
7778

@@ -91,6 +92,10 @@ enum BlockToStringMode {
9192
GLOBAL_FREQUENCY,
9293
}
9394

95+
private static final String INFO_KEY = "[HOT CODE INFO]";
96+
97+
private static final String WARNING_KEY = "[HOT CODE WARNING]";
98+
9499
private static String blocksToString(List<HIRBlock> blocks, BlockToStringMode mode) {
95100
StringBuilder sb = new StringBuilder();
96101
sb.append("[");
@@ -140,6 +145,18 @@ private static <X> List<X> takeUntil(List<X> list, int length) {
140145

141146
private static final int REPORT_HOT_FIRST_N = 3;
142147

148+
private static int getLengthCap(int len, int cap) {
149+
return len > cap ? cap : len;
150+
}
151+
152+
private static void info(String format, Object... args) {
153+
TTY.printf(INFO_KEY + format, args);
154+
}
155+
156+
private static void warn(String format, Object... args) {
157+
TTY.printf(WARNING_KEY + format, args);
158+
}
159+
143160
@Override
144161
protected void run(StructuredGraph graph, C c) {
145162
if (!(c instanceof CoreProviders)) {
@@ -170,30 +187,36 @@ protected void run(StructuredGraph graph, C c) {
170187
hottestGlobalLoops.sort((x, y) -> Double.compare(y.getCFGLoop().getHeader().getRelativeFrequency(), x.getCFGLoop().getHeader().getRelativeFrequency()));
171188

172189
final List<HIRBlock> hottestFirstBlocks = takeUntil(hottestBlocks, REPORT_HOT_FIRST_N);
173-
String hottestGlobalBlocksString = String.format("Hottest 3 blocks are %s %s %s", hottestFirstBlocks,
174-
blocksToString(hottestFirstBlocks, BlockToStringMode.BEGIN_NODE),
175-
blocksToString(hottestFirstBlocks, BlockToStringMode.GLOBAL_FREQUENCY));
176-
TTY.printf("[Hot Code Warning] %s\n", hottestGlobalBlocksString);
177-
if (Options.ReportHotCodePartsToIGV.getValue(graph.getOptions())) {
178-
graph.getDebug().dump(DebugContext.VERBOSE_LEVEL, graph, hottestGlobalBlocksString);
190+
if (!hottestFirstBlocks.isEmpty()) {
191+
String hottestGlobalBlocksString = String.format("Hottest %s blocks are %s %s %s", getLengthCap(hottestFirstBlocks.size(), 3), hottestFirstBlocks,
192+
blocksToString(hottestFirstBlocks, BlockToStringMode.BEGIN_NODE),
193+
blocksToString(hottestFirstBlocks, BlockToStringMode.GLOBAL_FREQUENCY));
194+
info("%s\n", hottestGlobalBlocksString);
195+
if (Options.ReportHotCodePartsToIGV.getValue(graph.getOptions())) {
196+
graph.getDebug().dump(Options.ReportHotCodIGVLevel.getValue(graph.getOptions()), graph, hottestGlobalBlocksString);
197+
}
179198
}
180199

181200
final List<Loop> hottestFirstLocalLoops = takeUntil(hottestLocalLoops, REPORT_HOT_FIRST_N);
182-
String hottestLocalLoopString = String.format("Hottest 3 local loops are %s %s",
183-
loopBlocksToString(hottestFirstLocalLoops, LoopToStringMode.BLOCK),
184-
loopBlocksToString(hottestFirstLocalLoops, LoopToStringMode.LOCAL_FREQUENCY));
185-
TTY.printf("[Hot Code Warning] %s\n", hottestLocalLoopString);
186-
if (Options.ReportHotCodePartsToIGV.getValue(graph.getOptions())) {
187-
graph.getDebug().dump(DebugContext.VERBOSE_LEVEL, graph, hottestLocalLoopString);
201+
if (!hottestFirstLocalLoops.isEmpty()) {
202+
String hottestLocalLoopString = String.format("Hottest %s local loops are %s %s", getLengthCap(hottestFirstLocalLoops.size(), 3),
203+
loopBlocksToString(hottestFirstLocalLoops, LoopToStringMode.BLOCK),
204+
loopBlocksToString(hottestFirstLocalLoops, LoopToStringMode.LOCAL_FREQUENCY));
205+
info("%s\n", hottestLocalLoopString);
206+
if (Options.ReportHotCodePartsToIGV.getValue(graph.getOptions())) {
207+
graph.getDebug().dump(Options.ReportHotCodIGVLevel.getValue(graph.getOptions()), graph, hottestLocalLoopString);
208+
}
188209
}
189210

190211
final List<Loop> hottestFirstGlobalLoops = takeUntil(hottestGlobalLoops, REPORT_HOT_FIRST_N);
191-
String hottestGlobalLoopString = String.format("Hottest 3 global loops are %s %s",
192-
loopBlocksToString(hottestFirstGlobalLoops, LoopToStringMode.BLOCK),
193-
loopBlocksToString(hottestFirstGlobalLoops, LoopToStringMode.GLOBAL_FREQUENCY));
194-
TTY.printf("[Hot Code Warning] %s\n", hottestGlobalLoopString);
195-
if (Options.ReportHotCodePartsToIGV.getValue(graph.getOptions())) {
196-
graph.getDebug().dump(DebugContext.VERBOSE_LEVEL, graph, hottestGlobalLoopString);
212+
if (!hottestGlobalLoops.isEmpty()) {
213+
String hottestGlobalLoopString = String.format("Hottest %s global loops are %s %s", getLengthCap(hottestGlobalLoops.size(), 3),
214+
loopBlocksToString(hottestFirstGlobalLoops, LoopToStringMode.BLOCK),
215+
loopBlocksToString(hottestFirstGlobalLoops, LoopToStringMode.GLOBAL_FREQUENCY));
216+
info("%s\n", hottestGlobalLoopString);
217+
if (Options.ReportHotCodePartsToIGV.getValue(graph.getOptions())) {
218+
graph.getDebug().dump(Options.ReportHotCodIGVLevel.getValue(graph.getOptions()), graph, hottestGlobalLoopString);
219+
}
197220
}
198221

199222
reportHotLoopGuardsInside(hottestGlobalLoops);
@@ -222,7 +245,7 @@ protected void run(StructuredGraph graph, C c) {
222245
private static void reportUnknownProfile(Loop l, Node inside, ControlFlowGraph cfg) {
223246
if (inside instanceof IfNode ifNode) {
224247
if (ifNode.profileSource().isUnknown()) {
225-
TTY.printf("[Hot Code Warning] Unknown profile for %s with f=%s in hot loop %s, nsp is %n\t%s%n", ifNode, cfg.blockFor(inside).getRelativeFrequency(), l,
248+
warn("Unknown profile for %s with f=%s in hot loop %s, nsp is %n\t%s%n", ifNode, cfg.blockFor(inside).getRelativeFrequency(), l,
226249
ifNode.getNodeSourcePosition());
227250
}
228251
}
@@ -240,7 +263,7 @@ private static void reportInvariantLoopIf(Loop l, Node inside) {
240263
if (inside instanceof IfNode ifNode) {
241264
LogicNode logicNode = ifNode.condition();
242265
if (!l.whole().contains(logicNode)) {
243-
TTY.printf("[Hot Code Warning] If %s with condition %s is inside loop %s while condition is not%n", ifNode, logicNode, l);
266+
warn("If %s with condition %s is inside loop %s while condition is not%n", ifNode, logicNode, l);
244267
}
245268
}
246269
}
@@ -266,9 +289,9 @@ private static void reportMemoryKillANYInLoop(Loop l, Node inside, ControlFlowGr
266289
if (sk.getKilledLocationIdentity().isAny()) {
267290
if (inside instanceof FixedNode) {
268291
// else we dont have a cfg position
269-
TTY.printf("[Hot Code Warning] Node %s kills any and has relative f=%s in loop %s %n", inside, cfg.blockFor(inside).getRelativeFrequency(), l);
292+
warn("Node %s kills any and has relative f=%s in loop %s %n", inside, cfg.blockFor(inside).getRelativeFrequency(), l);
270293
} else {
271-
TTY.printf("[Hot Code Warning] Node %s kills any in loop %s %n", inside, l);
294+
warn("Node %s kills any in loop %s %n", inside, l);
272295
}
273296
}
274297
}
@@ -314,7 +337,7 @@ private static void reportHotLoopGuardsInside(List<Loop> hottestGlobalLoops) {
314337
}
315338

316339
if (iv != null && limit != null) {
317-
TTY.printf("[Hot Code Warning] Guard %s condition %s inside loop with iv %s and limit %s%n", inside, compare, iv, limit);
340+
warn("Guard %s condition %s inside loop with iv %s and limit %s%n", inside, compare, iv, limit);
318341
}
319342
}
320343
}

0 commit comments

Comments
 (0)