@@ -180,6 +180,12 @@ const jvmArgsHelp = [
180180 " desc" : " 对象晋升老年代的年龄阈值" ,
181181 " defaultValue" : " 15" ,
182182 " example" : " -XX:MaxTenuringThreshold=15"
183+ },
184+ {
185+ " name" : " -XX:TargetSurvivorRatio" ,
186+ " desc" : " Survivor区目标使用率" ,
187+ " defaultValue" : " 50" ,
188+ " example" : " -XX:TargetSurvivorRatio=50"
183189 }
184190];
185191
@@ -230,6 +236,7 @@ const memoryConfig = ref({
230236 newRatio: 2 , // 新生代和老年代的比例,默认为2,表示新生代:老年代=1:2
231237 survivorRatio: 8 , // Eden区和Survivor区的比例,默认为8,表示Eden:Survivor=8:1
232238 maxTenuringThreshold: 15 , // 对象晋升年龄阈值,默认为15
239+ targetSurvivorRatio: 50 , // Survivor区目标使用率,默认为50%
233240});
234241
235242// JVM参数解析函数
@@ -239,7 +246,8 @@ const parseJvmArgs = (args: string) => {
239246 maxHeap: 1 ,
240247 newRatio: 2 ,
241248 survivorRatio: 8 ,
242- maxTenuringThreshold: 15
249+ maxTenuringThreshold: 15 ,
250+ targetSurvivorRatio: 50
243251 };
244252
245253 const xmsMatch = args .match (/ -Xms(\d + )([kmg] )? / i );
@@ -299,6 +307,15 @@ const parseJvmArgs = (args: string) => {
299307 }
300308 }
301309
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+
302319 // 验证参数
303320 if (result .initialHeap > result .maxHeap ) {
304321 throw new Error (' 初始堆大小不能大于最大堆大小' );
@@ -438,6 +455,29 @@ class gc {
438455 if (obj .age >= MAX_TENURING_THRESHOLD .value ) {
439456 return put2OldGen (obj )
440457 } 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+
441481 // 检查Survivor空间
442482 if (getSpaceUsed (SURVIVOR_TO .value ) + obj .size <= survivorSize .value ) {
443483 survivingObjects .push ({
0 commit comments