Skip to content

Commit 69f5235

Browse files
author
Kim Barrett
committed
8255596: Mutex safepoint checking options and flags should be scoped enums
Reviewed-by: tschatzl, rehn
1 parent d05df7c commit 69f5235

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

src/hotspot/share/runtime/mutex.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ void Mutex::check_safepoint_state(Thread* thread) {
5050
// If the JavaThread checks for safepoint, verify that the lock wasn't created with safepoint_check_never.
5151
if (thread->is_active_Java_thread()) {
5252
assert(_safepoint_check_required != _safepoint_check_never,
53-
"This lock should %s have a safepoint check for Java threads: %s",
54-
_safepoint_check_required ? "always" : "never", name());
53+
"This lock should never have a safepoint check for Java threads: %s",
54+
name());
5555

5656
// Also check NoSafepointVerifier, and thread state is _thread_in_vm
5757
thread->check_for_valid_safepoint_state();
@@ -65,8 +65,8 @@ void Mutex::check_safepoint_state(Thread* thread) {
6565
void Mutex::check_no_safepoint_state(Thread* thread) {
6666
check_block_state(thread);
6767
assert(!thread->is_active_Java_thread() || _safepoint_check_required != _safepoint_check_always,
68-
"This lock should %s have a safepoint check for Java threads: %s",
69-
_safepoint_check_required ? "always" : "never", name());
68+
"This lock should always have a safepoint check for Java threads: %s",
69+
name());
7070
}
7171
#endif // ASSERT
7272

src/hotspot/share/runtime/mutex.hpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,8 @@ class Mutex : public CHeapObj<mtSynchronizer> {
9999
void no_safepoint_verifier (Thread* thread, bool enable) NOT_DEBUG_RETURN;
100100

101101
public:
102-
enum {
103-
_allow_vm_block_flag = true,
104-
_as_suspend_equivalent_flag = true
105-
};
102+
static const bool _allow_vm_block_flag = true;
103+
static const bool _as_suspend_equivalent_flag = true;
106104

107105
// Locks can be acquired with or without a safepoint check. NonJavaThreads do not follow
108106
// the safepoint protocol when acquiring locks.
@@ -124,12 +122,17 @@ class Mutex : public CHeapObj<mtSynchronizer> {
124122
// deadlock can occur. We should check this by noting which
125123
// locks are shared, and walk held locks during safepoint checking.
126124

127-
enum SafepointCheckFlag {
125+
enum class SafepointCheckFlag {
128126
_safepoint_check_flag,
129127
_no_safepoint_check_flag
130128
};
129+
// Bring the enumerator names into class scope.
130+
static const SafepointCheckFlag _safepoint_check_flag =
131+
SafepointCheckFlag::_safepoint_check_flag;
132+
static const SafepointCheckFlag _no_safepoint_check_flag =
133+
SafepointCheckFlag::_no_safepoint_check_flag;
131134

132-
enum SafepointCheckRequired {
135+
enum class SafepointCheckRequired {
133136
_safepoint_check_never, // Mutexes with this value will cause errors
134137
// when acquired by a JavaThread with a safepoint check.
135138
_safepoint_check_sometimes, // A couple of special locks are acquired by JavaThreads sometimes
@@ -138,6 +141,13 @@ class Mutex : public CHeapObj<mtSynchronizer> {
138141
_safepoint_check_always // Mutexes with this value will cause errors
139142
// when acquired by a JavaThread without a safepoint check.
140143
};
144+
// Bring the enumerator names into class scope.
145+
static const SafepointCheckRequired _safepoint_check_never =
146+
SafepointCheckRequired::_safepoint_check_never;
147+
static const SafepointCheckRequired _safepoint_check_sometimes =
148+
SafepointCheckRequired::_safepoint_check_sometimes;
149+
static const SafepointCheckRequired _safepoint_check_always =
150+
SafepointCheckRequired::_safepoint_check_always;
141151

142152
NOT_PRODUCT(SafepointCheckRequired _safepoint_check_required;)
143153

src/hotspot/share/runtime/mutexLocker.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ class MutexUnlocker: StackObj {
298298
public:
299299
MutexUnlocker(Mutex* mutex, Mutex::SafepointCheckFlag flag = Mutex::_safepoint_check_flag) :
300300
_mutex(mutex),
301-
_no_safepoint_check(flag) {
301+
_no_safepoint_check(flag == Mutex::_no_safepoint_check_flag) {
302302
_mutex->unlock();
303303
}
304304

0 commit comments

Comments
 (0)