Skip to content

Commit 9421aee

Browse files
committed
[GR-65736] OptimizationUtility: fix documentation and naming.
PullRequest: graal/21055
2 parents 2ca91e9 + e8214e8 commit 9421aee

File tree

3 files changed

+90
-62
lines changed

3 files changed

+90
-62
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/StructuredGraph.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,17 +1339,20 @@ public OptimizationLog getOptimizationLog() {
13391339
*/
13401340
public interface GlobalProfileProvider {
13411341

1342-
GlobalProfileProvider DEFAULT = new GlobalProfileProvider() {
1342+
/**
1343+
* The default time returned when no global profile provider is available on the platform.
1344+
*/
1345+
int GLOBAL_PROFILE_PROVIDER_DISABLED = -1;
13431346

1344-
public static final int DEFAULT_TIME = -1;
1347+
GlobalProfileProvider DEFAULT = new GlobalProfileProvider() {
13451348

13461349
/**
13471350
* The default time provider always returns -1, i.e. the self time is unknown by
13481351
* default.
13491352
*/
13501353
@Override
13511354
public double getGlobalSelfTimePercent() {
1352-
return DEFAULT_TIME;
1355+
return GLOBAL_PROFILE_PROVIDER_DISABLED;
13531356
}
13541357

13551358
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) 2023, 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.phases.common.util;
26+
27+
import jdk.graal.compiler.nodes.StructuredGraph;
28+
import jdk.graal.compiler.options.Option;
29+
import jdk.graal.compiler.options.OptionKey;
30+
31+
/**
32+
* Utility class for managing and applying additional optimizer benefits to "super hot" code
33+
* regions.
34+
*
35+
* This class provides methods to identify, evaluate, and process compilation units that demonstrate
36+
* exceptional runtime significance based on global profiling data. Its functions enable the
37+
* optimizer to selectively apply advanced strategies and enhancements to code regions determined to
38+
* be of highest execution criticality, maximizing performance gains where they matter most.
39+
*/
40+
public class GlobalProfilesOptimizationUtility {
41+
42+
public static class Options {
43+
@Option(help = "Minimal self time for a compilation unit to be considered hot globally.")//
44+
public static final OptionKey<Double> HotCodeMinSelfTime = new OptionKey<>(0.001);
45+
46+
}
47+
48+
/**
49+
* Selects and returns the appropriate option value for the specified compilation unit based on
50+
* its optimization significance. If the provided {@link StructuredGraph} is determined to merit
51+
* prioritization for optimization - such as exhibiting high runtime significance or profiling
52+
* "hotness" - the {@code hotOption} value is returned. Otherwise, the {@code coldOption} value
53+
* is chosen. This selection allows the optimizer to allocate additional resources beyond
54+
* regular hotness to a compilation unit.
55+
*/
56+
public static <X> X selectOptionBySignificance(StructuredGraph graph, OptionKey<X> coldOption, OptionKey<X> hotOption) {
57+
return shouldPrioritizeForOptimization(graph) ? hotOption.getValue(graph.getOptions()) : coldOption.getValue(graph.getOptions());
58+
}
59+
60+
public static <X> X selectOptionBySignificance(StructuredGraph graph, X coldValue, OptionKey<X> hotOption) {
61+
return shouldPrioritizeForOptimization(graph) ? hotOption.getValue(graph.getOptions()) : coldValue;
62+
}
63+
64+
public static <X> X selectOptionBySignificance(StructuredGraph graph, X coldValue, X hotValue) {
65+
return shouldPrioritizeForOptimization(graph) ? hotValue : coldValue;
66+
}
67+
68+
/**
69+
* Determines if the specified graph merits prioritization for optimization. This method
70+
* evaluates the compilation unit's significance-based on heuristics such as self time relative
71+
* to overall execution - to decide whether it should receive additional optimizer benefits.
72+
* This assessment is heuristic and intended to guide the allocation of extra optimization
73+
* resources.
74+
*/
75+
public static boolean shouldPrioritizeForOptimization(StructuredGraph graph) {
76+
final double globalSelfTimePercent = graph.globalProfileProvider().getGlobalSelfTimePercent();
77+
if (globalSelfTimePercent == StructuredGraph.GlobalProfileProvider.GLOBAL_PROFILE_PROVIDER_DISABLED) {
78+
// We are in a mode where there is no self time data available. In JIT all compilation
79+
// units are hot but none is extra hot.
80+
return false;
81+
}
82+
return globalSelfTimePercent > Options.HotCodeMinSelfTime.getValue(graph.getOptions());
83+
}
84+
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/common/util/OptimizationUtility.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)