@@ -2577,20 +2577,22 @@ int JavaThread::java_suspend_self() {
2577
2577
// Helper routine to set up the correct thread state before calling java_suspend_self.
2578
2578
// This is called when regular thread-state transition helpers can't be used because
2579
2579
// 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
2585
2585
// safepoint could happen just after java_suspend_self() returns after being resumed,
2586
2586
// and the VM thread will see the _thread_blocked state. So we must check for a safepoint
2587
2587
// after restoring the state to make sure we won't leave while a safepoint is in progress.
2588
2588
// 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
2590
2590
// only _thread_in_native is possible when executing this code (based on our two callers).
2591
2591
// A thread that is _thread_in_native is already safepoint-safe and so it doesn't matter
2592
2592
// whether the VMThread sees the _thread_blocked state, or the _thread_in_native state,
2593
2593
// 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.
2594
2596
2595
2597
void JavaThread::java_suspend_self_with_safepoint_check () {
2596
2598
assert (this == Thread::current (), " invariant" );
0 commit comments