JVM Optimization Learning(五)

目录

一、JVM Optimization

1、G1

1、G1内存模型

2、基础概念

3、G1特点:

4、CMS日志分析

5、G1日志分析

2、GC参数

2.1、GC常用参数

2.2、Parallel常用参数

2.3、CMS常用参数

2.4、G1常用参数


一、JVM Optimization

1、G1

G1官网说明:Garbage First Garbage Collector Tuning

The Garbage First Garbage Collector (G1 GC) is the low-pause, server-style generational 
garbage collector for Java HotSpot VM. The G1 GC uses concurrent and parallel phases 
to achieve its target pause time and to maintain good throughput. When G1 GC determines 
that a garbage collection is necessary, it collects the regions with the least live data 
first (garbage first).
G1是Java HotSpot VM的低暂停、服务器端应用的垃圾收集器。G1 GC使用并行和并行阶段来实现其目标暂停
时间并保持良好的吞吐量。当G1GC确定有必要进行垃圾收集时,它首先收集具有最少活动数据的区域
(垃圾优先)。G1是一种服务端应用使用的垃圾收集器,目标是用在多核、大内存的机器上,它在大多数情况下可以实现指定
的GC暂停时间,同时还能保持较高的吞吐量。

分而治之+分层模型

1、G1内存模型

humongous:/hjuːˈmʌŋɡəs/ 巨大的、庞大的

humongous object:超过单个region的50%

it collects the regions with the least live data first (garbage first).垃圾优先

        每个分区都可能是年轻代也可能是老年代,但是在同一时刻只能属于某个代。
        年轻代、幸存区、老年代这些概念还存在,成为逻辑上的概念,这样方便复用之前分代框架的逻辑。在物理上不需要连续,则带来了额外的好处——有的分区内垃圾对象特别多,有的分区内垃圾对象很少,G1会优先回收垃圾对象特别多的分区,这样可以花费较少的时间来回收这些分区的垃圾,这也就是G1名字的由来,即首先收集垃圾最多的分区。
        新生代其实并不是适用于这种算法的,依然是在新生代满了的时候,对整个新生代进行回收——整个新生代中的对象,要么被回收、要么晋升,至于新生代也采取分区机制的原因,则是因为这样跟老年代的策略统一,方便调整代的大小。
        G1还是一种带压缩的收集器,在回收老年代的分区时,是将存活的对象从一个分区拷贝到另一个可用分区,这个拷贝的过程就实现了局部的压缩。每个分区的大小从1M到32M不等,但是都是2的幂次方。

2、基础概念

1、Card Table

由于做YGC时,需要扫描整个OLD区(因为OLD区有可能有引用指向Y区),效率非常低,所以JVM设计了CardTable, 如果一个OLD区CardTable中有对象指向Y区,就将它设为Dirty,下次扫描时,只需要扫描Dirty Card

在结构上,Card Table用BitMap来实现。(Dirty:肮脏的,脏数据)

2、CSet = Collection Set
一组可被回收的分区的集合。
在CSet中存活的数据会在GC过程中被移动到另一个可用分区,CSet中的分区可以来自Eden空间、survivor空间、或者老年代。
CSet会占用不到整个堆空间的1%大小。

3、RSet = RememberedSet    (Remembered:记得)

在Region中有一块区域,记录了其他Region中的对象到本Region的引用
RSet的价值在于使得垃圾收集器不需要扫描整个堆找到谁引用了当前分区中的对象,只需要扫描RSet即可。

4、RSet与赋值的效率

由于RSet 的存在,那么每次给对象赋引用的时候,就得做一些额外的操作,指的是在RSet中做一些额外的记录(在GC中被称为写屏障),这个写屏障 不等于 内存屏障

5、GC何时触发

YGC:Eden空间不足、多线程并行执行

FGC:Old空间不足、System.gc()

6、G1是否分代?G1垃圾回收器会产生FGC吗?

G1是逻辑分代,物理不分代。会产生FGC,最后的对象分配不开了

7、如果G1产生FGC,你应该做什么?

    1.扩内存

    2. 提高CPU性能

    3. 降低MixedGC触发的阈值,让MixedGC提早发生(默认是45%)

8、G1中的MixedGC

    1.=CMS

    2.XX:InitiatingHeapOccupacyPercent  默认值45%,当O超过这个值时,启动MixedGC

9、MixedGC的过程

    1.初始标记 STW

    2.并发标记

SATB算法:
Snapshot At The Beginning
GC开始时,通过root tracing得到一个Snapshot
维持并发GC的正确性
如何做到并发GC的正确性:
三色标记算法:
白:对象没有标记,标记阶段结束后,会被回收
灰:对象标记了,但是他的Field还没有标记或标记完
黑:对象标记了,且他的Field也标记完成

漏标

    在remark过程中,黑色指向了白色,如果不对黑色重新扫描,则会漏标。会把白色D对象当做没有新引用指向从而回收掉。

    并发标记过程中,删除了所有从灰色到白色的引用,会产生漏标,此时白色对象应该被回收。

漏标是指,本来是live object,但是由于没有遍历到,被当成garbage回收掉了

产生漏标:

    ①. 标记进行时增加了一个黑到白的引用,如果不重新对黑色进行处理,则会漏标
    ②. 标记进行时删除了灰对象到白对象的引用,那么这个白对象有可能被漏标

打破上述两个条件之一即可,解决漏标问题

    ①. incremental update -- 增量更新,关注引用的增加,把黑色重新标记为灰色,下次重新扫描属性,CMS使用。

    ②. SATB snapshot at the beginning – 关注引用的删除,当B->D消失时,要把这个引用推到GC的堆栈,保证D还能被GC扫描到,G1使用。

    3.最终标记 STW (重新标记)

    4.筛选回收 STW (并行)

10、为什么G1用SATB?

灰色 → 白色 引用消失时,如果没有黑色指向白色,引用会被push到堆栈。
下次扫描时拿到这个引用,由于有RSet的存在,不需要扫描整个堆去查找指向白色的引用,效率比较高。SATB 配合 RSet ,浑然天成

11、G1的Full GC

java 10以前是串行FullGC,之后是并行FullGC

12、G1新老年代比例

5%-60%,一般不用手工指定,也不要手工指定,因为这是G1预测停顿时间的基准

13、每个Region有多大 

取值1 2 4 8 16 32   即2的幂次方

手工指定 -XX:G1HeapRegionSize

3、G1特点:

  1. 并发收集
  2. 压缩空闲空间不会延长GC的暂停时间
  3. 更易预测的GC暂停时间
  4. 适用不需要实现很高的吞吐量的场景

4、CMS日志分析

JVM Optimization Learning(四)

中的JVM Optimization Case环境继续使用此环境

[root@localhost java]# java -Xms20M -Xmx20M -XX:+PrintGCDetails -XX:+UseConcMarkSweepGC com.lwz.jvm.T15_FullGC_Problem01
[GC (Allocation Failure) [ParNew: 5504K->640K(6144K), 0.0124495 secs] 5504K->1049K(19840K), 0.0126009 secs] [Times: user=0.01 sys=0.01, real=0.02 secs]
[GC (Allocation Failure) [ParNew: 6144K->640K(6144K), 0.0273421 secs] 6553K->2858K(19840K), 0.0274255 secs] [Times: user=0.08 sys=0.00, real=0.02 secs]
[GC (Allocation Failure) [ParNew: 6144K->640K(6144K), 0.0169154 secs] 8362K->6127K(19840K), 0.0171555 secs] [Times: user=0.05 sys=0.00, real=0.02 secs]
[GC (Allocation Failure) [ParNew: 6144K->640K(6144K), 0.0139854 secs] 11631K->9628K(19840K), 0.0140778 secs] [Times: user=0.05 sys=0.00, real=0.02 secs]
[GC (CMS Initial Mark) [1 CMS-initial-mark: 8988K(13696K)] 9628K(19840K), 0.0014297 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[CMS-concurrent-mark-start]
[CMS-concurrent-mark: 0.030/0.030 secs] [Times: user=0.04 sys=0.00, real=0.03 secs]
[CMS-concurrent-preclean-start]
[CMS-concurrent-preclean: 0.001/0.001 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (CMS Final Remark) [YG occupancy: 1274 K (6144 K)][Rescan (parallel) , 0.0012268 secs][weak refs processing, 0.0000665 secs][class unloading, 0.0014624 secs][scrub symbol table, 0.0007199 secs][scrub string table, 0.0003808 secs][1 CMS-remark: 8988K(13696K)] 10262K(19840K), 0.0041094 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[CMS-concurrent-sweep-start]
[CMS-concurrent-sweep: 0.015/0.015 secs] [Times: user=0.01 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 (CMS Initial Mark) [1 CMS-initial-mark: 8926K(13696K)] 10982K(19840K), 0.0012949 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[CMS-concurrent-mark-start]
[CMS-concurrent-mark: 0.018/0.018 secs] [Times: user=0.02 sys=0.00, real=0.02 secs]
[CMS-concurrent-preclean-start]
[CMS-concurrent-preclean: 0.002/0.002 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (CMS Final Remark) [YG occupancy: 2056 K (6144 K)][Rescan (parallel) , 0.0006445 secs][weak refs processing, 0.0000152 secs][class unloading, 0.0008104 secs][scrub symbol table, 0.0005612 secs][scrub string table, 0.0002756 secs][1 CMS-remark: 8926K(13696K)] 10982K(19840K), 0.0024193 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[CMS-concurrent-sweep-start]
[CMS-concurrent-sweep: 0.005/0.005 secs] [Times: user=0.01 sys=0.00, real=0.00 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 (CMS Initial Mark) [1 CMS-initial-mark: 8926K(13696K)] 11454K(19840K), 0.0018331 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[CMS-concurrent-mark-start]
[CMS-concurrent-mark: 0.031/0.031 secs] [Times: user=0.04 sys=0.00, real=0.03 secs]
[CMS-concurrent-preclean-start]
[CMS-concurrent-preclean: 0.004/0.004 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[GC (CMS Final Remark) [YG occupancy: 2528 K (6144 K)][Rescan (parallel) , 0.0086513 secs][weak refs processing, 0.0000225 secs][class unloading, 0.0009794 secs][scrub symbol table, 0.0005974 secs][scrub string table, 0.0002462 secs][1 CMS-remark: 8926K(13696K)] 11454K(19840K), 0.0106071 secs] [Times: user=0.04 sys=0.00, real=0.01 secs]
[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 (CMS Initial Mark) [1 CMS-initial-mark: 8926K(13696K)] 11791K(19840K), 0.0017124 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
[CMS-concurrent-mark-start]
[CMS-concurrent-mark: 0.028/0.028 secs] [Times: user=0.03 sys=0.00, real=0.02 secs]
[CMS-concurrent-preclean-start]
[CMS-concurrent-preclean: 0.002/0.002 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[CMS-concurrent-abortable-preclean-start]CMS: abort preclean due to time [CMS-concurrent-abortable-preclean: 1.068/5.088 secs] [Times: user=1.51 sys=0.00, real=5.08 secs]
[GC (CMS Final Remark) [YG occupancy: 4373 K (6144 K)][Rescan (parallel) , 0.0016615 secs][weak refs processing, 0.0000167 secs][class unloading, 0.0007608 secs][scrub symbol table, 0.0005483 secs][scrub string table, 0.0002508 secs][1 CMS-remark: 8926K(13696K)] 13299K(19840K), 0.0033322 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[CMS-concurrent-sweep-start]
[CMS-concurrent-sweep: 0.007/0.007 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[CMS-concurrent-reset-start]
[CMS-concurrent-reset: 0.012/0.012 secs] [Times: user=0.01 sys=0.00, real=0.02 secs]
[GC (CMS Initial Mark) [1 CMS-initial-mark: 8926K(13696K)] 13771K(19840K), 0.0030760 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[CMS-concurrent-mark-start]
[CMS-concurrent-mark: 0.027/0.027 secs] [Times: user=0.03 sys=0.00, real=0.03 secs]
[CMS-concurrent-preclean-start]
[CMS-concurrent-preclean: 0.005/0.005 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[CMS-concurrent-abortable-preclean-start]
[CMS-concurrent-abortable-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (CMS Final Remark) [YG occupancy: 4845 K (6144 K)][Rescan (parallel) , 0.0024014 secs][weak refs processing, 0.0000203 secs][class unloading, 0.0010572 secs][scrub symbol table, 0.0007175 secs][scrub string table, 0.0003684 secs][1 CMS-remark: 8926K(13696K)] 13771K(19840K), 0.0046857 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
[CMS-concurrent-sweep-start]
[CMS-concurrent-sweep: 0.007/0.007 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 (CMS Initial Mark) [1 CMS-initial-mark: 8926K(13696K)] 14998K(19840K), 0.0048182 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[CMS-concurrent-mark-start]
[CMS-concurrent-mark: 0.021/0.021 secs] [Times: user=0.03 sys=0.00, real=0.02 secs]
[CMS-concurrent-preclean-start]
[CMS-concurrent-preclean: 0.004/0.004 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[CMS-concurrent-abortable-preclean-start]
[CMS-concurrent-abortable-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (CMS Final Remark) [YG occupancy: 6072 K (6144 K)][Rescan (parallel) , 0.0032505 secs][weak refs processing, 0.0000216 secs][class unloading, 0.0010294 secs][scrub symbol table, 0.0006718 secs][scrub string table, 0.0003728 secs][1 CMS-remark: 8926K(13696K)] 14998K(19840K), 0.0055128 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
[CMS-concurrent-sweep-start]
[CMS-concurrent-sweep: 0.011/0.011 secs] [Times: user=0.01 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 (Allocation Failure) [ParNew: 6144K->640K(6144K), 0.0149299 secs] 14864K->12924K(19840K), 0.0150074 secs] [Times: user=0.06 sys=0.00, real=0.02 secs]
[GC (CMS Initial Mark) [1 CMS-initial-mark: 12284K(13696K)] 13014K(19840K), 0.0008257 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[CMS-concurrent-mark-start]
[CMS-concurrent-mark: 0.026/0.026 secs] [Times: user=0.03 sys=0.00, real=0.02 secs]
[CMS-concurrent-preclean-start]
[CMS-concurrent-preclean: 0.001/0.001 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[GC (CMS Final Remark) [YG occupancy: 1336 K (6144 K)][Rescan (parallel) , 0.0007401 secs][weak refs processing, 0.0000219 secs][class unloading, 0.0010162 secs][scrub symbol table, 0.0006404 secs][scrub string table, 0.0004188 secs][1 CMS-remark: 12284K(13696K)] 13621K(19840K), 0.0029844 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[CMS-concurrent-sweep-start]

ParNew年轻代:

[GC (Allocation Failure) [ParNew: 5504K->640K(6144K), 0.0124495 secs] 5504K->1049K(19840K), 0.0126009 secs] [Times: user=0.01 sys=0.01, real=0.02 secs]
ParNew:年轻代收集器
5504K->640K:收集前后的对比
(6144K):整个年轻代容量
5504K->1049K:整个堆的情况
(19840K):整个堆大小

CMS老年代回收日志---主要看1.频繁不频繁,2.花的时间长不长,是不是在我允许的范围之内

[GC (CMS Initial Mark) [1 CMS-initial-mark: 8988K(13696K)] 9628K(19840K), 0.0014297 secs][Times: user=0.00 sys=0.00, real=0.00 secs]//8988K(13696K) : 老年代使用(最大)//9628K(19840K) : 整个堆使用(最大)
[CMS-concurrent-mark-start]
[CMS-concurrent-mark: 0.030/0.030 secs] [Times: user=0.04 sys=0.00, real=0.03 secs]//这里的时间意义不大,因为是并发执行
[CMS-concurrent-preclean-start]
[CMS-concurrent-preclean: 0.001/0.001 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]//标记Card为Dirty,也称为Card Marking
[GC (CMS Final Remark) [YG occupancy: 1274 K (6144 K)][Rescan (parallel) , 0.0012268 secs]
[weak refs processing, 0.0000665 secs][class unloading, 0.0014624 secs][scrub symbol table,0.0007199 secs][scrub string table, 0.0003808 secs][1 CMS-remark: 8988K(13696K)]10262K(19840K), 0.0041094 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: 8988K(13696K): 阶段过后的老年代占用及容量//10262K(19840K): 阶段过后的堆占用及容量
[CMS-concurrent-sweep-start]
[CMS-concurrent-sweep: 0.015/0.015 secs] [Times: user=0.01 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做准备

5、G1日志分析

JVM Optimization Learning(四) ---JVM Optimization Case环境继续使用此环境

[root@localhost java]# java -Xms20M -Xmx20M -XX:+PrintGCDetails -XX:+UseG1GC com.lwz.jvm.T15_FullGC_Problem01
[GC pause (G1 Evacuation Pause) (young), 0.0091218 secs][Parallel Time: 7.8 ms, GC Workers: 4][GC Worker Start (ms): Min: 7838.5, Avg: 7842.2, Max: 7846.0, Diff: 7.5][Ext Root Scanning (ms): Min: 0.0, Avg: 1.0, Max: 2.0, Diff: 2.0, Sum: 4.0][Update RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Processed Buffers: Min: 0, Avg: 0.0, Max: 0, Diff: 0, Sum: 0][Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Code Root Scanning (ms): Min: 0.0, Avg: 0.1, Max: 0.2, Diff: 0.2, Sum: 0.2][Object Copy (ms): Min: 0.0, Avg: 2.5, Max: 5.2, Diff: 5.2, Sum: 10.0][Termination (ms): Min: 0.0, Avg: 0.2, Max: 0.4, Diff: 0.4, Sum: 1.0][Termination Attempts: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: 4][GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.1][GC Worker Total (ms): Min: 0.1, Avg: 3.9, Max: 7.6, Diff: 7.6, Sum: 15.5][GC Worker End (ms): Min: 7846.1, Avg: 7846.1, Max: 7846.1, Diff: 0.1][Code Root Fixup: 0.0 ms][Code Root Purge: 0.0 ms][Clear CT: 0.3 ms][Other: 1.0 ms][Choose CSet: 0.0 ms][Ref Proc: 0.5 ms][Ref Enq: 0.0 ms][Redirty Cards: 0.3 ms][Humongous Register: 0.0 ms][Humongous Reclaim: 0.0 ms][Free CSet: 0.0 ms][Eden: 12.0M(12.0M)->0.0B(10.0M) Survivors: 0.0B->2048.0K Heap: 12.0M(20.0M)->1952.0K(20.0M)][Times: user=0.02 sys=0.01, real=0.01 secs]
[GC pause (G1 Evacuation Pause) (young), 0.0184956 secs][Parallel Time: 16.2 ms, GC Workers: 4][GC Worker Start (ms): Min: 31098.3, Avg: 31098.9, Max: 31099.7, Diff: 1.3][Ext Root Scanning (ms): Min: 0.4, Avg: 2.9, Max: 8.0, Diff: 7.6, Sum: 11.4][Update RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Processed Buffers: Min: 0, Avg: 0.0, Max: 0, Diff: 0, Sum: 0][Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Code Root Scanning (ms): Min: 0.0, Avg: 0.1, Max: 0.4, Diff: 0.4, Sum: 0.4][Object Copy (ms): Min: 7.5, Avg: 12.4, Max: 14.2, Diff: 6.7, Sum: 49.7][Termination (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Termination Attempts: Min: 3, Avg: 4.2, Max: 8, Diff: 5, Sum: 17][GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.1][GC Worker Total (ms): Min: 14.6, Avg: 15.4, Max: 15.9, Diff: 1.3, Sum: 61.7][GC Worker End (ms): Min: 31114.3, Avg: 31114.3, Max: 31114.3, Diff: 0.0][Code Root Fixup: 0.0 ms][Code Root Purge: 0.0 ms][Clear CT: 0.8 ms][Other: 1.4 ms][Choose CSet: 0.0 ms][Ref Proc: 0.6 ms][Ref Enq: 0.0 ms][Redirty Cards: 0.6 ms][Humongous Register: 0.0 ms][Humongous Reclaim: 0.0 ms][Free CSet: 0.0 ms][Eden: 10.0M(10.0M)->0.0B(7168.0K) Survivors: 2048.0K->2048.0K Heap: 11.9M(20.0M)->6817.5K(20.0M)][Times: user=0.05 sys=0.01, real=0.02 secs]
[GC pause (G1 Evacuation Pause) (young) (to-space exhausted), 0.0245234 secs][Parallel Time: 16.8 ms, GC Workers: 4][GC Worker Start (ms): Min: 53252.5, Avg: 53252.7, Max: 53252.9, Diff: 0.4][Ext Root Scanning (ms): Min: 0.5, Avg: 0.7, Max: 0.9, Diff: 0.4, Sum: 2.8][Update RS (ms): Min: 2.9, Avg: 3.0, Max: 3.3, Diff: 0.4, Sum: 12.0][Processed Buffers: Min: 12, Avg: 14.2, Max: 18, Diff: 6, Sum: 57][Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.2][Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Object Copy (ms): Min: 12.1, Avg: 12.3, Max: 12.5, Diff: 0.5, Sum: 49.3][Termination (ms): Min: 0.0, Avg: 0.2, Max: 0.3, Diff: 0.3, Sum: 0.6][Termination Attempts: Min: 1, Avg: 1.2, Max: 2, Diff: 1, Sum: 5][GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1][GC Worker Total (ms): Min: 16.1, Avg: 16.2, Max: 16.5, Diff: 0.4, Sum: 65.0][GC Worker End (ms): Min: 53269.0, Avg: 53269.0, Max: 53269.0, Diff: 0.0][Code Root Fixup: 0.0 ms][Code Root Purge: 0.0 ms][Clear CT: 0.7 ms][Other: 7.0 ms][Evacuation Failure: 5.8 ms][Choose CSet: 0.0 ms][Ref Proc: 0.4 ms][Ref Enq: 0.0 ms][Redirty Cards: 0.6 ms][Humongous Register: 0.0 ms][Humongous Reclaim: 0.0 ms][Free CSet: 0.0 ms][Eden: 7168.0K(7168.0K)->0.0B(1024.0K) Survivors: 2048.0K->2048.0K Heap: 13.7M(20.0M)->19.0M(20.0M)][Times: user=0.08 sys=0.00, real=0.02 secs]
[GC pause (G1 Evacuation Pause) (young) (initial-mark) (to-space exhausted), 0.0435448 secs][Parallel Time: 35.5 ms, GC Workers: 4][GC Worker Start (ms): Min: 56073.6, Avg: 56073.8, Max: 56073.9, Diff: 0.3][Ext Root Scanning (ms): Min: 0.5, Avg: 0.6, Max: 0.8, Diff: 0.3, Sum: 2.5][Update RS (ms): Min: 0.0, Avg: 3.5, Max: 14.1, Diff: 14.1, Sum: 14.1][Processed Buffers: Min: 0, Avg: 14.2, Max: 57, Diff: 57, Sum: 57][Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.1][Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Object Copy (ms): Min: 20.1, Avg: 30.9, Max: 34.6, Diff: 14.5, Sum: 123.6][Termination (ms): Min: 0.0, Avg: 0.2, Max: 0.4, Diff: 0.4, Sum: 0.7][Termination Attempts: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: 4][GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][GC Worker Total (ms): Min: 35.1, Avg: 35.2, Max: 35.4, Diff: 0.3, Sum: 141.0][GC Worker End (ms): Min: 56109.0, Avg: 56109.0, Max: 56109.0, Diff: 0.0][Code Root Fixup: 0.0 ms][Code Root Purge: 0.0 ms][Clear CT: 0.6 ms][Other: 7.4 ms][Evacuation Failure: 6.4 ms][Choose CSet: 0.0 ms][Ref Proc: 0.4 ms][Ref Enq: 0.0 ms][Redirty Cards: 0.5 ms][Humongous Register: 0.0 ms][Humongous Reclaim: 0.0 ms][Free CSet: 0.0 ms][Eden: 1024.0K(1024.0K)->0.0B(1024.0K) Survivors: 2048.0K->0.0B Heap: 20.0M(20.0M)->20.0M(20.0M)][Times: user=0.07 sys=0.00, real=0.04 secs]
[GC concurrent-root-region-scan-start]
[GC concurrent-root-region-scan-end, 0.0001056 secs]
[GC concurrent-mark-start]
[Full GC (Allocation Failure)  20M->11M(20M), 0.0384932 secs][Eden: 0.0B(1024.0K)->0.0B(3072.0K) Survivors: 0.0B->0.0B Heap: 20.0M(20.0M)->11.1M(20.0M)], [Metaspace: 3879K->3873K(1056768K)][Times: user=0.05 sys=0.00, real=0.04 secs]
[GC concurrent-mark-abort]
[GC pause (G1 Evacuation Pause) (young), 0.0100011 secs][Parallel Time: 8.4 ms, GC Workers: 4][GC Worker Start (ms): Min: 65691.5, Avg: 65691.7, Max: 65691.8, Diff: 0.3][Ext Root Scanning (ms): Min: 0.4, Avg: 0.6, Max: 0.7, Diff: 0.3, Sum: 2.2][Update RS (ms): Min: 3.9, Avg: 4.0, Max: 4.1, Diff: 0.2, Sum: 16.0][Processed Buffers: Min: 13, Avg: 14.8, Max: 17, Diff: 4, Sum: 59][Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Object Copy (ms): Min: 3.4, Avg: 3.5, Max: 3.6, Diff: 0.2, Sum: 13.9][Termination (ms): Min: 0.0, Avg: 0.1, Max: 0.2, Diff: 0.2, Sum: 0.5][Termination Attempts: Min: 18, Avg: 22.8, Max: 26, Diff: 8, Sum: 91][GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1][GC Worker Total (ms): Min: 8.0, Avg: 8.2, Max: 8.4, Diff: 0.3, Sum: 32.8][GC Worker End (ms): Min: 65699.8, Avg: 65699.8, Max: 65699.8, Diff: 0.0][Code Root Fixup: 0.0 ms][Code Root Purge: 0.0 ms][Clear CT: 0.5 ms][Other: 1.0 ms][Choose CSet: 0.0 ms][Ref Proc: 0.5 ms][Ref Enq: 0.0 ms][Redirty Cards: 0.4 ms][Humongous Register: 0.0 ms][Humongous Reclaim: 0.0 ms][Free CSet: 0.0 ms][Eden: 3072.0K(3072.0K)->0.0B(1024.0K) Survivors: 0.0B->1024.0K Heap: 14.1M(20.0M)->13.6M(20.0M)][Times: user=0.04 sys=0.00, real=0.01 secs]
[GC pause (G1 Evacuation Pause) (young) (initial-mark), 0.0105135 secs][Parallel Time: 8.5 ms, GC Workers: 4][GC Worker Start (ms): Min: 69872.2, Avg: 69872.4, Max: 69872.6, Diff: 0.4][Ext Root Scanning (ms): Min: 0.5, Avg: 0.7, Max: 0.9, Diff: 0.4, Sum: 2.7][Update RS (ms): Min: 4.1, Avg: 4.2, Max: 4.3, Diff: 0.2, Sum: 16.7][Processed Buffers: Min: 12, Avg: 14.8, Max: 17, Diff: 5, Sum: 59][Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Object Copy (ms): Min: 3.1, Avg: 3.2, Max: 3.3, Diff: 0.2, Sum: 12.8][Termination (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.2][Termination Attempts: Min: 11, Avg: 14.2, Max: 16, Diff: 5, Sum: 57][GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1][GC Worker Total (ms): Min: 7.9, Avg: 8.1, Max: 8.3, Diff: 0.4, Sum: 32.6][GC Worker End (ms): Min: 69880.6, Avg: 69880.6, Max: 69880.6, Diff: 0.0][Code Root Fixup: 0.0 ms][Code Root Purge: 0.0 ms][Clear CT: 0.7 ms][Other: 1.4 ms][Choose CSet: 0.0 ms][Ref Proc: 0.7 ms][Ref Enq: 0.0 ms][Redirty Cards: 0.5 ms][Humongous Register: 0.0 ms][Humongous Reclaim: 0.0 ms][Free CSet: 0.0 ms][Eden: 1024.0K(1024.0K)->0.0B(1024.0K) Survivors: 1024.0K->1024.0K Heap: 14.6M(20.0M)->15.4M(20.0M)][Times: user=0.03 sys=0.00, real=0.01 secs]
[GC concurrent-root-region-scan-start]
[GC concurrent-root-region-scan-end, 0.0029410 secs]
[GC concurrent-mark-start]
[GC concurrent-mark-end, 0.0485784 secs]
[GC remark [Finalize Marking, 0.0005557 secs] [GC ref-proc, 0.0003018 secs] [Unloading, 0.0014276 secs], 0.0029364 secs][Times: user=0.01 sys=0.00, real=0.00 secs]
[GC cleanup 15M->15M(20M), 0.0013613 secs][Times: user=0.00 sys=0.00, real=0.00 secs]
[GC pause (G1 Evacuation Pause) (young), 0.0114531 secs][Parallel Time: 9.6 ms, GC Workers: 4][GC Worker Start (ms): Min: 73775.8, Avg: 73775.9, Max: 73776.1, Diff: 0.3][Ext Root Scanning (ms): Min: 0.4, Avg: 0.5, Max: 0.7, Diff: 0.3, Sum: 2.2][Update RS (ms): Min: 5.7, Avg: 5.8, Max: 5.9, Diff: 0.3, Sum: 23.0][Processed Buffers: Min: 15, Avg: 15.2, Max: 16, Diff: 1, Sum: 61][Scan RS (ms): Min: 0.0, Avg: 0.2, Max: 0.3, Diff: 0.2, Sum: 0.7][Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Object Copy (ms): Min: 2.7, Avg: 2.8, Max: 2.8, Diff: 0.1, Sum: 11.1][Termination (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Termination Attempts: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: 4][GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1][GC Worker Total (ms): Min: 9.1, Avg: 9.3, Max: 9.4, Diff: 0.3, Sum: 37.0][GC Worker End (ms): Min: 73785.2, Avg: 73785.2, Max: 73785.2, Diff: 0.0][Code Root Fixup: 0.0 ms][Code Root Purge: 0.0 ms][Clear CT: 0.6 ms][Other: 1.3 ms][Choose CSet: 0.0 ms][Ref Proc: 0.6 ms][Ref Enq: 0.0 ms][Redirty Cards: 0.4 ms][Humongous Register: 0.0 ms][Humongous Reclaim: 0.0 ms][Free CSet: 0.0 ms][Eden: 1024.0K(1024.0K)->0.0B(1024.0K) Survivors: 1024.0K->1024.0K Heap: 16.4M(20.0M)->16.7M(20.0M)][Times: user=0.04 sys=0.00, real=0.01 secs]
[GC pause (G1 Evacuation Pause) (mixed) (to-space exhausted), 0.0406284 secs][Parallel Time: 34.3 ms, GC Workers: 4][GC Worker Start (ms): Min: 77404.1, Avg: 77404.4, Max: 77404.7, Diff: 0.6][Ext Root Scanning (ms): Min: 0.3, Avg: 0.6, Max: 0.9, Diff: 0.6, Sum: 2.2][Update RS (ms): Min: 4.1, Avg: 4.2, Max: 4.2, Diff: 0.1, Sum: 16.8][Processed Buffers: Min: 13, Avg: 15.2, Max: 18, Diff: 5, Sum: 61][Scan RS (ms): Min: 0.0, Avg: 0.1, Max: 0.4, Diff: 0.4, Sum: 0.5][Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Object Copy (ms): Min: 28.7, Avg: 29.0, Max: 29.1, Diff: 0.4, Sum: 115.9][Termination (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Termination Attempts: Min: 1, Avg: 1.2, Max: 2, Diff: 1, Sum: 5][GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1][GC Worker Total (ms): Min: 33.6, Avg: 33.9, Max: 34.2, Diff: 0.6, Sum: 135.4][GC Worker End (ms): Min: 77438.3, Avg: 77438.3, Max: 77438.3, Diff: 0.0][Code Root Fixup: 0.0 ms][Code Root Purge: 0.0 ms][Clear CT: 0.5 ms][Other: 5.8 ms][Evacuation Failure: 4.3 ms][Choose CSet: 0.0 ms][Ref Proc: 0.7 ms][Ref Enq: 0.0 ms][Redirty Cards: 0.7 ms][Humongous Register: 0.0 ms][Humongous Reclaim: 0.0 ms][Free CSet: 0.0 ms][Eden: 1024.0K(1024.0K)->0.0B(1024.0K) Survivors: 1024.0K->1024.0K Heap: 17.7M(20.0M)->19.1M(20.0M)][Times: user=0.07 sys=0.00, real=0.04 secs]
[GC pause (G1 Evacuation Pause) (young) (to-space exhausted), 0.0146382 secs][Parallel Time: 11.7 ms, GC Workers: 4][GC Worker Start (ms): Min: 77445.6, Avg: 77445.8, Max: 77446.3, Diff: 0.7][Ext Root Scanning (ms): Min: 0.0, Avg: 0.4, Max: 0.6, Diff: 0.6, Sum: 1.6][Update RS (ms): Min: 0.0, Avg: 2.3, Max: 5.0, Diff: 5.0, Sum: 9.3][Processed Buffers: Min: 0, Avg: 65.5, Max: 156, Diff: 156, Sum: 262][Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Object Copy (ms): Min: 5.6, Avg: 8.3, Max: 10.6, Diff: 5.0, Sum: 33.1][Termination (ms): Min: 0.0, Avg: 0.1, Max: 0.3, Diff: 0.3, Sum: 0.5][Termination Attempts: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: 4][GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][GC Worker Total (ms): Min: 10.7, Avg: 11.2, Max: 11.4, Diff: 0.7, Sum: 44.6][GC Worker End (ms): Min: 77457.0, Avg: 77457.0, Max: 77457.0, Diff: 0.0][Code Root Fixup: 0.0 ms][Code Root Purge: 0.0 ms][Clear CT: 0.4 ms][Other: 2.6 ms][Evacuation Failure: 1.5 ms][Choose CSet: 0.0 ms][Ref Proc: 0.6 ms][Ref Enq: 0.0 ms][Redirty Cards: 0.4 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: 1024.0K->0.0B Heap: 19.1M(20.0M)->19.1M(20.0M)][Times: user=0.02 sys=0.00, real=0.01 secs]

G1日志young     参照CMS日志查看

[GC pause (G1 Evacuation Pause) (young), 0.0091218 secs][Parallel Time: 7.8 ms, GC Workers: 4][GC Worker Start (ms): Min: 7838.5, Avg: 7842.2, Max: 7846.0, Diff: 7.5][Ext Root Scanning (ms): Min: 0.0, Avg: 1.0, Max: 2.0, Diff: 2.0, Sum: 4.0][Update RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Processed Buffers: Min: 0, Avg: 0.0, Max: 0, Diff: 0, Sum: 0][Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Code Root Scanning (ms): Min: 0.0, Avg: 0.1, Max: 0.2, Diff: 0.2, Sum: 0.2][Object Copy (ms): Min: 0.0, Avg: 2.5, Max: 5.2, Diff: 5.2, Sum: 10.0][Termination (ms): Min: 0.0, Avg: 0.2, Max: 0.4, Diff: 0.4, Sum: 1.0][Termination Attempts: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: 4][GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.1][GC Worker Total (ms): Min: 0.1, Avg: 3.9, Max: 7.6, Diff: 7.6, Sum: 15.5][GC Worker End (ms): Min: 7846.1, Avg: 7846.1, Max: 7846.1, Diff: 0.1][Code Root Fixup: 0.0 ms][Code Root Purge: 0.0 ms][Clear CT: 0.3 ms]  //清理Card table[Other: 1.0 ms][Choose CSet: 0.0 ms][Ref Proc: 0.5 ms][Ref Enq: 0.0 ms][Redirty Cards: 0.3 ms][Humongous Register: 0.0 ms][Humongous Reclaim: 0.0 ms][Free CSet: 0.0 ms][Eden: 12.0M(12.0M)->0.0B(10.0M) Survivors: 0.0B->2048.0K Heap: 12.0M(20.0M)->1952.0K(20.0M)][Times: user=0.02 sys=0.01, real=0.01 secs]

G1日志mixedGC--混合回收

查看日志回收是否回收正常,没回收代表不正常

[GC pause (G1 Evacuation Pause) (young) (initial-mark) (to-space exhausted), 0.0435448 secs]
//young -> 年轻代 Evacuation(疏散,撤离)-> 复制存活对象 
//initial-mark 混合回收的阶段(mixedGC),这里是YGC混合老年代回收[Parallel Time: 35.5 ms, GC Workers: 4]  //4个GC线程[GC Worker Start (ms): Min: 56073.6, Avg: 56073.8, Max: 56073.9, Diff: 0.3][Ext Root Scanning (ms): Min: 0.5, Avg: 0.6, Max: 0.8, Diff: 0.3, Sum: 2.5][Update RS (ms): Min: 0.0, Avg: 3.5, Max: 14.1, Diff: 14.1, Sum: 14.1][Processed Buffers: Min: 0, Avg: 14.2, Max: 57, Diff: 57, Sum: 57][Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.1][Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][Object Copy (ms): Min: 20.1, Avg: 30.9, Max: 34.6, Diff: 14.5, Sum: 123.6][Termination (ms): Min: 0.0, Avg: 0.2, Max: 0.4, Diff: 0.4, Sum: 0.7][Termination Attempts: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: 4][GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0][GC Worker Total (ms): Min: 35.1, Avg: 35.2, Max: 35.4, Diff: 0.3, Sum: 141.0][GC Worker End (ms): Min: 56109.0, Avg: 56109.0, Max: 56109.0, Diff: 0.0][Code Root Fixup: 0.0 ms][Code Root Purge: 0.0 ms][Clear CT: 0.6 ms]   //清理Card table[Other: 7.4 ms][Evacuation Failure: 6.4 ms][Choose CSet: 0.0 ms][Ref Proc: 0.4 ms][Ref Enq: 0.0 ms][Redirty Cards: 0.5 ms][Humongous Register: 0.0 ms][Humongous Reclaim: 0.0 ms][Free CSet: 0.0 ms][Eden: 1024.0K(1024.0K)->0.0B(1024.0K) Survivors: 2048.0K->0.0B 
Heap: 20.0M(20.0M)->20.0M(20.0M)][Times: user=0.07 sys=0.00, real=0.04 secs]
//以下是混合回收其他阶段
[GC concurrent-root-region-scan-start]
[GC concurrent-root-region-scan-end, 0.0001056 secs]
[GC concurrent-mark-start]
//无法evacuation,进行FGC
[Full GC (Allocation Failure)  20M->11M(20M), 0.0384932 secs][Eden: 0.0B(1024.0K)->0.0B(3072.0K) Survivors: 0.0B->0.0B 
Heap: 20.0M(20.0M)->11.1M(20.0M)], [Metaspace: 3879K->3873K(1056768K)][Times: user=0.05 sys=0.00, real=0.04 secs]
[GC concurrent-mark-abort]

2、GC参数

2.1、GC常用参数

-Xmn -Xms -Xmx -Xss
  年轻代 最小堆 最大堆 栈空间
-XX:+UseTLAB
  使用TLAB,默认打开
-XX:+PrintTLAB
  打印TLAB的使用情况
-XX:TLABSize
  设置TLAB大小
-XX:+DisableExplictGC
  System.gc()不管用 ,FGC
-XX:+PrintGC

  打印GC信息
-XX:+PrintGCDetails

  打印GC详细信息
-XX:+PrintHeapAtGC

  打印GC堆栈信息
-XX:+PrintGCTimeStamps

  打印发生GC系统信息
-XX:+PrintGCApplicationConcurrentTime (低)
  打印应用程序时间
-XX:+PrintGCApplicationStoppedTime (低)
  打印应用程序暂停时长
-XX:+PrintReferenceGC (重要性低)
  记录回收了多少种不同引用类型的引用
-verbose:class
  类加载详细过程
-XX:+PrintVMOptions

  打印JVM运行时参数
-XX:+PrintFlagsFinal  (需要会)

   查找JVM命令设置的最终值

[root@localhost ~]# java -XX:+PrintFlagsFinal -version | grep G1double G1ConcMarkStepDurationMillis              = 10.000000                                                                {product}uintx G1ConcRSHotCardLimit                      = 4                                                                        {product}uintx G1ConcRSLogCacheSize                      = 10                                                                       {product}intx G1ConcRefinementGreenZone                 = 0                                                                        {product}intx G1ConcRefinementRedZone                   = 0                                                                        {product}intx G1ConcRefinementServiceIntervalMillis     = 300                                                                      {product}uintx G1ConcRefinementThreads                   = 0                                                                        {product}intx G1ConcRefinementThresholdStep             = 0                                                                        {product}intx G1ConcRefinementYellowZone                = 0                                                                        {product}uintx G1ConfidencePercent                       = 50                                                                       {product}uintx G1HeapRegionSize                          = 0                                                                        {product}uintx G1HeapWastePercent                        = 5                                                                        {product}uintx G1MixedGCCountTarget                      = 8                                                                        {product}intx G1RSetRegionEntries                       = 0                                                                        {product}uintx G1RSetScanBlockSize                       = 64                                                                       {product}intx G1RSetSparseRegionEntries                 = 0                                                                        {product}intx G1RSetUpdatingPauseTimePercent            = 10                                                                       {product}intx G1RefProcDrainInterval                    = 10                                                                       {product}uintx G1ReservePercent                          = 10                                                                       {product}uintx G1SATBBufferEnqueueingThresholdPercent    = 60                                                                       {product}intx G1SATBBufferSize                          = 1024                                                                     {product}intx G1UpdateBufferSize                        = 256                                                                      {product}bool G1UseAdaptiveConcRefinement               = true                                                                     {product}bool UseG1GC                                   = false                                                                    {product}
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)

-XX:+PrintFlagsInitial  (需要会)

   查找JVM命令初始化默认值

[root@localhost ~]# java -XX:+PrintFlagsInitial -version | grep CMSbool CMSAbortSemantics                         = false                               {product}uintx CMSAbortablePrecleanMinWorkPerIteration   = 100                                 {product}intx CMSAbortablePrecleanWaitMillis            = 100                                 {manageable}uintx CMSBitMapYieldQuantum                     = 10485760                            {product}uintx CMSBootstrapOccupancy                     = 50                                  {product}bool CMSClassUnloadingEnabled                  = true                                {product}uintx CMSClassUnloadingMaxInterval              = 0                                   {product}bool CMSCleanOnEnter                           = true                                {product}bool CMSCompactWhenClearAllSoftRefs            = true                                {product}uintx CMSConcMarkMultiple                       = 32                                  {product}bool CMSConcurrentMTEnabled                    = true                                {product}uintx CMSCoordinatorYieldSleepCount             = 10                                  {product}bool CMSDumpAtPromotionFailure                 = false                               {product}bool CMSEdenChunksRecordAlways                 = true                                {product}uintx CMSExpAvgFactor                           = 50                                  {product}bool CMSExtrapolateSweep                       = false                               {product}uintx CMSFullGCsBeforeCompaction                = 0                                   {product}uintx CMSIncrementalDutyCycle                   = 10                                  {product}uintx CMSIncrementalDutyCycleMin                = 0                                   {product}bool CMSIncrementalMode                        = false                               {product}uintx CMSIncrementalOffset                      = 0                                   {product}bool CMSIncrementalPacing                      = true                                {product}uintx CMSIncrementalSafetyFactor                = 10                                  {product}uintx CMSIndexedFreeListReplenish               = 4                                   {product}intx CMSInitiatingOccupancyFraction            = -1                                  {product}uintx CMSIsTooFullPercentage                    = 98                                  {product}double CMSLargeCoalSurplusPercent                = 0.950000                            {product}double CMSLargeSplitSurplusPercent               = 1.000000                            {product}bool CMSLoopWarn                               = false                               {product}uintx CMSMaxAbortablePrecleanLoops              = 0                                   {product}intx CMSMaxAbortablePrecleanTime               = 5000                                {product}uintx CMSOldPLABMax                             = 1024                                {product}uintx CMSOldPLABMin                             = 16                                  {product}uintx CMSOldPLABNumRefills                      = 4                                   {product}uintx CMSOldPLABReactivityFactor                = 2                                   {product}bool CMSOldPLABResizeQuicker                   = false                               {product}uintx CMSOldPLABToleranceFactor                 = 4                                   {product}bool CMSPLABRecordAlways                       = true                                {product}uintx CMSParPromoteBlocksToClaim                = 16                                  {product}bool CMSParallelInitialMarkEnabled             = true                                {product}bool CMSParallelRemarkEnabled                  = true                                {product}bool CMSParallelSurvivorRemarkEnabled          = true                                {product}uintx CMSPrecleanDenominator                    = 3                                   {product}uintx CMSPrecleanIter                           = 3                                   {product}uintx CMSPrecleanNumerator                      = 2                                   {product}bool CMSPrecleanRefLists1                      = true                                {product}bool CMSPrecleanRefLists2                      = false                               {product}bool CMSPrecleanSurvivors1                     = false                               {product}bool CMSPrecleanSurvivors2                     = true                                {product}uintx CMSPrecleanThreshold                      = 1000                                {product}bool CMSPrecleaningEnabled                     = true                                {product}bool CMSPrintChunksInDump                      = false                               {product}bool CMSPrintEdenSurvivorChunks                = false                               {product}bool CMSPrintObjectsInDump                     = false                               {product}uintx CMSRemarkVerifyVariant                    = 1                                   {product}bool CMSReplenishIntermediate                  = true                                {product}uintx CMSRescanMultiple                         = 32                                  {product}uintx CMSSamplingGrain                          = 16384                               {product}bool CMSScavengeBeforeRemark                   = false                               {product}uintx CMSScheduleRemarkEdenPenetration          = 50                                  {product}uintx CMSScheduleRemarkEdenSizeThreshold        = 2097152                             {product}uintx CMSScheduleRemarkSamplingRatio            = 5                                   {product}double CMSSmallCoalSurplusPercent                = 1.050000                            {product}double CMSSmallSplitSurplusPercent               = 1.100000                            {product}bool CMSSplitIndexedFreeListBlocks             = true                                {product}intx CMSTriggerInterval                        = -1                                  {manageable}uintx CMSTriggerRatio                           = 80                                  {product}intx CMSWaitDuration                           = 2000                                {manageable}uintx CMSWorkQueueDrainThreshold                = 10                                  {product}bool CMSYield                                  = true                                {product}uintx CMSYieldSleepCount                        = 0                                   {product}uintx CMSYoungGenPerWorker                      = 67108864                            {pd product}uintx CMS_FLSPadding                            = 1                                   {product}uintx CMS_FLSWeight                             = 75                                  {product}uintx CMS_SweepPadding                          = 1                                   {product}uintx CMS_SweepTimerThresholdMillis             = 10                                  {product}uintx CMS_SweepWeight                           = 75                                  {product}bool PrintCMSInitiationStatistics              = false                               {product}intx PrintCMSStatistics                        = 0                                   {product}bool UseCMSBestFit                             = true                                {product}bool UseCMSCollectionPassing                   = true                                {product}bool UseCMSCompactAtFullCollection             = true                                {product}bool UseCMSInitiatingOccupancyOnly             = false                               {product}
[root@localhost ~]#

-Xloggc:opt/log/gc.log
-XX:MaxTenuringThreshold
  GC升代年龄,最大值15
锁自旋次数 -XX:PreBlockSpin 热点代码检测参数-XX:CompileThreshold 逃逸分析 标量替换 
不建议设置

2.2、Parallel常用参数

-XX:SurvivorRatio
-XX:PreTenureSizeThreshold
  大对象到底多大
-XX:MaxTenuringThreshold

  GC升代年龄,最大值15
-XX:+ParallelGCThreads
  并行收集器的线程数,同样适用于CMS,一般设为和CPU核数相同
-XX:+UseAdaptiveSizePolicy
  自动选择各区大小比例

2.3、CMS常用参数

-XX:+UseConcMarkSweepGC

  启动CMS垃圾回收器
-XX:ParallelCMSThreads
  CMS线程数量
-XX:CMSInitiatingOccupancyFraction
  使用多少比例的老年代后开始CMS收集,默认是68%(近似值),如果频繁发生SerialOld卡顿,应该调小,(频繁CMS回收)

怎么解决CMS回收器,浮动垃圾和碎片化的问题?
-XX:+UseCMSCompactAtFullCollection
  在FGC时进行压缩
-XX:CMSFullGCsBeforeCompaction
  多少次FGC之后进行压缩

-XX:+CMSClassUnloadingEnabled

  回收不用的class
-XX:CMSInitiatingPermOccupancyFraction
  达到什么比例时进行Perm回收
GCTimeRatio
  设置GC时间占用程序运行时间的百分比,是一个建议时间
-XX:MaxGCPauseMillis
  停顿时间,是一个建议时间,GC会尝试用各种手段达到这个时间,比如减小年轻代

2.4、G1常用参数

-XX:+UseG1GC

  启动G1GC
-XX:MaxGCPauseMillis
  建议值,G1会尝试调整Young区的块数来达到这个值
-XX:GCPauseIntervalMillis
  GC的间隔时间
-XX:+G1HeapRegionSize
  设置分区大小,建议逐渐增大该值,1 2 4 8 16 32。
  随着size增加,垃圾的存活时间更长,GC间隔更长,但每次GC的时间也会更长
  ZGC做了改进(动态区块大小)
G1NewSizePercent
  新生代最小比例,默认为5%
G1MaxNewSizePercent
  新生代最大比例,默认为60%
GCTimeRatio
  GC时间建议比例,G1会根据这个值调整堆空间
ConcGCThreads
  线程数量
InitiatingHeapOccupancyPercent
  启动G1的堆空间占用比例

JVM Optimization Learning(四)

不断学习才能不断提高!
生如蝼蚁,当立鸿鹄之志,命比纸薄,应有不屈之心。
乾坤未定,你我皆是黑马,若乾坤已定,谁敢说我不能逆转乾坤?
努力吧,机会永远是留给那些有准备的人,否则,机会来了,没有实力,只能眼睁睁地看着机会溜走。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/214810.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【微软技术栈】发布自己造的轮子 -- 创建Nuget包(分布操作)

目录 1、您的项目 2、创建 .nuspec 文件 3、一张图片胜过一千个拉取请求 4、包括自述文件 MD 文件 5、构建软件包 6、将包部署到 Nuget.Org 7、手动上传软件包 8、自动化和脚本化部署 9、我们如何构建和部署 ErrLog.IO Nuget 包 10、Nuget统计数据 11、最后的思考 创建 Nuget 包…

生产上线需要注意的安全漏洞

一、关闭swagger 1、关闭swagger v3 # 需同时设置auto-startupfalse,否则/v3/api-docs等接口仍能继续访问 springfox:documentation:enabled: falseauto-startup: falseswagger-ui:enabled: false 2、关闭swagger v2 # 只要不是true就不启用 swagger:enable: fa…

YOLOv8/YOLOv7/YOLOv5/YOLOv4/Faster-rcnn系列算法改进【NO.83】将主干特征提取网络Backbone改为RevCol

前言 作为当前先进的深度学习目标检测算法YOLOv8,已经集合了大量的trick,但是还是有提高和改进的空间,针对具体应用场景下的检测难点,可以不同的改进方法。此后的系列文章,将重点对YOLOv8的如何改进进行详细的介绍,目的是为了给那些搞科研的同学需要创新点或者搞工程项目…

Vue3: 给表格多个字段添加排序功能

问题 在Vue3项目中,使用element-plus的表格组件绘制表格后,需要令表格的多个字段可以进行选择排序(选择升序或者降序)但是排序功能好像有时候会出错,需要排序的字段多了之后,排序功能有时候会不起作用 解…

分子生成领域的stable diffusion - GEOLDM

一、关于stable diffusion 很多人都知道stable diffusion,stable diffusion的出现改变了机器生成领域,让AI技术第一次无比的接近正常人。大语言模型,AIGC概念于是兴起。基于stable diffusion 大家开发了lora, hyperwork等微调技术…

JDK 9 模块化系统 (Module System) 和 多版本兼容 Jar (Multi-Release Jar)

博文目录 文章目录 Module System原因JDK 模块化模块描述文件关键字 启用模块化测试结论 Multi-Release jar (MRJAR)原因原理结论用 IDEA 创建多版本兼容 Jar项目结构pom.xml测试 Module System 原因 Java 9引入了模块化系统的主要原因是为了解决Java平台面临的复杂性和可维…

从电商API接口谈电商ERP系统介绍

部分网友反馈小红书APP出现闪退问题。对此,小红书客服微博发文称,如遇到小红书APP无法启动的情况,用户可前往App Store下载最新版本(详情可见: )小红书闪退崩溃出bug,IT人员要背故障吗&#xff…

【计算机网络实验】实验三 IP网络规划与路由设计(头歌)

目录 一、知识点 二、实验任务 三、头歌测试 一、知识点 IP子网掩码的两种表示方法 32位IP子网掩码,特点是从高位开始连续都是1,后面是连续的0,它有以下两种表示方法: 传统表示法,如:255.255.255.0IP前…

windows下oracle透明网关安装

上一次说了如何在Linux下安装oracle到sqlserver之间的透明网关,现在给大家继续介绍如何在windows下安装。 本文实验环境: 数据库类型 数据库版本 IP oracle 11204 192.168.238.122 MSSQL MSSQL 2008 192.168.239.40 一、oracle服务器配置ODBC源…

linux软件管理

八、软件管理 RPM相关命令 8.1 RPM包管理 8.1.1 RPM概述 RPM Package Manager (原Red Hat Package Manager,现在是一个递归缩写) ​ 由Red Hat公司提出,被众多 Linux 发行版所采用也称二进制( binary code) 无需编译,可以直接使用 ​ 无法设…

重磅!2023中国高校计算机大赛-人工智能创意赛结果出炉

目录 中国计算机大赛-人工智能创意赛现场C4-AI大赛颁奖及留影800个AI应用?这届大学生真能“搞事情”AI原生时代,百度要再培养500大模型人才 中国计算机大赛-人工智能创意赛现场 12月8日,杭州,一位“白发老人”突然摔倒在地&#…

Verilog学习 | 用initial语句写出固定的波形

initial beginia 0;ib 1;clk 0;#10ia 1; #20ib 0;#20ia 0; endalways #5 clk ~clk; 或者 initial clk 0;initial beginia 0;#10ia 1; #40ia 0; endinitial beginib 1;#30 ib 0; endalways #5 clk ~clk;

深入探索C语言中的二叉树:数据结构之旅

引言 在计算机科学领域,数据结构是基础中的基础。在众多数据结构中,二叉树因其在各种操作中的高效性而脱颖而出。二叉树是一种特殊的树形结构,每个节点最多有两个子节点:左子节点和右子节点。这种结构使得搜索、插入、删除等操作…

強強联手!M88明陞宣布与G2 电子竞技俱乐部成为官方合作伙伴!

M88明陞作为亚洲领先的在线游戏平台,正式宣布与G2电子竞技俱乐部建立具有突破性意义的官方合作伙伴关系,G2电子竞技俱乐部是全球领先的电子竞技品牌之一。作为官方合作伙伴关系,双方将合作开展一系列活动。 M88明陞将在G2 电子竞技俱乐部追求…

推荐4个优秀的 Python 时间序列分析库

时间序列分析在金融和医疗保健等领域至关重要,在这些领域,理解随时间变化的数据模式至关重要。在本文中,我们将介绍四个主要的Python库——statmodels、tslearn、tssearch和tsfresh——每个库都针对时间序列分析的不同方面进行了定制。这些库…

初识人工智能,一文读懂贝叶斯优化的知识文集(6)

🏆作者简介,普修罗双战士,一直追求不断学习和成长,在技术的道路上持续探索和实践。 🏆多年互联网行业从业经验,历任核心研发工程师,项目技术负责人。 🎉欢迎 👍点赞✍评论…

IDEA中配置Git

Git 在IDEA中使用Git1 在IDEA中配置Git2 在IDEA中使用Git2.1在IDEA中创建工程并将工程添加至Git2.2 将文件添加到暂存区2.3 提交文件2.4 将代码推送到远程仓库2.5 从远程仓库克隆工程到本地2.6 从远程拉取代码2.7 版本对比2.8 创建分支2.9 切换分支2.10 分支合并 3 使用IDEA进行…

【HarmonyOS开发】详解常见容器的使用

声明式UI提供了以下8种常见布局,开发者可根据实际应用场景选择合适的布局进行页面开发。 布局 应用场景 线性布局(Row、Column) 如果布局内子元素超过1个,且能够以某种方式线性排列时优先考虑此布局。 层叠布局(St…