JDK-6784422 : -XX:+HeapDumpOnOutOfMemoryError does not work when OOM caused by failure to alloc native thread
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-12-12
  • Updated: 2011-02-16
  • Resolved: 2010-12-17
Description
FULL PRODUCT VERSION :
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Server VM (build 11.0-b16, mixed mode)

and

java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b39)
Java HotSpot(TM) Server VM (build 14.0-b06, mixed mode)

FULL OS VERSION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
-XX:+HeapDumpOnOutOfMemoryError does not work when OOM caused by "unable to create new native thread"

Full dump:

Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
        at java.lang.Thread.start0(Native Method)
        at java.lang.Thread.start(Thread.java:597)
        at test.ConsumeThreads.main(ConsumeThreads.java:20)


THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Did not try

THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Using test program ConsumeThreads.java (provided below) and the command line:
java -server -XX:+HeapDumpOnOutOfMemoryError test.ConsumeThreads

EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected heap dump, did not get one
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
        at java.lang.Thread.start0(Native Method)
        at java.lang.Thread.start(Thread.java:597)
        at test.ConsumeThreads.main(ConsumeThreads.java:14)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package test;

import java.util.ArrayList;

public class ConsumeThreads
{
    public static void main(String[] args)
    {
        ArrayList list = new ArrayList();
        
        while (true)
        {
            Thread thread = new MyThread();
            thread.start();
            list.add(thread);
        }
    }
    
    static class MyThread
    extends Thread
    {
        public void run()
        {
            synchronized(this)
            {
                try
                {
                    this.wait();
                }
                catch (InterruptedException e)
                {
                    e.printStackTrace();
                }
            }
        }
    }

}
---------- END SOURCE ----------

Comments
EVALUATION The main report is not a bug, see evaluation -1 from dholmes. I can't reproduce the hs_err stack trace attached. My guess is that the pending exception is java.lang.OutOfMemoryError from the failed thread create, and the internal error happened as a side effect of that. Without a stack trace, it's hard to know what other code might have returned with an error and hit this ExceptionMark destructor.
17-12-2010

EVALUATION From the documentation: http://java.sun.com/javase/6/webnotes/trouble/TSG-VM/html/clopts.html The -XX:+HeapDumpOnOutOfMemoryError command-line option tells the HotSpot VM to generate a heap dump when an allocation from the Java heap or the permanent generation cannot be satisfied. ---- Allocation of a native thread is not from the heap or the permanent generation - hence failure to allocate one does not result in a heap dump. (There would be little point in dumping the heap as that is not what was exhausted.)
12-12-2008