Skip to content

Commit b92214a

Browse files
committed
8272480: Remove Mutex::access rank
Reviewed-by: dholmes, eosterlund
1 parent 596b075 commit b92214a

File tree

5 files changed

+30
-34
lines changed

5 files changed

+30
-34
lines changed

src/hotspot/share/runtime/mutex.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ Mutex::Mutex(int Rank, const char * name, bool allow_vm_block,
287287

288288
assert(_rank > special || _safepoint_check_required == _safepoint_check_never,
289289
"Special locks or below should never safepoint");
290+
291+
assert(_rank >= 0, "Bad lock rank");
290292
#endif
291293
}
292294

@@ -364,7 +366,6 @@ Mutex* Mutex::get_least_ranked_lock_besides_this(Mutex* locks) {
364366

365367
// Tests for rank violations that might indicate exposure to deadlock.
366368
void Mutex::check_rank(Thread* thread) {
367-
assert(this->rank() >= 0, "bad lock rank");
368369
Mutex* locks_owned = thread->owned_locks();
369370

370371
if (!SafepointSynchronize::is_at_safepoint()) {

src/hotspot/share/runtime/mutex.hpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,12 @@
4242
class Mutex : public CHeapObj<mtSynchronizer> {
4343

4444
public:
45-
// A special lock: Is a lock where you are guaranteed not to block while you are
46-
// holding it, i.e., no vm operation can happen, taking other (blocking) locks, etc.
47-
// The rank 'access' is similar to 'special' and has the same restrictions on usage.
48-
// It is reserved for locks that may be required in order to perform memory accesses
49-
// that require special barriers, e.g. SATB GC barriers, that in turn uses locks.
50-
// The rank 'tty' is also similar to 'special' and has the same restrictions.
51-
// It is reserved for the tty_lock.
52-
// Since memory accesses should be able to be performed pretty much anywhere
53-
// in the code, that requires locks required for performing accesses being
54-
// inherently a bit more special than even locks of the 'special' rank.
55-
// NOTE: It is critical that the rank 'special' be the lowest (earliest)
56-
// (except for "event" and "access") for the deadlock detection to work correctly.
57-
// While at a safepoint no mutexes of rank safepoint are held by any thread.
58-
// The rank named "leaf" is probably historical (and should
59-
// be changed) -- mutexes of this rank aren't really leaf mutexes
60-
// at all.
45+
// Special low level locks are given names and ranges avoid overlap.
6146
enum lock_types {
6247
event,
63-
access = event + 1,
64-
service = access + 3,
65-
tty = service + 3,
48+
service = event + 3,
49+
stackwatermark = service + 3,
50+
tty = stackwatermark + 3,
6651
special = tty + 3,
6752
oopstorage = special + 3,
6853
leaf = oopstorage + 2,

src/hotspot/share/runtime/mutexLocker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void mutex_init() {
241241

242242
def(Patching_lock , PaddedMutex , special, true, _safepoint_check_never); // used for safepointing and code patching.
243243
def(CompiledMethod_lock , PaddedMutex , special-1, true, _safepoint_check_never);
244-
def(MonitorDeflation_lock , PaddedMonitor, tty-2, true, _safepoint_check_never); // used for monitor deflation thread operations
244+
def(MonitorDeflation_lock , PaddedMonitor, special, true, _safepoint_check_never); // used for monitor deflation thread operations
245245
def(Service_lock , PaddedMonitor, service, true, _safepoint_check_never); // used for service thread operations
246246

247247
if (UseNotificationThread) {
@@ -320,7 +320,7 @@ void mutex_init() {
320320
def(JfrMsg_lock , PaddedMonitor, leaf, true, _safepoint_check_always);
321321
def(JfrBuffer_lock , PaddedMutex , leaf, true, _safepoint_check_never);
322322
def(JfrStream_lock , PaddedMutex , nonleaf + 1, false, _safepoint_check_never);
323-
def(JfrStacktrace_lock , PaddedMutex , tty-2, true, _safepoint_check_never);
323+
def(JfrStacktrace_lock , PaddedMutex , stackwatermark-1, true, _safepoint_check_never);
324324
def(JfrThreadSampler_lock , PaddedMonitor, leaf, true, _safepoint_check_never);
325325
#endif
326326

src/hotspot/share/runtime/stackWatermark.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ StackWatermark::StackWatermark(JavaThread* jt, StackWatermarkKind kind, uint32_t
164164
_next(NULL),
165165
_jt(jt),
166166
_iterator(NULL),
167-
_lock(Mutex::tty - 1, "stack_watermark_lock", true, Mutex::_safepoint_check_never),
167+
_lock(Mutex::stackwatermark, "StackWatermark_lock", true, Mutex::_safepoint_check_never),
168168
_kind(kind),
169169
_linked_watermark(NULL) {
170170
}

test/hotspot/gtest/runtime/test_mutex.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,19 @@ TEST_VM_ASSERT_MSG(MutexRank, mutex_trylock_rank_out_of_orderB,
128128
mutex_rankA->unlock();
129129
}
130130

131-
TEST_VM_ASSERT_MSG(MutexRank, mutex_lock_access_leaf,
132-
".* Attempting to acquire lock mutex_rank_leaf/.* out of order with lock mutex_rank_access/1 "
131+
TEST_VM_ASSERT_MSG(MutexRank, mutex_lock_event_leaf,
132+
".* Attempting to acquire lock mutex_rank_leaf/.* out of order with lock mutex_rank_event/0 "
133133
"-- possible deadlock") {
134134
JavaThread* THREAD = JavaThread::current();
135135
ThreadInVMfromNative invm(THREAD);
136136

137-
Mutex* mutex_rank_access = new Mutex(Mutex::access, "mutex_rank_access", false, Mutex::_safepoint_check_never);
137+
Mutex* mutex_rank_event = new Mutex(Mutex::event, "mutex_rank_event", false, Mutex::_safepoint_check_never);
138138
Mutex* mutex_rank_leaf = new Mutex(Mutex::leaf, "mutex_rank_leaf", false, Mutex::_safepoint_check_never);
139139

140-
mutex_rank_access->lock_without_safepoint_check();
140+
mutex_rank_event->lock_without_safepoint_check();
141141
mutex_rank_leaf->lock_without_safepoint_check();
142142
mutex_rank_leaf->unlock();
143-
mutex_rank_access->unlock();
143+
mutex_rank_event->unlock();
144144
}
145145

146146
TEST_VM_ASSERT_MSG(MutexRank, mutex_lock_tty_special,
@@ -220,19 +220,19 @@ TEST_VM_ASSERT_MSG(MutexRank, monitor_wait_rank_special,
220220
monitor_rank_special->unlock();
221221
}
222222

223-
TEST_VM_ASSERT_MSG(MutexRank, monitor_wait_access_leaf,
224-
".* Attempting to wait on monitor monitor_rank_access/1 while holding lock monitor_rank_tty/.*"
223+
TEST_VM_ASSERT_MSG(MutexRank, monitor_wait_event_tty,
224+
".* Attempting to wait on monitor monitor_rank_event/0 while holding lock monitor_rank_tty/.*"
225225
"-- possible deadlock. Should not block\\(wait\\) while holding a lock of rank special.") {
226226
JavaThread* THREAD = JavaThread::current();
227227
ThreadInVMfromNative invm(THREAD);
228228

229229
Monitor* monitor_rank_tty = new Monitor(Mutex::tty, "monitor_rank_tty", false, Mutex::_safepoint_check_never);
230-
Monitor* monitor_rank_access = new Monitor(Mutex::access, "monitor_rank_access", false, Mutex::_safepoint_check_never);
230+
Monitor* monitor_rank_event = new Monitor(Mutex::event, "monitor_rank_event", false, Mutex::_safepoint_check_never);
231231

232232
monitor_rank_tty->lock_without_safepoint_check();
233-
monitor_rank_access->lock_without_safepoint_check();
234-
monitor_rank_access->wait_without_safepoint_check(1);
235-
monitor_rank_access->unlock();
233+
monitor_rank_event->lock_without_safepoint_check();
234+
monitor_rank_event->wait_without_safepoint_check(1);
235+
monitor_rank_event->unlock();
236236
monitor_rank_tty->unlock();
237237
}
238238

@@ -251,4 +251,14 @@ TEST_VM_ASSERT_MSG(MutexRank, monitor_wait_tty_special,
251251
monitor_rank_tty->unlock();
252252
monitor_rank_special->unlock();
253253
}
254+
255+
TEST_VM_ASSERT_MSG(MutexRank, monitor_negative_rank,
256+
".*Bad lock rank") {
257+
JavaThread* THREAD = JavaThread::current();
258+
ThreadInVMfromNative invm(THREAD);
259+
260+
Monitor* monitor_rank_broken = new Monitor(Mutex::event-1, "monitor_rank_broken", false, Mutex::_safepoint_check_never);
261+
monitor_rank_broken->lock_without_safepoint_check();
262+
monitor_rank_broken->unlock();
263+
}
254264
#endif // ASSERT

0 commit comments

Comments
 (0)