Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8369442

ExitOnOutOfMemoryError should exit more gracefully

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • hotspot
    • None

      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 in JDK-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 keeps JDK-8274136 from re-occuring, as we gracefully shutdown things.

            shade Aleksey Shipilev
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: