diff --git a/src/hotspot/share/utilities/vmError.cpp b/src/hotspot/share/utilities/vmError.cpp index a290602e0be..41f8975ce47 100644 --- a/src/hotspot/share/utilities/vmError.cpp +++ b/src/hotspot/share/utilities/vmError.cpp @@ -1725,6 +1725,10 @@ void VMError::report_and_die(int id, const char* message, const char* detail_fmt _size = size; jio_vsnprintf(_detail_msg, sizeof(_detail_msg), detail_fmt, detail_args); + // Jfr::on_vm_shutdown should be called before installing crash handler for error reporting + // because LeakProfiler::emit_events() would kick both VM Operation and long-running execution. + JFR_ONLY(Jfr::on_vm_shutdown(static_cast(_id) == OOM_JAVA_HEAP_FATAL, true);) + reporting_started(); if (!TestUnresponsiveErrorHandler) { // Record reporting_start_time unless we're running the @@ -1898,8 +1902,6 @@ void VMError::report_and_die(int id, const char* message, const char* detail_fmt log.set_fd(-1); } - JFR_ONLY(Jfr::on_vm_shutdown(static_cast(_id) == OOM_JAVA_HEAP_FATAL, true);) - if (PrintNMTStatistics) { fdStream fds(fd_out); MemTracker::final_report(&fds);