日志配置
在VM argument选项中可配置如下:
-Xms256m --jvm堆的最小值
-Xmx256m --jvm堆的最大值
-XX:+PrintGCTimeStamps -- 打印出GC的时间信息
-XX:+PrintGCDetails --打印出GC的详细信息
-verbose:gc --开启gc日志
-Xloggc:d:/gc.log -- gc日志的存放位置
-Xmn10M -- 新生代内存区域的大小
-XX:SurvivorRatio=8 --新生代内存区域中Eden和Survivor的比例
PS日志
[GC(Allocation Failure)
>[GC表示YGC,否则是FGC(GC原因
[DefNew:5698->129k(7268k),0.03735498 secs]
>[年代:回收前年轻代空间->回收后年轻代空间(年轻代总大小),耗时]
5698k->3465k(1984k),0.09856210 secs]**
>回收前堆占用空间->回收后堆占用空间(堆总空间),耗时]
[Times:user=0.00 sys=0.09,rel=0.09 secs]
>[Linux times:用户耗时,系统耗时,真正耗时]
eden space 5632K, 94% used [0x00000000ff980000,0x00000000ffeb3e28,0x00000000fff00000)
> 后面的内存地址指的是,起始地址,使用空间结束地址,整体空间结束地址
Metaspace used 3529k,capacity 5569k,committed 5864k,reserved 116795l
> 已经使用,总容量,虚拟内存占用,虚拟内存保留
CMS日志
使用命令 -XX:+PrintGCDetails -XX:+UseConcMarkSweepGC 可以表示打印GC日志详情,使用CMS垃圾回收器
[GC (Allocation Failure) [ParNew: 6144K->640K(6144K), 0.0265885 secs] 6585K->2770K(19840K), 0.0268035 secs] [Times: user=0.02 sys=0.00, real=0.02 secs]
>ParNew:年轻代回收器
[GC (CMS Initial Mark) [1 CMS-initial-mark: 8511K(13696K)] 9866K(19840K), 0.0040321 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
>CMS-initial-mark表示mixed模式开启,混合回收。8511 (13696) : 老年代使用(最大),9866 (19840) : 整个堆使用(最大)
[CMS-concurrent-mark-start]
[CMS-concurrent-mark: 0.018/0.018 secs] [Times: user=0.01 sys=0.00, real=0.02 secs]
>这里的时间意义不大,因为是并发执行
[CMS-concurrent-preclean-start]
[CMS-concurrent-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
>标记Card为Dirty,也称为Card Marking
[GC (CMS Final Remark) [YG occupancy: 1597 K (6144 K)][Rescan (parallel) , 0.0008396 secs][weak refs processing, 0.0000138 secs][class unloading, 0.0005404 secs][scrub symbol table, 0.0006169 secs][scrub string table, 0.0004903 secs][1 CMS-remark: 8511K(13696K)] 10108K(19840K), 0.0039567 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
>STW阶段,YG occupancy:年轻代占用及容量
>[Rescan (parallel):STW下的存活对象标记
>weak refs processing: 弱引用处理
>class unloading: 卸载用不到的class
>scrub symbol(string) table:
>cleaning up symbol and string tables which hold class-level metadata and
>internalized string respectively
>CMS-remark: 8511K(13696K): 阶段过后的老年代占用及容量
>10108K(19840K): 阶段过后的堆占用及容量
[CMS-concurrent-sweep-start]
[CMS-concurrent-sweep: 0.005/0.005 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
>标记已经完成,进行并发清理
[CMS-concurrent-reset-start]
[CMS-concurrent-reset: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
>重置内部结构,为下次GC做准备
G1日志
[GC pause (G1 Evacuation Pause) (young) (initial-mark), 0.0015790 secs]
>young -> 年轻代 Evacuation-> 复制存活对象
>initial-mark 混合回收的阶段,这里是YGC混合老年代回收
[Parallel Time: 1.5 ms, GC Workers: 1]
>一个GC线程
[GC Worker Start (ms): 92635.7]
[Ext Root Scanning (ms): 1.1]
[Update RS (ms): 0.0]
[Processed Buffers: 1]
[Scan RS (ms): 0.0]
[Code Root Scanning (ms): 0.0]
[Object Copy (ms): 0.1]
[Termination (ms): 0.0]
[Termination Attempts: 1]
[GC Worker Other (ms): 0.0]
[GC Worker Total (ms): 1.2]
[GC Worker End (ms): 92636.9]
[Code Root Fixup: 0.0 ms]
[Code Root Purge: 0.0 ms]
[Clear CT: 0.0 ms]
[Other: 0.1 ms]
[Choose CSet: 0.0 ms]
[Ref Proc: 0.0 ms]
[Ref Enq: 0.0 ms]
[Redirty Cards: 0.0 ms]
[Humongous Register: 0.0 ms]
[Humongous Reclaim: 0.0 ms]
[Free CSet: 0.0 ms]
[Eden: 0.0B(1024.0K)->0.0B(1024.0K) Survivors: 0.0B->0.0B Heap: 18.8M(20.0M)->18.8M(20.0M)]
[Times: user=0.00 sys=0.00, real=0.00 secs]
>以下是混合回收其他阶段
[GC concurrent-root-region-scan-start]
[GC concurrent-root-region-scan-end, 0.0000078 secs]
[GC concurrent-mark-start]
>无法evacuation,进行FGC
[Full GC (Allocation Failure) 18M->18M(20M), 0.0719656 secs]
[Eden: 0.0B(1024.0K)->0.0B(1024.0K) Survivors: 0.0B->0.0B Heap: 18.8M(20.0M)->18.8M(20.0M)], [Metaspace: 38
76K->3876K(1056768K)] [Times: user=0.07 sys=0.00, real=0.07 secs]