Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/runtime/flags/jvmFlagAccess.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_JVMFLAGACCESS_HPP
26
#define SHARE_RUNTIME_FLAGS_JVMFLAGACCESS_HPP
27
28
#include "memory/allStatic.hpp"
29
#include "runtime/flags/jvmFlag.hpp"
30
#include "utilities/vmEnums.hpp"
31
32
class FlagAccessImpl;
33
class JVMFlagLimit;
34
class outputStream;
35
36
// Use this macro in combination with JVMFlag::{read, write} and JVMFlagAccess::{get, set}
37
// to safely access the underlying variable of a JVMFlag:
38
//
39
// JVMFlag* flag = JVMFlag::flag_from_enum(FLAG_MEMBER_ENUM(ObjectAlignmentInBytes));
40
//
41
// /* If you use a wrong type, a run-time assertion will happen */
42
// intx v = flag->read<intx>();
43
//
44
// /* If you use a wrong type, or a NULL flag, an error code is returned */
45
// JVMFlag::Error err = JVMFlagAccess::get<JVM_FLAG_TYPE(intx)>(flag, &v, origin);
46
47
#define JVM_FLAG_TYPE(t) \
48
t, JVMFlag::TYPE_ ## t
49
50
// This class provides a unified interface for getting/setting the JVM flags, with support
51
// for (1) type correctness checks, (2) range checks, (3) constraint checks. Two main types
52
// of setters are provided. See notes below on which one to use.
53
class JVMFlagAccess : AllStatic {
54
inline static const FlagAccessImpl* access_impl(const JVMFlag* flag);
55
static JVMFlag::Error set_impl(JVMFlag* flag, void* value, JVMFlagOrigin origin);
56
static JVMFlag::Error set_or_assert(JVMFlagsEnum flag_enum, int type_enum, void* value, JVMFlagOrigin origin);
57
58
static bool is_correct_type(const JVMFlag* flag, int type_enum) {
59
if (type_enum == JVMFlag::TYPE_ccstr) {
60
if (!flag->is_ccstr()) { // ccstr or ccstrlist
61
return false;
62
}
63
} else {
64
if (flag->type() != type_enum) {
65
return false;
66
}
67
}
68
return true;
69
}
70
71
public:
72
static JVMFlag::Error check_range(const JVMFlag* flag, bool verbose);
73
static JVMFlag::Error check_constraint(const JVMFlag* flag, void * func, bool verbose);
74
static void print_range(outputStream* st, const JVMFlag* flag, const JVMFlagLimit* range);
75
static void print_range(outputStream* st, const JVMFlag* flag);
76
77
template <typename T, int type_enum>
78
static JVMFlag::Error get(const JVMFlag* flag, T* value) {
79
// The caller must not not mix incompatible types such as
80
// set<double, JVMFlag::TYPE_int>(flag, double_ptr);
81
assert(JVMFlag::is_compatible_type<T>(type_enum), "must be");
82
83
if (flag == NULL) {
84
return JVMFlag::INVALID_FLAG;
85
}
86
if (!is_correct_type(flag, type_enum)) {
87
return JVMFlag::WRONG_FORMAT;
88
}
89
90
*value = flag->read<T>();
91
return JVMFlag::SUCCESS;
92
}
93
94
// This is a *flag specific* setter. It should be used only via by the
95
// FLAG_SET_{DEFAULT, CMDLINE, ERGO, MGMT} macros.
96
// It's used to set a specific flag whose type is statically known. A mismatched
97
// type_enum will result in an assert.
98
template <typename T, int type_enum>
99
static JVMFlag::Error set(JVMFlagsEnum flag_enum, T value, JVMFlagOrigin origin) {
100
return set_or_assert(flag_enum, type_enum, &value, origin);
101
}
102
103
// This is a *generic* setter. It should be used by code that can set a number of different
104
// flags, often according to external input that may contain errors.
105
// Examples callers are arguments.cpp, writeableFlags.cpp, and WB_SetXxxVMFlag functions.
106
// A mismatched type_enum would result in a JVMFlag::WRONG_FORMAT code.
107
template <typename T, int type_enum>
108
static JVMFlag::Error set(JVMFlag* flag, T* value, JVMFlagOrigin origin) {
109
// The caller must not not mix incompatible types such as
110
// set<double, JVMFlag::TYPE_int>(flag, double_ptr);
111
assert(JVMFlag::is_compatible_type<T>(type_enum), "must be");
112
113
if (flag == NULL) {
114
return JVMFlag::INVALID_FLAG;
115
}
116
if (!is_correct_type(flag, type_enum)) {
117
return JVMFlag::WRONG_FORMAT;
118
}
119
120
return set_impl(flag, (void*)value, origin);
121
}
122
123
// Special handling needed for ccstr
124
// Contract: JVMFlag will make private copy of the incoming value.
125
// Outgoing value is always malloc-ed, and caller MUST call free.
126
static JVMFlag::Error set_ccstr(JVMFlag* flag, ccstr* value, JVMFlagOrigin origin);
127
128
// Handy aliases
129
static JVMFlag::Error get_ccstr(const JVMFlag* flag, ccstr* value) {
130
return get<JVM_FLAG_TYPE(ccstr)>(flag, value);
131
}
132
133
static JVMFlag::Error set_bool (JVMFlag* f, bool* v, JVMFlagOrigin origin) { return set<JVM_FLAG_TYPE(bool)> (f, v, origin); }
134
static JVMFlag::Error set_int (JVMFlag* f, int* v, JVMFlagOrigin origin) { return set<JVM_FLAG_TYPE(int)> (f, v, origin); }
135
static JVMFlag::Error set_uint (JVMFlag* f, uint* v, JVMFlagOrigin origin) { return set<JVM_FLAG_TYPE(uint)> (f, v, origin); }
136
static JVMFlag::Error set_intx (JVMFlag* f, intx* v, JVMFlagOrigin origin) { return set<JVM_FLAG_TYPE(intx)> (f, v, origin); }
137
static JVMFlag::Error set_uintx (JVMFlag* f, uintx* v, JVMFlagOrigin origin) { return set<JVM_FLAG_TYPE(uintx)> (f, v, origin); }
138
static JVMFlag::Error set_uint64_t(JVMFlag* f, uint64_t* v, JVMFlagOrigin origin) { return set<JVM_FLAG_TYPE(uint64_t)>(f, v, origin); }
139
static JVMFlag::Error set_size_t (JVMFlag* f, size_t* v, JVMFlagOrigin origin) { return set<JVM_FLAG_TYPE(size_t)> (f, v, origin); }
140
static JVMFlag::Error set_double (JVMFlag* f, double* v, JVMFlagOrigin origin) { return set<JVM_FLAG_TYPE(double)> (f, v, origin); }
141
};
142
143
#endif // SHARE_RUNTIME_FLAGS_JVMFLAGACCESS_HPP
144
145