HotSpot JVM continuously monitors allocation rates and objects lifetimes. It tries to achieve two key factors:
- let short-lived objects die in eden
- promote long-lived object to heap on time to prevent unnecessarily copying between survivor spaces
In a nutshell you can describe it as the HotSpot have some configured threshold which indicates how much pecentage of total allocated heap have to by free after running garbage collector. For example if this threshold is configured for 70% and after running full GC heap usage will be 80%, then additional memory will be allocated to hit the threshold. Of course bigger heap means longer pauses while smaller heap means more frequent collections.
But you have to remember that JVM is very complex, and you can change this behaviour, for example by using flags:
AdaptiveSizePausePolicy
, which will pick heap size to achieve shortest pausesAdaptiveSizeThroughPutPolicy
, which will pick heap size to achieve highest throughtputGCTimeLimit
andGCTimeRatio
, which sets time spent in application execution