代码清单3-5.
/**
* VM参数:-verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8
*
*/
public class MinorGCTest {
private static final int _1MB = 1024*1024;
public static void testAllocation(){
byte[] allocation1,allocation2,allocation3,allocation4;
allocation1 = new byte[2*_1MB];
allocation2 = new byte[2*_1MB];
allocation3 = new byte[2*_1MB];
allocation4 = new byte[4*_1MB];
}
public static void main(String[] args) {
testAllocation();
}
}
结果是
<?xml version="1.0" ?>
<verbosegc version="20101027_AA">
<initialized>
<attribute name="gcPolicy" value="-Xgcpolicy:optthruput" />
<attribute name="maxHeapSize" value="0x1400000" />
<attribute name="initialHeapSize" value="0x1400000" />
<attribute name="compressedRefs" value="false" />
<attribute name="pageSize" value="0x1000" />
<attribute name="requestedPageSize" value="0x1000" />
</initialized>
</verbosegc>
为什么没有出现垃圾回收日志?
------解决思路----------------------
运行时是否设置了 -Xms -Xmx -Xmn
如果是eclipse需要在run configuration 中进行设置