public class _01PrintGCDetails {
public static void main(String[] args) {
ArrayList<byte[]> list = new ArrayList<>();
for (int i = 0; i < 500; i++) {
byte[] arr = new byte[1024 * 1024];
list.add(arr);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
[GC (Allocation Failure) [DefNew: 3843K->512K(4928K), 0.0034569 secs] 3843K->2649K(15872K), 0.0043457 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [DefNew: 4738K->0K(4928K), 0.0038790 secs] 6875K->6745K(15872K), 0.0039024 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [DefNew: 4205K->0K(4928K), 0.0024967 secs] 10950K->10841K(15872K), 0.0025230 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [DefNew: 4220K->1K(4928K), 0.0038292 secs][Tenured: 14937K->14938K(15056K), 0.0015664 secs] 15061K->14938K(19984K), [Metaspace: 2252K->2252K(4480K)], 0.0055458 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
[GC (Allocation Failure) [DefNew: 9435K->1027K(11264K), 0.0091230 secs] 24374K->24158K(36164K), 0.0091612 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[GC (Allocation Failure) [DefNew: 10447K->1024K(11264K), 0.0075598 secs][Tenured: 32350K->32350K(33124K), 0.0017955 secs] 33578K->33374K(44388K), [Metaspace: 2279K->2279K(4480K)], 0.0095590 secs] [Times: user=0.00 sys=0.01, real=0.01 secs]
[GC (Allocation Failure) [DefNew: 21373K->2072K(24320K), 0.0132403 secs] 53724K->52855K(78240K), 0.0132947 secs] [Times: user=0.00 sys=0.02, real=0.01 secs]
[GC (Allocation Failure) [DefNew: 22954K->2048K(24320K), 0.0126333 secs][Tenured: 71288K->71288K(71396K), 0.0020584 secs] 73738K->73336K(95716K), [Metaspace: 2283K->2283K(4480K)], 0.0150118 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
[GC (Allocation Failure) [DefNew: 46984K->5120K(53568K), 0.0272463 secs] 118272K->117369K(172384K), 0.0273079 secs] [Times: user=0.02 sys=0.01, real=0.03 secs]
[GC (Allocation Failure) [DefNew: 52101K->5120K(53568K), 0.0294453 secs][Tenured: 158330K->158302K(158908K), 0.0266126 secs] 164350K->163422K(212476K), [Metaspace: 2283K->2283K(4480K)], 0.0563373 secs] [Times: user=0.05 sys=0.02, real=0.06 secs]
[GC (Allocation Failure) [DefNew: 69947K->69947K(78656K), 0.0000182 secs][Tenured: 158302K->174687K(174784K), 0.0243151 secs] 228249K->227936K(253440K), [Metaspace: 2283K->2283K(4480K)], 0.0243971 secs] [Times: user=0.03 sys=0.00, real=0.03 secs]
[Full GC (Allocation Failure) [Tenured: 174687K->174687K(174784K), 0.0027962 secs] 252803K->252513K(253440K), [Metaspace: 2283K->2283K(4480K)], 0.0028338 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
[Full GC (Allocation Failure) [Tenured: 174687K->174670K(174784K), 0.0309642 secs] 252513K->252496K(253440K), [Metaspace: 2283K->2283K(4480K)], 0.0310148 secs] [Times: user=0.03 sys=0.00, real=0.03 secs]
Heap
def new generation total 78656K, used 78148K [0x05600000, 0x0ab50000, 0x0ab50000)
eden space 69952K, 100% used [0x05600000, 0x09a50000, 0x09a50000)
from space 8704K, 94% used [0x09a50000, 0x0a251168, 0x0a2d0000)
to space 8704K, 0% used [0x0a2d0000, 0x0a2d0000, 0x0ab50000)
tenured generation total 174784K, used 174670K [0x0ab50000, 0x15600000, 0x15600000)
the space 174784K, 99% used [0x0ab50000, 0x155e3850, 0x155e3a00, 0x15600000)
Metaspace used 2303K, capacity 2344K, committed 2368K, reserved 4480K
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at gc.logs._01PrintGCDetails.main(_01PrintGCDetails.java:14)
【参数解析】
GC、Full GC: GC的类型
GC只在新生代上进行
Full GC包括永久代(元空间),新生代, 老年代
Allocation Failure
: GC发生的原因,即内存分配失败
21373K->2072K
:堆在GC前的使用大小和GC后的使用大小
78656K
:堆空间的总大小
0.0273079 secs
: GC耗时
PSYoungGen
:表示当前使用了Parallel Scavenge并行垃圾收集器进行新生代回收
ParOldGen
:表示当前使用了Parallel Old并行垃圾收集器进行老年代回收
Metaspace
: 元数据区GC前后大小的变化,JDK1.8中引入了元数据区以替代永久代
Times
: user: 指的是垃圾收集器花费的所有CPU时间,sys:花费在等待系统调用或系统事件的时间,real:GC从开始到结束的时间,包括其他进程占用时间片的实际时间
Heap
:整个堆内存的详细使用以及回收情况
【垃圾回收器说明】
Serial收集器在新生代的名字是De fault New Generation, 因此显示的是" DefNew"
ParNew收集器在新生代的名字会变成" ParNew",意思是"Parallel New Generation"
Parallel Scavenge收 集器在新生代的名字是" PSYoungGen"
G1收集器,会显示为"garbage-first heap"
“[GC"和”[Full GC"说明了这次垃圾收集的停顿类型,如果有"Full"则说明GC发生了"Stop The World
老年代的收集和新生代道理一样,名字也是收集器决定的
可以用一些工具去分析这些GC日志
常用的日志分析工具有:
GCVIewer、 GREasy、 GCHisto、 GCLogViewer、 Hp jmeter、 garbagecat等…
GReasy日志分析
GReasy