Setting the heap and nursery size for garbage collection

Garbage collection is the process of freeing unused objects in the JVM so that portions of the heap can be reused.

Garbage collection occurs when there is a request for memory, and the request cannot be readily satisfied from the free memory available in the heap (allocation failure). Garbage collection also occurs when a Java class library System.gc() call is made. In this case garbage collection occurs immediately and synchronously.

While the function provided by the SUN HotSpot and IBM garbage collectors is the same, the underlying technology is different. For both JVMs garbage collection takes place in three phases: mark, sweep, and an optional compact phase.

The implementation of the garbage collection phases is different because the Sun HotSpot engine is a generational collector and the IBM JVM is not. A detailed discussion of the HotSpot generational collector can be found at the following URL: http://java.sun.com/docs/hotspot/gc/index.html

With the IBM JVM, the full heap is consumed before a garbage collection is triggered. The first phase is to mark all referenced objects in the region being collected, which leaves all un-referenced objects unmarked and the space they occupy free to be collected and reused. Following the mark phase, free chunks of memory are added to a freelist. This phase is referred to as sweeping. For performance reasons, the IBM JVM only frees chunks of heap space greater than 512 bytes.

Following the sweep phase, a compact phase is sometimes performed. The compact phase moves objects closer together to create larger contiguous free chunks. Because compaction is time-consuming, avoid it when possible For most System.gc() calls compaction is performed. The IBM JVM has been optimized to avoid compaction.

The following table explains which phases of garbage collection are multi-threaded and which are concurrent. Concurrent means the process runs while the application threads continue to execute. If the process is not concurrent it means that the program pauses during that phase of garbage collection.

Table 47. JVM Release Mark Sweep Compact

JVM release Type Mark Sweep Compact
Sun HotSpot 1.3.1 Multithreaded No No No
Sun HotSpot 1.3.1 Concurrent No No No
IBM JVM 1.3.1 Multithreaded Yes Yes No
IBM JVM 1.3.1 Concurrent Optional No No

Copyright IBM Corp. 1997, 2004