JDK-8155585 : ExitOnOutOfMemory doesn't work well for outof memory error
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 8u92
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2016-04-28
  • Updated: 2021-04-20
  • Resolved: 2016-05-02
Related Reports
Duplicate :  
Relates :  
Description
New Vm option ExitOnOutOfMemory doesn't work well, when we tried to create multiple threads in a loop. In this case it failed to allocate memory and OOM occurs. Instead of crashing progrma keep running

Comments
The same issue is discussed at JDK-8155004. Closing this bug as a duplicate
02-05-2016

With latest code it seems to me, it works as expected. shafi@shafi-ahmad:~/Bugs/JDK-8155004$ java -version java version "1.8.0-internal-debug" Java(TM) SE Runtime Environment (build 1.8.0-internal-debug-shafi_2016_04_22_12_37-b00) Java HotSpot(TM) 64-Bit Server VM (build 25.71-b00-debug, mixed mode) shafi@shafi-ahmad:~/Bugs/JDK-8155004$ javac Test.java shafi@shafi-ahmad:~/Bugs/JDK-8155004$ java -Xmx2048k -Xms2048k -XX:+CrashOnOutOfMemoryError Test Aborting due to java.lang.OutOfMemoryError: Java heap space # To suppress the following error report, specify this argument # after -XX: or in .hotspotrc: SuppressErrorAt=/debug.cpp:308 # # A fatal error has been detected by the Java Runtime Environment: # # Internal Error (/home/shafi/Java/jdk8/jdk8u-dev/hotspot/src/share/vm/utilities/debug.cpp:308), pid=6555, tid=0x00007f9b9c126700 # fatal error: OutOfMemory encountered: Java heap space # # JRE version: Java(TM) SE Runtime Environment (8.0) (build 1.8.0-internal-debug-shafi_2016_04_22_12_37-b00) # Java VM: Java HotSpot(TM) 64-Bit Server VM (25.71-b00-debug mixed mode linux-amd64 compressed oops) # Core dump written. Default location: /home/shafi/Bugs/JDK-8155004/core or core.6555 # # An error report file with more information is saved as: # /home/shafi/Bugs/JDK-8155004/hs_err_pid6555.log # # If you would like to submit a bug report, please visit: # http://bugreport.java.com/bugreport/crash.jsp # Current thread is 140306315110144 Dumping core ... Aborted (core dumped)
28-04-2016

This seems to be exactly the same as JDK-8155004. Note that the termination cause on JDK 9 is different to that in 8u92 - in 9 we are running out of Java heap; in 8u92 we are unable to create the native thread. We don't do Exit/CrashOnOutOfMemoryError processing when we fail to create native threads, in either 9 or 8u.
28-04-2016

Program works fine in 9-ea b115. In 8u92 after oom program will be still running, required to press ctr+c to retun. Below is the output -sh-4.1$ /opt/java/jdk1.8.0_92/bin/javac Test.java -sh-4.1$ /opt/java/jdk1.8.0_92/bin/java -Xmx2048k -Xms2048k -XX:+ExitOnOutOfMemoryError Test Exception in thread "Thread-0" java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Thread.java:714) at Test.lambda$main$1(Test.java:13) at java.lang.Thread.run(Thread.java:745) ^C-sh-4.1$ /opt/java/jdk -sh-4.1$ /opt/java/jdk-9_ea-115/bin/javac Test.java -sh-4.1$ /opt/java/jdk-9_ea-115/bin/java -Xmx2048k -Xms2048k -XX:+ExitOnOutOfMemoryError Test Terminating due to java.lang.OutOfMemoryError: Java heap space -sh-4.1$
28-04-2016

There is an element of non-determinism as to where you will run out of memory first. If it is creating the native thread then you won't get the desired result. If it is the Java heap then you will.
28-04-2016