8183569: Assert the same limits are used in parse_xss and globals.hpp

Reviewed-by: stuefe, kbarrett
This commit is contained in:
Ioi Lam 2021-03-03 02:59:23 +00:00
parent 5de0f4b2ce
commit 044e2a2a49
4 changed files with 58 additions and 15 deletions

@ -44,6 +44,7 @@
#include "runtime/arguments.hpp"
#include "runtime/flags/jvmFlag.hpp"
#include "runtime/flags/jvmFlagAccess.hpp"
#include "runtime/flags/jvmFlagLimit.hpp"
#include "runtime/globals_extension.hpp"
#include "runtime/java.hpp"
#include "runtime/os.inline.hpp"
@ -2270,6 +2271,11 @@ jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* ou
const julong min_ThreadStackSize = 0;
const julong max_ThreadStackSize = 1 * M;
// Make sure the above values match the range set in globals.hpp
const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
const julong min_size = min_ThreadStackSize * K;
const julong max_size = max_ThreadStackSize * K;

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,6 +29,7 @@
#include "utilities/enumIterator.hpp"
#include "utilities/macros.hpp"
#include "utilities/vmEnums.hpp"
#include <type_traits>
class outputStream;
@ -290,6 +291,26 @@ public:
static const char* flag_error_str(JVMFlag::Error error);
// type checking
#define CHECK_COMPATIBLE(type) \
case TYPE_##type: \
assert(sizeof(T) == sizeof(type) && \
std::is_integral<T>::value == std::is_integral<type>::value && \
std::is_signed <T>::value == std::is_signed <type>::value, "must be"); \
break;
template <typename T>
static void assert_compatible_type(int type_enum) {
#ifndef PRODUCT
switch (type_enum) {
JVM_FLAG_NON_STRING_TYPES_DO(CHECK_COMPATIBLE);
default: ShouldNotReachHere();
}
#endif
}
#undef CHECK_COMPATIBLE
public:
static void printSetFlags(outputStream* out);

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -92,7 +92,7 @@ public:
// macro body starts here -------------------+
// |
// v
#define FLAG_LIMIT_DEFINE( type, name, ...) ); constexpr JVMTypedFlagLimit<type> limit_##name(0
#define FLAG_LIMIT_DEFINE( type, name, ...) ); constexpr JVMTypedFlagLimit<type> limit_##name(JVMFlag::TYPE_##type
#define FLAG_LIMIT_DEFINE_DUMMY(type, name, ...) ); constexpr DummyLimit nolimit_##name(0
#define FLAG_LIMIT_PTR( type, name, ...) ), LimitGetter<type>::get_limit(&limit_##name, 0
#define FLAG_LIMIT_PTR_NONE( type, name, ...) ), LimitGetter<type>::no_limit(0

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -50,6 +50,8 @@ typedef JVMFlag::Error (*JVMFlagConstraintFunc_size_t)(size_t value, bool verbos
typedef JVMFlag::Error (*JVMFlagConstraintFunc_double)(double value, bool verbose);
typedef JVMFlag::Error (*JVMFlagConstraintFunc_ccstr)(ccstr value, bool verbose);
template <typename T> class JVMTypedFlagLimit;
// A JVMFlagLimit is created for each JVMFlag that has a range() and/or constraint() in its declaration in
// the globals_xxx.hpp file.
//
@ -68,6 +70,10 @@ class JVMFlagLimit {
char _phase;
char _kind;
#ifdef ASSERT
int _type_enum;
#endif
static const JVMFlagLimit* const* flagLimits;
static JVMFlagsEnum _last_checked;
static JVMFlagConstraintPhase _validating_phase;
@ -97,7 +103,8 @@ public:
char phase() const { return _phase; }
char kind() const { return _kind; }
constexpr JVMFlagLimit(short func, short phase, short kind) : _constraint_func(func), _phase(phase), _kind(kind) {}
constexpr JVMFlagLimit(int type_enum, short func, short phase, short kind)
: _constraint_func(func), _phase(phase), _kind(kind) DEBUG_ONLY(COMMA _type_enum(type_enum)) {}
static const JVMFlagLimit* get_range(const JVMFlag* flag) {
return get_range_at(flag->flag_enum());
@ -130,6 +137,9 @@ public:
}
static JVMFlagConstraintPhase validating_phase() { return _validating_phase; }
template <typename T>
const JVMTypedFlagLimit<T>* cast() const;
};
enum ConstraintMarker {
@ -144,27 +154,33 @@ class JVMTypedFlagLimit : public JVMFlagLimit {
public:
// dummy - no range or constraint. This object will not be emitted into the .o file
// because we declare it as "const" but has no reference to it.
constexpr JVMTypedFlagLimit(int dummy) :
JVMFlagLimit(0, 0, 0), _min(0), _max(0) {}
constexpr JVMTypedFlagLimit(int type_enum) :
JVMFlagLimit(0, 0, 0, 0), _min(0), _max(0) {}
// range only
constexpr JVMTypedFlagLimit(int dummy, T min, T max) :
JVMFlagLimit(0, 0, HAS_RANGE), _min(min), _max(max) {}
constexpr JVMTypedFlagLimit(int type_enum, T min, T max) :
JVMFlagLimit(type_enum, 0, 0, HAS_RANGE), _min(min), _max(max) {}
// constraint only
constexpr JVMTypedFlagLimit(int dummy, ConstraintMarker dummy2, short func, int phase) :
JVMFlagLimit(func, phase, HAS_CONSTRAINT), _min(0), _max(0) {}
constexpr JVMTypedFlagLimit(int type_enum, ConstraintMarker dummy2, short func, int phase) :
JVMFlagLimit(type_enum, func, phase, HAS_CONSTRAINT), _min(0), _max(0) {}
// range and constraint
constexpr JVMTypedFlagLimit(int dummy, T min, T max, ConstraintMarker dummy2, short func, int phase) :
JVMFlagLimit(func, phase, HAS_RANGE | HAS_CONSTRAINT), _min(min), _max(max) {}
constexpr JVMTypedFlagLimit(int type_enum, T min, T max, ConstraintMarker dummy2, short func, int phase) :
JVMFlagLimit(type_enum, func, phase, HAS_RANGE | HAS_CONSTRAINT), _min(min), _max(max) {}
// constraint and range
constexpr JVMTypedFlagLimit(int dummy, ConstraintMarker dummy2, short func, int phase, T min, T max) :
JVMFlagLimit(func, phase, HAS_RANGE | HAS_CONSTRAINT), _min(min), _max(max) {}
constexpr JVMTypedFlagLimit(int type_enum, ConstraintMarker dummy2, short func, int phase, T min, T max) :
JVMFlagLimit(type_enum, func, phase, HAS_RANGE | HAS_CONSTRAINT), _min(min), _max(max) {}
T min() const { return _min; }
T max() const { return _max; }
};
template <typename T>
const JVMTypedFlagLimit<T>* JVMFlagLimit::cast() const {
DEBUG_ONLY(JVMFlag::assert_compatible_type<T>(_type_enum));
return static_cast<const JVMTypedFlagLimit<T>*>(this);
}
#endif // SHARE_RUNTIME_FLAGS_JVMFLAGLIMIT_HPP