(Note that when I say "JVM", I really mean "Hotspot", and I'm running the latest Java 1.6 update.)
Example situation:
My JVM is running with -Xmx set to 1gb. Currently, the heap has 500mb allocated, of which 450mb is used. The program needs to load another 200 mb on the heap. Currently, there is 300mb worth of "collectable" garbage in the heap (we'll assume it's all in the oldest generation.)
Under normal operation, the JVM will grow the heap to 700 mb or so, and garbage collect when it gets around to it.
What I would like in that situation is for the JVM to gc first, then allocate the new stuff, so that we end up with the heap size staying at 500mb, and the used heap at 350mb.
Is there a JVM parameter combo that does that?
CMS
is generally inferior toG1
, although perhaps your answer predates it. – Ponton