390767K(462208K), 0.0325540 sec-6ren">
gpt4 book ai didi

java - "GC--"在 java 垃圾收集日志中意味着什么?

转载 作者:搜寻专家 更新时间:2023-11-01 00:58:00 26 4
gpt4 key购买 nike

我们打开了详细的 GC 日志记录以跟踪已知的内存泄漏并在日志中获得以下条目:

...
3607872.687: [GC 471630K->390767K(462208K), 0.0325540 secs]
3607873.213: [GC-- 458095K->462181K(462208K), 0.2757790 secs]
3607873.488: [Full GC 462181K->382186K(462208K), 1.5346420 secs]
...

我理解其中的第一个和第三个,但是“GC--”是什么意思?

最佳答案

我的 gc 输出中有这些行:

44871.602: [GC-- [PSYoungGen: 342848K->342848K(345600K)] 961401K->1041877K(1044672K), 0.1018780 secs] [Times: user=0.16 sys=0.00, real=0.11 secs]

我读了 Yishai 的回答,它是有道理的,但我想在 Java GC 源代码中亲眼看看,当 JVM 在 GC 日志中打印“--”以及为什么。

因为据我所知,Young Gen 的“Parallel Scavenge”是一个 stop-the-world GC,因此不可能有任何对象与此 GC 并行创建。 (见 https://blogs.oracle.com/jonthecollector/entry/our_collectors )

您可以在 jdk 源代码中找到它(参见 http://hg.openjdk.java.net/jdk7/jdk7 )g1CollectedHeap.cpp 和 psScavenge.cpp

jdk7-ee67ee3bd597/hotspot/src/share$ egrep -h -A2 -B5 -r '"\-\-"' *
# G1 Collector
if (evacuation_failed()) {
remove_self_forwarding_pointers();
if (PrintGCDetails) {
gclog_or_tty->print(" (to-space overflow)");
} else if (PrintGC) {
gclog_or_tty->print("--");
}
}
--
# Parallel Scavenge Collector
promotion_failure_occurred = promotion_failed();
if (promotion_failure_occurred) {
clean_up_failed_promotion();
if (PrintGC) {
gclog_or_tty->print("--");
}
}

使用 GC 的原因——使用 Parallel Scavenge 收集器

Young GC 遇到提升失败(参见 http://mail.openjdk.java.net/pipermail/hotspot-gc-use/2010-March/000567.html ):

A promotion failure is a scavenge that does not succeed because there is not enough space in the old gen to do all the needed promotions. The scavenge is in essence unwound and then a full STW compaction of the entire heap is done.

'Not enough space'并不一定意味着old空间不够,而是old空间严重碎片化(见http://blog.ragozin.info/2011/10/java-cg-hotspots-cms-and-heap.html):

[...] it is impossible to find certain amount of continuous memory to promote particular large object, even though total number of free bytes is large enough.

这两个 JVM 选项可以帮助您分析堆碎片(请参阅 http://blog.ragozin.info/2011/10/java-cg-hotspots-cms-and-heap.html ):

-XX:+PrintPromotionFailure
-XX:PrintFLSStatistics=1

GC 的原因——使用 G1 收集器

当 Survivor Region 没有足够的空间容纳来自 Young Region 的幸存对象时,G1 的疏散失败。

我不知道 G1 收集器是否以 Full GC 响应疏散失败。

关于java - "GC--"在 java 垃圾收集日志中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9625480/

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