如何看GC Debug日志内容

在学习GC机制时,发现有些东西通过普通的jvm参数是很难看到的,比如在ParallelGC触发悲观机制时,如果想看到此时新生代的平均晋升大小似乎就不可能的,发现在JDK源代码中有类似下面这样的if块:
if (PrintGCDetails && Verbose) {
  gclog_or_tty->print(result ? "  do scavenge: " : "  skip scavenge: ");
  gclog_or_tty->print_cr(" average_promoted " SIZE_FORMAT
    " padded_average_promoted " SIZE_FORMAT
    " free in old gen " SIZE_FORMAT,
    (size_t) policy->average_promoted_in_bytes(),
    (size_t) policy->padded_average_promoted_in_bytes(),
    old_gen->free_in_bytes());
  if (young_gen->used_in_bytes() <
      (size_t) policy->padded_average_promoted_in_bytes()) {
    gclog_or_tty->print_cr(" padded_promoted_average is greater"
      " than maximum promotion = " SIZE_FORMAT, young_gen->used_in_bytes());
  }
}

这里即使打开了-XX:+PrintGCDetails选项也是不行的,因为只有在Debug版本中,才能够设置-XX:+Verbose参数。

Debug版本的JDK的下载地址如下:
http://download.java.net/jdk6/6u25/promoted/b03/binaries/

或者使用如下方法自己搞一个Debug的Build(还没有试):
http://www.softwareengineeringsolutions.com/thoughts/Java-Debug-Build.htm

有了Debug版本的JDK后,在jvm参数中需要增加以下值:
引用
-Xloggc:./gc.log
-XX:+PrintGCDetails
-XX:+Verbose


运行程序后再看看gc.log,可以看到日志信息多了很多,找到触发fullGC的地方,可以看到以下日志:
引用
full after scavenge:  average_promoted 6291504 padded_average_promoted 6291504 free in old gen 4194256

很清楚,是因为MinorGC后的悲观策略检查发现平均晋升大小(6MB)>旧生代剩余大小(4MB)导致的FullGC。

你可能感兴趣的:(java,jdk debug build,gclog)