-XX:+PrintCompilation 输出中的这个新列是什么?

What's this new column in -XX:+PrintCompilation output?

最近在使用 -XX:+PrintCompilation (JDK 8r111) 检查方法编译时,我注意到一个新的专栏没有出现在 documentation I can find 主题中:

          this column
               |
               |
               v
600    1  s    3       java.util.Hashtable::get (69 bytes)
601    4       3       java.lang.Character::toLowerCase (6 bytes)
601    8       3       java.io.UnixFileSystem::normalize (75 bytes)
602   12       3       java.lang.ThreadLocal::get (38 bytes)
602   14       3       java.lang.ThreadLocal$ThreadLocalMap::getEntry (42 bytes)
602   18       2       java.lang.String::startsWith (72 bytes)
602   10       4       java.lang.String::equals (81 bytes)
602    2 %     4       java.lang.String::hashCode @ 24 (55 bytes)
602   16  s!   3       sun.misc.URLClassPath::getLoader (197 bytes)
603   23     n 0       java.lang.System::arraycopy (native)   (static)
604   27     n 0       sun.misc.Unsafe::getObjectVolatile (native)   

知道这是什么意思吗?它似乎在 0 和 3 之间变化,本地方法始终为 0,而其他方法始终为非零。

这是分层编译模式下的

  • 在第 1、2、3 层,代码由 C1 编译,具有不同数量的额外分析。这听起来可能违反直觉,但其中最优化的是第 1 层,因为它没有分析开销(也没有机会进一步优化)。
  • 在第 4 层,代码由 C2 编译。要生成高度优化的代码,C2 需要在第 3 层或解释期间收集执行统计信息。

这是分层编译流程的样子。您可以在 .

中找到解释

可以在 HotSpot source code comments 中找到更多详细信息,其中定义的级别如下:

  • 0 级 - 口译员
  • 级别 1 - 完全优化的 C1(无分析)
  • 2 级 - 具有调用和后台计数器的 C1
  • 级别 3 - 具有完整分析的 C1(级别 2 + MDO)
  • 4 级 - C2