JVM

11-选择合适的垃圾收集器

2021-06-11  本文已影响0人  紫荆秋雪_文

一个垃圾收集器除了垃圾收集这个本职工作之外,它还要负责堆的管理与布局、对象的分配、与解释器的协作、与编译器的协作、与监控子系统协作等职责,其中至少堆的管理和对象的分配这部分功能是Java虚拟机能够正常运作的必要支出,是一个最小化功能的垃圾收集器也必须实现的内容。

一、收集器的权衡

选取时主要考量因素

二、虚拟机及垃圾收集器日志

-Xlog[:[selector][:[output][:[decorators][:output-options]]]]
add,age,alloc,annotation,aot,arguments,attach,barrier,biasedlocking,blocks,bot,breakpoint,bytecode,
-  日志级别从低到高,共有Trace、Debug、Info、Warning、Error、Off六种级别,日志级别决定了输出信息的详细程度,默认级别为Info,HotSpot的日志规则与Log4j、Slf4j这类Java日志框架大体上市一直的。

实例——JDK9的G1收集器

bash-3.2$ java -Xlog:gc GCTest [0.222s][info][gc] Using G1 [2.825s][info][gc] GC(0) Pause Young (G1 Evacuation Pause) 26M->5M(256M) 355.623ms [3.096s][info][gc] GC(1) Pause Young (G1 Evacuation Pause) 14M->7M(256M) 50.030ms [3.385s][info][gc] GC(2) Pause Young (G1 Evacuation Pause) 17M->10M(256M) 40.576ms
bash-3.2$ java -Xlog:gc* GCTest [0.233s][info][gc,heap] Heap region size: 1M [0.383s][info][gc ] Using G1 [0.383s][info][gc,heap,coops] Heap address: 0xfffffffe50400000, size: 4064 MB, Compressed Oops mode: Non-zero based: 0xfffffffe50000000, Oop shift amount: 3 [3.064s][info][gc,start ] GC(0) Pause Young (G1 Evacuation Pause) gc,task ] GC(0) Using 23 workers of 23 for evacuation [3.420s][info][gc,phases ] GC(0) Pre Evacuate Collection Set: 0.2ms [3.421s][info][gc,phases ] GC(0) Evacuate Collection Set: 348.0ms gc,phases ] GC(0) Post Evacuate Collection Set: 6.2ms [3.421s][info][gc,phases ] GC(0) Other: 2.8ms gc,heap ] GC(0) Eden regions: 24->0(9) [3.421s][info][gc,heap ] GC(0) Survivor regions: 0->3(3) [3.421s][info][gc,heap ] GC(0) Old regions: 0->2 [3.421s][info][gc,heap ] GC(0) Humongous regions: 2->1 [3.421s][info][gc,metaspace ] GC(0) Metaspace: 4719K->4719K(1056768K) [3.421s][info][gc ] GC(0) Pause Young (G1 Evacuation Pause) 26M->5M(256M) 357.743ms [3.422s][info][gc,cpu ] GC(0) User=0.70s Sys=5.13s Real=0.36s [3.648s][info][gc,start ] GC(1) Pause Young (G1 Evacuation Pause) [3.648s][info][gc,task ] GC(1) Using 23 workers of 23 for evacuation [3.699s][info][gc,phases ] GC(1) Pre Evacuate Collection Set: 0.3ms gc,phases ] GC(1) Evacuate Collection Set: 45.6ms gc,phases ] GC(1) Post Evacuate Collection Set: 3.4ms gc,phases ] GC(1) Other: 1.7ms gc,heap ] GC(1) Eden regions: 9->0(10) [3.699s][info][gc,heap ] GC(1) Survivor regions: 3->2(2) [3.699s][info][gc,heap ] GC(1) Old regions: 2->5 [3.700s][info][gc,heap ] GC(1) Humongous regions: 1->1 [3.700s][info][gc,metaspace ] GC(1) Metaspace: 4726K->4726K(1056768K) [3.700s][info][gc ] GC(1) Pause Young (G1 Evacuation Pause) 14M->7M(256M) 51.872ms [3.700s][info][gc,cpu ] GC(1) User=0.56s Sys=0.46s Real=0.05s

三、垃圾收集器参数总结

image.png
image.png
上一篇下一篇

猜你喜欢

热点阅读