1 /*
2 * Copyright (c) 2016, 2024, 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.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_COMPILER_COMPILERDEFINITIONS_HPP
26 #define SHARE_COMPILER_COMPILERDEFINITIONS_HPP
27
28 #include "memory/allStatic.hpp"
29 #include "utilities/globalDefinitions.hpp"
30
31 // The (closed set) of concrete compiler classes.
32 enum CompilerType : u1 {
33 compiler_none,
34 compiler_c1,
35 compiler_c2,
36 compiler_jvmci,
37 compiler_number_of_types
38 };
39
40 extern const char* compilertype2name_tab[compiler_number_of_types]; // Map CompilerType to its name
41 inline const char* compilertype2name(CompilerType t) { return (uint)t < compiler_number_of_types ? compilertype2name_tab[t] : "invalid"; }
42
43 // Handy constants for deciding which compiler mode to use.
44 enum MethodCompilation {
45 InvocationEntryBci = -1, // i.e., not a on-stack replacement compilation
46 BeforeBci = InvocationEntryBci,
47 AfterBci = -2,
48 UnwindBci = -3,
49 AfterExceptionBci = -4,
50 UnknownBci = -5,
51 InvalidFrameStateBci = -6
52 };
53
54 // Enumeration to distinguish tiers of compilation
55 enum CompLevel : s1 {
56 CompLevel_any = -1, // Used for querying the state
57 CompLevel_all = -1, // Used for changing the state
58 CompLevel_none = 0, // Interpreter
59 CompLevel_simple = 1, // C1
60 CompLevel_limited_profile = 2, // C1, invocation & backedge counters
61 CompLevel_full_profile = 3, // C1, invocation & backedge counters + mdo
62 CompLevel_full_optimization = 4 // C2 or JVMCI
63 };
64
65 class CompilationModeFlag : AllStatic {
66 enum class Mode {
67 NORMAL,
68 QUICK_ONLY,
69 HIGH_ONLY,
70 HIGH_ONLY_QUICK_INTERNAL
71 };
72 static Mode _mode;
73 static void print_error();
74 public:
75 static bool initialize();
76 static bool normal() { return _mode == Mode::NORMAL; }
77 static bool quick_only() { return _mode == Mode::QUICK_ONLY; }
78 static bool high_only() { return _mode == Mode::HIGH_ONLY; }
79 static bool high_only_quick_internal() { return _mode == Mode::HIGH_ONLY_QUICK_INTERNAL; }
80
81 static bool disable_intermediate() { return high_only() || high_only_quick_internal(); }
82 static bool quick_internal() { return !high_only(); }
83
84 static void set_high_only_quick_internal() { _mode = Mode::HIGH_ONLY_QUICK_INTERNAL; }
85 static void set_quick_only() { _mode = Mode::QUICK_ONLY; }
86 static void set_high_only() { _mode = Mode::HIGH_ONLY; }
87 };
88
89 inline bool is_c1_compile(int comp_level) {
90 return comp_level > CompLevel_none && comp_level < CompLevel_full_optimization;
91 }
92
93 inline bool is_c2_compile(int comp_level) {
94 return comp_level == CompLevel_full_optimization;
95 }
96
97 inline bool is_compile(int comp_level) {
98 return is_c1_compile(comp_level) || is_c2_compile(comp_level);
99 }
100
101 class CompilerConfig : public AllStatic {
102 public:
103 // Scale compile thresholds
104 // Returns threshold scaled with CompileThresholdScaling
105 static intx scaled_compile_threshold(intx threshold, double scale);
106 static intx scaled_compile_threshold(intx threshold);
107 static intx jvmflag_scaled_compile_threshold(intx threshold);
108
109 // Returns freq_log scaled with CompileThresholdScaling
110 static intx scaled_freq_log(intx freq_log, double scale);
111 static intx scaled_freq_log(intx freq_log);
112 static intx jvmflag_scaled_freq_log(intx freq_log);
113
114 static bool check_args_consistency(bool status);
115
116 static void ergo_initialize();
117
118 // Which compilers are baked in?
119 constexpr static bool has_c1() { return COMPILER1_PRESENT(true) NOT_COMPILER1(false); }
120 constexpr static bool has_c2() { return COMPILER2_PRESENT(true) NOT_COMPILER2(false); }
121 constexpr static bool has_jvmci() { return JVMCI_ONLY(true) NOT_JVMCI(false); }
122 constexpr static bool has_tiered() { return has_c1() && (has_c2() || has_jvmci()); }
123
124 inline static bool is_jvmci_compiler();
125 inline static bool is_jvmci();
126 inline static bool is_interpreter_only();
127
128 // is_*_only() functions describe situations in which the JVM is in one way or another
129 // forced to use a particular compiler or their combination. The constraint functions
130 // deliberately ignore the fact that there may also be methods installed
131 // through JVMCI (where the JVMCI compiler was invoked not through the broker). Be sure
132 // to check for those (using is_jvmci()) in situations where it matters.
133
134 inline static bool is_tiered();
135
136 inline static bool is_c1_enabled();
137 inline static bool is_c1_only();
138 inline static bool is_c1_simple_only();
139 inline static bool is_c1_or_interpreter_only_no_jvmci();
140 inline static bool is_c1_only_no_jvmci();
141 inline static bool is_c1_profiling();
142
143 inline static bool is_jvmci_compiler_enabled();
144 inline static bool is_jvmci_compiler_only();
145
146 inline static bool is_c2_only();
147 inline static bool is_c2_enabled();
148 inline static bool is_c2_or_jvmci_compiler_only();
149 inline static bool is_c2_or_jvmci_compiler_enabled();
150
151 inline static size_t min_code_cache_size();
152
153 private:
154 static bool is_compilation_mode_selected();
155 static void set_compilation_policy_flags();
156 static void set_jvmci_specific_flags();
157 static void set_legacy_emulation_flags();
158 static void set_client_emulation_mode_flags();
159 };
160
161 #endif // SHARE_COMPILER_COMPILERDEFINITIONS_HPP
--- EOF ---