Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/runtime/flags/jvmFlagLimit.hpp
40957 views
1
/*
2
* Copyright (c) 2020, 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_JVMFLAGLIMIT_HPP
26
#define SHARE_RUNTIME_FLAGS_JVMFLAGLIMIT_HPP
27
28
#include "runtime/flags/jvmFlag.hpp"
29
30
class outputStream;
31
template <typename T> class JVMTypedFlagLimit;
32
33
enum class JVMFlagConstraintPhase : int {
34
// Will be validated during argument processing (Arguments::parse_argument).
35
AtParse = 0,
36
// Will be validated inside Threads::create_vm(), right after Arguments::apply_ergo().
37
AfterErgo = 1,
38
// Will be validated inside universe_init(), right after Metaspace::global_initialize().
39
AfterMemoryInit = 2
40
};
41
42
43
typedef JVMFlag::Error (*JVMFlagConstraintFunc_bool)(bool value, bool verbose);
44
typedef JVMFlag::Error (*JVMFlagConstraintFunc_int)(int value, bool verbose);
45
typedef JVMFlag::Error (*JVMFlagConstraintFunc_intx)(intx value, bool verbose);
46
typedef JVMFlag::Error (*JVMFlagConstraintFunc_uint)(uint value, bool verbose);
47
typedef JVMFlag::Error (*JVMFlagConstraintFunc_uintx)(uintx value, bool verbose);
48
typedef JVMFlag::Error (*JVMFlagConstraintFunc_uint64_t)(uint64_t value, bool verbose);
49
typedef JVMFlag::Error (*JVMFlagConstraintFunc_size_t)(size_t value, bool verbose);
50
typedef JVMFlag::Error (*JVMFlagConstraintFunc_double)(double value, bool verbose);
51
typedef JVMFlag::Error (*JVMFlagConstraintFunc_ccstr)(ccstr value, bool verbose);
52
53
template <typename T> class JVMTypedFlagLimit;
54
55
// A JVMFlagLimit is created for each JVMFlag that has a range() and/or constraint() in its declaration in
56
// the globals_xxx.hpp file.
57
//
58
// To query the range information of a JVMFlag:
59
// JVMFlagLimit::get_range(JVMFlag*)
60
// JVMFlagLimit::get_range_at(int flag_enum)
61
// If the given flag doesn't have a range, NULL is returned.
62
//
63
// To query the constraint information of a JVMFlag:
64
// JVMFlagLimit::get_constraint(JVMFlag*)
65
// JVMFlagLimit::get_constraint_at(int flag_enum)
66
// If the given flag doesn't have a constraint, NULL is returned.
67
68
class JVMFlagLimit {
69
short _constraint_func;
70
char _phase;
71
char _kind;
72
73
#ifdef ASSERT
74
int _type_enum;
75
#endif
76
77
static const JVMFlagLimit* const* flagLimits;
78
static JVMFlagsEnum _last_checked;
79
static JVMFlagConstraintPhase _validating_phase;
80
81
protected:
82
static constexpr int HAS_RANGE = 1;
83
static constexpr int HAS_CONSTRAINT = 2;
84
85
private:
86
static const JVMFlagLimit* get_kind_at(JVMFlagsEnum flag_enum, int required_kind) {
87
const JVMFlagLimit* limit = at(flag_enum);
88
if (limit != NULL && (limit->_kind & required_kind) != 0) {
89
_last_checked = flag_enum;
90
return limit;
91
} else {
92
return NULL;
93
}
94
}
95
96
static const JVMFlagLimit* at(JVMFlagsEnum flag_enum) {
97
JVMFlag::assert_valid_flag_enum(flag_enum);
98
return flagLimits[static_cast<int>(flag_enum)];
99
}
100
101
public:
102
void* constraint_func() const;
103
char phase() const { return _phase; }
104
char kind() const { return _kind; }
105
106
constexpr JVMFlagLimit(int type_enum, short func, short phase, short kind)
107
: _constraint_func(func), _phase(phase), _kind(kind) DEBUG_ONLY(COMMA _type_enum(type_enum)) {}
108
109
static const JVMFlagLimit* get_range(const JVMFlag* flag) {
110
return get_range_at(flag->flag_enum());
111
}
112
static const JVMFlagLimit* get_range_at(JVMFlagsEnum flag_enum) {
113
return get_kind_at(flag_enum, HAS_RANGE);
114
}
115
116
static const JVMFlagLimit* get_constraint(const JVMFlag* flag) {
117
return get_constraint_at(flag->flag_enum());
118
}
119
static const JVMFlagLimit* get_constraint_at(JVMFlagsEnum flag_enum) {
120
return get_kind_at(flag_enum, HAS_CONSTRAINT);
121
}
122
123
static const JVMFlag* last_checked_flag();
124
125
// Is the current value of each JVM flag within the allowed range (if specified)
126
static bool check_all_ranges();
127
void print_range(outputStream* st, const JVMFlag* flag) const;
128
129
// Does the current value of each JVM flag satisfy the specified constraint
130
static bool check_all_constraints(JVMFlagConstraintPhase phase);
131
132
// If range/constraint checks fail, print verbose error messages only if we are parsing
133
// arguments from the command-line. Silently ignore any invalid values that are
134
// set programmatically via FLAG_SET_ERGO, etc.
135
static bool verbose_checks_needed() {
136
return _validating_phase == JVMFlagConstraintPhase::AtParse;
137
}
138
139
static JVMFlagConstraintPhase validating_phase() { return _validating_phase; }
140
141
template <typename T>
142
const JVMTypedFlagLimit<T>* cast() const;
143
};
144
145
enum ConstraintMarker {
146
next_two_args_are_constraint,
147
};
148
149
template <typename T>
150
class JVMTypedFlagLimit : public JVMFlagLimit {
151
const T _min;
152
const T _max;
153
154
public:
155
// dummy - no range or constraint. This object will not be emitted into the .o file
156
// because we declare it as "const" but has no reference to it.
157
constexpr JVMTypedFlagLimit(int type_enum) :
158
JVMFlagLimit(0, 0, 0, 0), _min(0), _max(0) {}
159
160
// range only
161
constexpr JVMTypedFlagLimit(int type_enum, T min, T max) :
162
JVMFlagLimit(type_enum, 0, 0, HAS_RANGE), _min(min), _max(max) {}
163
164
// constraint only
165
constexpr JVMTypedFlagLimit(int type_enum, ConstraintMarker dummy2, short func, int phase) :
166
JVMFlagLimit(type_enum, func, phase, HAS_CONSTRAINT), _min(0), _max(0) {}
167
168
// range and constraint
169
constexpr JVMTypedFlagLimit(int type_enum, T min, T max, ConstraintMarker dummy2, short func, int phase) :
170
JVMFlagLimit(type_enum, func, phase, HAS_RANGE | HAS_CONSTRAINT), _min(min), _max(max) {}
171
172
// constraint and range
173
constexpr JVMTypedFlagLimit(int type_enum, ConstraintMarker dummy2, short func, int phase, T min, T max) :
174
JVMFlagLimit(type_enum, func, phase, HAS_RANGE | HAS_CONSTRAINT), _min(min), _max(max) {}
175
176
T min() const { return _min; }
177
T max() const { return _max; }
178
};
179
180
template <typename T>
181
const JVMTypedFlagLimit<T>* JVMFlagLimit::cast() const {
182
DEBUG_ONLY(JVMFlag::assert_compatible_type<T>(_type_enum));
183
return static_cast<const JVMTypedFlagLimit<T>*>(this);
184
}
185
186
#endif // SHARE_RUNTIME_FLAGS_JVMFLAGLIMIT_HPP
187
188