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

Memory leak when exception is thrown in static initializer

XMLWordPrintable

    • b01
    • generic
    • generic
    • Verified

        The attached test case tries to load and initialize the following class in a loop:

        /** Class that will throw exception in clinit. */
        final class ErrorInClinit {
            static {
                willThrowError();
            }
            /** Implemented default constructor. */
            private ErrorInClinit() { }
            /** Method that throws error. */
            static void willThrowError() {
                throw new NoClassDefFoundError("check");
            }
        }

        Process size grows rapidly, and eventually hits OS limits:

        $ ulimit -v 2000000

        $ /set/vmsqe/jdk/re/7/promoted/ea/b106/binaries/linux-amd64/bin/java KS &

        $ jps -l | grep KS | (read a b; while :; do ps -o pid,size,rss,vsize --no-headers $a; sleep 10; done)
        14121 1308576 56720 1356100
        14121 1439648 171100 1487172
        14121 1505184 285096 1552708
        14121 1636256 399216 1683780
        14121 1767328 513372 1814852
        14121 1898400 627564 1945924
        #
        # A fatal error has been detected by the Java Runtime Environment:
        #
        # java.lang.OutOfMemoryError: requested 41 bytes for char in /BUILD_AREA/jdk7/hotspot/src/share/vm/oops/instanceKlass.cpp. Out of swap space?
        #
        # Internal Error (allocation.inline.hpp:39), pid=14121, tid=139729910605584
        # Error: char in /BUILD_AREA/jdk7/hotspot/src/share/vm/oops/instanceKlass.cpp
        #
        # JRE version: 7.0
        # Java VM: Java HotSpot(TM) 64-Bit Server VM (19.0-b05 mixed mode linux-amd64 compressed oops)
        # An error report file with more information is saved as:
        # /set/vmsqe/home/sd208054/ws/ksleak/src/hs_err_pid14121.log
        #
        # If you would like to submit a bug report, please visit:
        # http://java.sun.com/webapps/bugreport/crash.jsp

              kamg Keith Mcguigan (Inactive)
              sdolgovorcl Sergey Dolgov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: