33
33
#include " utilities/macros.hpp"
34
34
35
35
#ifdef ASSERT
36
- void Monitor ::check_safepoint_state (Thread* thread, bool do_safepoint_check) {
36
+ void Mutex ::check_safepoint_state (Thread* thread, bool do_safepoint_check) {
37
37
// If the JavaThread checks for safepoint, verify that the lock wasn't created with safepoint_check_never.
38
- SafepointCheckRequired not_allowed = do_safepoint_check ? Monitor ::_safepoint_check_never :
39
- Monitor ::_safepoint_check_always;
38
+ SafepointCheckRequired not_allowed = do_safepoint_check ? Mutex ::_safepoint_check_never :
39
+ Mutex ::_safepoint_check_always;
40
40
assert (!thread->is_active_Java_thread () || _safepoint_check_required != not_allowed,
41
41
" This lock should %s have a safepoint check for Java threads: %s" ,
42
42
_safepoint_check_required ? " always" : " never" , name ());
43
43
44
44
// If defined with safepoint_check_never, a NonJavaThread should never ask to safepoint check either.
45
- assert (thread->is_Java_thread () || !do_safepoint_check || _safepoint_check_required != Monitor ::_safepoint_check_never,
45
+ assert (thread->is_Java_thread () || !do_safepoint_check || _safepoint_check_required != Mutex ::_safepoint_check_never,
46
46
" NonJavaThread should not check for safepoint" );
47
47
}
48
48
#endif // ASSERT
49
49
50
- void Monitor ::lock (Thread * self) {
50
+ void Mutex ::lock (Thread * self) {
51
51
check_safepoint_state (self, true );
52
52
53
53
DEBUG_ONLY (check_prelock_state (self, true ));
54
54
assert (_owner != self, " invariant" );
55
55
56
- Monitor* in_flight_monitor = NULL ;
56
+ Mutex* in_flight_mutex = NULL ;
57
57
DEBUG_ONLY (int retry_cnt = 0 ;)
58
58
bool is_active_Java_thread = self->is_active_Java_thread ();
59
59
while (!_lock.try_lock ()) {
@@ -62,18 +62,18 @@ void Monitor::lock(Thread * self) {
62
62
#ifdef ASSERT
63
63
check_block_state (self);
64
64
if (retry_cnt++ > 3 ) {
65
- log_trace (vmmonitor )(" JavaThread " INTPTR_FORMAT " on %d attempt trying to acquire vmmonitor %s" , p2i (self), retry_cnt, _name);
65
+ log_trace (vmmutex )(" JavaThread " INTPTR_FORMAT " on %d attempt trying to acquire vmmutex %s" , p2i (self), retry_cnt, _name);
66
66
}
67
67
#endif // ASSERT
68
68
69
69
// Is it a JavaThread participating in the safepoint protocol.
70
70
if (is_active_Java_thread) {
71
71
assert (rank () > Mutex::special, " Potential deadlock with special or lesser rank mutex" );
72
- { ThreadBlockInVMWithDeadlockCheck tbivmdc ((JavaThread *) self, &in_flight_monitor );
73
- in_flight_monitor = this ; // save for ~ThreadBlockInVMWithDeadlockCheck
72
+ { ThreadBlockInVMWithDeadlockCheck tbivmdc ((JavaThread *) self, &in_flight_mutex );
73
+ in_flight_mutex = this ; // save for ~ThreadBlockInVMWithDeadlockCheck
74
74
_lock.lock ();
75
75
}
76
- if (in_flight_monitor != NULL ) {
76
+ if (in_flight_mutex != NULL ) {
77
77
// Not unlocked by ~ThreadBlockInVMWithDeadlockCheck
78
78
break ;
79
79
}
@@ -87,7 +87,7 @@ void Monitor::lock(Thread * self) {
87
87
set_owner (self);
88
88
}
89
89
90
- void Monitor ::lock () {
90
+ void Mutex ::lock () {
91
91
this ->lock (Thread::current ());
92
92
}
93
93
@@ -97,22 +97,22 @@ void Monitor::lock() {
97
97
// safepoint-safe and so will prevent a safepoint from being reached. If used
98
98
// in the wrong way this can lead to a deadlock with the safepoint code.
99
99
100
- void Monitor ::lock_without_safepoint_check (Thread * self) {
100
+ void Mutex ::lock_without_safepoint_check (Thread * self) {
101
101
check_safepoint_state (self, false );
102
102
assert (_owner != self, " invariant" );
103
103
_lock.lock ();
104
104
assert_owner (NULL );
105
105
set_owner (self);
106
106
}
107
107
108
- void Monitor ::lock_without_safepoint_check () {
108
+ void Mutex ::lock_without_safepoint_check () {
109
109
lock_without_safepoint_check (Thread::current ());
110
110
}
111
111
112
112
113
113
// Returns true if thread succeeds in grabbing the lock, otherwise false.
114
114
115
- bool Monitor ::try_lock () {
115
+ bool Mutex ::try_lock () {
116
116
Thread * const self = Thread::current ();
117
117
DEBUG_ONLY (check_prelock_state (self, false );)
118
118
@@ -124,12 +124,12 @@ bool Monitor::try_lock() {
124
124
return false ;
125
125
}
126
126
127
- void Monitor ::release_for_safepoint () {
127
+ void Mutex ::release_for_safepoint () {
128
128
assert_owner (NULL );
129
129
_lock.unlock ();
130
130
}
131
131
132
- void Monitor ::unlock () {
132
+ void Mutex ::unlock () {
133
133
assert_owner (Thread::current ());
134
134
set_owner (NULL );
135
135
_lock.unlock ();
@@ -147,7 +147,7 @@ void Monitor::notify_all() {
147
147
148
148
#ifdef ASSERT
149
149
void Monitor::assert_wait_lock_state (Thread* self) {
150
- Monitor * least = get_least_ranked_lock_besides_this (self->owned_locks ());
150
+ Mutex * least = get_least_ranked_lock_besides_this (self->owned_locks ());
151
151
assert (least != this , " Specification of get_least_... call above" );
152
152
if (least != NULL && least->rank () <= special) {
153
153
::tty->print (" Attempting to wait on monitor %s/%d while holding"
@@ -194,10 +194,10 @@ bool Monitor::wait(long timeout, bool as_suspend_equivalent) {
194
194
// abdicating the lock in wait
195
195
set_owner (NULL );
196
196
JavaThread *jt = (JavaThread *)self;
197
- Monitor* in_flight_monitor = NULL ;
197
+ Mutex* in_flight_mutex = NULL ;
198
198
199
199
{
200
- ThreadBlockInVMWithDeadlockCheck tbivmdc (jt, &in_flight_monitor );
200
+ ThreadBlockInVMWithDeadlockCheck tbivmdc (jt, &in_flight_mutex );
201
201
OSThreadWaitState osts (self->osthread (), false /* not Object.wait() */ );
202
202
if (as_suspend_equivalent) {
203
203
jt->set_suspend_equivalent ();
@@ -206,7 +206,7 @@ bool Monitor::wait(long timeout, bool as_suspend_equivalent) {
206
206
}
207
207
208
208
wait_status = _lock.wait (timeout);
209
- in_flight_monitor = this ; // save for ~ThreadBlockInVMWithDeadlockCheck
209
+ in_flight_mutex = this ; // save for ~ThreadBlockInVMWithDeadlockCheck
210
210
211
211
// were we externally suspended while we were waiting?
212
212
if (as_suspend_equivalent && jt->handle_special_suspend_equivalent_condition ()) {
@@ -220,7 +220,7 @@ bool Monitor::wait(long timeout, bool as_suspend_equivalent) {
220
220
}
221
221
}
222
222
223
- if (in_flight_monitor != NULL ) {
223
+ if (in_flight_mutex != NULL ) {
224
224
// Not unlocked by ~ThreadBlockInVMWithDeadlockCheck
225
225
assert_owner (NULL );
226
226
// Conceptually reestablish ownership of the lock.
@@ -232,7 +232,7 @@ bool Monitor::wait(long timeout, bool as_suspend_equivalent) {
232
232
return wait_status != 0 ; // return true IFF timeout
233
233
}
234
234
235
- Monitor ::~Monitor () {
235
+ Mutex ::~Mutex () {
236
236
assert_owner (NULL );
237
237
}
238
238
@@ -241,34 +241,34 @@ bool is_sometimes_ok(const char* name) {
241
241
return (strcmp (name, " Threads_lock" ) == 0 || strcmp (name, " Heap_lock" ) == 0 || strcmp (name, " SR_lock" ) == 0 );
242
242
}
243
243
244
- Monitor::Monitor (int Rank, const char * name, bool allow_vm_block,
245
- SafepointCheckRequired safepoint_check_required) : _owner(NULL ) {
244
+ Mutex::Mutex (int Rank, const char * name, bool allow_vm_block,
245
+ SafepointCheckRequired safepoint_check_required) : _owner(NULL ) {
246
246
assert (os::mutex_init_done (), " Too early!" );
247
247
if (name == NULL ) {
248
248
strcpy (_name, " UNKNOWN" );
249
249
} else {
250
- strncpy (_name, name, MONITOR_NAME_LEN - 1 );
251
- _name[MONITOR_NAME_LEN - 1 ] = ' \0 ' ;
250
+ strncpy (_name, name, MUTEX_NAME_LEN - 1 );
251
+ _name[MUTEX_NAME_LEN - 1 ] = ' \0 ' ;
252
252
}
253
253
#ifdef ASSERT
254
254
_allow_vm_block = allow_vm_block;
255
255
_rank = Rank;
256
256
_safepoint_check_required = safepoint_check_required;
257
257
258
- assert (_safepoint_check_required != Monitor ::_safepoint_check_sometimes || is_sometimes_ok (name),
258
+ assert (_safepoint_check_required != Mutex ::_safepoint_check_sometimes || is_sometimes_ok (name),
259
259
" Lock has _safepoint_check_sometimes %s" , name);
260
260
#endif
261
261
}
262
262
263
- Mutex::Mutex (int Rank, const char * name, bool allow_vm_block,
263
+ Monitor::Monitor (int Rank, const char * name, bool allow_vm_block,
264
264
SafepointCheckRequired safepoint_check_required) :
265
- Monitor (Rank, name, allow_vm_block, safepoint_check_required) {}
265
+ Mutex (Rank, name, allow_vm_block, safepoint_check_required) {}
266
266
267
- bool Monitor ::owned_by_self () const {
267
+ bool Mutex ::owned_by_self () const {
268
268
return _owner == Thread::current ();
269
269
}
270
270
271
- void Monitor ::print_on_error (outputStream* st) const {
271
+ void Mutex ::print_on_error (outputStream* st) const {
272
272
st->print (" [" PTR_FORMAT, p2i (this ));
273
273
st->print (" ] %s" , _name);
274
274
st->print (" - owner thread: " PTR_FORMAT, p2i (_owner));
@@ -278,7 +278,7 @@ void Monitor::print_on_error(outputStream* st) const {
278
278
// Non-product code
279
279
280
280
#ifndef PRODUCT
281
- void Monitor ::print_on (outputStream* st) const {
281
+ void Mutex ::print_on (outputStream* st) const {
282
282
st->print_cr (" Mutex: [" PTR_FORMAT " ] %s - owner: " PTR_FORMAT,
283
283
p2i (this ), _name, p2i (_owner));
284
284
}
@@ -287,7 +287,7 @@ void Monitor::print_on(outputStream* st) const {
287
287
#ifndef PRODUCT
288
288
#ifdef ASSERT
289
289
290
- void Monitor ::assert_owner (Thread * expected) {
290
+ void Mutex ::assert_owner (Thread * expected) {
291
291
const char * msg = " invalid owner" ;
292
292
if (expected == NULL ) {
293
293
msg = " should be un-owned" ;
@@ -300,8 +300,8 @@ void Monitor::assert_owner(Thread * expected) {
300
300
msg, p2i (_owner), p2i (expected));
301
301
}
302
302
303
- Monitor * Monitor ::get_least_ranked_lock (Monitor * locks) {
304
- Monitor *res, *tmp;
303
+ Mutex* Mutex ::get_least_ranked_lock (Mutex * locks) {
304
+ Mutex *res, *tmp;
305
305
for (res = tmp = locks; tmp != NULL ; tmp = tmp->next ()) {
306
306
if (tmp->rank () < res->rank ()) {
307
307
res = tmp;
@@ -320,8 +320,8 @@ Monitor * Monitor::get_least_ranked_lock(Monitor * locks) {
320
320
return res;
321
321
}
322
322
323
- Monitor* Monitor ::get_least_ranked_lock_besides_this (Monitor * locks) {
324
- Monitor *res, *tmp;
323
+ Mutex* Mutex ::get_least_ranked_lock_besides_this (Mutex * locks) {
324
+ Mutex *res, *tmp;
325
325
for (res = NULL , tmp = locks; tmp != NULL ; tmp = tmp->next ()) {
326
326
if (tmp != this && (res == NULL || tmp->rank () < res->rank ())) {
327
327
res = tmp;
@@ -341,7 +341,7 @@ Monitor* Monitor::get_least_ranked_lock_besides_this(Monitor* locks) {
341
341
}
342
342
343
343
344
- bool Monitor ::contains (Monitor * locks, Monitor * lock) {
344
+ bool Mutex ::contains (Mutex * locks, Mutex * lock) {
345
345
for (; locks != NULL ; locks = locks->next ()) {
346
346
if (locks == lock) {
347
347
return true ;
@@ -356,7 +356,7 @@ bool Monitor::contains(Monitor* locks, Monitor * lock) {
356
356
// might indicate exposure to deadlock.
357
357
// Rather like an EventListener for _owner (:>).
358
358
359
- void Monitor ::set_owner_implementation (Thread *new_owner) {
359
+ void Mutex ::set_owner_implementation (Thread *new_owner) {
360
360
// This function is solely responsible for maintaining
361
361
// and checking the invariant that threads and locks
362
362
// are in a 1/N relation, with some some locks unowned.
@@ -377,7 +377,7 @@ void Monitor::set_owner_implementation(Thread *new_owner) {
377
377
// link "this" into the owned locks list
378
378
379
379
#ifdef ASSERT // Thread::_owned_locks is under the same ifdef
380
- Monitor * locks = get_least_ranked_lock (new_owner->owned_locks ());
380
+ Mutex * locks = get_least_ranked_lock (new_owner->owned_locks ());
381
381
// Mutex::set_owner_implementation is a friend of Thread
382
382
383
383
assert (this ->rank () >= 0 , " bad lock rank" );
@@ -415,11 +415,11 @@ void Monitor::set_owner_implementation(Thread *new_owner) {
415
415
_owner = NULL ; // set the owner
416
416
417
417
#ifdef ASSERT
418
- Monitor * locks = old_owner->owned_locks ();
418
+ Mutex* locks = old_owner->owned_locks ();
419
419
420
420
// remove "this" from the owned locks list
421
421
422
- Monitor * prev = NULL ;
422
+ Mutex* prev = NULL ;
423
423
bool found = false ;
424
424
for (; locks != NULL ; prev = locks, locks = locks->next ()) {
425
425
if (locks == this ) {
@@ -440,7 +440,7 @@ void Monitor::set_owner_implementation(Thread *new_owner) {
440
440
441
441
442
442
// Factored out common sanity checks for locking mutex'es. Used by lock() and try_lock()
443
- void Monitor ::check_prelock_state (Thread *thread, bool safepoint_check) {
443
+ void Mutex ::check_prelock_state (Thread *thread, bool safepoint_check) {
444
444
if (safepoint_check) {
445
445
assert ((!thread->is_active_Java_thread () || ((JavaThread *)thread)->thread_state () == _thread_in_vm)
446
446
|| rank () == Mutex::special, " wrong thread state for using locks" );
@@ -454,13 +454,13 @@ void Monitor::check_prelock_state(Thread *thread, bool safepoint_check) {
454
454
" locking not allowed when crash protection is set" );
455
455
}
456
456
457
- void Monitor ::check_block_state (Thread *thread) {
457
+ void Mutex ::check_block_state (Thread *thread) {
458
458
if (!_allow_vm_block && thread->is_VM_thread ()) {
459
459
warning (" VM thread blocked on lock" );
460
460
print ();
461
461
BREAKPOINT;
462
462
}
463
- assert (_owner != thread, " deadlock: blocking on monitor owned by current thread" );
463
+ assert (_owner != thread, " deadlock: blocking on mutex owned by current thread" );
464
464
}
465
465
466
466
#endif // PRODUCT
0 commit comments