占用cpu高的线程的堆栈如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
Thread 1 (process 17775): #0 0x00007fa870981179 in Klass::subklass() const () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #1 0x00007fa8706d15c5 in Dependencies::find_finalizable_subclass(Klass*) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #2 0x00007fa8705df8ee in ciInstanceKlass::has_finalizable_subclass() () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #3 0x00007fa87052483e in GraphBuilder::call_register_finalizer() () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #4 0x00007fa87052b2a5 in GraphBuilder::method_return(Instruction*) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #5 0x00007fa87053185f in GraphBuilder::iterate_bytecodes_for_block(int) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #6 0x00007fa87052ec4b in GraphBuilder::iterate_all_blocks(bool) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #7 0x00007fa87052f5e6 in GraphBuilder::try_inline_full(ciMethod*, bool, Bytecodes::Code, Instruction*) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #8 0x00007fa87052f7df in GraphBuilder::try_inline(ciMethod*, bool, Bytecodes::Code, Instruction*) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #9 0x00007fa870530912 in GraphBuilder::invoke(Bytecodes::Code) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #10 0x00007fa87053183d in GraphBuilder::iterate_bytecodes_for_block(int) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #11 0x00007fa87052ec4b in GraphBuilder::iterate_all_blocks(bool) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #12 0x00007fa87052f5e6 in GraphBuilder::try_inline_full(ciMethod*, bool, Bytecodes::Code, Instruction*) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #13 0x00007fa87052f7df in GraphBuilder::try_inline(ciMethod*, bool, Bytecodes::Code, Instruction*) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #14 0x00007fa870530912 in GraphBuilder::invoke(Bytecodes::Code) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #15 0x00007fa87053183d in GraphBuilder::iterate_bytecodes_for_block(int) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #16 0x00007fa87052ebf2 in GraphBuilder::iterate_all_blocks(bool) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #17 0x00007fa8705337a7 in GraphBuilder::GraphBuilder(Compilation*, IRScope*) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #18 0x00007fa87053c127 in IRScope::IRScope(Compilation*, IRScope*, int, ciMethod*, int, bool) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #19 0x00007fa87053c23f in IR::IR(Compilation*, ciMethod*, int) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #20 0x00007fa87051b25b in Compilation::build_hir() () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #21 0x00007fa87051b61e in Compilation::compile_java_method() () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #22 0x00007fa87051b74e in Compilation::compile_method() () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #23 0x00007fa87051babe in Compilation::Compilation(AbstractCompiler*, ciEnv*, ciMethod*, int, BufferBlob*) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #24 0x00007fa87051c869 in Compiler::compile_method(ciEnv*, ciMethod*, int) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #25 0x00007fa87066f43a in CompileBroker::invoke_compiler_on_method(CompileTask*) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #26 0x00007fa8706703e6 in CompileBroker::compiler_thread_loop() () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #27 0x00007fa870c2386f in JavaThread::thread_main_inner() () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #28 0x00007fa870c2399c in JavaThread::run() () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #29 0x00007fa870ad7de8 in java_start(Thread*) () from /usr/java/jdk1.8.0_45/jre/lib/amd64/server/libjvm.so #30 0x0000003202c079d1 in start_thread () from /lib64/libpthread.so.0 #31 0x00000032028e88fd in clone () from /lib64/libc.so.6 |
gdb 跟进发现:线程在函数Dependencies::find_finalizable_subclass(Klass*) 中,应该有一个循环,不断地调用函数Klass::subklass()
解决办法:
The fix was simple – disable CMS class unloading options when -Xnoclassgc or -XX:-ClassUnloading are specified.
参考资料:
https://blogs.oracle.com/poonam/entry/jvm_hang_with_cms_collector
想阅读jvm源码吗? https://blogs.oracle.com/sundararajan/entry/so_you_want_to_read