@@ -180,6 +180,12 @@ const jvmArgsHelp = [
180
180
" desc" : " 对象晋升老年代的年龄阈值" ,
181
181
" defaultValue" : " 15" ,
182
182
" example" : " -XX:MaxTenuringThreshold=15"
183
+ },
184
+ {
185
+ " name" : " -XX:TargetSurvivorRatio" ,
186
+ " desc" : " Survivor区目标使用率" ,
187
+ " defaultValue" : " 50" ,
188
+ " example" : " -XX:TargetSurvivorRatio=50"
183
189
}
184
190
];
185
191
@@ -230,6 +236,7 @@ const memoryConfig = ref({
230
236
newRatio: 2 , // 新生代和老年代的比例,默认为2,表示新生代:老年代=1:2
231
237
survivorRatio: 8 , // Eden区和Survivor区的比例,默认为8,表示Eden:Survivor=8:1
232
238
maxTenuringThreshold: 15 , // 对象晋升年龄阈值,默认为15
239
+ targetSurvivorRatio: 50 , // Survivor区目标使用率,默认为50%
233
240
});
234
241
235
242
// JVM参数解析函数
@@ -239,7 +246,8 @@ const parseJvmArgs = (args: string) => {
239
246
maxHeap: 1 ,
240
247
newRatio: 2 ,
241
248
survivorRatio: 8 ,
242
- maxTenuringThreshold: 15
249
+ maxTenuringThreshold: 15 ,
250
+ targetSurvivorRatio: 50
243
251
};
244
252
245
253
const xmsMatch = args .match (/ -Xms(\d + )([kmg] )? / i );
@@ -299,6 +307,15 @@ const parseJvmArgs = (args: string) => {
299
307
}
300
308
}
301
309
310
+ // 解析TargetSurvivorRatio参数
311
+ const targetSurvivorRatioMatch = args .match (/ -XX:TargetSurvivorRatio=(\d + )/ i );
312
+ if (targetSurvivorRatioMatch ) {
313
+ result .targetSurvivorRatio = parseInt (targetSurvivorRatioMatch [1 ]);
314
+ if (result .targetSurvivorRatio < 0 || result .targetSurvivorRatio > 100 ) {
315
+ throw new Error (' TargetSurvivorRatio必须在0到100之间' );
316
+ }
317
+ }
318
+
302
319
// 验证参数
303
320
if (result .initialHeap > result .maxHeap ) {
304
321
throw new Error (' 初始堆大小不能大于最大堆大小' );
@@ -438,6 +455,29 @@ class gc {
438
455
if (obj .age >= MAX_TENURING_THRESHOLD .value ) {
439
456
return put2OldGen (obj )
440
457
} else {
458
+ // 动态年龄判定
459
+ const ageMap = new Map <number , number >();
460
+ heapObjects .value
461
+ .filter (o => o .space === currentFromSpace .value )
462
+ .forEach (o => {
463
+ ageMap .set (o .age , (ageMap .get (o .age ) || 0 ) + o .size );
464
+ });
465
+
466
+ let totalSize = 0 ;
467
+ let targetAge = obj .age ;
468
+ for (let age = 0 ; age <= obj .age ; age ++ ) {
469
+ totalSize += ageMap .get (age ) || 0 ;
470
+ if (totalSize > survivorSize .value * memoryConfig .value .targetSurvivorRatio / 100 ) {
471
+ targetAge = age ;
472
+ break ;
473
+ }
474
+ }
475
+
476
+ if (obj .age >= targetAge ) {
477
+ operationLogs .value .unshift (` 对象 ${obj .name } 因动态年龄判定晋升到老年代 ` );
478
+ return put2OldGen (obj );
479
+ }
480
+
441
481
// 检查Survivor空间
442
482
if (getSpaceUsed (SURVIVOR_TO .value ) + obj .size <= survivorSize .value ) {
443
483
survivingObjects .push ({
0 commit comments