Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/runtime/flags/jvmFlagLimit.cpp
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
#include "precompiled.hpp"
26
#include "memory/allocation.inline.hpp"
27
#include "gc/shared/jvmFlagConstraintsGC.hpp"
28
#include "runtime/flags/jvmFlag.hpp"
29
#include "runtime/flags/jvmFlagAccess.hpp"
30
#include "runtime/flags/jvmFlagLimit.hpp"
31
#include "runtime/flags/jvmFlagConstraintsCompiler.hpp"
32
#include "runtime/flags/jvmFlagConstraintsRuntime.hpp"
33
#include "runtime/globals_extension.hpp"
34
#include "gc/shared/referenceProcessor.hpp"
35
#include "oops/markWord.hpp"
36
#include "runtime/task.hpp"
37
38
//----------------------------------------------------------------------
39
// Build flagLimitTable[]
40
41
#define CONSTRAINT_ENUM(func) constraint_enum_ ## func
42
#define CONSTRAINT_ENUM_(type, func) CONSTRAINT_ENUM(func),
43
#define CONSTRAINT_FUNC(type, func) (void*)&func,
44
45
enum JVMFlagConstraintsEnum : int {
46
ALL_CONSTRAINTS(CONSTRAINT_ENUM_)
47
NUM_JVMFlagConstraintsEnum
48
};
49
50
static void* const flagConstraintTable[NUM_JVMFlagConstraintsEnum] = {
51
ALL_CONSTRAINTS(CONSTRAINT_FUNC)
52
};
53
54
void* JVMFlagLimit::constraint_func() const {
55
int i = _constraint_func;
56
assert(0 <= i && i < NUM_JVMFlagConstraintsEnum, "sanity");
57
return flagConstraintTable[i];
58
}
59
60
struct DummyLimit {
61
char dummy;
62
constexpr DummyLimit(...) : dummy() {}
63
};
64
65
template <typename T>
66
class LimitGetter {
67
public:
68
// These functions return NULL for develop flags in a PRODUCT build
69
static constexpr const JVMFlagLimit* no_limit(...) {
70
return NULL;
71
}
72
73
// This is for flags that have neither range no constraint. We don't need the JVMFlagLimit struct.
74
static constexpr const JVMFlagLimit* get_limit(const JVMTypedFlagLimit<T>* p, int dummy) {
75
return NULL;
76
}
77
78
static constexpr const JVMFlagLimit* get_limit(const JVMTypedFlagLimit<T>* p, int dummy, T min, T max) {
79
return p;
80
}
81
static constexpr const JVMFlagLimit* get_limit(const JVMTypedFlagLimit<T>* p, int dummy, ConstraintMarker dummy2, short func, int phase) {
82
return p;
83
}
84
static constexpr const JVMFlagLimit* get_limit(const JVMTypedFlagLimit<T>* p, int dummy, T min, T max, ConstraintMarker dummy2, short func, int phase) {
85
return p;
86
}
87
static constexpr const JVMFlagLimit* get_limit(const JVMTypedFlagLimit<T>* p, int dummy, ConstraintMarker dummy2, short func, int phase, T min, T max) {
88
return p;
89
}
90
};
91
92
// macro body starts here -------------------+
93
// |
94
// v
95
#define FLAG_LIMIT_DEFINE( type, name, ...) ); constexpr JVMTypedFlagLimit<type> limit_##name(JVMFlag::TYPE_##type
96
#define FLAG_LIMIT_DEFINE_DUMMY(type, name, ...) ); constexpr DummyLimit nolimit_##name(0
97
#define FLAG_LIMIT_PTR( type, name, ...) ), LimitGetter<type>::get_limit(&limit_##name, 0
98
#define FLAG_LIMIT_PTR_NONE( type, name, ...) ), LimitGetter<type>::no_limit(0
99
#define APPLY_FLAG_RANGE(...) , __VA_ARGS__
100
#define APPLY_FLAG_CONSTRAINT(func, phase) , next_two_args_are_constraint, (short)CONSTRAINT_ENUM(func), int(JVMFlagConstraintPhase::phase)
101
102
constexpr JVMTypedFlagLimit<int> limit_dummy
103
(
104
#ifdef PRODUCT
105
ALL_FLAGS(FLAG_LIMIT_DEFINE_DUMMY,
106
FLAG_LIMIT_DEFINE_DUMMY,
107
FLAG_LIMIT_DEFINE,
108
FLAG_LIMIT_DEFINE,
109
FLAG_LIMIT_DEFINE_DUMMY,
110
APPLY_FLAG_RANGE,
111
APPLY_FLAG_CONSTRAINT)
112
#else
113
ALL_FLAGS(FLAG_LIMIT_DEFINE,
114
FLAG_LIMIT_DEFINE,
115
FLAG_LIMIT_DEFINE,
116
FLAG_LIMIT_DEFINE,
117
FLAG_LIMIT_DEFINE,
118
APPLY_FLAG_RANGE,
119
APPLY_FLAG_CONSTRAINT)
120
#endif
121
);
122
123
static constexpr const JVMFlagLimit* const flagLimitTable[1 + NUM_JVMFlagsEnum] = {
124
// Because FLAG_LIMIT_PTR must start with an "),", we have to place a dummy element here.
125
LimitGetter<int>::get_limit(NULL, 0
126
127
#ifdef PRODUCT
128
ALL_FLAGS(FLAG_LIMIT_PTR_NONE,
129
FLAG_LIMIT_PTR_NONE,
130
FLAG_LIMIT_PTR,
131
FLAG_LIMIT_PTR,
132
FLAG_LIMIT_PTR_NONE,
133
APPLY_FLAG_RANGE,
134
APPLY_FLAG_CONSTRAINT)
135
#else
136
ALL_FLAGS(FLAG_LIMIT_PTR,
137
FLAG_LIMIT_PTR,
138
FLAG_LIMIT_PTR,
139
FLAG_LIMIT_PTR,
140
FLAG_LIMIT_PTR,
141
APPLY_FLAG_RANGE,
142
APPLY_FLAG_CONSTRAINT)
143
#endif
144
)
145
};
146
147
JVMFlagsEnum JVMFlagLimit::_last_checked = INVALID_JVMFlagsEnum;
148
JVMFlagConstraintPhase JVMFlagLimit::_validating_phase = JVMFlagConstraintPhase::AtParse;
149
150
const JVMFlagLimit* const* JVMFlagLimit::flagLimits = &flagLimitTable[1]; // excludes dummy
151
152
const JVMFlag* JVMFlagLimit::last_checked_flag() {
153
if (_last_checked != INVALID_JVMFlagsEnum) {
154
return JVMFlag::flag_from_enum(_last_checked);
155
} else {
156
return NULL;
157
}
158
}
159
160
bool JVMFlagLimit::check_all_ranges() {
161
bool status = true;
162
for (int i = 0; i < NUM_JVMFlagsEnum; i++) {
163
JVMFlagsEnum flag_enum = static_cast<JVMFlagsEnum>(i);
164
if (get_range_at(flag_enum) != NULL &&
165
JVMFlagAccess::check_range(JVMFlag::flag_from_enum(flag_enum), true) != JVMFlag::SUCCESS) {
166
status = false;
167
}
168
}
169
return status;
170
}
171
172
// Check constraints for specific constraint phase.
173
bool JVMFlagLimit::check_all_constraints(JVMFlagConstraintPhase phase) {
174
guarantee(phase > _validating_phase, "Constraint check is out of order.");
175
_validating_phase = phase;
176
177
bool status = true;
178
for (int i = 0; i < NUM_JVMFlagsEnum; i++) {
179
JVMFlagsEnum flag_enum = static_cast<JVMFlagsEnum>(i);
180
const JVMFlagLimit* constraint = get_constraint_at(flag_enum);
181
if (constraint != NULL && constraint->phase() == static_cast<int>(phase) &&
182
JVMFlagAccess::check_constraint(JVMFlag::flag_from_enum(flag_enum),
183
constraint->constraint_func(), true) != JVMFlag::SUCCESS) {
184
status = false;
185
}
186
}
187
return status;
188
}
189
190
void JVMFlagLimit::print_range(outputStream* st, const JVMFlag* flag) const {
191
JVMFlagAccess::print_range(st, flag, this);
192
}
193
194