Skip to content

Commit 226faa5

Browse files
committedSep 23, 2020
8253241: Update comment on java_suspend_self_with_safepoint_check()
Reviewed-by: dcubed, dholmes
1 parent bd67975 commit 226faa5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed
 

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -2577,20 +2577,22 @@ int JavaThread::java_suspend_self() {
25772577
// Helper routine to set up the correct thread state before calling java_suspend_self.
25782578
// This is called when regular thread-state transition helpers can't be used because
25792579
// we can be in various states, in particular _thread_in_native_trans.
2580-
// Because this thread is external suspended the safepoint code will count it as at
2581-
// a safepoint, regardless of what its actual current thread-state is. But
2582-
// is_ext_suspend_completed() may be waiting to see a thread transition from
2583-
// _thread_in_native_trans to _thread_blocked. So we set the thread state directly
2584-
// to _thread_blocked. The problem with setting thread state directly is that a
2580+
// We have to set the thread state directly to _thread_blocked so that it will
2581+
// be seen to be safepoint/handshake safe whilst suspended. This is also
2582+
// necessary to allow a thread in is_ext_suspend_completed, that observed the
2583+
// _thread_in_native_trans state, to proceed.
2584+
// The problem with setting thread state directly is that a
25852585
// safepoint could happen just after java_suspend_self() returns after being resumed,
25862586
// and the VM thread will see the _thread_blocked state. So we must check for a safepoint
25872587
// after restoring the state to make sure we won't leave while a safepoint is in progress.
25882588
// However, not all initial-states are allowed when performing a safepoint check, as we
2589-
// should never be blocking at a safepoint whilst in those states. Of these 'bad' states
2589+
// should never be blocking at a safepoint whilst in those states(*). Of these 'bad' states
25902590
// only _thread_in_native is possible when executing this code (based on our two callers).
25912591
// A thread that is _thread_in_native is already safepoint-safe and so it doesn't matter
25922592
// whether the VMThread sees the _thread_blocked state, or the _thread_in_native state,
25932593
// and so we don't need the explicit safepoint check.
2594+
// (*) See switch statement in SafepointSynchronize::block() for thread states that are
2595+
// allowed when performing a safepoint check.
25942596

25952597
void JavaThread::java_suspend_self_with_safepoint_check() {
25962598
assert(this == Thread::current(), "invariant");

0 commit comments

Comments
 (0)
Please sign in to comment.