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

OutOfMemoryError fails to generate stack trace as it now ought

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • hs21
    • 6
    • hotspot
    • b02
    • x86
    • windows_xp
    • Verified

        FULL PRODUCT VERSION :
        java version "1.6.0-beta2"
        Java(TM) SE Runtime Environment (build 1.6.0-beta2-b86)
        Java HotSpot(TM) Client VM (build 1.6.0-beta2-b86, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows XP [Version 5.1.2600]

        A DESCRIPTION OF THE PROBLEM :
        One of the stated goals of Mustang is to "Improve the diagnosability of java.lang.OutOfMemoryError".

        In particular:
        "For example, you should now see a stack trace when an OutOfMemoryError is thrown when the heap is full."
        http://java.sun.com/developer/technicalArticles/J2SE/Desktop/JavaSE6_build39.html
          See also:
        http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4753347
        which claims that mustang(b34) fixed this.

        But I have a simple test class (see below) which should generate an OutOfMemoryError. But not only does it fail to generate the long promised OutOfMemoryError stack trace, it even fails to notify me that an OutOfMemoryError occured at all--it simply says that an Exception happened.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Enter the following code into a file named MemErrDiagnose.java
        Then compile and run it on a command line (or in your favorite IDE) using

        javac MemErrDiagnose.java

        java -classpath ./ -Xmx10m MemErrDiagnose


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Running the java command described above should result in a few lines like

        allocate #1
        allocate #2

        followed by a complete stack trace of the OutOfMemoryError. The OutOfMemoryError should also state that it was specifically due to lack of heap space.
        ACTUAL -
        Running the java command described above actually produced just the following output

        allocate #1
        allocate #2
        Exception in thread "main"

        That last line is the problem: it is totally generic (not even a OutOfMemoryError) and it lacks a stack trace.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.util.*;

        public class MemErrDiagnose {

        private static final Random random = new Random();
        private static long count = 0;
        private static final List<Object> list = new LinkedList<Object>();

        public static void main(String[] args) {
        try {
        while (true) {
        allocate();
        }
        }
        catch (Throwable t) {
        System.err.println( t.getClass().getName() );
        t.printStackTrace( System.err );
        }
        }

        private static void allocate() {
        System.out.println( "allocate #" + (++count) );
        int n = random.nextInt(1000 * 1000);
        for (int i = 0; i < n; i++) {
        list.add( new Object() );
        }
        }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        None that I know of.

              coleenp Coleen Phillimore
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: