Frage

A JVM application runs on Oracle Hotspot JVM, it starts up with default JVM settings, but with 100MB of initial heap size and 1GB of maximum heap size.

Under which circumstances will JVM decide to grow the current heap size, instead of trying GC?

War es hilfreich?

Lösung

HotSpot JVM continuously monitors allocation rates and objects lifetimes. It tries to achieve two key factors:

  1. let short-lived objects die in eden
  2. 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 pauses
  • AdaptiveSizeThroughPutPolicy, which will pick heap size to achieve highest throughtput
  • GCTimeLimit and GCTimeRatio, which sets time spent in application execution

Andere Tipps

Number of object which occupies the Heap increases while garbage collection is not possible.

When objects not possible to collect as garbage since they are use by current process, JVM need to increase it's heap size towards it is maximum to allow to create new objects.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top