File tree Expand file tree Collapse file tree 1 file changed +20
-16
lines changed
Expand file tree Collapse file tree 1 file changed +20
-16
lines changed Original file line number Diff line number Diff line change @@ -176,26 +176,30 @@ public class GCTest {
176176
177177大部分情况,对象都会首先在 Eden 区域分配,在一次新生代垃圾回收后,如果对象还存活,则会进入 s0 或者 s1,并且对象的年龄还会加 1(Eden 区->Survivor 区后对象的初始年龄变为 1),当它的年龄增加到一定程度(默认为 15 岁),就会被晋升到老年代中。对象晋升到老年代的年龄阈值,可以通过参数 ` -XX:MaxTenuringThreshold ` 来设置。
178178
179- > 修正([ issue552] ( https://github.com/Snailclimb/JavaGuide/issues/552 ) ):“Hotspot 遍历所有对象时,按照年龄从小到大对其所占用的大小进行累积,当累积的某个年龄大小超过了 survivor 区的一半时 ,取这个年龄和 MaxTenuringThreshold 中更小的一个值,作为新的晋升年龄阈值”。
179+ > 修正([ issue552] ( https://github.com/Snailclimb/JavaGuide/issues/552 ) ):“Hotspot 遍历所有对象时,按照年龄从小到大对其所占用的大小进行累积,当累积的某个年龄大小超过了 survivor 区的 50% 时(默认值是 50%,可以通过 ` -XX:TargetSurvivorRatio=percent ` 来设置,参见 [ issue1199 ] ( https://github.com/Snailclimb/JavaGuide/issues/1199 ) ) ,取这个年龄和 MaxTenuringThreshold 中更小的一个值,作为新的晋升年龄阈值”。
180180>
181- > ** 动态年龄计算的代码如下**
181+ > jdk8官方文档引用 :https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html 。
182+ >
183+ > ![ ] ( https://guide-blog-images.oss-cn-shenzhen.aliyuncs.com/java-guide-blog/image-20210523201742303.png )
184+ >
185+ > ** 动态年龄计算的代码如下:**
182186>
183187> ``` c++
184188> uint ageTable::compute_tenuring_threshold (size_t survivor_capacity) {
185- > //survivor_capacity是survivor空间的大小
186- > size_t desired_survivor_size = (size_t)((((double)survivor_capacity)*TargetSurvivorRatio)/100);
187- > size_t total = 0;
188- > uint age = 1;
189- > while (age < table_size) {
190- > //sizes数组是每个年龄段对象大小
191- > total += sizes[age];
192- > if (total > desired_survivor_size) {
193- > break;
194- > }
195- > age++;
196- > }
197- > uint result = age < MaxTenuringThreshold ? age : MaxTenuringThreshold;
198- > ...
189+ > //survivor_capacity是survivor空间的大小
190+ > size_t desired_survivor_size = (size_t)((((double)survivor_capacity)* TargetSurvivorRatio)/100);
191+ > size_t total = 0;
192+ > uint age = 1;
193+ > while (age < table_size) {
194+ > //sizes数组是每个年龄段对象大小
195+ > total += sizes[ age] ;
196+ > if (total > desired_survivor_size) {
197+ > break;
198+ > }
199+ > age++;
200+ > }
201+ > uint result = age < MaxTenuringThreshold ? age : MaxTenuringThreshold;
202+ > ...
199203> }
200204>
201205> ```
You can’t perform that action at this time.
0 commit comments