Java Reference
In-Depth Information
The JVM determines whether to increase or decrease the size of the survivor spaces (subject
to the defined ratios) based on how full a survivor space is after a GC. The survivor spaces
will be resized so that they are, by default, 50% full after a GC. That value can be changed
with the -XX:TargetSurvivorRatio= N flag.
Finally, there is the question of how many GC cycles an object will remain ping-ponging
between the survivor spaces before being moved into the old generation. That answer is de-
termined by the tenuring threshold. The JVM continually calculates what it thinks the best
tenuring threshold is. The threshold starts at the value specified by the -
XX:InitialTenuringThreshold= N flag (the default is 7 for the throughput and G1 collect-
ors, and 6 for CMS). The JVM will ultimately determine a threshold between 1 and the value
specified by the -XX:MaxTenuringThreshold= N flag; for the throughput and G1 collectors,
the default maximum threshold is 15, and for CMS it is 6.
ALWAYS AND NEVER TENURE
The tenuring threshold will always take on some range between 1 and MaxTenuringThreshold .
Even if the JVM is started with an initial tenuring threshold equal to the maximum tenuring
threshold, the JVM may decrease that value.
There are two flags that can circumvent that behavior at either extreme. If you know that objects
that survive a young collection will always be around for a long time, you can specify -
XX:+AlwaysTenure (by default, false ), which is essentially the same as setting the MaxTenurin-
gThreshold to 0. This is a very, very rare situation; it means that objects will always be promoted
to the old generation rather than stored in a survivor space.
The second flag is -XX:+NeverTenure (also false by default). This flag affects two things: it be-
haves as if the initial and max tenuring thresholds are infinity, and it prevents the JVM from ad-
justing that threshold down. In other words, as long as there is room in the survivor space, no ob-
ject will ever be promoted to the old generation.
Given all that, which values might be tuned under which circumstances? It is helpful to look
at the tenuring statistics, which can be added to the GC log by including the flag -
XX:+PrintTenuringDistribution (which is false by default).
The most important thing to look for is whether the survivor spaces are so small that during a
minor GC, objects are promoted directly from eden into the old generation. The reason to
Search WWH ::




Custom Search