Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/runtime/flags/jvmFlag.hpp
40957 views
1
/*
2
* Copyright (c) 1997, 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_RUNTIME_FLAGS_JVMFLAG_HPP
26
#define SHARE_RUNTIME_FLAGS_JVMFLAG_HPP
27
28
#include "utilities/globalDefinitions.hpp"
29
#include "utilities/enumIterator.hpp"
30
#include "utilities/macros.hpp"
31
#include "utilities/vmEnums.hpp"
32
#include <type_traits>
33
34
class outputStream;
35
36
enum class JVMFlagOrigin : int {
37
// This is the value returned by JVMFlag::get_origin(). It records who
38
// has most recently changed the value of a JVMFlag. DEFAULT means that the
39
// flag was never changed, or was most recently changed by FLAG_SET_DEFAULT.
40
DEFAULT = 0,
41
COMMAND_LINE = 1,
42
ENVIRON_VAR = 2,
43
CONFIG_FILE = 3,
44
MANAGEMENT = 4,
45
ERGONOMIC = 5,
46
ATTACH_ON_DEMAND = 6,
47
INTERNAL = 7,
48
JIMAGE_RESOURCE = 8,
49
};
50
51
ENUMERATOR_RANGE(JVMFlagOrigin, JVMFlagOrigin::DEFAULT, JVMFlagOrigin::JIMAGE_RESOURCE)
52
53
class JVMFlag {
54
friend class VMStructs;
55
56
public:
57
enum Flags : int {
58
VALUE_ORIGIN_BITS = 4,
59
VALUE_ORIGIN_MASK = right_n_bits(VALUE_ORIGIN_BITS),
60
61
// flag kind
62
KIND_PRODUCT = 1 << 4,
63
KIND_MANAGEABLE = 1 << 5,
64
KIND_DIAGNOSTIC = 1 << 6,
65
KIND_EXPERIMENTAL = 1 << 7,
66
KIND_NOT_PRODUCT = 1 << 8,
67
KIND_DEVELOP = 1 << 9,
68
KIND_PLATFORM_DEPENDENT = 1 << 10,
69
KIND_C1 = 1 << 11,
70
KIND_C2 = 1 << 12,
71
KIND_ARCH = 1 << 13,
72
KIND_LP64_PRODUCT = 1 << 14,
73
KIND_JVMCI = 1 << 15,
74
75
// Note the difference:
76
// f->get_origin() == COMMAND_LINE
77
// f was mostly recently set by the command-line
78
// f->_flags & WAS_SET_ON_COMMAND_LINE
79
// f was specified on the command-line (but may have since been updated by
80
// someone else like FLAG_SET_ERGO)
81
WAS_SET_ON_COMMAND_LINE = 1 << 17,
82
83
KIND_MASK = ~(VALUE_ORIGIN_MASK | WAS_SET_ON_COMMAND_LINE)
84
};
85
86
enum Error {
87
// no error
88
SUCCESS = 0,
89
// flag name is missing
90
MISSING_NAME,
91
// flag value is missing
92
MISSING_VALUE,
93
// error parsing the textual form of the value
94
WRONG_FORMAT,
95
// flag is not writable
96
NON_WRITABLE,
97
// flag value is outside of its bounds
98
OUT_OF_BOUNDS,
99
// flag value violates its constraint
100
VIOLATES_CONSTRAINT,
101
// there is no flag with the given name
102
INVALID_FLAG,
103
// the flag can only be set only on command line during invocation of the VM
104
COMMAND_LINE_ONLY,
105
// the flag may only be set once
106
SET_ONLY_ONCE,
107
// the flag is not writable in this combination of product/debug build
108
CONSTANT,
109
// other, unspecified error related to setting the flag
110
ERR_OTHER
111
};
112
113
enum MsgType {
114
NONE = 0,
115
DIAGNOSTIC_FLAG_BUT_LOCKED,
116
EXPERIMENTAL_FLAG_BUT_LOCKED,
117
DEVELOPER_FLAG_BUT_PRODUCT_BUILD,
118
NOTPRODUCT_FLAG_BUT_PRODUCT_BUILD
119
};
120
121
#define JVM_FLAG_NON_STRING_TYPES_DO(f) \
122
f(bool) \
123
f(int) \
124
f(uint) \
125
f(intx) \
126
f(uintx) \
127
f(uint64_t) \
128
f(size_t) \
129
f(double)
130
131
#define JVM_FLAG_TYPE_DECLARE(t) \
132
TYPE_ ## t,
133
134
enum FlagType : int {
135
JVM_FLAG_NON_STRING_TYPES_DO(JVM_FLAG_TYPE_DECLARE)
136
// The two string types are a bit irregular: is_ccstr() returns true for both types.
137
TYPE_ccstr,
138
TYPE_ccstrlist,
139
NUM_FLAG_TYPES
140
};
141
142
private:
143
void* _addr;
144
const char* _name;
145
Flags _flags;
146
int _type;
147
148
NOT_PRODUCT(const char* _doc;)
149
150
public:
151
// points to all Flags static array
152
static JVMFlag* flags;
153
154
// number of flags
155
static size_t numFlags;
156
157
private:
158
static JVMFlag* find_flag(const char* name, size_t length, bool allow_locked, bool return_flag);
159
160
public:
161
constexpr JVMFlag() : _addr(), _name(), _flags(), _type() NOT_PRODUCT(COMMA _doc()) {}
162
163
constexpr JVMFlag(int flag_enum, FlagType type, const char* name,
164
void* addr, int flags, int extra_flags, const char* doc);
165
166
constexpr JVMFlag(int flag_enum, FlagType type, const char* name,
167
void* addr, int flags, const char* doc);
168
169
static JVMFlag* find_flag(const char* name) {
170
return find_flag(name, strlen(name), false, false);
171
}
172
static JVMFlag* find_declared_flag(const char* name, size_t length) {
173
return find_flag(name, length, true, true);
174
}
175
static JVMFlag* find_declared_flag(const char* name) {
176
return find_declared_flag(name, strlen(name));
177
}
178
179
static JVMFlag* fuzzy_match(const char* name, size_t length, bool allow_locked = false);
180
181
static void assert_valid_flag_enum(JVMFlagsEnum i) NOT_DEBUG_RETURN;
182
static void check_all_flag_declarations() NOT_DEBUG_RETURN;
183
184
inline JVMFlagsEnum flag_enum() const {
185
JVMFlagsEnum i = static_cast<JVMFlagsEnum>(this - JVMFlag::flags);
186
assert_valid_flag_enum(i);
187
return i;
188
}
189
190
static JVMFlag* flag_from_enum(JVMFlagsEnum flag_enum) {
191
assert_valid_flag_enum(flag_enum);
192
return &JVMFlag::flags[flag_enum];
193
}
194
195
#define JVM_FLAG_TYPE_ACCESSOR(t) \
196
bool is_##t() const { return _type == TYPE_##t;} \
197
t get_##t() const { assert(is_##t(), "sanity"); return *((t*) _addr); }
198
199
JVM_FLAG_NON_STRING_TYPES_DO(JVM_FLAG_TYPE_ACCESSOR)
200
201
bool is_ccstr() const { return _type == TYPE_ccstr || _type == TYPE_ccstrlist; }
202
bool ccstr_accumulates() const { return _type == TYPE_ccstrlist; }
203
ccstr get_ccstr() const { assert(is_ccstr(), "sanity"); return *((ccstr*) _addr); }
204
void set_ccstr(ccstr value) { assert(is_ccstr(), "sanity"); *((ccstr*) _addr) = value; }
205
206
#define JVM_FLAG_AS_STRING(t) \
207
case TYPE_##t: return STR(t);
208
209
const char* type_string() const {
210
return type_string_for((FlagType)_type);
211
}
212
213
static const char* type_string_for(FlagType t) {
214
switch(t) {
215
JVM_FLAG_NON_STRING_TYPES_DO(JVM_FLAG_AS_STRING)
216
case TYPE_ccstr: return "ccstr";
217
case TYPE_ccstrlist: return "ccstrlist";
218
default:
219
ShouldNotReachHere();
220
return "unknown";
221
}
222
}
223
224
int type() const { return _type; }
225
const char* name() const { return _name; }
226
227
// Do not use JVMFlag::read() or JVMFlag::write() directly unless you know
228
// what you're doing. Use FLAG_SET_XXX macros or JVMFlagAccess instead.
229
template <typename T> T read() const {
230
assert_compatible_type<T>(_type);
231
return *static_cast<T*>(_addr);
232
}
233
234
template <typename T> void write(T value) {
235
assert_compatible_type<T>(_type);
236
*static_cast<T*>(_addr) = value;
237
}
238
239
JVMFlagOrigin get_origin() const { return JVMFlagOrigin(_flags & VALUE_ORIGIN_MASK); }
240
void set_origin(JVMFlagOrigin origin);
241
242
bool is_default() const { return (get_origin() == JVMFlagOrigin::DEFAULT); }
243
bool is_ergonomic() const { return (get_origin() == JVMFlagOrigin::ERGONOMIC); }
244
bool is_command_line() const { return (_flags & WAS_SET_ON_COMMAND_LINE) != 0; }
245
void set_command_line() { _flags = Flags(_flags | WAS_SET_ON_COMMAND_LINE); }
246
bool is_jimage_resource() const { return (get_origin() == JVMFlagOrigin::JIMAGE_RESOURCE); }
247
bool is_product() const { return (_flags & KIND_PRODUCT) != 0; }
248
bool is_manageable() const { return (_flags & KIND_MANAGEABLE) != 0; }
249
bool is_diagnostic() const { return (_flags & KIND_DIAGNOSTIC) != 0; }
250
bool is_experimental() const { return (_flags & KIND_EXPERIMENTAL) != 0; }
251
bool is_notproduct() const { return (_flags & KIND_NOT_PRODUCT) != 0; }
252
bool is_develop() const { return (_flags & KIND_DEVELOP) != 0; }
253
254
bool is_constant_in_binary() const;
255
256
bool is_unlocker() const;
257
bool is_unlocked() const;
258
259
// Only manageable flags can be accessed by writeableFlags.cpp
260
bool is_writeable() const { return is_manageable(); }
261
// All flags except "manageable" are assumed to be internal flags.
262
bool is_external() const { return is_manageable(); }
263
264
void clear_diagnostic();
265
void clear_experimental();
266
void set_product();
267
268
JVMFlag::MsgType get_locked_message(char*, int) const;
269
270
static bool is_default(JVMFlagsEnum flag);
271
static bool is_ergo(JVMFlagsEnum flag);
272
static bool is_cmdline(JVMFlagsEnum flag);
273
static bool is_jimage_resource(JVMFlagsEnum flag);
274
static void setOnCmdLine(JVMFlagsEnum flag);
275
276
277
// printRanges will print out flags type, name and range values as expected by -XX:+PrintFlagsRanges
278
void print_on(outputStream* st, bool withComments = false, bool printRanges = false) const;
279
void print_kind(outputStream* st, unsigned int width) const;
280
void print_origin(outputStream* st, unsigned int width) const;
281
void print_as_flag(outputStream* st) const;
282
283
static const char* flag_error_str(JVMFlag::Error error);
284
285
private:
286
// type checking - the following functions make sure you access *_addr as
287
// the correct type <T>
288
289
static void assert_valid_type_enum(int type_enum) {
290
assert(0 <= type_enum && type_enum < NUM_FLAG_TYPES, "sanity");
291
}
292
293
// The following computation is not universal, but should be correct
294
// for the limited number of types that can be stored inside a JVMFlag.
295
template <typename T>
296
static constexpr int type_signature() {
297
return int(sizeof(T)) |
298
(((std::is_integral<T>::value) ? 1 : 0) << 8) |
299
(((std::is_signed<T>::value) ? 1 : 0) << 9) |
300
(((std::is_pointer<T>::value) ? 1 : 0) << 10);
301
}
302
303
static const int type_signatures[];
304
305
public:
306
template <typename T>
307
static void assert_compatible_type(int type_enum) {
308
assert(is_compatible_type<T>(type_enum), "must be");
309
}
310
311
template <typename T>
312
static bool is_compatible_type(int type_enum) {
313
assert_valid_type_enum(type_enum);
314
return type_signatures[type_enum] == type_signature<T>();
315
}
316
317
public:
318
static void printSetFlags(outputStream* out);
319
320
// printRanges will print out flags type, name and range values as expected by -XX:+PrintFlagsRanges
321
static void printFlags(outputStream* out, bool withComments, bool printRanges = false, bool skipDefaults = false);
322
static void printError(bool verbose, const char* msg, ...) ATTRIBUTE_PRINTF(2, 3);
323
324
static void verify() PRODUCT_RETURN;
325
};
326
327
#define DECLARE_CONSTRAINT(type, func) JVMFlag::Error func(type value, bool verbose);
328
329
#endif // SHARE_RUNTIME_FLAGS_JVMFLAG_HPP
330
331