Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The HotSpot JVM manages heap space in generations -- that is, memory pools for both new and old objects.
Memory in the Java HotSpot virtual machine is organized into three generations: a young generation, an old
generation, and a permanent generation. The new The young generation includes the new object space (eden), plus two survivor spaces (SS#1 and SS#2).
New objects allocate in eden. Longer-lived objects are moved from the young generation and tenured to the new generation and tenured to the old generation.
hows old generation. One survivor space is empty at any time, and serves as a destination of the next, copying collection of any live objects in eden and the other survivor space. Objects are copied between survivor spaces in this way until they are old enough to be tenured, or copied to the tenured generation. There is another heap section, called the permanent generation, which holds the JVM's class and method objects.
which holds data needed by the virtual machine to describe objects that do not have an equivalence at the Java language level. For example objects describing classes and methods are stored in the permanent generation. The -XX:MaxPermSize=64m command line parameter controls the permanent generation's size.

As these objects accumulate, eventually a low memory condition occurs, forcing garbage collection to take place. When the young generation fills up, a young generation collection (sometimes referred to as a minor collection)
of just that generation is performed. When the old or permanent generation fills up, what is known as a full
collection (sometimes referred to as a major collection) is typically done. That is, all generations are collected.

Performance Considerations

There are two primary measures of garbage collection performance. Throughput is the percentage of total time not spent in garbage collection, considered over long periods of time. Throughput includes time spent in allocation (but tuning for speed of allocation is generally not needed.) Pauses are the times when an application appears unresponsive because garbage collection is occurring.

Users have different requirements of garbage collection. For example, some consider the right metric for a web server to be throughput, since pauses during garbage collection may be tolerable, or simply obscured by network latencies. However, in an interactive graphics program even short pauses may negatively affect the user experience.

Some users are sensitive to other considerations. Footprint is the working set of a process, measured in pages and cache lines. On systems with limited physical memory or many processes, footprint may dictate scalability. Promptness is the time between when an object becomes dead and when the memory becomes available, an important consideration for distributed systems, including remote method invocation (RMI).

In general, a particular generation sizing chooses a trade-off between these considerations. For example, a very large young generation may maximize throughput, but does so at the expense of footprint, promptness, and pause times. young generation pauses can be minimized by using a small young generation at the expense of throughput. To a first approximation, the sizing of one generation does not affect the collection frequency and pause times for another generation.

There is no one right way to size generations. The best choice is determined by the way the application uses memory as well as user requirements. For this reason the virtual machine's choice of a garbage collectior are not always optimal, and may be overridden by the user in the form of command line options, described below.

Garbage collection Algorithms:

...