Skip to content

Commit 13918a4

Browse files
committedAug 28, 2020
8252414: Redundant suspend check when determining if a java thread is safe
Reviewed-by: dholmes, dcubed, coleenp
1 parent 4b1b547 commit 13918a4

File tree

2 files changed

+1
-30
lines changed

2 files changed

+1
-30
lines changed
 

‎src/hotspot/share/runtime/handshake.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,6 @@ bool HandshakeState::can_process_handshake() {
450450

451451
bool HandshakeState::possibly_can_process_handshake() {
452452
// Note that this method is allowed to produce false positives.
453-
if (_handshakee->is_ext_suspended()) {
454-
return true;
455-
}
456453
if (_handshakee->is_terminated()) {
457454
return true;
458455
}

‎src/hotspot/share/runtime/safepoint.cpp

+1-27
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ static bool safepoint_safe_with(JavaThread *thread, JavaThreadState state) {
653653
}
654654

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

893-
// Check for a thread that is suspended. Note that thread resume tries
894-
// to grab the Threads_lock which we own here, so a thread cannot be
895-
// resumed during safepoint synchronization.
896-
897-
// We check to see if this thread is suspended without locking to
898-
// avoid deadlocking with a third thread that is waiting for this
899-
// thread to be suspended. The third thread can notice the safepoint
900-
// that we're trying to start at the beginning of its SR_lock->wait()
901-
// call. If that happens, then the third thread will block on the
902-
// safepoint while still holding the underlying SR_lock. We won't be
903-
// able to get the SR_lock and we'll deadlock.
904-
//
905-
// We don't need to grab the SR_lock here for two reasons:
906-
// 1) The suspend flags are both volatile and are set with an
907-
// Atomic::cmpxchg() call so we should see the suspended
908-
// state right away.
909-
// 2) We're being called from the safepoint polling loop; if
910-
// we don't see the suspended state on this iteration, then
911-
// we'll come around again.
912-
//
913-
bool is_suspended = _thread->is_ext_suspended();
914-
if (is_suspended) {
915-
account_safe_thread();
916-
return;
917-
}
918-
919893
if (safepoint_safe_with(_thread, stable_state)) {
920894
check_for_lazy_critical_native(_thread, stable_state);
921895
account_safe_thread();

0 commit comments

Comments
 (0)
Please sign in to comment.