Managing Memory and Garbage Collection
memory structures. The difference between the maximum address space and the total of those
values is the amount of memory that can be allocated to the heap.
You can improve performance by increasing your heap size or using a different garbage
collector. In general, for long-running server applications, use the J2SE throughput collector on
machines with multiple processors (-XX:+AggressiveHeap) and as large a heap as you can fit in
the free memory of your machine.
Heap Tuning Parameters
You can control the heap size with the following JVM parameters:
■
■
■
■
■
■
■
■
The -Xms and -Xmx parameters define the minimum and maximum heap sizes, respectively.
Since GC occurs when the generations fill up, throughput is inversely proportional to the
amount of the memory available. By default, the JVM grows or shrinks the heap at each GC to
try to keep the proportion of free space to the living objects at each collection within a specific
range. This range is set as a percentage by the parameters -XX:MinHeapFreeRatio=minimum
and -XX:MaxHeapFreeRatio=maximum; and the total size bounded by -Xms and -Xmx.
Set the values of -Xms and -Xmx equal to each other for a fixed heap size. When the heap grows
or shrinks, the JVM must recalculate the old and new generation sizes to maintain a predefined
NewRatio.
The NewSize and MaxNewSize parameters control the new generation's minimum and
maximum size. Regulate the new generation size by setting these parameters equal. The bigger
the younger generation, the less often minor collections occur. The size of the young generation
relative to the old generation is controlled by NewRatio. For example, setting -XX:NewRatio=3
means that the ratio between the old and young generation is 1:3, the combined size of eden and
the survivor spaces will be fourth of the heap.
By default, the Enterprise Server is invoked with the Java HotSpot Server JVM. The default
NewRatio for the Server JVM is 2: the old generation occupies 2/3 of the heap while the new
generation occupies 1/3. The larger new generation can accommodate many more short-lived
objects, decreasing the need for slow major collections. The old generation is still sufficiently
large enough to hold many long-lived objects.
To size the Java heap:
88
Sun GlassFish Enterprise Server 2.1 Performance Tuning Guide • January 2009
-Xmsvalue
-Xmxvalue
-XX:MinHeapFreeRatio=minimum
-XX:MaxHeapFreeRatio=maximum
-XX:NewRatio=ratio
-XX:NewSize=size
-XX:MaxNewSize=size
-XX:+AggressiveHeap
Need help?
Do you have a question about the Sun GlassFish Enterprise Server 2.1 and is the answer not in the manual?
Questions and answers