mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-18 01:54:47 +02:00
8222988: Use MonitorLocker rather than MutexLocker when wait/notify used
Fixed use cases in code except CMS. Reviewed-by: rehn, dcubed
This commit is contained in:
parent
ed9eac2bb9
commit
ccb2e9d925
21 changed files with 91 additions and 101 deletions
|
@ -794,14 +794,12 @@ bool JavaThread::wait_for_ext_suspend_completion(int retries, int delay,
|
|||
// safepoint requests from the VMThread
|
||||
|
||||
{
|
||||
MutexLocker ml(SR_lock());
|
||||
Thread* t = Thread::current();
|
||||
MonitorLocker ml(SR_lock(),
|
||||
t->is_Java_thread() ? Mutex::_safepoint_check_flag : Mutex::_no_safepoint_check_flag);
|
||||
// wait with safepoint check (if we're a JavaThread - the WatcherThread
|
||||
// can also call this) and increase delay with each retry
|
||||
if (Thread::current()->is_Java_thread()) {
|
||||
SR_lock()->wait(i * delay);
|
||||
} else {
|
||||
SR_lock()->wait_without_safepoint_check(i * delay);
|
||||
}
|
||||
ml.wait(i * delay);
|
||||
|
||||
is_suspended = is_ext_suspend_completed(true /* called_by_wait */,
|
||||
delay, bits);
|
||||
|
@ -1405,7 +1403,7 @@ WatcherThread::WatcherThread() : NonJavaThread() {
|
|||
int WatcherThread::sleep() const {
|
||||
// The WatcherThread does not participate in the safepoint protocol
|
||||
// for the PeriodicTask_lock because it is not a JavaThread.
|
||||
MutexLocker ml(PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
|
||||
MonitorLocker ml(PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
|
||||
|
||||
if (_should_terminate) {
|
||||
// check for termination before we do any housekeeping or wait
|
||||
|
@ -1425,7 +1423,7 @@ int WatcherThread::sleep() const {
|
|||
jlong time_before_loop = os::javaTimeNanos();
|
||||
|
||||
while (true) {
|
||||
bool timedout = PeriodicTask_lock->wait_without_safepoint_check(remaining);
|
||||
bool timedout = ml.wait(remaining);
|
||||
jlong now = os::javaTimeNanos();
|
||||
|
||||
if (remaining == 0) {
|
||||
|
@ -1548,12 +1546,12 @@ void WatcherThread::stop() {
|
|||
}
|
||||
}
|
||||
|
||||
MutexLocker mu(Terminator_lock);
|
||||
MonitorLocker mu(Terminator_lock);
|
||||
|
||||
while (watcher_thread() != NULL) {
|
||||
// This wait should make safepoint checks, wait without a timeout,
|
||||
// and wait as a suspend-equivalent condition.
|
||||
Terminator_lock->wait(0, Mutex::_as_suspend_equivalent_flag);
|
||||
mu.wait(0, Mutex::_as_suspend_equivalent_flag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2424,7 +2422,7 @@ int JavaThread::java_suspend_self() {
|
|||
(is_Java_thread() && !((JavaThread*)this)->has_last_Java_frame()),
|
||||
"must have walkable stack");
|
||||
|
||||
MutexLocker ml(SR_lock(), Mutex::_no_safepoint_check_flag);
|
||||
MonitorLocker ml(SR_lock(), Mutex::_no_safepoint_check_flag);
|
||||
|
||||
assert(!this->is_ext_suspended(),
|
||||
"a thread trying to self-suspend should not already be suspended");
|
||||
|
@ -2452,7 +2450,7 @@ int JavaThread::java_suspend_self() {
|
|||
|
||||
// _ext_suspended flag is cleared by java_resume()
|
||||
while (is_ext_suspended()) {
|
||||
this->SR_lock()->wait_without_safepoint_check();
|
||||
ml.wait();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -3844,10 +3842,10 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) {
|
|||
// Wait for the VM thread to become ready, and VMThread::run to initialize
|
||||
// Monitors can have spurious returns, must always check another state flag
|
||||
{
|
||||
MutexLocker ml(Notify_lock);
|
||||
MonitorLocker ml(Notify_lock);
|
||||
os::start_thread(vmthread);
|
||||
while (vmthread->active_handles() == NULL) {
|
||||
Notify_lock->wait();
|
||||
ml.wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4325,11 +4323,11 @@ bool Threads::destroy_vm() {
|
|||
_vm_complete = false;
|
||||
#endif
|
||||
// Wait until we are the last non-daemon thread to execute
|
||||
{ MutexLocker nu(Threads_lock);
|
||||
{ MonitorLocker nu(Threads_lock);
|
||||
while (Threads::number_of_non_daemon_threads() > 1)
|
||||
// This wait should make safepoint checks, wait without a timeout,
|
||||
// and wait as a suspend-equivalent condition.
|
||||
Threads_lock->wait(0, Mutex::_as_suspend_equivalent_flag);
|
||||
nu.wait(0, Mutex::_as_suspend_equivalent_flag);
|
||||
}
|
||||
|
||||
EventShutdown e;
|
||||
|
@ -4465,7 +4463,7 @@ void Threads::remove(JavaThread* p, bool is_daemon) {
|
|||
|
||||
// Extra scope needed for Thread_lock, so we can check
|
||||
// that we do not remove thread without safepoint code notice
|
||||
{ MutexLocker ml(Threads_lock);
|
||||
{ MonitorLocker ml(Threads_lock);
|
||||
|
||||
assert(ThreadsSMRSupport::get_java_thread_list()->includes(p), "p must be present");
|
||||
|
||||
|
@ -4493,7 +4491,7 @@ void Threads::remove(JavaThread* p, bool is_daemon) {
|
|||
// Only one thread left, do a notify on the Threads_lock so a thread waiting
|
||||
// on destroy_vm will wake up.
|
||||
if (number_of_non_daemon_threads() == 1) {
|
||||
Threads_lock->notify_all();
|
||||
ml.notify_all();
|
||||
}
|
||||
}
|
||||
ThreadService::remove_thread(p, is_daemon);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue