代码部分
/**
* -Xmx20m -Xms20m -Xmn2m -XX:SurvivorRatio=2 -XX:+PrintGCDetails
* -Xmx20m -Xms20m -Xmn7m -XX:SurvivorRatio=2 -XX:+PrintGCDetails
* -Xmx20m -Xms20m -Xmn15m -XX:SurvivorRatio=8 -XX:+PrintGCDetails
*
* -Xmx20M -Xms20M -XX:NewRatio=2 -XX:+PrintGCDetails
*
* @author Geym
*/
public class NewSizeDemo {
public static void main(String[] args) {
byte[] b=null;
for(int i=0;i<3;i++)
b=new byte[1*1024*1024];
}
}
分析* -Xmx20m -Xms20m -Xmn7m -XX:SurvivorRatio=2 -XX:+PrintGCDetails
-Xmn7m代表新生代内存,一般设置为堆内存的1/3或者1/4;-XX:SurvivorRatio=2表示新生代eden:from:to=2:1:1;eden+from+to=7m
数据先从from到to到eden到老年代
后台打印日志
Heap
PSYoungGen total 5632K, used 4822K [0x00000000ff900000, 0x0000000100000000, 0x0000000100000000)
eden space 4096K, 80% used [0x00000000ff900000,0x00000000ffc380e8,0x00000000ffd00000)
from space 1536K, 99% used [0x00000000ffe80000,0x00000000ffffda78,0x0000000100000000)
to space 1536K, 0% used [0x00000000ffd00000,0x00000000ffd00000,0x00000000ffe80000)
ParOldGen total 13312K, used 335K [0x00000000fec00000, 0x00000000ff900000, 0x00000000ff900000)
object space 13312K, 2% used [0x00000000fec00000,0x00000000fec53c18,0x00000000ff900000)
Metaspace used 3439K, capacity 4620K, committed 4864K, reserved 1056768K
class space used 361K, capacity 392K, committed 512K, reserved 1048576K
Disconnected from the target VM, address: '127.0.0.1:54413', transport: 'socket'
eden:from:to=2:1:1
eden+from+to=7m
程序连续申请了3M=eden*80%+from*99%