|
| 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 | +} |
0 commit comments