8272480: Remove Mutex::access rank

Reviewed-by: dholmes, eosterlund
This commit is contained in:
Coleen Phillimore 2021-08-27 13:51:39 +00:00
parent 596b075591
commit b92214a8d0
5 changed files with 30 additions and 34 deletions

View File

@ -287,6 +287,8 @@ Mutex::Mutex(int Rank, const char * name, bool allow_vm_block,
assert(_rank > special || _safepoint_check_required == _safepoint_check_never, assert(_rank > special || _safepoint_check_required == _safepoint_check_never,
"Special locks or below should never safepoint"); "Special locks or below should never safepoint");
assert(_rank >= 0, "Bad lock rank");
#endif #endif
} }
@ -364,7 +366,6 @@ Mutex* Mutex::get_least_ranked_lock_besides_this(Mutex* locks) {
// Tests for rank violations that might indicate exposure to deadlock. // Tests for rank violations that might indicate exposure to deadlock.
void Mutex::check_rank(Thread* thread) { void Mutex::check_rank(Thread* thread) {
assert(this->rank() >= 0, "bad lock rank");
Mutex* locks_owned = thread->owned_locks(); Mutex* locks_owned = thread->owned_locks();
if (!SafepointSynchronize::is_at_safepoint()) { if (!SafepointSynchronize::is_at_safepoint()) {

View File

@ -42,27 +42,12 @@
class Mutex : public CHeapObj<mtSynchronizer> { class Mutex : public CHeapObj<mtSynchronizer> {
public: public:
// A special lock: Is a lock where you are guaranteed not to block while you are // Special low level locks are given names and ranges avoid overlap.
// holding it, i.e., no vm operation can happen, taking other (blocking) locks, etc.
// The rank 'access' is similar to 'special' and has the same restrictions on usage.
// It is reserved for locks that may be required in order to perform memory accesses
// that require special barriers, e.g. SATB GC barriers, that in turn uses locks.
// The rank 'tty' is also similar to 'special' and has the same restrictions.
// It is reserved for the tty_lock.
// Since memory accesses should be able to be performed pretty much anywhere
// in the code, that requires locks required for performing accesses being
// inherently a bit more special than even locks of the 'special' rank.
// NOTE: It is critical that the rank 'special' be the lowest (earliest)
// (except for "event" and "access") for the deadlock detection to work correctly.
// While at a safepoint no mutexes of rank safepoint are held by any thread.
// The rank named "leaf" is probably historical (and should
// be changed) -- mutexes of this rank aren't really leaf mutexes
// at all.
enum lock_types { enum lock_types {
event, event,
access = event + 1, service = event + 3,
service = access + 3, stackwatermark = service + 3,
tty = service + 3, tty = stackwatermark + 3,
special = tty + 3, special = tty + 3,
oopstorage = special + 3, oopstorage = special + 3,
leaf = oopstorage + 2, leaf = oopstorage + 2,

View File

@ -241,7 +241,7 @@ void mutex_init() {
def(Patching_lock , PaddedMutex , special, true, _safepoint_check_never); // used for safepointing and code patching. def(Patching_lock , PaddedMutex , special, true, _safepoint_check_never); // used for safepointing and code patching.
def(CompiledMethod_lock , PaddedMutex , special-1, true, _safepoint_check_never); def(CompiledMethod_lock , PaddedMutex , special-1, true, _safepoint_check_never);
def(MonitorDeflation_lock , PaddedMonitor, tty-2, true, _safepoint_check_never); // used for monitor deflation thread operations def(MonitorDeflation_lock , PaddedMonitor, special, true, _safepoint_check_never); // used for monitor deflation thread operations
def(Service_lock , PaddedMonitor, service, true, _safepoint_check_never); // used for service thread operations def(Service_lock , PaddedMonitor, service, true, _safepoint_check_never); // used for service thread operations
if (UseNotificationThread) { if (UseNotificationThread) {
@ -320,7 +320,7 @@ void mutex_init() {
def(JfrMsg_lock , PaddedMonitor, leaf, true, _safepoint_check_always); def(JfrMsg_lock , PaddedMonitor, leaf, true, _safepoint_check_always);
def(JfrBuffer_lock , PaddedMutex , leaf, true, _safepoint_check_never); def(JfrBuffer_lock , PaddedMutex , leaf, true, _safepoint_check_never);
def(JfrStream_lock , PaddedMutex , nonleaf + 1, false, _safepoint_check_never); def(JfrStream_lock , PaddedMutex , nonleaf + 1, false, _safepoint_check_never);
def(JfrStacktrace_lock , PaddedMutex , tty-2, true, _safepoint_check_never); def(JfrStacktrace_lock , PaddedMutex , stackwatermark-1, true, _safepoint_check_never);
def(JfrThreadSampler_lock , PaddedMonitor, leaf, true, _safepoint_check_never); def(JfrThreadSampler_lock , PaddedMonitor, leaf, true, _safepoint_check_never);
#endif #endif

View File

@ -164,7 +164,7 @@ StackWatermark::StackWatermark(JavaThread* jt, StackWatermarkKind kind, uint32_t
_next(NULL), _next(NULL),
_jt(jt), _jt(jt),
_iterator(NULL), _iterator(NULL),
_lock(Mutex::tty - 1, "stack_watermark_lock", true, Mutex::_safepoint_check_never), _lock(Mutex::stackwatermark, "StackWatermark_lock", true, Mutex::_safepoint_check_never),
_kind(kind), _kind(kind),
_linked_watermark(NULL) { _linked_watermark(NULL) {
} }

View File

@ -128,19 +128,19 @@ TEST_VM_ASSERT_MSG(MutexRank, mutex_trylock_rank_out_of_orderB,
mutex_rankA->unlock(); mutex_rankA->unlock();
} }
TEST_VM_ASSERT_MSG(MutexRank, mutex_lock_access_leaf, TEST_VM_ASSERT_MSG(MutexRank, mutex_lock_event_leaf,
".* Attempting to acquire lock mutex_rank_leaf/.* out of order with lock mutex_rank_access/1 " ".* Attempting to acquire lock mutex_rank_leaf/.* out of order with lock mutex_rank_event/0 "
"-- possible deadlock") { "-- possible deadlock") {
JavaThread* THREAD = JavaThread::current(); JavaThread* THREAD = JavaThread::current();
ThreadInVMfromNative invm(THREAD); ThreadInVMfromNative invm(THREAD);
Mutex* mutex_rank_access = new Mutex(Mutex::access, "mutex_rank_access", false, Mutex::_safepoint_check_never); Mutex* mutex_rank_event = new Mutex(Mutex::event, "mutex_rank_event", false, Mutex::_safepoint_check_never);
Mutex* mutex_rank_leaf = new Mutex(Mutex::leaf, "mutex_rank_leaf", false, Mutex::_safepoint_check_never); Mutex* mutex_rank_leaf = new Mutex(Mutex::leaf, "mutex_rank_leaf", false, Mutex::_safepoint_check_never);
mutex_rank_access->lock_without_safepoint_check(); mutex_rank_event->lock_without_safepoint_check();
mutex_rank_leaf->lock_without_safepoint_check(); mutex_rank_leaf->lock_without_safepoint_check();
mutex_rank_leaf->unlock(); mutex_rank_leaf->unlock();
mutex_rank_access->unlock(); mutex_rank_event->unlock();
} }
TEST_VM_ASSERT_MSG(MutexRank, mutex_lock_tty_special, TEST_VM_ASSERT_MSG(MutexRank, mutex_lock_tty_special,
@ -220,19 +220,19 @@ TEST_VM_ASSERT_MSG(MutexRank, monitor_wait_rank_special,
monitor_rank_special->unlock(); monitor_rank_special->unlock();
} }
TEST_VM_ASSERT_MSG(MutexRank, monitor_wait_access_leaf, TEST_VM_ASSERT_MSG(MutexRank, monitor_wait_event_tty,
".* Attempting to wait on monitor monitor_rank_access/1 while holding lock monitor_rank_tty/.*" ".* Attempting to wait on monitor monitor_rank_event/0 while holding lock monitor_rank_tty/.*"
"-- possible deadlock. Should not block\\(wait\\) while holding a lock of rank special.") { "-- possible deadlock. Should not block\\(wait\\) while holding a lock of rank special.") {
JavaThread* THREAD = JavaThread::current(); JavaThread* THREAD = JavaThread::current();
ThreadInVMfromNative invm(THREAD); ThreadInVMfromNative invm(THREAD);
Monitor* monitor_rank_tty = new Monitor(Mutex::tty, "monitor_rank_tty", false, Mutex::_safepoint_check_never); Monitor* monitor_rank_tty = new Monitor(Mutex::tty, "monitor_rank_tty", false, Mutex::_safepoint_check_never);
Monitor* monitor_rank_access = new Monitor(Mutex::access, "monitor_rank_access", false, Mutex::_safepoint_check_never); Monitor* monitor_rank_event = new Monitor(Mutex::event, "monitor_rank_event", false, Mutex::_safepoint_check_never);
monitor_rank_tty->lock_without_safepoint_check(); monitor_rank_tty->lock_without_safepoint_check();
monitor_rank_access->lock_without_safepoint_check(); monitor_rank_event->lock_without_safepoint_check();
monitor_rank_access->wait_without_safepoint_check(1); monitor_rank_event->wait_without_safepoint_check(1);
monitor_rank_access->unlock(); monitor_rank_event->unlock();
monitor_rank_tty->unlock(); monitor_rank_tty->unlock();
} }
@ -251,4 +251,14 @@ TEST_VM_ASSERT_MSG(MutexRank, monitor_wait_tty_special,
monitor_rank_tty->unlock(); monitor_rank_tty->unlock();
monitor_rank_special->unlock(); monitor_rank_special->unlock();
} }
TEST_VM_ASSERT_MSG(MutexRank, monitor_negative_rank,
".*Bad lock rank") {
JavaThread* THREAD = JavaThread::current();
ThreadInVMfromNative invm(THREAD);
Monitor* monitor_rank_broken = new Monitor(Mutex::event-1, "monitor_rank_broken", false, Mutex::_safepoint_check_never);
monitor_rank_broken->lock_without_safepoint_check();
monitor_rank_broken->unlock();
}
#endif // ASSERT #endif // ASSERT