"-XX:NewRatio" - Ratio of Tenured and "new" Generation

This section describes the default 'new' ratio (size ratio of tenured vs. 'new' generation).

If your application uses lots of short-lived objects, you may want to lower the ratio of Tenured generation over "new" generation by using the "-XX:NewRatio" JVM option.

By default, the "NewRatio" is set to 2.33 based tests we did in the last tutorial. If we specify "-XX:NewRatio=1" and "-Xms40m -Xmx40m", then 40 MB heap will be divided equally to 20 MB for the "new" generation and 20 MB for the tenured generation.

herong> java -Xms40m -Xmx40m -XX:NewRatio=1 -XX:+UseSerialGC \
   -Xlog:gc+heap=info GarbageCollection
...
[debug][gc,heap] GC(0) Heap after GC invocations=1 (full 0):
                        def new generation   total 18432K, used 2048K [...
[debug][gc,heap] GC(0)   eden space 16384K,   0% used [...
[debug][gc,heap] GC(0)   from space 2048K, 100% used [...
[debug][gc,heap] GC(0)   to   space 2048K,   0% used [...
[debug][gc,heap] GC(0)  tenured generation   total 20480K, used 2249K [...
[debug][gc,heap] GC(0)    the space 20480K,  10% used [...

The output confirms that the NewRatio is about 1 (or 20480K/18432K).

If you want to decrease the "new" generation size, you can specify "-XX:NewRatio=3" and "-Xms40m -Xmx40m", which will give us about 30 MB of tenured generation and 10 MB of "new" generation:

herong> java -Xms40m -Xmx40m -XX:NewRatio=3 -XX:+UseSerialGC \
   -Xlog:gc+heap=info GarbageCollection

...
[debug][gc,heap] GC(0) Heap after GC invocations=1 (full 0):
                        def new generation   total 9216K, used 1024K [...
[debug][gc,heap] GC(0)   eden space 8192K,   0% used [...
[debug][gc,heap] GC(0)   from space 1024K, 100% used [...
[debug][gc,heap] GC(0)   to   space 1024K,   0% used [...
[debug][gc,heap] GC(0)  tenured generation   total 30720K, used 2041K [...
[debug][gc,heap] GC(0)    the space 30720K,   6% used [...

You can also specify the "new" generation size directly with "-XX:NewSize=..." and "-XX:MaxNewSize=..." options to give a range:

herong> java -Xms40m -Xmx40m -XX:NewSize=9m -XX:MaxNewSize=11m \
   -XX:+UseSerialGC -Xlog:gc+heap=info GarbageCollection
...
[debug][gc,heap] GC(0) Heap after GC invocations=1 (full 0):
                        def new generation   total 8320K, used 896K [...
[debug][gc,heap] GC(0)   eden space 7424K,   0% used [...
[debug][gc,heap] GC(0)   from space 896K, 100% used [...
[debug][gc,heap] GC(0)   to   space 896K,   0% used [...
[debug][gc,heap] GC(0)  tenured generation   total 31744K, used 1805K [...
[debug][gc,heap] GC(0)    the space 31744K,   5% used [...

Table of Contents

 About This Book

 Heap Memory Area and Size Control

 JVM Garbage Collection Logging

 Introduction of Garbage Collectors

Serial Collector - "+XX:+UseSerialGC"

 What Is Serial Collector

 GC Log Message Format for Serial Collector

 GC Log Message Examples of Serial Collector

 Log Message Types from Serial Collector

 Serial Collector Stops Application for Minor/Major GC

 Usage Report on Heap Memory Areas

 Default NewRatio - Old vs. New Generation

"-XX:NewRatio" - Ratio of Tenured and "new" Generation

 "-XX:SurvivorRatio" - Ratio of Eden and Survivor Space

 Serial GC Tracing - Tight Heap

 Serial GC Tracing - Tight Heap (Part 2)

 Serial GC Tracing - Tight Heap (Part 3)

 Serial GC Tracing - Plenty of Heap

 Serial GC Tracing - Aged Live Objects

 Serial GC Tracing - Tenuring Threshold

 "-XX:TargetSurvivorRatio" - Second Tenuring Condition

 Serial GC Tracing - Tenuring Threshold Controlled

 "-XX:+NeverTenure" and "-XX:+AlwaysTenure" Working

 Minor GC Triggering Condition of Serial Collector

 Parallel Collector - "+XX:+UseParallelGC"

 Concurrent Mark-Sweep (CMS) Collector - "+XX:+UseConcMarkSweepGC"

 Garbage First (G1) Collector - "+XX:+UseG1GC"

 The Z Garbage Collector (ZGC) - "+XX:+UseZGC"

 Object References and Garbage Collection

 Garbage Collection Performance Test Program

 Performance Tests on Serial Collector

 Performance Tests on Parallel collector

 Performance Tests on Concurrent collector

 Performance Tests on G1 collector

 Garbage Collection Performance Test Summary

 References

 Full Version in PDF/EPUB