Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8252414: Redundant suspend check when determining if a java thread is…
… safe

Reviewed-by: dholmes, dcubed, coleenp
  • Loading branch information
robehn committed Aug 28, 2020
1 parent 85eca9b commit 19216ac7c7d21b07d5bd63e53f47fb6533479f53
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 30 deletions.
@@ -450,9 +450,6 @@ bool HandshakeState::can_process_handshake() {

bool HandshakeState::possibly_can_process_handshake() {
// Note that this method is allowed to produce false positives.
if (_handshakee->is_ext_suspended()) {
return true;
}
if (_handshakee->is_terminated()) {
return true;
}
@@ -653,7 +653,7 @@ static bool safepoint_safe_with(JavaThread *thread, JavaThreadState state) {
}

bool SafepointSynchronize::handshake_safe(JavaThread *thread) {
if (thread->is_ext_suspended() || thread->is_terminated()) {
if (thread->is_terminated()) {
return true;
}
JavaThreadState stable_state;
@@ -890,32 +890,6 @@ void ThreadSafepointState::examine_state_of_thread(uint64_t safepoint_count) {
return;
}

// Check for a thread that is suspended. Note that thread resume tries
// to grab the Threads_lock which we own here, so a thread cannot be
// resumed during safepoint synchronization.

// We check to see if this thread is suspended without locking to
// avoid deadlocking with a third thread that is waiting for this
// thread to be suspended. The third thread can notice the safepoint
// that we're trying to start at the beginning of its SR_lock->wait()
// call. If that happens, then the third thread will block on the
// safepoint while still holding the underlying SR_lock. We won't be
// able to get the SR_lock and we'll deadlock.
//
// We don't need to grab the SR_lock here for two reasons:
// 1) The suspend flags are both volatile and are set with an
// Atomic::cmpxchg() call so we should see the suspended
// state right away.
// 2) We're being called from the safepoint polling loop; if
// we don't see the suspended state on this iteration, then
// we'll come around again.
//
bool is_suspended = _thread->is_ext_suspended();
if (is_suspended) {
account_safe_thread();
return;
}

if (safepoint_safe_with(_thread, stable_state)) {
check_for_lazy_critical_native(_thread, stable_state);
account_safe_thread();

0 comments on commit 19216ac

Please sign in to comment.