8273251: Call check_possible_safepoint() from SafepointMechanism::process_if_requested()

Reviewed-by: coleenp, dholmes
This commit is contained in:
Patricio Chilano Mateo 2021-09-02 21:22:47 +00:00
parent 29e0f1386d
commit 92b05fe0f4
3 changed files with 17 additions and 21 deletions

View File

@ -77,16 +77,6 @@ class ThreadStateTransition : public StackObj {
protected:
JavaThread* _thread;
private:
static inline void transition_and_process(JavaThread *thread, JavaThreadState to, bool check_asyncs) {
// Check NoSafepointVerifier. This also clears unhandled oops if CheckUnhandledOops is used.
thread->check_possible_safepoint();
thread->set_thread_state_fence(_thread_in_vm);
SafepointMechanism::process_if_requested_with_exit_check(thread, check_asyncs);
thread->set_thread_state(to);
}
public:
ThreadStateTransition(JavaThread *thread) : _thread(thread) {
assert(thread != NULL, "must be active Java thread");
@ -106,13 +96,17 @@ class ThreadStateTransition : public StackObj {
assert(thread->thread_state() == _thread_in_native, "coming from wrong thread state");
assert(to == _thread_in_vm || to == _thread_in_Java, "invalid transition");
assert(!thread->has_last_Java_frame() || thread->frame_anchor()->walkable(), "Unwalkable stack in native transition");
transition_and_process(thread, to, to != _thread_in_Java ? false : check_asyncs);
thread->set_thread_state_fence(_thread_in_vm);
SafepointMechanism::process_if_requested_with_exit_check(thread, to != _thread_in_Java ? false : check_asyncs);
thread->set_thread_state(to);
}
static inline void transition_from_vm(JavaThread *thread, JavaThreadState to, bool check_asyncs = true) {
assert(thread->thread_state() == _thread_in_vm, "coming from wrong thread state");
if (to == _thread_in_Java) {
transition_and_process(thread, _thread_in_Java, check_asyncs);
SafepointMechanism::process_if_requested_with_exit_check(thread, check_asyncs);
thread->set_thread_state(to);
} else {
assert(to == _thread_in_native || to == _thread_blocked, "invalid transition");
// Check NoSafepointVerifier. This also clears unhandled oops if CheckUnhandledOops is used.

View File

@ -85,15 +85,8 @@ bool SafepointMechanism::should_process(JavaThread* thread, bool allow_suspend)
}
void SafepointMechanism::process_if_requested(JavaThread* thread, bool allow_suspend) {
// Macos/aarch64 should be in the right state for safepoint (e.g.
// deoptimization needs WXWrite). Crashes caused by the wrong state rarely
// happens in practice, making such issues hard to find and reproduce.
#if defined(ASSERT) && defined(__APPLE__) && defined(AARCH64)
if (AssertWXAtThreadSync) {
thread->assert_wx_state(WXWrite);
}
#endif
// Check NoSafepointVerifier. This also clears unhandled oops if CheckUnhandledOops is used.
thread->check_possible_safepoint();
if (local_poll_armed(thread)) {
process(thread, allow_suspend);

View File

@ -948,6 +948,15 @@ void JavaThread::check_possible_safepoint() {
// Clear unhandled oops in JavaThreads so we get a crash right away.
clear_unhandled_oops();
#endif // CHECK_UNHANDLED_OOPS
// Macos/aarch64 should be in the right state for safepoint (e.g.
// deoptimization needs WXWrite). Crashes caused by the wrong state rarely
// happens in practice, making such issues hard to find and reproduce.
#if defined(__APPLE__) && defined(AARCH64)
if (AssertWXAtThreadSync) {
assert_wx_state(WXWrite);
}
#endif
}
void JavaThread::check_for_valid_safepoint_state() {