29
29
import java .util .List ;
30
30
import java .util .Optional ;
31
31
32
- import jdk .graal .compiler .debug .DebugContext ;
33
32
import jdk .graal .compiler .debug .TTY ;
34
33
import jdk .graal .compiler .graph .Node ;
35
34
import jdk .graal .compiler .nodes .FixedGuardNode ;
@@ -72,6 +71,8 @@ public static class Options {
72
71
//@formatter:off
73
72
@ Option (help = "" , type = OptionType .Debug )
74
73
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 );
75
76
//@formatter:on
76
77
}
77
78
@@ -91,6 +92,10 @@ enum BlockToStringMode {
91
92
GLOBAL_FREQUENCY ,
92
93
}
93
94
95
+ private static final String INFO_KEY = "[HOT CODE INFO]" ;
96
+
97
+ private static final String WARNING_KEY = "[HOT CODE WARNING]" ;
98
+
94
99
private static String blocksToString (List <HIRBlock > blocks , BlockToStringMode mode ) {
95
100
StringBuilder sb = new StringBuilder ();
96
101
sb .append ("[" );
@@ -140,6 +145,18 @@ private static <X> List<X> takeUntil(List<X> list, int length) {
140
145
141
146
private static final int REPORT_HOT_FIRST_N = 3 ;
142
147
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
+
143
160
@ Override
144
161
protected void run (StructuredGraph graph , C c ) {
145
162
if (!(c instanceof CoreProviders )) {
@@ -170,30 +187,36 @@ protected void run(StructuredGraph graph, C c) {
170
187
hottestGlobalLoops .sort ((x , y ) -> Double .compare (y .getCFGLoop ().getHeader ().getRelativeFrequency (), x .getCFGLoop ().getHeader ().getRelativeFrequency ()));
171
188
172
189
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
+ }
179
198
}
180
199
181
200
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
+ }
188
209
}
189
210
190
211
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
+ }
197
220
}
198
221
199
222
reportHotLoopGuardsInside (hottestGlobalLoops );
@@ -222,7 +245,7 @@ protected void run(StructuredGraph graph, C c) {
222
245
private static void reportUnknownProfile (Loop l , Node inside , ControlFlowGraph cfg ) {
223
246
if (inside instanceof IfNode ifNode ) {
224
247
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 ,
226
249
ifNode .getNodeSourcePosition ());
227
250
}
228
251
}
@@ -240,7 +263,7 @@ private static void reportInvariantLoopIf(Loop l, Node inside) {
240
263
if (inside instanceof IfNode ifNode ) {
241
264
LogicNode logicNode = ifNode .condition ();
242
265
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 );
244
267
}
245
268
}
246
269
}
@@ -266,9 +289,9 @@ private static void reportMemoryKillANYInLoop(Loop l, Node inside, ControlFlowGr
266
289
if (sk .getKilledLocationIdentity ().isAny ()) {
267
290
if (inside instanceof FixedNode ) {
268
291
// 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 );
270
293
} 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 );
272
295
}
273
296
}
274
297
}
@@ -314,7 +337,7 @@ private static void reportHotLoopGuardsInside(List<Loop> hottestGlobalLoops) {
314
337
}
315
338
316
339
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 );
318
341
}
319
342
}
320
343
}
0 commit comments