Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Corrected links that should have been relative instead of absolute.

JVM Types:

On machines that are not server-class machines, the default values for JVM, garbage collector, and heap sizes
are
• the client JVM
• the serial garbage collector
• Initial heap size of 4MB
• Maximum heap size of 64MB

On machines that have at least 2 CPU's and at least 2 GB of physical memory are considered server-class machines which means that by default the settings are:

    * The -server compiler
    * The -XX:+UseParallelGC parallel (throughput) garbage collector
    * The -Xms initial heap size is 1/64th of the machine's physical memory
    * The -Xmx maximum heap size is 1/4th of the machine's physical memory (up to 1 GB max).

Heap layout

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 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 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 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:

• Serial versus Parallel
• Concurrent versus Stop-the-world

Ratio of old to new generations

You can divide the heap into old and new generations using the NewRatio parameter. If you use -XX:NewRatio=5, then you create an old-to-new ratio of 5:1; the old generation occupies 5/6 of the heap while the new generation occupies 1/6 of the heap. If you increase the new generation's size, minor collections may occur less often. However, because the -Xmx parameter sets the total heap size, you also decrease the old generation's size. This may increase the frequency of major collections.

The default NewRatio for the HotSpot Client JVM is 8; the old generation occupies 8/9 of the heap while the new generation occupies 1/9

The default NewRatio for the HotSpot Server JVM is 2; the old generation occupies 2/3 of the heap while the new generation occupies 1/3, as Figure 4 above shows. The larger new generation can accommodate many more short-lived objects, thus decreasing the need for slow major collections. The old generation is still sufficiently large enough to hold many long-lived objects.

When no client or server parameter is provided, the Java HotSpot VM 1.3.1 uses its default value. The default is the first line in the jvm.cfg file, which is located in the <jvm_dir>/jre/lib directory. Rather than modifying all your startup scripts to add the -server parameter, you can make -server the first noncomment line in the file.

JVM command line options

 Options to select garbage collection
-XX:+UseSerialGC  Serial
-XX:+UseParallelGC  Parallel
-XX:+UseParallelOldGC  Parallel compacting
-XX:+UseConcMarkSweepGC Concurrent mark-sweep (CMS)

Options for Garbage Collector Statistics
-XX:+PrintGC Outputs basic information at every garbage collection.
-XX:+PrintGCDetails Outputs more detailed information at every garbage collection.
-XX:+PrintGCTimeStamps Outputs a time stamp at the start of each garbage collection event. Used with
-XX:+PrintGC or -XX:+PrintGCDetails to show when each garbage collection begins.

Heap options:
-Xms<size>        set initial Java heap size
-Xmx<size>        set maximum Java heap size
-Xss<size>        set java thread stack size
-XX:NewSize= Default initial size of the new (young) generation,in bytes.
-XX:NewRatio=n   Ratio between the young and old generations.
-XX:SurvivorRatio=n Ratio between each survivor space and Eden. For
example, if n is 7, each survivor space is one-ninth
of the young generation (not one-eighth, because
there are two survivor spaces).
-XX:MaxPermSize=n  Platform-dependent Maximum size of the permanent generation