Java 垃圾收集日志消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/895444/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 20:47:05  来源:igfitidea点击:

Java Garbage Collection Log messages

javalogginggarbage-collection

提问by Ethan Heilman

I have configured java to dump garbage collection information into the logs (verbose GC). I am unsure of what the garbage collection entries in the logs mean. A sample of these entries are posted below. I've searched around on Googleand have not found solid explanations.

我已将 java 配置为将垃圾收集信息转储到日志中(详细 GC)。我不确定日志中的垃圾收集条目是什么意思。下面发布了这些条目的示例。我在谷歌搜索过,没有找到可靠的解释。

I have some reasonable guesses, but I'm looking for answers which provide strict definitions of what the numbers in the entries mean, backed up by credible sources. An automatic +1 to all answers which cite sun documentation. My questions are:

我有一些合理的猜测,但我正在寻找答案,这些答案对条目中的数字的含义提供了严格的定义,并得到了可靠来源的支持。对引用 sun 文档的所有答案自动 +1。我的问题是:

  1. What does PSYoungGen refer to? I assume it has something to do with the previous (younger?) generation, but what exactly?
  2. What is the difference between the second triplet of numbers and the first?
  3. Why is a name(PSYoungGen) specified for the first triplet of numbers but not the second?
  4. What does each number (memory size) in the triplet mean. For example in 109884K->14201K(139904K), is the memory before GC 109884k and then it is reduced to 14201K. How is the third number relevant? Why would we require a second set of numbers?
  1. PSYoungGen 指的是什么?我认为这与上一代(年轻?)有关,但究竟是什么?
  2. 第二个数字三元组和第一个数字有什么区别?
  3. 为什么为第一个数字三元组指定了名称(PSYoungGen)而不是第二个?
  4. 三元组中的每个数字(内存大小)是什么意思。比如在109884K->14201K(139904K)中,就是GC之前的内存109884k然后减到14201K。第三个数字如何相关?为什么我们需要第二组数字?

8109.128: [GC [PSYoungGen: 109884K->14201K(139904K)] 691015K->595332K(1119040K), 0.0454530 secs]

8112.111: [GC [PSYoungGen: 126649K->15528K(142336K)] 707780K->605892K(1121472K), 0.0934560 secs]

8112.802: [GC [PSYoungGen: 130344K->3732K(118592K)] 720708K->607895K(1097728K), 0.0682690 secs]

8109.128:[GC [PSYoungGen:109884K->14201K(139904K)] 691015K->595332K(1119040K),0.0454530 秒]

8112.111:[GC [PSYoungGen:126649K->15528K(142336K)] 707780K->605892K(1121472K),0.0934560 秒]

8112.802:[GC [PSYoungGen:130344K->3732K(118592K)] 720708K->607895K(1097728K),0.0682690 秒]

采纳答案by Michael Myers

Most of it is explained in the GC Tuning Guide(which you would do well to read anyway).

大部分内容在GC 调优指南中都有解释(无论如何你最好阅读一下)。

The command line option -verbose:gccauses information about the heap and garbage collection to be printed at each collection. For example, here is output from a large server application:

[GC 325407K->83000K(776768K), 0.2300771 secs]
[GC 325816K->83372K(776768K), 0.2454258 secs]
[Full GC 267628K->83769K(776768K), 1.8479984 secs]

Here we see two minor collections followed by one major collection. The numbers before and after the arrow (e.g., 325407K->83000Kfrom the first line) indicate the combined size of live objects before and after garbage collection, respectively. After minor collections the size includes some objects that are garbage (no longer alive) but that cannot be reclaimed. These objects are either contained in the tenured generation, or referenced from the tenured or permanent generations.

The next number in parentheses (e.g., (776768K)again from the first line) is the committed size of the heap: the amount of space usable for java objects without requesting more memory from the operating system. Note that this number does not include one of the survivor spaces, since only one can be used at any given time, and also does not include the permanent generation, which holds metadata used by the virtual machine.

The last item on the line (e.g., 0.2300771 secs) indicates the time taken to perform the collection; in this case approximately a quarter of a second.

The format for the major collection in the third line is similar.

The format of the output produced by -verbose:gcis subject to change in future releases.

