Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/compiler/compilerDefinitions.hpp
40930 views
1
/*
2
* Copyright (c) 2016, 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.
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 "compiler/compiler_globals.hpp"
29
#include "jvmci/jvmci_globals.hpp"
30
#include "memory/allocation.hpp"
31
#include "runtime/globals.hpp"
32
33
// The (closed set) of concrete compiler classes.
34
enum CompilerType {
35
compiler_none,
36
compiler_c1,
37
compiler_c2,
38
compiler_jvmci,
39
compiler_number_of_types
40
};
41
42
extern const char* compilertype2name_tab[compiler_number_of_types]; // Map CompilerType to its name
43
inline const char* compilertype2name(CompilerType t) { return (uint)t < compiler_number_of_types ? compilertype2name_tab[t] : NULL; }
44
45
// Handy constants for deciding which compiler mode to use.
46
enum MethodCompilation {
47
InvocationEntryBci = -1, // i.e., not a on-stack replacement compilation
48
BeforeBci = InvocationEntryBci,
49
AfterBci = -2,
50
UnwindBci = -3,
51
AfterExceptionBci = -4,
52
UnknownBci = -5,
53
InvalidFrameStateBci = -6
54
};
55
56
// Enumeration to distinguish tiers of compilation
57
enum CompLevel {
58
CompLevel_any = -1, // Used for querying the state
59
CompLevel_all = -1, // Used for changing the state
60
CompLevel_none = 0, // Interpreter
61
CompLevel_simple = 1, // C1
62
CompLevel_limited_profile = 2, // C1, invocation & backedge counters
63
CompLevel_full_profile = 3, // C1, invocation & backedge counters + mdo
64
CompLevel_full_optimization = 4 // C2 or JVMCI
65
};
66
67
class CompilationModeFlag : AllStatic {
68
enum class Mode {
69
NORMAL,
70
QUICK_ONLY,
71
HIGH_ONLY,
72
HIGH_ONLY_QUICK_INTERNAL
73
};
74
static Mode _mode;
75
static void print_error();
76
public:
77
static bool initialize();
78
static bool normal() { return _mode == Mode::NORMAL; }
79
static bool quick_only() { return _mode == Mode::QUICK_ONLY; }
80
static bool high_only() { return _mode == Mode::HIGH_ONLY; }
81
static bool high_only_quick_internal() { return _mode == Mode::HIGH_ONLY_QUICK_INTERNAL; }
82
83
static bool disable_intermediate() { return high_only() || high_only_quick_internal(); }
84
static bool quick_internal() { return !high_only(); }
85
86
static void set_high_only_quick_internal() { _mode = Mode::HIGH_ONLY_QUICK_INTERNAL; }
87
static void set_quick_only() { _mode = Mode::QUICK_ONLY; }
88
static void set_high_only() { _mode = Mode::HIGH_ONLY; }
89
};
90
91
inline bool is_c1_compile(int comp_level) {
92
return comp_level > CompLevel_none && comp_level < CompLevel_full_optimization;
93
}
94
95
inline bool is_c2_compile(int comp_level) {
96
return comp_level == CompLevel_full_optimization;
97
}
98
99
inline bool is_compile(int comp_level) {
100
return is_c1_compile(comp_level) || is_c2_compile(comp_level);
101
}
102
103
104
// States of Restricted Transactional Memory usage.
105
enum RTMState {
106
NoRTM = 0x2, // Don't use RTM
107
UseRTM = 0x1, // Use RTM
108
ProfileRTM = 0x0 // Use RTM with abort ratio calculation
109
};
110
111
#ifndef INCLUDE_RTM_OPT
112
#define INCLUDE_RTM_OPT 0
113
#endif
114
#if INCLUDE_RTM_OPT
115
#define RTM_OPT_ONLY(code) code
116
#else
117
#define RTM_OPT_ONLY(code)
118
#endif
119
120
class CompilerConfig : public AllStatic {
121
public:
122
// Scale compile thresholds
123
// Returns threshold scaled with CompileThresholdScaling
124
static intx scaled_compile_threshold(intx threshold, double scale);
125
static intx scaled_compile_threshold(intx threshold);
126
127
// Returns freq_log scaled with CompileThresholdScaling
128
static intx scaled_freq_log(intx freq_log, double scale);
129
static intx scaled_freq_log(intx freq_log);
130
131
static bool check_args_consistency(bool status);
132
133
static void ergo_initialize();
134
135
// Which compilers are baked in?
136
constexpr static bool has_c1() { return COMPILER1_PRESENT(true) NOT_COMPILER1(false); }
137
constexpr static bool has_c2() { return COMPILER2_PRESENT(true) NOT_COMPILER2(false); }
138
constexpr static bool has_jvmci() { return JVMCI_ONLY(true) NOT_JVMCI(false); }
139
constexpr static bool has_tiered() { return has_c1() && (has_c2() || has_jvmci()); }
140
141
static bool is_jvmci_compiler() { return JVMCI_ONLY(has_jvmci() && UseJVMCICompiler) NOT_JVMCI(false); }
142
static bool is_jvmci() { return JVMCI_ONLY(has_jvmci() && EnableJVMCI) NOT_JVMCI(false); }
143
static bool is_interpreter_only();
144
145
// is_*_only() functions describe situations in which the JVM is in one way or another
146
// forced to use a particular compiler or their combination. The constraint functions
147
// deliberately ignore the fact that there may also be methods installed
148
// through JVMCI (where the JVMCI compiler was invoked not through the broker). Be sure
149
// to check for those (using is_jvmci()) in situations where it matters.
150
//
151
152
// Is the JVM in a configuration that permits only c1-compiled methods (level 1,2,3)?
153
static bool is_c1_only() {
154
if (!is_interpreter_only() && has_c1()) {
155
const bool c1_only = !has_c2() && !is_jvmci_compiler();
156
const bool tiered_degraded_to_c1_only = TieredCompilation && TieredStopAtLevel >= CompLevel_simple && TieredStopAtLevel < CompLevel_full_optimization;
157
const bool c1_only_compilation_mode = CompilationModeFlag::quick_only();
158
return c1_only || tiered_degraded_to_c1_only || c1_only_compilation_mode;
159
}
160
return false;
161
}
162
163
static bool is_c1_or_interpreter_only_no_jvmci() {
164
assert(is_jvmci_compiler() && is_jvmci() || !is_jvmci_compiler(), "JVMCI compiler implies enabled JVMCI");
165
return !is_jvmci() && (is_interpreter_only() || is_c1_only());
166
}
167
168
static bool is_c1_only_no_jvmci() {
169
return is_c1_only() && !is_jvmci();
170
}
171
172
// Is the JVM in a configuration that permits only c1-compiled methods at level 1?
173
static bool is_c1_simple_only() {
174
if (is_c1_only()) {
175
const bool tiered_degraded_to_level_1 = TieredCompilation && TieredStopAtLevel == CompLevel_simple;
176
const bool c1_only_compilation_mode = CompilationModeFlag::quick_only();
177
const bool tiered_off = !TieredCompilation;
178
return tiered_degraded_to_level_1 || c1_only_compilation_mode || tiered_off;
179
}
180
return false;
181
}
182
183
static bool is_c2_enabled() {
184
return has_c2() && !is_interpreter_only() && !is_c1_only() && !is_jvmci_compiler();
185
}
186
187
static bool is_jvmci_compiler_enabled() {
188
return is_jvmci_compiler() && !is_interpreter_only() && !is_c1_only();
189
}
190
// Is the JVM in a configuration that permits only c2-compiled methods?
191
static bool is_c2_only() {
192
if (is_c2_enabled()) {
193
const bool c2_only = !has_c1();
194
// There is no JVMCI compiler to replace C2 in the broker, and the user (or ergonomics)
195
// is forcing C1 off.
196
const bool c2_only_compilation_mode = CompilationModeFlag::high_only();
197
const bool tiered_off = !TieredCompilation;
198
return c2_only || c2_only_compilation_mode || tiered_off;
199
}
200
return false;
201
}
202
203
// Is the JVM in a configuration that permits only jvmci-compiled methods?
204
static bool is_jvmci_compiler_only() {
205
if (is_jvmci_compiler_enabled()) {
206
const bool jvmci_compiler_only = !has_c1();
207
// JVMCI compiler replaced C2 and the user (or ergonomics) is forcing C1 off.
208
const bool jvmci_only_compilation_mode = CompilationModeFlag::high_only();
209
const bool tiered_off = !TieredCompilation;
210
return jvmci_compiler_only || jvmci_only_compilation_mode || tiered_off;
211
}
212
return false;
213
}
214
215
static bool is_c2_or_jvmci_compiler_only() {
216
return is_c2_only() || is_jvmci_compiler_only();
217
}
218
219
// Tiered is basically C1 & (C2 | JVMCI) minus all the odd cases with restrictions.
220
static bool is_tiered() {
221
assert(is_c1_simple_only() && is_c1_only() || !is_c1_simple_only(), "c1 simple mode must imply c1-only mode");
222
return has_tiered() && !is_interpreter_only() && !is_c1_only() && !is_c2_or_jvmci_compiler_only();
223
}
224
225
static bool is_c1_enabled() {
226
return has_c1() && !is_interpreter_only() && !is_c2_or_jvmci_compiler_only();
227
}
228
229
static bool is_c1_profiling() {
230
const bool c1_only_profiling = is_c1_only() && !is_c1_simple_only();
231
const bool tiered = is_tiered();
232
return c1_only_profiling || tiered;
233
}
234
235
236
static bool is_c2_or_jvmci_compiler_enabled() {
237
return is_c2_enabled() || is_jvmci_compiler_enabled();
238
}
239
240
241
private:
242
static bool is_compilation_mode_selected();
243
static void set_compilation_policy_flags();
244
static void set_jvmci_specific_flags();
245
static void set_legacy_emulation_flags();
246
static void set_client_emulation_mode_flags();
247
};
248
249
#endif // SHARE_COMPILER_COMPILERDEFINITIONS_HPP
250
251