gpt4 book ai didi

java - `jcmd PID GC.class_histogram`在收集数据之前会调用完整GC吗?

转载 作者:行者123 更新时间:2023-12-02 06:19:10 27 4
gpt4 key购买 nike

当我运行jcmd PID help GC.heap_dump时,帮助清楚地表明将调用完整GC,除非指定-all标志:

GC.heap_dump ... Impact: High: Depends on Java heap size and content. Request a full GC unless the '-all' option is specified. <...>

-all : [optional] Inspect all objects, including unreachable objects (BOOLEAN, false)

如果我运行jcmd PID help GC.class_histogram,该帮助没有说明任何有关强制执行完整GC的内容,但是“影响”仍然被认为是“高”,并且该选项仍然有一个 -all 标志,其行为与 GC.heap_dump 完全相同:

GC.class_histogram ... Impact: High: Depends on Java heap size and content.

-all : [optional] Inspect all objects, including unreachable objects (BOOLEAN, false)

我尝试在几个环境中运行此命令,但未调用完整 GC。然而,由于它“取决于Java堆大小和内容”我不能确定。

那么在某些情况下jcmd PID GC.class_histogram可以调用完整GC吗?如果是,它们是什么?

最佳答案

jcmd PID GC.class_histogram默认会导致Full GC。

如果目标 JVM 使用 -XX:+PrintGC 启动,您将看到类似的日志消息

// JDK 8:
[Full GC (Heap Inspection Initiated GC) 1397K->331K(126720K), 0.0023298 secs]

// JDK 9:
[15.503s][info ][gc] GC(0) Pause Full (Heap Inspection Initiated GC) 2M->0M(8M) 8.107ms

但是,使用 -all 选项时,GC.class_histogram 不会进行 Full GC,这与 GC.heap_dump 完全相同。在 HotSpot sources 中找到证明:

void ClassHistogramDCmd::execute(DCmdSource source, TRAPS) {
VM_GC_HeapInspection heapop(output(),
!_all.value() /* request full gc if false */);
VMThread::execute(&heapop);
}

关于java - `jcmd PID GC.class_histogram`在收集数据之前会调用完整GC吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48446767/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com