Java GC: How is "Desired Survivor Size" calculated?

I am using HotSpot JVM 1.6.0_45 for Solaris. Here are my options regarding Heap:

-Xms8G
-Xmx8G
-XX:MaxTenuringThreshold=14
-XX:NewSize=2184M
-XX:MaxNewSize=2184M
-XX:SurvivorRatio=1

      

With these settings, I would expect Eden and 2 Survivors to be the same size 728M. After observing in VisualVM / VisualGC, this is what we get.

Here's an excerpt from my verbose gc logs:

2014-09-16T16:42:15.357+0200: 6.796: [GC 6.796: [ParNew Desired survivor size 381681664 bytes, new threshold 14 (max 14)
- age   1:   16125960 bytes,   16125960 total
- age   2:   16259512 bytes,   32385472 total
- age   3:    2435240 bytes,   34820712 total
- age   4:   17179320 bytes,   52000032 total
- age   5:   43986952 bytes,   95986984 total
- age   6:   20858328 bytes,  116845312 total
- age   7:   31571664 bytes,  148416976 total
- age   8:   41614872 bytes,  190031848 total
- age   9:   33191568 bytes,  223223416 total
- age  10:   22887432 bytes,  246110848 total
- age  11:        168 bytes,  246111016 total
- age  12:        184 bytes,  246111200 total 
: 1006811K->407353K(1490944K), 0.3248414 secs] 1006811K->407353K(7643136K), 0.3252604 secs] [Times: user=3.70 sys=0.04, real=0.33 secs] 
2014-09-16T16:42:24.650+0200: 16.089: [GC 16.089: [ParNew Desired survivor size 381681664 bytes, new threshold 14 (max 14)
- age   1:   21959968 bytes,   21959968 total
- age   2:   11169584 bytes,   33129552 total
- age   3:   15663128 bytes,   48792680 total
- age   4:    2435168 bytes,   51227848 total
- age   5:   17177584 bytes,   68405432 total
- age   6:   43976040 bytes,  112381472 total
- age   7:   20246264 bytes,  132627736 total
- age   8:   31478896 bytes,  164106632 total
- age   9:   41613872 bytes,  205720504 total
- age  10:   33190832 bytes,  238911336 total
- age  11:   22889304 bytes,  261800640 total
- age  12:        168 bytes,  261800808 total
- age  13:        184 bytes,  261800992 total
: 1152825K->302652K(1490944K), 0.3356240 secs] 1152825K->302652K(7643136K), 0.3360389 secs] [Times: user=3.96 sys=0.03, real=0.34 secs]

      

  • Why is the desired survivor size equal to "Survivor Space Size / 2"?

I understand that 2 survivors (728 MB each) are used alternatively by the JVM, but I can't figure out why it seems to use half of 728Mb (the desired survivor size determining when the memory will depend)

  1. From one GC to another, the bytes of age x + 1 must be equal to or less than the bytes of age x from the previous GC. But in my example, why is the age 11 of the second GC (22889304 bytes) higher than the age of 10 of the first GC (22887432 bytes)?
+3


source to share


2 answers


The default value for SurvivorRation is 50%. See jvm -XX: TargetSurvivorRatio = 50 parameter



http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

+1


source


Regarding the first question, the desired survivor space means the maximum survivor space used by living objects after each Small GC, which is calculated by SURVIVOR_SPACE * TargetSurvivorRatio / 100, so you get half the survivor by default. If the size of the live object exceeds the desired space for the survivors, the JVM will lower the threshold to force some objects to move to the old generation in the next GC.



I am also interested in the second question.

0


source







All Articles