Path: blob/master/src/hotspot/share/runtime/flags/jvmFlagLimit.hpp
40957 views
/*1* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_RUNTIME_FLAGS_JVMFLAGLIMIT_HPP25#define SHARE_RUNTIME_FLAGS_JVMFLAGLIMIT_HPP2627#include "runtime/flags/jvmFlag.hpp"2829class outputStream;30template <typename T> class JVMTypedFlagLimit;3132enum class JVMFlagConstraintPhase : int {33// Will be validated during argument processing (Arguments::parse_argument).34AtParse = 0,35// Will be validated inside Threads::create_vm(), right after Arguments::apply_ergo().36AfterErgo = 1,37// Will be validated inside universe_init(), right after Metaspace::global_initialize().38AfterMemoryInit = 239};404142typedef JVMFlag::Error (*JVMFlagConstraintFunc_bool)(bool value, bool verbose);43typedef JVMFlag::Error (*JVMFlagConstraintFunc_int)(int value, bool verbose);44typedef JVMFlag::Error (*JVMFlagConstraintFunc_intx)(intx value, bool verbose);45typedef JVMFlag::Error (*JVMFlagConstraintFunc_uint)(uint value, bool verbose);46typedef JVMFlag::Error (*JVMFlagConstraintFunc_uintx)(uintx value, bool verbose);47typedef JVMFlag::Error (*JVMFlagConstraintFunc_uint64_t)(uint64_t value, bool verbose);48typedef JVMFlag::Error (*JVMFlagConstraintFunc_size_t)(size_t value, bool verbose);49typedef JVMFlag::Error (*JVMFlagConstraintFunc_double)(double value, bool verbose);50typedef JVMFlag::Error (*JVMFlagConstraintFunc_ccstr)(ccstr value, bool verbose);5152template <typename T> class JVMTypedFlagLimit;5354// A JVMFlagLimit is created for each JVMFlag that has a range() and/or constraint() in its declaration in55// the globals_xxx.hpp file.56//57// To query the range information of a JVMFlag:58// JVMFlagLimit::get_range(JVMFlag*)59// JVMFlagLimit::get_range_at(int flag_enum)60// If the given flag doesn't have a range, NULL is returned.61//62// To query the constraint information of a JVMFlag:63// JVMFlagLimit::get_constraint(JVMFlag*)64// JVMFlagLimit::get_constraint_at(int flag_enum)65// If the given flag doesn't have a constraint, NULL is returned.6667class JVMFlagLimit {68short _constraint_func;69char _phase;70char _kind;7172#ifdef ASSERT73int _type_enum;74#endif7576static const JVMFlagLimit* const* flagLimits;77static JVMFlagsEnum _last_checked;78static JVMFlagConstraintPhase _validating_phase;7980protected:81static constexpr int HAS_RANGE = 1;82static constexpr int HAS_CONSTRAINT = 2;8384private:85static const JVMFlagLimit* get_kind_at(JVMFlagsEnum flag_enum, int required_kind) {86const JVMFlagLimit* limit = at(flag_enum);87if (limit != NULL && (limit->_kind & required_kind) != 0) {88_last_checked = flag_enum;89return limit;90} else {91return NULL;92}93}9495static const JVMFlagLimit* at(JVMFlagsEnum flag_enum) {96JVMFlag::assert_valid_flag_enum(flag_enum);97return flagLimits[static_cast<int>(flag_enum)];98}99100public:101void* constraint_func() const;102char phase() const { return _phase; }103char kind() const { return _kind; }104105constexpr JVMFlagLimit(int type_enum, short func, short phase, short kind)106: _constraint_func(func), _phase(phase), _kind(kind) DEBUG_ONLY(COMMA _type_enum(type_enum)) {}107108static const JVMFlagLimit* get_range(const JVMFlag* flag) {109return get_range_at(flag->flag_enum());110}111static const JVMFlagLimit* get_range_at(JVMFlagsEnum flag_enum) {112return get_kind_at(flag_enum, HAS_RANGE);113}114115static const JVMFlagLimit* get_constraint(const JVMFlag* flag) {116return get_constraint_at(flag->flag_enum());117}118static const JVMFlagLimit* get_constraint_at(JVMFlagsEnum flag_enum) {119return get_kind_at(flag_enum, HAS_CONSTRAINT);120}121122static const JVMFlag* last_checked_flag();123124// Is the current value of each JVM flag within the allowed range (if specified)125static bool check_all_ranges();126void print_range(outputStream* st, const JVMFlag* flag) const;127128// Does the current value of each JVM flag satisfy the specified constraint129static bool check_all_constraints(JVMFlagConstraintPhase phase);130131// If range/constraint checks fail, print verbose error messages only if we are parsing132// arguments from the command-line. Silently ignore any invalid values that are133// set programmatically via FLAG_SET_ERGO, etc.134static bool verbose_checks_needed() {135return _validating_phase == JVMFlagConstraintPhase::AtParse;136}137138static JVMFlagConstraintPhase validating_phase() { return _validating_phase; }139140template <typename T>141const JVMTypedFlagLimit<T>* cast() const;142};143144enum ConstraintMarker {145next_two_args_are_constraint,146};147148template <typename T>149class JVMTypedFlagLimit : public JVMFlagLimit {150const T _min;151const T _max;152153public:154// dummy - no range or constraint. This object will not be emitted into the .o file155// because we declare it as "const" but has no reference to it.156constexpr JVMTypedFlagLimit(int type_enum) :157JVMFlagLimit(0, 0, 0, 0), _min(0), _max(0) {}158159// range only160constexpr JVMTypedFlagLimit(int type_enum, T min, T max) :161JVMFlagLimit(type_enum, 0, 0, HAS_RANGE), _min(min), _max(max) {}162163// constraint only164constexpr JVMTypedFlagLimit(int type_enum, ConstraintMarker dummy2, short func, int phase) :165JVMFlagLimit(type_enum, func, phase, HAS_CONSTRAINT), _min(0), _max(0) {}166167// range and constraint168constexpr JVMTypedFlagLimit(int type_enum, T min, T max, ConstraintMarker dummy2, short func, int phase) :169JVMFlagLimit(type_enum, func, phase, HAS_RANGE | HAS_CONSTRAINT), _min(min), _max(max) {}170171// constraint and range172constexpr JVMTypedFlagLimit(int type_enum, ConstraintMarker dummy2, short func, int phase, T min, T max) :173JVMFlagLimit(type_enum, func, phase, HAS_RANGE | HAS_CONSTRAINT), _min(min), _max(max) {}174175T min() const { return _min; }176T max() const { return _max; }177};178179template <typename T>180const JVMTypedFlagLimit<T>* JVMFlagLimit::cast() const {181DEBUG_ONLY(JVMFlag::assert_compatible_type<T>(_type_enum));182return static_cast<const JVMTypedFlagLimit<T>*>(this);183}184185#endif // SHARE_RUNTIME_FLAGS_JVMFLAGLIMIT_HPP186187188