命令行选项-verbose:gc导致在每次收集时打印有关堆和垃圾收集的信息。例如,这是一个大型服务器应用程序的输出:

[GC 325407K->83000K(776768K), 0.2300771 secs]
[GC 325816K->83372K(776768K), 0.2454258 secs]
[Full GC 267628K->83769K(776768K), 1.8479984 secs]

在这里,我们看到两个次要集合,然后是一个主要集合。箭头前后的数字(例如,325407K->83000K从第一行开始)分别表示垃圾收集前后活动对象的组合大小。在次要收集之后,大小包括一些垃圾(不再活动)但无法回收的对象。这些对象要么包含在老年代,要么被老年代或永久代引用。

括号中的下一个数字(例如,(776768K)再次从第一行开始)是堆的提交大小:Java 对象可使用的空间量,而无需从操作系统请求更多内存。请注意,此数字不包括幸存者空间之一,因为在任何给定时间只能使用一个,也不包括永久代,其中保存了虚拟机使用的元数据。

行上的最后一项(例如,0.2300771 secs)表示执行收集所花费的时间;在这种情况下大约四分之一秒。

第三行中主要集合的格式类似。

生成的输出格式-verbose:gc在未来版本中可能会发生变化。

I'm not certain why there's a PSYoungGen in yours; did you change the garbage collector?

我不确定你为什么会有一个 PSYoungGen;你改变了垃圾收集器吗?

回答by michaeljoseph

  1. PSYoungGen refers to the garbage collector in use for the minor collection. PS stands for Parallel Scavenge.
  2. The first set of numbers are the before/after sizes of the young generation and the second set are for the entire heap. (Diagnosing a Garbage Collection problemdetails the format)
  3. The name indicates the generation and collector in question, the second set are for the entire heap.
  1. PSYoungGen 指的是用于次要收集的垃圾收集器。PS代表并行清除。
  2. 第一组数字是年轻代之前/之后的大小,第二组数字是整个堆的大小。(诊断垃圾收集问题详细说明了格式)
  3. 名称表示有问题的代和收集器,第二组用于整个堆。

An example of an associated full GC also shows the collectors used for the old and permanent generations:

一个关联 full GC 的示例还显示了用于旧代和永久代的收集器:

3.757: [Full GC [PSYoungGen: 2672K->0K(35584K)] 
            [ParOldGen: 3225K->5735K(43712K)] 5898K->5735K(79296K) 
            [PSPermGen: 13533K->13516K(27584K)], 0.0860402 secs]

Finally, breaking down one line of your example log output:

最后,分解您的示例日志输出的一行:

8109.128: [GC [PSYoungGen: 109884K->14201K(139904K)] 691015K->595332K(1119040K), 0.0454530 secs]
  • 107Mbused before GC, 14Mbused after GC, max young generation size 137Mb
  • 675Mbheap used before GC, 581Mbheap used after GC, 1Gbmax heap size
  • minor GC occurred 8109.128seconds since the start of the JVM and took 0.04seconds
  • GC前使用107Mb,GC后使用14Mb,最大年轻代大小137Mb
  • GC 前使用675Mb堆,GC后使用581Mb堆,1Gb最大堆大小
  • 次要 GC 发生 在 JVM 启动后8109.128秒,耗时0.04

回答by Andrei

I just wanted to mention that one can get the detailed GC log with the

我只想提一下,可以通过以下方式获取详细的 GC 日志

-XX:+PrintGCDetails 

parameter. Then you see the PSYoungGen or PSPermGen output like in the answer.

范围。然后您会看到 PSYoungGen 或 PSPermGen 输出,如答案中所示。

Also -Xloggc:gc.logseems to generate the same output like -verbose:gcbut you can specify an output file in the first.

-Xloggc:gc.log似乎产生像相同的输出-verbose:gc,但是你可以指定在第一个输出文件。

Example usage:

用法示例:

java -Xloggc:./memory.log -XX:+PrintGCDetails Memory

To visualize the data better you can try gcviewer(a more recent version can be found on github).

为了更好地可视化数据,您可以尝试gcviewer(可以在github上找到更新的版本)。

Take care to write the parameters correctly, I forgot the "+" and my JBoss would not start up, without any error message!

注意参数写对,我忘记了“+”,我的JBoss启动不了,没有任何错误信息!