Skip to content

Commit 98403b7

Browse files
author
Doug Simon
committed
8342854: [JVMCI] Block secondary thread reporting a JVMCI fatal error
Reviewed-by: never
1 parent 9a7a850 commit 98403b7

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/hotspot/share/jvmci/jvmci.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ char* JVMCI::_shared_library_path = nullptr;
5050
volatile bool JVMCI::_in_shutdown = false;
5151
StringEventLog* JVMCI::_events = nullptr;
5252
StringEventLog* JVMCI::_verbose_events = nullptr;
53-
volatile intx JVMCI::_fatal_log_init_thread = -1;
53+
volatile intx JVMCI::_first_error_tid = -1;
5454
volatile int JVMCI::_fatal_log_fd = -1;
5555
const char* JVMCI::_fatal_log_filename = nullptr;
5656

@@ -354,7 +354,7 @@ void JVMCI::fatal_log(const char* buf, size_t count) {
354354
intx current_thread_id = os::current_thread_id();
355355
intx invalid_id = -1;
356356
int log_fd;
357-
if (_fatal_log_init_thread == invalid_id && Atomic::cmpxchg(&_fatal_log_init_thread, invalid_id, current_thread_id) == invalid_id) {
357+
if (_first_error_tid == invalid_id && Atomic::cmpxchg(&_first_error_tid, invalid_id, current_thread_id) == invalid_id) {
358358
if (ErrorFileToStdout) {
359359
log_fd = 1;
360360
} else if (ErrorFileToStderr) {
@@ -375,14 +375,13 @@ void JVMCI::fatal_log(const char* buf, size_t count) {
375375
}
376376
}
377377
_fatal_log_fd = log_fd;
378-
} else {
379-
// Another thread won the race to initialize the stream. Give it time
380-
// to complete initialization. VM locks cannot be used as the current
381-
// thread might not be attached to the VM (e.g. a native thread started
382-
// within libjvmci).
383-
while (_fatal_log_fd == -1) {
384-
os::naked_short_sleep(50);
385-
}
378+
} else if (_first_error_tid != current_thread_id) {
379+
// This is not the first thread reporting a libjvmci error
380+
tty->print_cr("[thread " INTX_FORMAT " also had an error in the JVMCI native library]",
381+
current_thread_id);
382+
383+
// Fatal error reporting is single threaded so just block this thread.
384+
os::infinite_sleep();
386385
}
387386
fdStream log(_fatal_log_fd);
388387
log.write(buf, count);

src/hotspot/share/jvmci/jvmci.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ class JVMCI : public AllStatic {
117117
// The path of the file underlying _fatal_log_fd if it is a normal file.
118118
static const char* _fatal_log_filename;
119119

120-
// Native thread id of thread that will initialize _fatal_log_fd.
121-
static volatile intx _fatal_log_init_thread;
120+
// Thread id of the first thread reporting a libjvmci error.
121+
static volatile intx _first_error_tid;
122122

123123
// JVMCI event log (shows up in hs_err crash logs).
124124
static StringEventLog* _events;

0 commit comments

Comments
 (0)