8255596: Mutex safepoint checking options and flags should be scoped enums

Reviewed-by: tschatzl, rehn
This commit is contained in:
Kim Barrett 2020-11-02 10:16:40 +00:00
parent d05df7c17a
commit 69f5235e16
3 changed files with 21 additions and 11 deletions
src/hotspot/share/runtime

@ -50,8 +50,8 @@ void Mutex::check_safepoint_state(Thread* thread) {
// If the JavaThread checks for safepoint, verify that the lock wasn't created with safepoint_check_never.
if (thread->is_active_Java_thread()) {
assert(_safepoint_check_required != _safepoint_check_never,
"This lock should %s have a safepoint check for Java threads: %s",
_safepoint_check_required ? "always" : "never", name());
"This lock should never have a safepoint check for Java threads: %s",
name());
// Also check NoSafepointVerifier, and thread state is _thread_in_vm
thread->check_for_valid_safepoint_state();
@ -65,8 +65,8 @@ void Mutex::check_safepoint_state(Thread* thread) {
void Mutex::check_no_safepoint_state(Thread* thread) {
check_block_state(thread);
assert(!thread->is_active_Java_thread() || _safepoint_check_required != _safepoint_check_always,
"This lock should %s have a safepoint check for Java threads: %s",
_safepoint_check_required ? "always" : "never", name());
"This lock should always have a safepoint check for Java threads: %s",
name());
}
#endif // ASSERT

@ -99,10 +99,8 @@ class Mutex : public CHeapObj<mtSynchronizer> {
void no_safepoint_verifier (Thread* thread, bool enable) NOT_DEBUG_RETURN;
public:
enum {
_allow_vm_block_flag = true,
_as_suspend_equivalent_flag = true
};
static const bool _allow_vm_block_flag = true;
static const bool _as_suspend_equivalent_flag = true;
// Locks can be acquired with or without a safepoint check. NonJavaThreads do not follow
// the safepoint protocol when acquiring locks.
@ -124,12 +122,17 @@ class Mutex : public CHeapObj<mtSynchronizer> {
// deadlock can occur. We should check this by noting which
// locks are shared, and walk held locks during safepoint checking.
enum SafepointCheckFlag {
enum class SafepointCheckFlag {
_safepoint_check_flag,
_no_safepoint_check_flag
};
// Bring the enumerator names into class scope.
static const SafepointCheckFlag _safepoint_check_flag =
SafepointCheckFlag::_safepoint_check_flag;
static const SafepointCheckFlag _no_safepoint_check_flag =
SafepointCheckFlag::_no_safepoint_check_flag;
enum SafepointCheckRequired {
enum class SafepointCheckRequired {
_safepoint_check_never, // Mutexes with this value will cause errors
// when acquired by a JavaThread with a safepoint check.
_safepoint_check_sometimes, // A couple of special locks are acquired by JavaThreads sometimes
@ -138,6 +141,13 @@ class Mutex : public CHeapObj<mtSynchronizer> {
_safepoint_check_always // Mutexes with this value will cause errors
// when acquired by a JavaThread without a safepoint check.
};
// Bring the enumerator names into class scope.
static const SafepointCheckRequired _safepoint_check_never =
SafepointCheckRequired::_safepoint_check_never;
static const SafepointCheckRequired _safepoint_check_sometimes =
SafepointCheckRequired::_safepoint_check_sometimes;
static const SafepointCheckRequired _safepoint_check_always =
SafepointCheckRequired::_safepoint_check_always;
NOT_PRODUCT(SafepointCheckRequired _safepoint_check_required;)

@ -298,7 +298,7 @@ class MutexUnlocker: StackObj {
public:
MutexUnlocker(Mutex* mutex, Mutex::SafepointCheckFlag flag = Mutex::_safepoint_check_flag) :
_mutex(mutex),
_no_safepoint_check(flag) {
_no_safepoint_check(flag == Mutex::_no_safepoint_check_flag) {
_mutex->unlock();
}