Skip to content
Permalink
Browse files
8273251: Call check_possible_safepoint() from SafepointMechanism::pro…
…cess_if_requested()

Reviewed-by: coleenp, dholmes
  • Loading branch information
pchilano committed Sep 2, 2021
1 parent 29e0f13 commit 92b05fe0f41b91aa88e77473725ae92ee13b052f
Showing with 17 additions and 21 deletions.
  1. +6 −12 src/hotspot/share/runtime/interfaceSupport.inline.hpp
  2. +2 −9 src/hotspot/share/runtime/safepointMechanism.inline.hpp
  3. +9 −0 src/hotspot/share/runtime/thread.cpp
@@ -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.
@@ -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);
@@ -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() {

1 comment on commit 92b05fe

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 92b05fe Sep 2, 2021

Please sign in to comment.