运行结果: [GC (Allocation Failure) [DefNew: 7129K->531K(9216K), 0.0037131 secs] 7129K->6675K(19456K), 0.0137564 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] Heap def new generation total 9216K, used 4709K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000) eden space 8192K, 51% used [0x00000000fec00000, 0x00000000ff014930, 0x00000000ff400000) f rom space 1024K, 51% used [0x00000000ff500000, 0x00000000ff584c58, 0x00000000ff600000) to space 1024K, 0% used [0x00000000ff400000, 0x00000000ff400000, 0x00000000ff500000) tenured generation total 10240K, used 6144K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000) the space 10240K, 60% used [0x00000000ff600000, 0x00000000ffc00030, 0x00000000ffc00200, 0x0000000100000000) Metaspace used 2573K, capacity 4486K, committed 4864K, reserved 1056768K class space used 285K, capacity 386K, committed 512K, reserved 1048576K 注意:使用64位的需要添加参数-XX:+UseSerialGC,使其强制使用SerialGC 以上的方法试图分配3个2MB大小和一个4MB大小的对象,在运行通过 -Xms20M -Xmx20M -Xmn10M三个参数限制了Java堆大小为20MB,不可扩展,其中10MB分配给新生代,剩下的10MB分配给老年代。-XX:SurvivorRatio=0决定了新生代中Eden区与一个Survivor区的空间比例为8:1,从输出的结果也可以清晰地看到“eden space 8192K、f rom space 1024K、to space 1024K”的信息,新生代的总可用空间为9216KB(Eden区+一个Survivor区的总容量)。
Minor GC:指发生在新生代的垃圾收集动作,因为 Java 对象大多都具备朝生夕灭的特性,所以 Minor GC 非常频繁,一般回收速度也比较快。。
Major GC/Full GC:指发生在老年代的 GC,出现了 Major GC,经常会伴随至少一次的 Minor GC(但非绝对的,在 ParallelScavenge 收集器的收集策略里就有直接进行 Major GC 的策略选择过程) 。MajorGC 的速度一般会比 Minor GC 慢 10倍以上。
运行结果: Heap def new generation total 9216K, used 1148K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000) eden space 8192K, 14% used [0x00000000fec00000, 0x00000000fed1f3f0, 0x00000000ff400000) f rom space 1024K, 0% used [0x00000000ff400000, 0x00000000ff400000, 0x00000000ff500000) to space 1024K, 0% used [0x00000000ff500000, 0x00000000ff500000, 0x00000000ff600000) tenured generation total 10240K, used 4096K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000) the space 10240K, 40% used [0x00000000ff600000, 0x00000000ffa00010, 0x00000000ffa00200, 0x0000000100000000) Metaspace used 2572K, capacity 4486K, committed 4864K, reserved 1056768K class space used 285K, capacity 386K, committed 512K, reserved 1048576K
[GC (Allocation Failure) [DefNew: 19374K->1555K(36864K), 0.0073413 secs] 19374K->17939K(77824K), 0.0073791 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[GC (Allocation Failure) [DefNew: 17939K->0K(36864K), 0.0016595 secs] 34323K->17938K(77824K), 0.0016844 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
def new generation total 36864K, used 16712K [0x00000000fb000000, 0x00000000fd800000, 0x00000000fd800000)
eden space 32768K, 51% used [0x00000000fb000000, 0x00000000fc052040, 0x00000000fd000000)
**f rom space 4096K, 0%** used [0x00000000fd000000, 0x00000000fd000000, 0x00000000fd400000)
to space 4096K, 0% used [0x00000000fd400000, 0x00000000fd400000, 0x00000000fd800000)
tenured generation total 40960K, used 17938K [0x00000000fd800000, 0x0000000100000000, 0x0000000100000000)
**the space 40960K, 43%** used [0x00000000fd800000, 0x00000000fe984970, 0x00000000fe984a00, 0x0000000100000000)
Metaspace used 2573K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 285K, capacity 386K, committed 512K, reserved 1048576K
1
2
3
4
5
6
7
8
9
10
11
以MaxTenuringThreshold=15得到的结果:
[GC (Allocation Failure) [DefNew
Desired survivor size 2097152 bytes, new threshold 15 (max 15)
- age 1: 1592488 bytes, 1592488 total
: 19374K->1555K(36864K), 0.0089774 secs] 19374K->17939K(77824K), 0.0090155 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[GC (Allocation Failure) [DefNew
Desired survivor size 2097152 bytes, new threshold 15 (max 15)
- age 2: 1591648 bytes, 1591648 total
: 17939K->1554K(36864K), 0.0011282 secs] 34323K->17938K(77824K), 0.0011471 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
def new generation total 36864K, used 18266K [0x00000000fb000000, 0x00000000fd800000, 0x00000000fd800000)
eden space 32768K, 51% used [0x00000000fb000000, 0x00000000fc052040, 0x00000000fd000000)
f rom space 4096K, 37% used [0x00000000fd000000, 0x00000000fd184960, 0x00000000fd400000)
to space 4096K, 0% used [0x00000000fd400000, 0x00000000fd400000, 0x00000000fd800000)
tenured generation total 40960K, used 16384K [0x00000000fd800000, 0x0000000100000000, 0x0000000100000000)
the space 40960K, 40% used [0x00000000fd800000, 0x00000000fe800010, 0x00000000fe800200, 0x0000000100000000)
Metaspace used 2572K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 285K, capacity 386K, committed 512K, reserved 1048576K