From ba004ef0b39f2d8d526a8195b497f9e4f2e56b3e Mon Sep 17 00:00:00 2001 From: Doug Simon Date: Tue, 29 Jun 2021 23:39:01 +0200 Subject: [PATCH] respect ErrorFileToStdout and ErrorFileToStderr flags --- src/hotspot/share/jvmci/jvmci.cpp | 23 +++++++++++++++-------- src/hotspot/share/utilities/vmError.cpp | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/hotspot/share/jvmci/jvmci.cpp b/src/hotspot/share/jvmci/jvmci.cpp index 29f208d6b9c51..623582562190e 100644 --- a/src/hotspot/share/jvmci/jvmci.cpp +++ b/src/hotspot/share/jvmci/jvmci.cpp @@ -220,19 +220,26 @@ void JVMCI::fatal_log(const char* buf, size_t count) { intx invalid_id = -1; if (_fatal_log_init_thread == invalid_id && Atomic::cmpxchg(&_fatal_log_init_thread, invalid_id, current_thread_id) == invalid_id) { static char name_buffer[O_BUFLEN]; - int fd = VMError::prepare_log_file(JVMCINativeLibraryErrorFile, LIBJVMCI_ERR_FILE, true, name_buffer, sizeof(name_buffer)); - if (fd != -1) { - FILE* fp = os::open(fd, "w"); - if (fp != NULL) { - _fatal_log_stream = new fileStream(fp); + static fdStream log(-1); + if (ErrorFileToStdout) { + log.set_fd(1); + } else if (ErrorFileToStderr) { + log.set_fd(2); + } else { + int fd = VMError::prepare_log_file(JVMCINativeLibraryErrorFile, LIBJVMCI_ERR_FILE, true, name_buffer, sizeof(name_buffer)); + if (fd != -1) { _fatal_log_filename = name_buffer; + log.set_fd(fd); } else { int e = errno; - tty->print("Can't open file to dump JVMCI shared library crash data. Error: "); + tty->print("Can't open JVMCI shared library error report file. Error: "); tty->print_raw_cr(os::strerror(e)); - tty->print_cr("JVMCI shared library crash data will be written to console."); - _fatal_log_stream = tty; + tty->print_cr("JVMCI shared library error report will be written to console."); + + // See notes in VMError::report_and_die about hard coding tty to 1 + log.set_fd(1); } + _fatal_log_stream = &log; } } else { // Another thread won the race to initialize the stream. Give it time diff --git a/src/hotspot/share/utilities/vmError.cpp b/src/hotspot/share/utilities/vmError.cpp index 383e691996f6e..ec14e2095cae5 100644 --- a/src/hotspot/share/utilities/vmError.cpp +++ b/src/hotspot/share/utilities/vmError.cpp @@ -1589,7 +1589,7 @@ void VMError::report_and_die(int id, const char* message, const char* detail_fmt #if INCLUDE_JVMCI if (JVMCI::fatal_log_filename() != NULL) { - out.print_raw("#\n# The JVMCI shared library error data is saved as:\n# "); + out.print_raw("#\n# The JVMCI shared library error report file is saved as:\n# "); out.print_raw_cr(JVMCI::fatal_log_filename()); } #endif