RFR: 8369442: ExitOnOutOfMemoryError should exit more gracefully

David Holmes dholmes at openjdk.org
Fri Oct 10 01:11:05 UTC 2025


On Thu, 9 Oct 2025 08:35:50 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

> See RFE for more discussion. It seems we have a leeway in defining what "exit" means for `-XX:+ExitOnOutOfMemoryError`, and this PR does it more akin to `JVM_Halt`, rather than abrupt `os::_exit`. This gives VM a chance to shutdown some of its subsystems gracefully.
> 
> Comments welcome!
> 
> Additional testing:
>  - [x] Linux x86_64 server fastdebug, `tier1`
>  - [ ] Linux x86_64 server fastdebug, `all`

One concern I just realized with this, is that we will now grab the Heap_lock before doing the `VM_Exit` safepoint op. But we are calling this in the context of a failed allocation, so are we sure this will always be safe and not e.g. cause a deadlock?

I don't know who might use ExitOnOutOfMemoryError, nor in what way, so it is hard to say whether this change might break something

src/hotspot/share/utilities/debug.cpp line 287:

> 285:     if (ExitOnOutOfMemoryError) {
> 286:       tty->print_cr("Terminating due to java.lang.OutOfMemoryError: %s", message);
> 287:       // Gracefully exit with no cleanup hooks run.

Suggestion:

      // Gracefully exit with no cleanup hooks run - just like JVM_Halt

-------------

PR Review: https://git.openjdk.org/jdk/pull/27718#pullrequestreview-3321041988
PR Review Comment: https://git.openjdk.org/jdk/pull/27718#discussion_r2418275876


More information about the hotspot-dev mailing list