From 98403b75df0a0737bdf082231f38c5c0019fe4c9 Mon Sep 17 00:00:00 2001 From: Doug Simon Date: Wed, 23 Oct 2024 20:01:14 +0000 Subject: [PATCH] 8342854: [JVMCI] Block secondary thread reporting a JVMCI fatal error Reviewed-by: never --- src/hotspot/share/jvmci/jvmci.cpp | 19 +++++++++---------- src/hotspot/share/jvmci/jvmci.hpp | 4 ++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/hotspot/share/jvmci/jvmci.cpp b/src/hotspot/share/jvmci/jvmci.cpp index 447792b6fca..48d286e91ed 100644 --- a/src/hotspot/share/jvmci/jvmci.cpp +++ b/src/hotspot/share/jvmci/jvmci.cpp @@ -50,7 +50,7 @@ char* JVMCI::_shared_library_path = nullptr; volatile bool JVMCI::_in_shutdown = false; StringEventLog* JVMCI::_events = nullptr; StringEventLog* JVMCI::_verbose_events = nullptr; -volatile intx JVMCI::_fatal_log_init_thread = -1; +volatile intx JVMCI::_first_error_tid = -1; volatile int JVMCI::_fatal_log_fd = -1; const char* JVMCI::_fatal_log_filename = nullptr; @@ -354,7 +354,7 @@ void JVMCI::fatal_log(const char* buf, size_t count) { intx current_thread_id = os::current_thread_id(); intx invalid_id = -1; int log_fd; - if (_fatal_log_init_thread == invalid_id && Atomic::cmpxchg(&_fatal_log_init_thread, invalid_id, current_thread_id) == invalid_id) { + if (_first_error_tid == invalid_id && Atomic::cmpxchg(&_first_error_tid, invalid_id, current_thread_id) == invalid_id) { if (ErrorFileToStdout) { log_fd = 1; } else if (ErrorFileToStderr) { @@ -375,14 +375,13 @@ void JVMCI::fatal_log(const char* buf, size_t count) { } } _fatal_log_fd = log_fd; - } else { - // Another thread won the race to initialize the stream. Give it time - // to complete initialization. VM locks cannot be used as the current - // thread might not be attached to the VM (e.g. a native thread started - // within libjvmci). - while (_fatal_log_fd == -1) { - os::naked_short_sleep(50); - } + } else if (_first_error_tid != current_thread_id) { + // This is not the first thread reporting a libjvmci error + tty->print_cr("[thread " INTX_FORMAT " also had an error in the JVMCI native library]", + current_thread_id); + + // Fatal error reporting is single threaded so just block this thread. + os::infinite_sleep(); } fdStream log(_fatal_log_fd); log.write(buf, count); diff --git a/src/hotspot/share/jvmci/jvmci.hpp b/src/hotspot/share/jvmci/jvmci.hpp index 1e9fa08898f..4c1d828004e 100644 --- a/src/hotspot/share/jvmci/jvmci.hpp +++ b/src/hotspot/share/jvmci/jvmci.hpp @@ -117,8 +117,8 @@ class JVMCI : public AllStatic { // The path of the file underlying _fatal_log_fd if it is a normal file. static const char* _fatal_log_filename; - // Native thread id of thread that will initialize _fatal_log_fd. - static volatile intx _fatal_log_init_thread; + // Thread id of the first thread reporting a libjvmci error. + static volatile intx _first_error_tid; // JVMCI event log (shows up in hs_err crash logs). static StringEventLog* _events;