@@ -171,7 +171,7 @@ const jvmArgsHelp = [
171
171
},
172
172
{
173
173
" name" : " -XX:SurvivorRatio" ,
174
- " desc" : " Eden区与Survivor区的比例 " ,
174
+ " desc" : " Eden 区与 Survivor 区的比例 " ,
175
175
" defaultValue" : " 8" ,
176
176
" example" : " -XX:SurvivorRatio=8"
177
177
},
@@ -181,9 +181,15 @@ const jvmArgsHelp = [
181
181
" defaultValue" : " 15" ,
182
182
" example" : " -XX:MaxTenuringThreshold=15"
183
183
},
184
+ {
185
+ " name" : " -XX:PretenureSizeThreshold" ,
186
+ " desc" : " 大对象直接进入老年代的阈值" ,
187
+ " defaultValue" : " 0" ,
188
+ " example" : " -XX:PretenureSizeThreshold=1048576"
189
+ },
184
190
{
185
191
" name" : " -XX:TargetSurvivorRatio" ,
186
- " desc" : " Survivor区目标使用率 " ,
192
+ " desc" : " Survivor 区目标使用率 " ,
187
193
" defaultValue" : " 50" ,
188
194
" example" : " -XX:TargetSurvivorRatio=50"
189
195
}
@@ -237,8 +243,10 @@ const memoryConfig = ref({
237
243
survivorRatio: 8 , // Eden区和Survivor区的比例,默认为8,表示Eden:Survivor=8:1
238
244
maxTenuringThreshold: 15 , // 对象晋升年龄阈值,默认为15
239
245
targetSurvivorRatio: 50 , // Survivor区目标使用率,默认为50%
246
+ pretenureSizeThreshold: 0 , // 大对象直接进入老年代的阈值,默认为0,表示不启用
240
247
});
241
248
249
+
242
250
// JVM参数解析函数
243
251
const parseJvmArgs = (args : string ) => {
244
252
const result = {
@@ -247,7 +255,8 @@ const parseJvmArgs = (args: string) => {
247
255
newRatio: 2 ,
248
256
survivorRatio: 8 ,
249
257
maxTenuringThreshold: 15 ,
250
- targetSurvivorRatio: 50
258
+ targetSurvivorRatio: 50 ,
259
+ pretenureSizeThreshold: 0
251
260
};
252
261
253
262
const xmsMatch = args .match (/ -Xms(\d + )([kmg] )? / i );
@@ -316,6 +325,15 @@ const parseJvmArgs = (args: string) => {
316
325
}
317
326
}
318
327
328
+ // 解析PretenureSizeThreshold参数
329
+ const pretenureSizeThresholdMatch = args .match (/ -XX:PretenureSizeThreshold=(\d + )/ i );
330
+ if (pretenureSizeThresholdMatch ) {
331
+ result .pretenureSizeThreshold = parseInt (pretenureSizeThresholdMatch [1 ]);
332
+ if (result .pretenureSizeThreshold < 0 ) {
333
+ throw new Error (' PretenureSizeThreshold必须大于等于0' );
334
+ }
335
+ }
336
+
319
337
// 验证参数
320
338
if (result .initialHeap > result .maxHeap ) {
321
339
throw new Error (' 初始堆大小不能大于最大堆大小' );
@@ -585,7 +603,17 @@ const createObject = () => {
585
603
isGarbageCollectable: newObject .value .isGarbageCollectable
586
604
} as HeapObject ;
587
605
588
- if (sizeInBytes > edenSize .value ) {
606
+ if (sizeInBytes >= memoryConfig .value .pretenureSizeThreshold && memoryConfig .value .pretenureSizeThreshold > 0 ) {
607
+ // 对象大小超过阈值,直接进入Old Gen区
608
+ if (getSpaceUsed (MEMORY_SPACE .OLD_GEN ) + newObj .size > oldGenSize .value ) {
609
+ throw applicationError (' java.lang.OutOfMemoryError: Java heap space' );
610
+ }
611
+
612
+ newObj .space = MEMORY_SPACE .OLD_GEN ;
613
+ newObj .position = getNextPosition (MEMORY_SPACE .OLD_GEN );
614
+ heapObjects .value .push (newObj );
615
+ operationLogs .value .unshift (` 对象大小(${formatBytes (sizeInBytes )})超过阈值(${formatBytes (memoryConfig .value .pretenureSizeThreshold )}),直接进入老年代 ` );
616
+ } else if (sizeInBytes > edenSize .value ) {
589
617
// 对象大小超过Eden区大小,尝试直接进入Old Gen区
590
618
if (getSpaceUsed (MEMORY_SPACE .OLD_GEN ) + newObj .size > oldGenSize .value ) {
591
619
throw applicationError (' java.lang.OutOfMemoryError: Java heap space' );
0 commit comments