diff --git a/src/hotspot/share/runtime/handshake.cpp b/src/hotspot/share/runtime/handshake.cpp index 39ae4f18998f2..e6a12677a19c2 100644 --- a/src/hotspot/share/runtime/handshake.cpp +++ b/src/hotspot/share/runtime/handshake.cpp @@ -202,7 +202,7 @@ static void handle_timeout(HandshakeOperation* op, JavaThread* target) { } if (target != nullptr) { - VMError::set_handshake_timed_out_thread(p2i(target)); + VMError::set_handshake_timed_out_thread(target); if (os::signal_thread(target, SIGILL, "cannot be handshaked")) { // Give target a chance to report the error and terminate the VM. os::naked_sleep(3000); diff --git a/src/hotspot/share/runtime/safepoint.cpp b/src/hotspot/share/runtime/safepoint.cpp index 6fcf1e6c0f5bf..ef9e0981913b7 100644 --- a/src/hotspot/share/runtime/safepoint.cpp +++ b/src/hotspot/share/runtime/safepoint.cpp @@ -651,7 +651,7 @@ void SafepointSynchronize::print_safepoint_timeout() { // Send the blocking thread a signal to terminate and write an error file. for (JavaThreadIteratorWithHandle jtiwh; JavaThread *cur_thread = jtiwh.next(); ) { if (cur_thread->safepoint_state()->is_running()) { - VMError::set_safepoint_timed_out_thread(p2i(cur_thread)); + VMError::set_safepoint_timed_out_thread(cur_thread); if (!os::signal_thread(cur_thread, SIGILL, "blocking a safepoint")) { break; // Could not send signal. Report fatal error. } diff --git a/src/hotspot/share/utilities/vmError.cpp b/src/hotspot/share/utilities/vmError.cpp index bd882a7ef3cbb..19c9773dfe522 100644 --- a/src/hotspot/share/utilities/vmError.cpp +++ b/src/hotspot/share/utilities/vmError.cpp @@ -104,8 +104,8 @@ int VMError::_lineno; size_t VMError::_size; const size_t VMError::_reattempt_required_stack_headroom = 64 * K; const intptr_t VMError::segfault_address = pd_segfault_address; -volatile intptr_t VMError::_handshake_timed_out_thread = p2i(nullptr); -volatile intptr_t VMError::_safepoint_timed_out_thread = p2i(nullptr); +Thread* volatile VMError::_handshake_timed_out_thread = nullptr; +Thread* volatile VMError::_safepoint_timed_out_thread = nullptr; // List of environment variables that should be reported in error log file. static const char* env_list[] = { @@ -821,10 +821,10 @@ void VMError::report(outputStream* st, bool _verbose) { st->print(" (0x%x)", _id); // signal number st->print(" at pc=" PTR_FORMAT, p2i(_pc)); if (_siginfo != nullptr && os::signal_sent_by_kill(_siginfo)) { - if (_handshake_timed_out_thread == p2i(_thread)) { - st->print(" (sent by handshake timeout handler"); - } else if (_safepoint_timed_out_thread == p2i(_thread)) { - st->print(" (sent by safepoint timeout handler"); + if (get_handshake_timed_out_thread() == _thread) { + st->print(" (sent by handshake timeout handler)"); + } else if (get_safepoint_timed_out_thread() == _thread) { + st->print(" (sent by safepoint timeout handler)"); } else { st->print(" (sent by kill)"); } @@ -1338,12 +1338,24 @@ void VMError::report(outputStream* st, bool _verbose) { # undef END } -void VMError::set_handshake_timed_out_thread(intptr_t thread_addr) { - _handshake_timed_out_thread = thread_addr; +void VMError::set_handshake_timed_out_thread(Thread* thread) { + // Only preserve the first thread to time-out this way. The atomic operation ensures + // visibility to the target thread. + Atomic::replace_if_null(&_handshake_timed_out_thread, thread); } -void VMError::set_safepoint_timed_out_thread(intptr_t thread_addr) { - _safepoint_timed_out_thread = thread_addr; +void VMError::set_safepoint_timed_out_thread(Thread* thread) { + // Only preserve the first thread to time-out this way. The atomic operation ensures + // visibility to the target thread. + Atomic::replace_if_null(&_safepoint_timed_out_thread, thread); +} + +Thread* VMError::get_handshake_timed_out_thread() { + return Atomic::load(&_handshake_timed_out_thread); +} + +Thread* VMError::get_safepoint_timed_out_thread() { + return Atomic::load(&_safepoint_timed_out_thread); } // Report for the vm_info_cmd. This prints out the information above omitting diff --git a/src/hotspot/share/utilities/vmError.hpp b/src/hotspot/share/utilities/vmError.hpp index 96e37acff576f..5e5e074fb20c7 100644 --- a/src/hotspot/share/utilities/vmError.hpp +++ b/src/hotspot/share/utilities/vmError.hpp @@ -143,8 +143,8 @@ class VMError : public AllStatic { static void clear_step_start_time(); // Handshake/safepoint timed out threads - static volatile intptr_t _handshake_timed_out_thread; - static volatile intptr_t _safepoint_timed_out_thread; + static Thread* volatile _handshake_timed_out_thread; + static Thread* volatile _safepoint_timed_out_thread; WINDOWS_ONLY([[noreturn]] static void raise_fail_fast(const void* exrecord, const void* context);) @@ -223,8 +223,10 @@ class VMError : public AllStatic { static bool was_assert_poison_crash(const void* sigInfo); - static void set_handshake_timed_out_thread(intptr_t thread_addr); - static void set_safepoint_timed_out_thread(intptr_t thread_addr); + static void set_handshake_timed_out_thread(Thread* thread); + static void set_safepoint_timed_out_thread(Thread* thread); + static Thread* get_handshake_timed_out_thread(); + static Thread* get_safepoint_timed_out_thread(); }; class VMErrorCallback { diff --git a/test/hotspot/jtreg/runtime/Safepoint/TestAbortVMOnSafepointTimeout.java b/test/hotspot/jtreg/runtime/Safepoint/TestAbortVMOnSafepointTimeout.java index e28dd7f4d2ae2..b46a5deb70def 100644 --- a/test/hotspot/jtreg/runtime/Safepoint/TestAbortVMOnSafepointTimeout.java +++ b/test/hotspot/jtreg/runtime/Safepoint/TestAbortVMOnSafepointTimeout.java @@ -88,7 +88,7 @@ private static void verifyAbortVmApplied(OutputAnalyzer output) { } else { output.shouldContain("SIGILL"); if (Platform.isLinux()) { - output.shouldContain("(sent by safepoint timeout handler"); + output.shouldContain("(sent by safepoint timeout handler)"); } } output.shouldNotHaveExitValue(0);