Java – Are ratios between spaces/generations in the Java Heap constant

garbage-collectionjavajvm

I have read this article about virtual machine garbage collection tuning to understand the java garbage collector better. Each space has a Virtual heap space area which it can grow into as the heap space needed gets closer to the max heap size. This can be seen in this picture:
Java GC arrangement of generations
(source: oracle.com)

You can set the ratio between Young Generation and Old (Tenured) Generation with the NewRatio parameter, and the ratio between Eden Space and Survivor Space with the SurvivorRatio parameter.

Recently this question was asked about finding out the default ratios for the heap spaces. It says you should use the PrintGCDetails parameter and calculate the ratios manually.

My question is: Does the size of the different heap spaces increase by the same ratio, thus keeping the ratio set between them at startup constant during the whole runtime of the application? For example, if Young Generation and Old/Tenured Generation has a default NewRatio of 3, and the initial reserved heap space is 100MB for Young, and 300MB for Old. If more memory needs to be reserved for the Old Space, lets say 300MB more making it 600MB total. Does memory reserved for Young Space also double to 200MB keeping the ratio intact?

Best Answer

I think you are referring to GC Ergonomics and the Adaptive Size Policy

  • a feature of the Hotspost GC that automatically adapts the sizes of the generations at runtime based on the current allocation behavior of the running application.
  • This feature is ON by default and controls/adapts the size of the generations at runtime.
  • in fact, some of the GC parameters will be ignored if you do not disable Adaptive Size policy, eg. -XX:SurvivorRatio=.

You can disable the Adaptive Size Policy by using the -XX:-UseAdaptiveSizePolicy. Once you disabled the AdaptiveSizePolicy, the GC will respect the initial size of the generations as specified by your startup parameters (e.g. -Xms, -Xmx, -XX:MaxNewSize=,-XX:NewSize=, -XX:SurvivorRatio=) and they will remain constant.

You can find more on Adaptive Size policy in UseAdaptiveSizePolicy and other jvm opts.