知乎网站内容建设的逻辑,厦门酒店团购网站建设,高端网站建设创新,开发是什么意思【README】基础知识 1、 Minor GC/新生代GC#xff1a;指发生在新生代的垃圾收集动作#xff0c;因为java对象大多都具备朝生夕灭的特性#xff0c;所以minor gc比较频繁#xff0c;一般回收速度也比较快#xff1b; 2、 Major GC/Full GC/老年代GC#xff1a;发生…【README】基础知识 1、 Minor GC/新生代GC指发生在新生代的垃圾收集动作因为java对象大多都具备朝生夕灭的特性所以minor gc比较频繁一般回收速度也比较快 2、 Major GC/Full GC/老年代GC发生在老年代的gc出现了major gc 经常会伴着出现minor gc(并非绝对)。Major gc的速度一般会比minor gc慢10倍以上
【1】对象优先在eden区域分配
/*** 对象优先在eden区域分配*/
public class Page93 {private static final int _1MB 1024 * 1024;public static void main(String[] args) {minorGC(); }/*** vm params: -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:PrintGCDetails -XX:SurvivorRatio8*/private static void minorGC() {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]; }
}
// gc日志和内存区域使用情况
HeapPSYoungGen total 9216K, used 7291K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)eden space 8192K, 89% used [0x00000000ff600000,0x00000000ffd1efb0,0x00000000ffe00000)from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)ParOldGen total 10240K, used 4096K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)object space 10240K, 40% used [0x00000000fec00000,0x00000000ff000010,0x00000000ff600000)Metaspace used 2624K, capacity 4486K, committed 4864K, reserved 1056768Kclass space used 279K, capacity 386K, committed 512K, reserved 1048576K1.1、jvm参数分析
-Xms20M设置java堆容量最小值
-Xmx20M设置 java堆容量最大值
-Xmn10M设置java堆新生代容量所以java堆老年代容量为20M-10M10M
-XX:PrintGCDetials设置在发生gc时打印内存回收日志并且在进程退出时输出当前的内存各区域分配情况
-XX:SurvivorRatio设置Eden:Suivivor: Suivivor 8:1:1
所以java堆的新生代的可用容量为9MEden区1个Survivor区的总容量
1.2、PSYoungGen表示其堆新生代的垃圾收集器是Parallel Scavenge吞吐量自适应
总容量0x0000000100000000-0x00000000ff6000000xa00000字节10MB
已使用容量7298K
Eden区容量8M已使用量0x00000000ffd20b48-0x00000000ff6000000x0000000000720b48(16)7M131K
Survivor区容量1M使用量0
Survivor区容量1M使用量0
1.3、ParOldGen标识其堆老年代的垃圾收集器是 Parallel Old吞吐量优先收集器组合POPS
总容量0x00000000ff600000-0x00000000fec000000xa00000字节10MB
已使用量4M 【2】大对象直接进入老年代
/*** 大对象直接进入老年代*/
public class Page94 {private static final int _1MB 1024 * 1024;public static void main(String[] args) {testPretenureSizeThreshold(); }/*** vm params: -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:PrintGCDetails -XX:SurvivorRatio8 -XX:PretenureSizeThreshold3145728(3M)*/private static void testPretenureSizeThreshold() {byte[] allocation;allocation new byte[4 * _1MB]; }
}
// gc日志和内存区域使用情况
HeapPSYoungGen total 9216K, used 5243K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)eden space 8192K, 64% used [0x00000000ff600000,0x00000000ffb1ef90,0x00000000ffe00000)from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)ParOldGen total 10240K, used 0K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)object space 10240K, 0% used [0x00000000fec00000,0x00000000fec00000,0x00000000ff600000)Metaspace used 2624K, capacity 4486K, committed 4864K, reserved 1056768Kclass space used 279K, capacity 386K, committed 512K, reserved 1048576K【3】长期存活对象将进入老年代
/*** 长期存活的对象进入老年代 */
public class Page95 {private static final int _1MB 1024 * 1024;public static void main(String[] args) {testTenuringThreshold(); }/*** vm params: -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:PrintGCDetails -XX:SurvivorRatio8 * -XX:MaxTenuringThreshold1 -XX:PrintTenuringDistribution */private static void testTenuringThreshold() {byte[] allocation1, allocation2, allocation3;allocation1 new byte[_1MB / 4];/* 什么时候进入老年代取决于 XX:MaxTenuringThreshold 设置 */allocation2 new byte[4 * _1MB];allocation3 new byte[4 * _1MB];allocation3 null; allocation3 new byte[4 * _1MB]; }
}
// gc日志和内存区域使用情况
HeapPSYoungGen total 9216K, used 5499K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)eden space 8192K, 67% used [0x00000000ff600000,0x00000000ffb5efa0,0x00000000ffe00000)from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)ParOldGen total 10240K, used 8192K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)object space 10240K, 80% used [0x00000000fec00000,0x00000000ff400020,0x00000000ff600000)Metaspace used 2624K, capacity 4486K, committed 4864K, reserved 1056768Kclass space used 279K, capacity 386K, committed 512K, reserved 1048576K【4】动态对象年龄判定
/*** 动态对象年龄判定*/
public class Page97 {private static final int _1MB 1024 * 1024;public static void main(String[] args) {testTenuringThreshold();}/*** vm params: -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:PrintGCDetails* -XX:SurvivorRatio8 -XX:MaxTenuringThreshold15* -XX:PrintTenuringDistribution*/private static void testTenuringThreshold() {byte[] allocation1, allocation2, allocation3, allocation4;allocation1 new byte[_1MB / 4];/* allocation1allocation2 大于survivor空间一半 */allocation2 new byte[_1MB / 4];allocation3 new byte[4 * _1MB];allocation4 new byte[4 * _1MB];allocation4 null;allocation4 new byte[4 * _1MB];allocation4 new byte[4 * _1MB];allocation4 new byte[4 * _1MB];}
}
// gc日志和内存区域使用情况
[GC (Allocation Failure) --[PSYoungGen: 5591K-5591K(9216K)] 13783K-14047K(19456K), 0.0013548 secs] [Times: user0.00 sys0.00, real0.00 secs]
[Full GC (Ergonomics) [PSYoungGen: 5591K-0K(9216K)] [ParOldGen: 8456K-9216K(10240K)] 14047K-9216K(19456K), [Metaspace: 2617K-2617K(1056768K)], 0.0061721 secs] [Times: user0.00 sys0.00, real0.01 secs]
[GC (Allocation Failure) --[PSYoungGen: 4096K-4096K(9216K)] 13312K-13312K(19456K), 0.0006086 secs] [Times: user0.00 sys0.00, real0.00 secs]
[Full GC (Ergonomics) [PSYoungGen: 4096K-0K(9216K)] [ParOldGen: 9216K-9215K(10240K)] 13312K-9215K(19456K), [Metaspace: 2618K-2618K(1056768K)], 0.0050350 secs] [Times: user0.00 sys0.00, real0.01 secs]
HeapPSYoungGen total 9216K, used 4178K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)eden space 8192K, 51% used [0x00000000ff600000,0x00000000ffa14930,0x00000000ffe00000)from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)ParOldGen total 10240K, used 9215K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)object space 10240K, 89% used [0x00000000fec00000,0x00000000ff4ffcc0,0x00000000ff600000)Metaspace used 2624K, capacity 4486K, committed 4864K, reserved 1056768Kclass space used 279K, capacity 386K, committed 512K, reserved 1048576K【5】空间分配担保
/*** 空间分配担保*/
public class Page99 {private static final int _1MB 1024 * 1024;public static void main(String[] args) {testHandlePromotion();}/** * vm params: -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:PrintGCDetails* -XX:SurvivorRatio8 -XX:-HandlePromotionFailure(HandlePromotionFailure这个参数不起作用)*/private static void testHandlePromotion() {byte[] allocation1, allocation2, allocation3, allocation4, allocation5, allocation6, allocation7;allocation1 new byte[2 * _1MB];allocation2 new byte[2 * _1MB];allocation3 new byte[2 * _1MB];allocation1 null;allocation4 new byte[2 * _1MB];allocation5 new byte[2 * _1MB];allocation6 new byte[2 * _1MB];allocation4 null;allocation5 null;allocation6 null;allocation7 new byte[2 * _1MB];}
}
// gc日志和内存区域使用情况
[GC (Allocation Failure) [PSYoungGen: 7127K-728K(9216K)] 7127K-4832K(19456K), 0.0027073 secs] [Times: user0.00 sys0.00, real0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 7032K-584K(9216K)] 11136K-4688K(19456K), 0.0009033 secs] [Times: user0.00 sys0.00, real0.00 secs]
HeapPSYoungGen total 9216K, used 2796K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)eden space 8192K, 27% used [0x00000000ff600000,0x00000000ff8290e0,0x00000000ffe00000)from space 1024K, 57% used [0x00000000fff00000,0x00000000fff92020,0x0000000100000000)to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)ParOldGen total 10240K, used 4104K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)object space 10240K, 40% used [0x00000000fec00000,0x00000000ff002020,0x00000000ff600000)Metaspace used 2624K, capacity 4486K, committed 4864K, reserved 1056768Kclass space used 279K, capacity 386K, committed 512K, reserved 1048576K