Hitachi

uCosminexus Application Server System Design Guide


7.2.1 Overview of serial GC

GC is a technique that automatically reclaims memory that a program has finished using, making that memory available to other programs.

Program processing stops while GC is occurring. For this reason, appropriate implementation of GC significantly impacts the processing performance of the system.

The Java objects created in the program using new, occupy the memory space that is managed by JavaVM. The time period from the point where Java object gets created up to the point where it becomes redundant is called the lifespan of a Java object.

There are two types of Java objects; those with a short lifespan and those with a long lifespan. In the case of a Java application running on the server, a number of Java objects are created by request and response, or by transaction management. These Java objects have a short lifespan, as they become redundant when the processing ends. On the other hand, the Java objects that are continuously being used while the application is running have a long lifespan.

To implement GC effectively, you need to reclaim memory efficiently by targeting objects with a short lifespan. Another key to maintaining system performance is to avoid unnecessary GC for repeatedly used objects with long lifespans. An approach that achieves both these objectives is generational GC.

Generational GC manages Java objects in a New area which stores objects with a short lifespan, and a Tenured area which stores objects with a long lifespan. The New area is further divided into an Eden area for objects that were just created by the new operator, and a Survivor area for objects that have survived GC at least once. Java objects that have undergone GC in the New area a certain number of times are determined to have long-term utility and transferred to the Tenured area.

The following figure shows an overview of the memory spaces managed by generational GC and how Java objects move among them.

Figure 7‒1: Overview of memory spaces managed by generational GC and Java objects

[Figure]

There are two types of GC executed by generational GC under the serial GC technique.

Generally, copy GC takes less time to perform than Full GC.

The following explains GC processing using the example of a specific Java object (Object A).

Processing executed in the Eden area

After creating an object A, the object A is destroyed if not used when the first copy GC is executed.

If object A is used when first copy GC is executed, the object A moves from the Eden area to the Survivor area.

Processing executed in the Survivor area

The object A that moved to the Survivor area, moves from the Survivor area to the Tenured area even when the copy GC is executed for several times afterwards. The threshold value for frequently moving the object differs according to the used state of the JavaVM options and the Java heap. In Figure 7-1, the threshold value is assumed to be n times.

After moving to the Survivor area, if object A is not used when the copy GC is executed less than n times, then the object A is destroyed by that copy GC.

Processing executed in the Tenured area

Once the object A is moved to the Tenured area, the object A cannot be destroyed by the copy GC, because the copy GC is executed only for the Eden area and the Survivor area.

Moving objects in this way increases the used space of the Tenured area. Full GC is triggered when the used space of the Tenured area reaches a certain size.

When tuning the JavaVM, by setting the appropriate size and ratio of each memory space in the JavaVM options, you can prevent unnecessary objects from being moved to the Tenured area. This reduces the frequency with which Full GC occurs.