8301229: Clean up SuspendibleThreadSet::_suspend_all
Reviewed-by: stefank, kbarrett, tschatzl
This commit is contained in:
parent
f50cda7d45
commit
7fae3a1d8d
@ -50,7 +50,7 @@ bool SuspendibleThreadSet::is_synchronized() {
|
|||||||
void SuspendibleThreadSet::join() {
|
void SuspendibleThreadSet::join() {
|
||||||
assert(!Thread::current()->is_suspendible_thread(), "Thread already joined");
|
assert(!Thread::current()->is_suspendible_thread(), "Thread already joined");
|
||||||
MonitorLocker ml(STS_lock, Mutex::_no_safepoint_check_flag);
|
MonitorLocker ml(STS_lock, Mutex::_no_safepoint_check_flag);
|
||||||
while (suspend_all()) {
|
while (should_yield()) {
|
||||||
ml.wait();
|
ml.wait();
|
||||||
}
|
}
|
||||||
_nthreads++;
|
_nthreads++;
|
||||||
@ -63,16 +63,16 @@ void SuspendibleThreadSet::leave() {
|
|||||||
assert(_nthreads > 0, "Invalid");
|
assert(_nthreads > 0, "Invalid");
|
||||||
DEBUG_ONLY(Thread::current()->clear_suspendible_thread();)
|
DEBUG_ONLY(Thread::current()->clear_suspendible_thread();)
|
||||||
_nthreads--;
|
_nthreads--;
|
||||||
if (suspend_all() && is_synchronized()) {
|
if (should_yield() && is_synchronized()) {
|
||||||
// This leave completes a request, so inform the requestor.
|
// This leave completes a request, so inform the requestor.
|
||||||
_synchronize_wakeup->signal();
|
_synchronize_wakeup->signal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SuspendibleThreadSet::yield() {
|
void SuspendibleThreadSet::yield_slow() {
|
||||||
assert(Thread::current()->is_suspendible_thread(), "Must have joined");
|
assert(Thread::current()->is_suspendible_thread(), "Must have joined");
|
||||||
MonitorLocker ml(STS_lock, Mutex::_no_safepoint_check_flag);
|
MonitorLocker ml(STS_lock, Mutex::_no_safepoint_check_flag);
|
||||||
if (suspend_all()) {
|
if (should_yield()) {
|
||||||
_nthreads_stopped++;
|
_nthreads_stopped++;
|
||||||
if (is_synchronized()) {
|
if (is_synchronized()) {
|
||||||
if (ConcGCYieldTimeout > 0) {
|
if (ConcGCYieldTimeout > 0) {
|
||||||
@ -82,7 +82,7 @@ void SuspendibleThreadSet::yield() {
|
|||||||
// This yield completes the request, so inform the requestor.
|
// This yield completes the request, so inform the requestor.
|
||||||
_synchronize_wakeup->signal();
|
_synchronize_wakeup->signal();
|
||||||
}
|
}
|
||||||
while (suspend_all()) {
|
while (should_yield()) {
|
||||||
ml.wait();
|
ml.wait();
|
||||||
}
|
}
|
||||||
assert(_nthreads_stopped > 0, "Invalid");
|
assert(_nthreads_stopped > 0, "Invalid");
|
||||||
@ -97,7 +97,7 @@ void SuspendibleThreadSet::synchronize() {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
MonitorLocker ml(STS_lock, Mutex::_no_safepoint_check_flag);
|
MonitorLocker ml(STS_lock, Mutex::_no_safepoint_check_flag);
|
||||||
assert(!suspend_all(), "Only one at a time");
|
assert(!should_yield(), "Only one at a time");
|
||||||
Atomic::store(&_suspend_all, true);
|
Atomic::store(&_suspend_all, true);
|
||||||
if (is_synchronized()) {
|
if (is_synchronized()) {
|
||||||
return;
|
return;
|
||||||
@ -120,7 +120,7 @@ void SuspendibleThreadSet::synchronize() {
|
|||||||
|
|
||||||
#ifdef ASSERT
|
#ifdef ASSERT
|
||||||
MonitorLocker ml(STS_lock, Mutex::_no_safepoint_check_flag);
|
MonitorLocker ml(STS_lock, Mutex::_no_safepoint_check_flag);
|
||||||
assert(suspend_all(), "STS not synchronizing");
|
assert(should_yield(), "STS not synchronizing");
|
||||||
assert(is_synchronized(), "STS not synchronized");
|
assert(is_synchronized(), "STS not synchronized");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ void SuspendibleThreadSet::synchronize() {
|
|||||||
void SuspendibleThreadSet::desynchronize() {
|
void SuspendibleThreadSet::desynchronize() {
|
||||||
assert(Thread::current()->is_VM_thread(), "Must be the VM thread");
|
assert(Thread::current()->is_VM_thread(), "Must be the VM thread");
|
||||||
MonitorLocker ml(STS_lock, Mutex::_no_safepoint_check_flag);
|
MonitorLocker ml(STS_lock, Mutex::_no_safepoint_check_flag);
|
||||||
assert(suspend_all(), "STS not synchronizing");
|
assert(should_yield(), "STS not synchronizing");
|
||||||
assert(is_synchronized(), "STS not synchronized");
|
assert(is_synchronized(), "STS not synchronized");
|
||||||
Atomic::store(&_suspend_all, false);
|
Atomic::store(&_suspend_all, false);
|
||||||
ml.notify_all();
|
ml.notify_all();
|
||||||
|
@ -41,10 +41,9 @@ class SuspendibleThreadSet : public AllStatic {
|
|||||||
friend class SuspendibleThreadSetLeaver;
|
friend class SuspendibleThreadSetLeaver;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static volatile bool _suspend_all;
|
|
||||||
|
|
||||||
static uint _nthreads;
|
static uint _nthreads;
|
||||||
static uint _nthreads_stopped;
|
static uint _nthreads_stopped;
|
||||||
|
static volatile bool _suspend_all;
|
||||||
static double _suspend_all_start;
|
static double _suspend_all_start;
|
||||||
|
|
||||||
static bool is_synchronized();
|
static bool is_synchronized();
|
||||||
@ -55,14 +54,19 @@ private:
|
|||||||
// Removes the current thread from the set.
|
// Removes the current thread from the set.
|
||||||
static void leave();
|
static void leave();
|
||||||
|
|
||||||
static bool suspend_all() { return Atomic::load(&_suspend_all); }
|
// Suspends the current thread if a suspension is in progress.
|
||||||
|
static void yield_slow();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Returns true if an suspension is in progress.
|
// Returns true if an suspension is in progress.
|
||||||
static bool should_yield() { return suspend_all(); }
|
static bool should_yield() { return Atomic::load(&_suspend_all); }
|
||||||
|
|
||||||
// Suspends the current thread if a suspension is in progress.
|
// Suspends the current thread if a suspension is in progress.
|
||||||
static void yield();
|
static void yield() {
|
||||||
|
if (should_yield()) {
|
||||||
|
yield_slow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Returns when all threads in the set are suspended.
|
// Returns when all threads in the set are suspended.
|
||||||
static void synchronize();
|
static void synchronize();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user