
Managing Memory and Garbage Collection
Managing Memory and Garbage Collection
The efficiency of any application depends on how well memory and garbage collection are managed. The following sections provide information on optimizing memory and allocation functions:
■“Goals” on page 32
■“Tracing Garbage Collection” on page 86
■“Other Garbage Collector Settings” on page 86
■“Tuning the Java Heap” on page 87
■“Rebasing DLLs on Windows” on page 89
■“Further Information” on page 91
Tuning the Garbage Collector
Garbage collection (GC) reclaims the heap space previously allocated to objects no longer needed. The process of locating and removing the dead objects can stall any application and consume as much as 25 percent throughput.
Almost all Java Runtime Environments come with a generational object memory system and sophisticated GC algorithms. A generational memory system divides the heap into a few carefully sized partitions called generations. The efficiency of a generational memory system is based on the observation that most of the objects are short lived. As these objects accumulate, a low memory condition occurs forcing GC to take place.
The heap space is divided into the old and the new generation. The new generation includes the new object space (eden), and two survivor spaces. The JVM allocates new objects in the eden space, and moves longer lived objects from the new generation to the old generation.
The young generation uses a fast copying garbage collector which employs two
The frequent young space collections are quick (a few milliseconds), while the full generation collection takes a longer (tens of milliseconds to a few seconds, depending upon the heap size).
Other GC algorithms, such as the Concurrent Mark Sweep (CMS) algorithm, are incremental. They divide the full GC into several incremental pieces. This provides a high probability of small pauses. This process comes with an overhead and is not required for enterprise web applications.
84 | Sun GlassFish Enterprise Server 2.1 Performance Tuning Guide • January 2009 |