Original case where I discovered this: used Epsilon to reproduce JDK-8360595 that triggers when OOM happens in many threads at once, and it almost works. But Epsilon seems to exit very abruptly, with a single OOME terminating the whole JVM. Barely any other thread is able to do anything before VM goes down.
I believe this is due to Epsilon opting into +ExitOnOutOfMemoryError, which is implemented as abrupt os::_exit. I see that David argued inJDK-8274136 that we should maybe perform a more graceful shutdown with +EOOME.
Looking at current shutdown code, I think +EOOME misses flushing the log streams, verifications, stats printing, all that jazz as well.
With a simple:
diff --git a/src/hotspot/share/utilities/debug.cpp b/src/hotspot/share/utilities/debug.cpp
index 6d8a82b6798..add692aa5ee 100644
--- a/src/hotspot/share/utilities/debug.cpp
+++ b/src/hotspot/share/utilities/debug.cpp
@@ -284,7 +284,9 @@ void report_java_out_of_memory(const char* message) {
if (ExitOnOutOfMemoryError) {
tty->print_cr("Terminating due to java.lang.OutOfMemoryError: %s", message);
- os::_exit(3); // quick exit with no cleanup hooks run
+ // Gracefully exit with no cleanup hooks run.
+ before_exit(JavaThread::current());
+ vm_exit(3);
}
}
}
...JDK-8360595 catches much more threads with OOMEs.
I believe it keepsJDK-8274136 from re-occuring, as we gracefully shutdown things.
I believe this is due to Epsilon opting into +ExitOnOutOfMemoryError, which is implemented as abrupt os::_exit. I see that David argued in
Looking at current shutdown code, I think +EOOME misses flushing the log streams, verifications, stats printing, all that jazz as well.
With a simple:
diff --git a/src/hotspot/share/utilities/debug.cpp b/src/hotspot/share/utilities/debug.cpp
index 6d8a82b6798..add692aa5ee 100644
--- a/src/hotspot/share/utilities/debug.cpp
+++ b/src/hotspot/share/utilities/debug.cpp
@@ -284,7 +284,9 @@ void report_java_out_of_memory(const char* message) {
if (ExitOnOutOfMemoryError) {
tty->print_cr("Terminating due to java.lang.OutOfMemoryError: %s", message);
- os::_exit(3); // quick exit with no cleanup hooks run
+ // Gracefully exit with no cleanup hooks run.
+ before_exit(JavaThread::current());
+ vm_exit(3);
}
}
}
...JDK-8360595 catches much more threads with OOMEs.
I believe it keeps
- relates to
-
JDK-8274136 -XX:+ExitOnOutOfMemoryError calls exit while threads are running
-
- Resolved
-
-
JDK-8138745 Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
-
- Resolved
-
- links to
-
Review(master) openjdk/jdk/27718