PretenureSizeThreshold
7070 단어 [27]JVM
XX:PretenureSizeThreshold
XX:PretenureSizeThreshold가 이 값을 초과할 때 대상은old구역에서 메모리를 직접 분배합니다
Frequently Asked Questions about Garbage Collection
There is a flag (available in 1.4.2 and later) l-XX:PretenureSizeThreshold= that can be set to limit the size of allocations in the young generation. Any allocation larger than this will not be attempted in the young generation and so will be allocated out of the old generation. The default size for PretenureSizeThreshold is 0 which says that any size can be allocated in the young generation
테스트 프로그램.
PretenureSizeThreshold 기본값 및 역할 참조
public class PretenureSizeThreshold
{
/**
* VM: Args: -Xms20m -Xmx30m -Xmn10m -XX:PretenureSizeThreshold=4m -XX:+HeapDumpOnOutOfMemoryError -XX:+UseConcMarkSweepGC -XX:+PrintFlagsFinal -XX:+PrintGCDetails -Xloggc:./gc.log
* @param args
*/
public static void main(String[] args)
{
//byte[] array = new byte[9*1024*1024];
byte[] array = new byte[6*1024*1024];
//byte[] array1 = new byte[1*1024*1024];
for(MemoryPoolMXBean memoryPoolMXBean: ManagementFactory.getMemoryPoolMXBeans()){
System.out.println(memoryPoolMXBean.getName()
+ " total:"+memoryPoolMXBean.getUsage().getCommitted()
+" used:"+memoryPoolMXBean.getUsage().getUsed());
}
try {
Thread.sleep(10000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
테스트-1
-Xms20m -Xmx30m -Xmn10m
-XX:+HeapDumpOnOutOfMemoryError
-XX:+UseConcMarkSweepGC -XX:+PrintFlagsFinal
아래에서 보다.(1)byte[]array = new byte[910241024]일 경우.
Code Cache total:2555904 used:1221888
Metaspace total:4980736 used:2877544
Compressed Class Space total:524288 used:308512
Par Eden Space total:8388608 used:1359440
Par Survivor Space total:1048576 used:0
CMS Old Gen total:10485760 used:9437200
Eden은 8M, 두 Survivor는 각각 1M입니다.Old Gen은 10M입니다.우리가 분배한 대상은 9M으로 Eden보다 크기 때문에 OldGen,used:9437200에 직접 분배한다.
(2)byte[]array = newbyte[610241024]일 경우.모두 Eden에 분배합니다.
Code Cache total:2555904 used:1224064
Metaspace total:4980736 used:2879976
Compressed Class Space total:524288 used:309080
Par Eden Space total:8388608 used:7650912
Par Survivor Space total:1048576 used:0
CMS Old Gen total:10485760 used:0
테스트-2
byte[]array = new byte[610241024];이것은 VM 매개 변수입니다.
-Xms20m -Xmx30m -Xmn10m -XX:PretenureSizeThreshold=4m
-XX:+HeapDumpOnOutOfMemoryError -XX:+UseConcMarkSweepGC
-XX:+PrintFlagsFinal -XX:+PrintGCDetails -Xloggc:./gc.log
Eden은 8M, 두 Survivor는 각각 1M입니다.Old Gen은 10M입니다.PretenureSizeThreshold=4M을 설정한 후 OldGen에 객체 메모리를 직접 할당할 수 있습니다.
Code Cache total:2555904 used:1229312
Metaspace total:4980736 used:2881872
Compressed Class Space total:524288 used:309080
Par Eden Space total:8388608 used:1359440
Par Survivor Space total:1048576 used:0
CMS Old Gen total:10485760 used:6291472
인쇄 GC log 설정
-XX:+PrintFlagsFinal -XX:+PrintGCDetails -Xloggc:./gc.log
[gcviewer] 다운로드(https://sourceforge.net/projects/gcviewer/) gc 로그를 보고 gcviewer를 시작합니다.
java -jar gcviewer-1.36-SNAPSHOT.jar
gc log를 열면 분석 가능