Java 垃圾收集日志消息 [英] Java Garbage Collection Log messages

查看:35
本文介绍了Java 垃圾收集日志消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将 Java 配置为将垃圾收集信息转储到日志中(verbose GC).我不确定日志中的垃圾收集条目是什么意思.下面发布了这些条目的示例.我在 Google 上四处搜索,但没有找到可靠的解释.

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

  1. PSYoungGen 指的是什么?我认为这与上一代(年轻?)有关,但究竟是什么?
  2. 第二个数字三元组和第一个数字有什么区别?
  3. 为什么为第一个数字三元组指定名称 (PSYoungGen) 而不是为第二个数字指定名称?
  4. 三元组中的每个数字(内存大小)是什么意思.比如在109884K->14201K(139904K)中,就是GC之前的内存109884k然后减到14201K.第三个数字有什么关系?为什么我们需要第二组数字?

<块引用>

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秒]

解决方案

大部分在 GC 调优指南(无论如何你最好阅读一下).

<块引用>

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

[GC 325407K->83000K(776768K)​​, 0.2300771 秒][GC 325816K->83372K(776768K)​​,0.2454258 秒][完整 GC 267628K->83769K(776768K)​​,1.8479984 秒]

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

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

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

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

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

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

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 Google and have not found solid explanations.

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:

  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?

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]

解决方案

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

The command line option -verbose:gc causes 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->83000K from 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:gc is subject to change in future releases.

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

这篇关于Java 垃圾收集日志消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