Skip to content

Commit ce5b158

Browse files
committed
add ReportHotMetricsAfterPhases to report hot parts in the IR with a set
of initial performance warnings based on static IR data
1 parent 271e4f1 commit ce5b158

File tree

3 files changed

+405
-0
lines changed

3 files changed

+405
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package jdk.graal.compiler.core.test;
26+
27+
import java.io.ByteArrayOutputStream;
28+
29+
import org.junit.Test;
30+
31+
import jdk.graal.compiler.api.directives.GraalDirectives;
32+
import jdk.graal.compiler.debug.LogStream;
33+
import jdk.graal.compiler.debug.TTY;
34+
import jdk.graal.compiler.options.OptionValues;
35+
import jdk.graal.compiler.phases.BasePhase;
36+
37+
public class ReportHotMetricsTest extends GraalCompilerTest {
38+
39+
public static boolean PRINT_STDOUT = false;
40+
41+
static int sideEffect;
42+
43+
public static int snippet01(int limit1) {
44+
int result = 0;
45+
for (int i = 0; GraalDirectives.injectIterationCount(100000, i < limit1); i++) {
46+
// this if is missing a profile and should be reported
47+
if (i > sideEffect) {
48+
// this kill should be reported
49+
GraalDirectives.sideEffect(123);
50+
} else {
51+
result += i;
52+
}
53+
}
54+
return result;
55+
}
56+
57+
@Test
58+
public void testAbsNegate() {
59+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
60+
try (TTY.Filter ttyFilter = new TTY.Filter(new LogStream(bos))) {
61+
OptionValues opt = new OptionValues(getInitialOptions(), BasePhase.PhaseOptions.ReportHotMetricsAfterPhases, "BoxNodeIdentity=*.snippet01");
62+
test(opt, "snippet01", 100);
63+
}
64+
// the missing profile
65+
assertTrue(bos.toString().contains("[Hot Code Warning] Unknown profile for"));
66+
// the killing of any
67+
assertTrue(bos.toString().contains(" kills any and has relative"));
68+
69+
if (PRINT_STDOUT) {
70+
TTY.println("%s%n", bos.toString());
71+
}
72+
}
73+
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/BasePhase.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import jdk.graal.compiler.options.OptionKey;
6363
import jdk.graal.compiler.options.OptionType;
6464
import jdk.graal.compiler.options.OptionValues;
65+
import jdk.graal.compiler.phases.common.ReportHotCodePhase;
6566
import jdk.graal.compiler.phases.contract.NodeCostUtil;
6667
import jdk.graal.compiler.phases.contract.PhaseSizeContract;
6768
import jdk.graal.compiler.serviceprovider.GraalServices;
@@ -203,6 +204,8 @@ public static class PhaseOptions {
203204
public static final OptionKey<Integer> MinimalGraphNodeSizeCheckSize = new OptionKey<>(1000);
204205
@Option(help = "Exclude certain phases from compilation based on the given phase filter(s)." + PhaseFilterKey.HELP, type = OptionType.Debug)
205206
public static final PhaseFilterKey CompilationExcludePhases = new PhaseFilterKey(null, null);
207+
@Option(help = "Report hot metrics after each phase matching the given phase filter(s).", type = OptionType.Debug)
208+
public static final PhaseFilterKey ReportHotMetricsAfterPhases = new PhaseFilterKey(null, null);
206209
// @formatter:on
207210
}
208211

@@ -495,6 +498,12 @@ public final void apply(final StructuredGraph graph, final C context, final bool
495498
}
496499
}
497500

501+
if (PhaseOptions.ReportHotMetricsAfterPhases.matches(options, this, graph)) {
502+
String label = graph.name != null ? graph.name : graph.method().format("%H.%n(%p)");
503+
TTY.println("Reporting hot metrics after " + getName() + " during compilation of " + label);
504+
new ReportHotCodePhase().apply(graph, context);
505+
}
506+
498507
} catch (Throwable t) {
499508
throw debug.handle(t);
500509
}

0 commit comments

Comments
 (0)