JDK-4796926 : Loading java.lang.Shutdown when permanent generation is full crashes JVM
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2002-12-20
  • Updated: 2012-10-08
  • Resolved: 2003-09-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Related Reports
Relates :  
Relates :  
Description
Compile the follwoing program:

    import java.util.LinkedList;

    public class InternStringALot {
        // The point of this class is to intern a lot of Strings,
        // to fill up the permanent generation and fail an assertion 
        // during shutdown.
        // This is *not* a bug with interning Strings, just that
        // this was the easiest way I could think of to fill up
        // the permanent generation.
        //
        // Run with:
        //    java -XX:MaxPermSize=4M -XX:+PrintGCDetails -XX:+PrintHeapAtGC InternStringALot

        public static void main(String arg[]) {
            long count = 20000;
            String base = "ABCEDFEGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz";
            if (arg.length > 0) {
                try {
                    count = Long.parseLong(arg[0]);
                } catch (NumberFormatException nfe) {
                    // Just ignore it.
                }
            }
            if (arg.length > 1) {
                base = arg[1];
            }
            System.out.println("Running with ");
            System.out.println("    base:  " + base);
            System.out.println("    count: " + Long.toString(count));
            long i = 0;
            try {
                for (i = 0; i < count; i += 1) {
                    list.add(base.concat(Long.toString(i)).intern());
                }
            } catch (OutOfMemoryError oome) {
                System.out.println("Caught OutOfMemoryError at iteration: " +
                                   Long.toString(i));
            }
        }

        private static LinkedList list = new LinkedList();
    }

and run it with the command line:

    % java -XX:MaxPermSize=4M InternStringALot

and you should produce the result:

    Running with 
	base:  ABCEDFEGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz
	count: 20000
    Caught OutOfMemoryError at iteration: 18345
    #
    # HotSpot Virtual Machine Error, Internal Error
    # Please report this error at
    # http://java.sun.com/cgi-bin/bugreport.cgi
    #
    # Java VM: Java HotSpot(TM) Client VM (1.4.2-beta-b08 mixed mode)
    #
    # Error ID: 455843455054494F4E530E4350500104 01
    #
    # Problematic Thread: prio=5 tid=0x0002e158 nid=0x1 runnable 
    #

    Heap at VM Abort:
    Heap
     def new generation   total 2112K, used 0K [0xf5000000, 0xf5220000, 0xf5710000)
      eden space 2048K,   0% used [0xf5000000, 0xf5000000, 0xf5200000)
      from space 64K,   0% used [0xf5200000, 0xf5200000, 0xf5210000)
      to   space 64K,   0% used [0xf5210000, 0xf5210000, 0xf5220000)
     tenured generation   total 1408K, used 514K [0xf5710000, 0xf5870000, 0xf9000000)
       the space 1408K,  36% used [0xf5710000, 0xf5790870, 0xf5790a00, 0xf5870000)
     compacting perm gen  total 4096K, used 4095K [0xf9000000, 0xf9400000, 0xf9400000)
       the space 4096K,  99% used [0xf9000000, 0xf93fffd0, 0xf9400000, 0xf9400000)
    Abort (core dumped)

The problem is that permanent generation is full when the JVM goes 
to run the shutdown hooks by loading java.lang.Shutdown.

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b22
14-06-2004

PUBLIC COMMENTS Loading java.lang.Shutdown when permanent generation is full crashes JVM
10-06-2004

SUGGESTED FIX One fix might be for the JVM to preload java.lang.Shutdown. That probably doesn't violate any class loading ordering constraints. ###@###.### 2002-12-20 The shutdown class would have been loaded if any shutdown hooks had been registered -- so this bug occurs in the case where there are no registered shutdown hooks. Currently, the Shutdown class - runs shutdown hooks - runs finalizers if runFinalizersOnExit (deprecated) was set Rather than affect startup time by preloading another class, the new suggested fix is to simply not call Shutdown.shutdown() if the Shutdown class hasn't already been loaded, and the VM cannot load it. ###@###.### 2003-09-18 Attached 2 new test cases to bug report, WithHook and WithHookSet, which add exit hooks to the original test case. These demonstrate that adding exit hooks will cause Shutdown to be loaded earlier. (WithHookSet attempts to run us out of memory during the running of the exit hook). ###@###.### 2003-09-18 Also added test case ExitFinalizers.java, which demonstrates that a call to Runtime.runFinalizersOnExit(true) will cause the Shutdown class to be loaded (it sets a flag in Shutdown, which is used during the shutdown sequence to decide if the finalizers should be run). ###@###.### 2003-09-18 Files: update: src/share/vm/runtime/thread.cpp ###@###.### 2003-09-19
18-09-2003

EVALUATION . Committing this to tiger for Jane. ###@###.### 2002-12-20 The crash occurs while loading the Shutdown class in order to run the shutdown hooks. Note that if any hooks had been registered, the Shutdown class would already have been loaded. ###@###.### 2003-09-18
18-09-2003