Java 8 JIT线程似乎陷入无限循环

Java 8 JIT线程似乎陷入无限循环

问题描述:

我在Java 8中编写了一个服务器应用程序,并使用java 1.8.0u25运行它。

I wrote a server application in Java 8, and running it with java 1.8.0u25.

它在前几个小时工作正常,但在它实现之后5k~10k请求,VM进程的一个线程使用其中一个CPU的100%。

It works fine for the first several hours, but after it gets about 5k~10k requests, a thread of the VM process uses 100% of one of the CPUs.

所以我尝试了 jstack 让VM进程检查有问题的线程是什么,并且它显示线程(线程id是14303 = 0x37df)是C2 CompilerThread0:

So I tried jstack for the VM process to check what the problematic thread was, and it showed that the thread(thread id was 14303=0x37df) was "C2 CompilerThread0":

"C2 CompilerThread0" #6 daemon prio=9 os_prio=0 tid=0x00002aaabc12a000 nid=0x37df runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

使用 jstack -m ,线程的堆栈跟踪为以下内容:

And with jstack -m, the stack trace of the thread was as the following:

----------------- 14303 -----------------
0x00002b99b67693c3  _ZN16PhaseMacroExpand27process_users_of_allocationEP8CallNode + 0x2a3
0x00002b99b676ec3b  _ZN16PhaseMacroExpand23eliminate_allocate_nodeEP12AllocateNode + 0x1cb
0x00002b99b676ee65  _ZN16PhaseMacroExpand21eliminate_macro_nodesEv + 0x1a5
0x00002b99b6772769  _ZN16PhaseMacroExpand18expand_macro_nodesEv + 0x19
0x00002b99b640b01b  _ZN7Compile8OptimizeEv + 0xa6b
0x00002b99b640c53c  _ZN7CompileC1EP5ciEnvP10C2CompilerP8ciMethodibbb + 0x13bc
0x00002b99b635f9c8  _ZN10C2Compiler14compile_methodEP5ciEnvP8ciMethodi + 0x198
0x00002b99b6414c6a  _ZN13CompileBroker25invoke_compiler_on_methodEP11CompileTask + 0xc8a
0x00002b99b6417650  _ZN13CompileBroker20compiler_thread_loopEv + 0x620
0x00002b99b69a2e8f  _ZN10JavaThread17thread_main_innerEv + 0xdf
0x00002b99b69a2fbc  _ZN10JavaThread3runEv + 0x11c
0x00002b99b6860d48  _ZL10java_startP6Thread + 0x108

每次我尝试 jstack -m 时,这个线程的堆栈跟踪都是一样的,但是方法旁边的数字(程序计数器?)at堆栈顶部 _ZN16PhaseMacroExpand27process_users_of_allocationEP8CallNode 0x290 0x2b1 0x2a3 0x29f

And every time I tried jstack -m, the stack trace of this thread was all the same, but the number beside the method(program counter?) at the top of the stack _ZN16PhaseMacroExpand27process_users_of_allocationEP8CallNode was 0x290, 0x2b1, 0x2a3, or 0x29f.

C2 CompilerThread0 看起来像是一个执行JIT编译的线程,并且堆栈跟踪似乎陷入无限循环或其他什么。

C2 CompilerThread0 looks like a thread doing JIT compilation, and the stack trace seems like it fell into an infinite loop or something.

我想知道这是否是JVM的JIT编译器的错误。如果是,我如何指定我的应用程序的哪个方法使JVM变得疯狂,以及如何解决(或解决)这个问题?我尝试了 -XX:+ PrintCompilation 选项,但它没有多大帮助,因为它没有显示哪个线程编译了哪个方法。
如果它不是JVM的问题,那会发生什么呢?

I wonder if this could be a bug of JIT compiler of JVM. If it is, how can I specify which method of my application makes the JVM crazy and how can I solve(or work around) this problem? I tried -XX:+PrintCompilation option, but it did not help much because it didn't show which thread compiled which method. If it is not a problem of JVM, what could make this thing happen?

它看起来确实像JIT编译器错误,可能是在分配消除优化中。

尝试使用 -XX运行:-EliminateAllocations JVM选项。

It indeed looks like a JIT compiler bug, presumably in allocation elimination optimization.
Try running with -XX:-EliminateAllocations JVM option.

您还可以添加 -XX:+ UnlockDiagnosticVMOptions -XX:+ LogCompilation 以生成详细的编译日志,每个编译器线程都有一个单独的输出文件。

You may also add -XX:+UnlockDiagnosticVMOptions -XX:+LogCompilation to produce detailed compilation log with a separate output file per compiler thread.