8222811: Consolidate MutexLockerEx and MutexLocker

Make MutexLocker be MutexLockerEx implementation, remove MutexLockerEx calls.

Reviewed-by: dcubed, dholmes, pliden, rehn
This commit is contained in:
Coleen Phillimore 2019-04-25 10:56:31 -04:00
parent 88303d1c60
commit fbafef11c0
127 changed files with 718 additions and 746 deletions

View file

@ -718,7 +718,11 @@ bool JavaThread::is_ext_suspend_completed(bool called_by_wait, int delay,
// temporarily drops SR_lock while doing wait with safepoint check
// (if we're a JavaThread - the WatcherThread can also call this)
// and increase delay with each retry
SR_lock()->wait(!Thread::current()->is_Java_thread(), i * delay);
if (Thread::current()->is_Java_thread()) {
SR_lock()->wait(i * delay);
} else {
SR_lock()->wait_without_safepoint_check(i * delay);
}
// check the actual thread state instead of what we saved above
if (thread_state() != _thread_in_native_trans) {
@ -759,7 +763,7 @@ bool JavaThread::wait_for_ext_suspend_completion(int retries, int delay,
reset_bits = *bits;
{
MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
MutexLocker ml(SR_lock(), Mutex::_no_safepoint_check_flag);
is_suspended = is_ext_suspend_completed(true /* called_by_wait */,
delay, bits);
pending = is_external_suspend();
@ -793,7 +797,11 @@ bool JavaThread::wait_for_ext_suspend_completion(int retries, int delay,
MutexLocker ml(SR_lock());
// wait with safepoint check (if we're a JavaThread - the WatcherThread
// can also call this) and increase delay with each retry
SR_lock()->wait(!Thread::current()->is_Java_thread(), i * delay);
if (Thread::current()->is_Java_thread()) {
SR_lock()->wait(i * delay);
} else {
SR_lock()->wait_without_safepoint_check(i * delay);
}
is_suspended = is_ext_suspend_completed(true /* called_by_wait */,
delay, bits);
@ -1289,7 +1297,7 @@ NonJavaThread::NonJavaThread() : Thread(), _next(NULL) {
NonJavaThread::~NonJavaThread() { }
void NonJavaThread::add_to_the_list() {
MutexLockerEx ml(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
MutexLocker ml(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
// Initialize BarrierSet-related data before adding to list.
BarrierSet::barrier_set()->on_thread_attach(this);
OrderAccess::release_store(&_next, _the_list._head);
@ -1298,7 +1306,7 @@ void NonJavaThread::add_to_the_list() {
void NonJavaThread::remove_from_the_list() {
{
MutexLockerEx ml(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
MutexLocker ml(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
// Cleanup BarrierSet-related data before removing from list.
BarrierSet::barrier_set()->on_thread_detach(this);
NonJavaThread* volatile* p = &_the_list._head;
@ -1312,7 +1320,7 @@ void NonJavaThread::remove_from_the_list() {
// Wait for any in-progress iterators. Concurrent synchronize is not
// allowed, so do it while holding a dedicated lock. Outside and distinct
// from NJTList_lock in case an iteration attempts to lock it.
MutexLockerEx ml(NonJavaThreadsListSync_lock, Mutex::_no_safepoint_check_flag);
MutexLocker ml(NonJavaThreadsListSync_lock, Mutex::_no_safepoint_check_flag);
_the_list._protect.synchronize();
_next = NULL; // Safe to drop the link now.
}
@ -1397,7 +1405,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.
MutexLockerEx ml(PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
MutexLocker ml(PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
if (_should_terminate) {
// check for termination before we do any housekeeping or wait
@ -1417,8 +1425,7 @@ int WatcherThread::sleep() const {
jlong time_before_loop = os::javaTimeNanos();
while (true) {
bool timedout = PeriodicTask_lock->wait(Mutex::_no_safepoint_check_flag,
remaining);
bool timedout = PeriodicTask_lock->wait_without_safepoint_check(remaining);
jlong now = os::javaTimeNanos();
if (remaining == 0) {
@ -1506,7 +1513,7 @@ void WatcherThread::run() {
// Signal that it is terminated
{
MutexLockerEx mu(Terminator_lock, Mutex::_no_safepoint_check_flag);
MutexLocker mu(Terminator_lock, Mutex::_no_safepoint_check_flag);
_watcher_thread = NULL;
Terminator_lock->notify_all();
}
@ -1546,8 +1553,7 @@ void WatcherThread::stop() {
while (watcher_thread() != NULL) {
// This wait should make safepoint checks, wait without a timeout,
// and wait as a suspend-equivalent condition.
Terminator_lock->wait(!Mutex::_no_safepoint_check_flag, 0,
Mutex::_as_suspend_equivalent_flag);
Terminator_lock->wait(0, Mutex::_as_suspend_equivalent_flag);
}
}
@ -1990,7 +1996,7 @@ void JavaThread::exit(bool destroy_vm, ExitType exit_type) {
// in order to not surprise the thread that made the suspend request.
while (true) {
{
MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
MutexLocker ml(SR_lock(), Mutex::_no_safepoint_check_flag);
if (!is_external_suspend()) {
set_terminated(_thread_exiting);
ThreadService::current_thread_exiting(this, is_daemon(threadObj()));
@ -2359,7 +2365,7 @@ void JavaThread::java_suspend() {
return;
}
{ MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
{ MutexLocker ml(SR_lock(), Mutex::_no_safepoint_check_flag);
if (!is_external_suspend()) {
// a racing resume has cancelled us; bail out now
return;
@ -2418,7 +2424,7 @@ int JavaThread::java_suspend_self() {
(is_Java_thread() && !((JavaThread*)this)->has_last_Java_frame()),
"must have walkable stack");
MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
MutexLocker ml(SR_lock(), Mutex::_no_safepoint_check_flag);
assert(!this->is_ext_suspended(),
"a thread trying to self-suspend should not already be suspended");
@ -2446,7 +2452,7 @@ int JavaThread::java_suspend_self() {
// _ext_suspended flag is cleared by java_resume()
while (is_ext_suspended()) {
this->SR_lock()->wait(Mutex::_no_safepoint_check_flag);
this->SR_lock()->wait_without_safepoint_check();
}
}
return ret;
@ -2588,7 +2594,7 @@ void JavaThread::java_resume() {
return;
}
MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
MutexLocker ml(SR_lock(), Mutex::_no_safepoint_check_flag);
clear_external_suspend();
@ -4338,8 +4344,7 @@ bool Threads::destroy_vm() {
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(!Mutex::_no_safepoint_check_flag, 0,
Mutex::_as_suspend_equivalent_flag);
Threads_lock->wait(0, Mutex::_as_suspend_equivalent_flag);
}
EventShutdown e;
@ -4370,7 +4375,7 @@ bool Threads::destroy_vm() {
// queue until after the vm thread is dead. After this point,
// we'll never emerge out of the safepoint before the VM exits.
MutexLockerEx ml(Heap_lock, Mutex::_no_safepoint_check_flag);
MutexLocker ml(Heap_lock, Mutex::_no_safepoint_check_flag);
VMThread::wait_for_vm_thread_exit();
assert(SafepointSynchronize::is_at_safepoint(), "VM thread should exit at Safepoint");