Skip to content

Commit

Permalink
8273251: Call check_possible_safepoint() from SafepointMechanism::pro…
Browse files Browse the repository at this point in the history
…cess_if_requested()

Reviewed-by: coleenp, dholmes
  • Loading branch information
pchilano committed Sep 2, 2021
1 parent 29e0f13 commit 92b05fe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
18 changes: 6 additions & 12 deletions src/hotspot/share/runtime/interfaceSupport.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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.
Expand Down
11 changes: 2 additions & 9 deletions src/hotspot/share/runtime/safepointMechanism.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/hotspot/share/runtime/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

1 comment on commit 92b05fe

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.