How to get Java stacks when JVM can't reach a safepoint

前端 未结 3 461
傲寒
傲寒 2020-12-24 14:41

We recently had a situation where one of our production JVMs would randomly freeze. The Java process was burning CPU, but all visible activity would cease: no log output, no

相关标签:
3条回答
  • 2020-12-24 14:52

    Your problem interested me very much. You were right about JIT. First I tried to play with GC types, but this did not have any effect. Then I tried to disable JIT and everything worked fine:

    java -Djava.compiler=NONE Tests
    

    Then printed out JIT compilations:

    java -XX:+PrintCompilation Tests
    

    And noticed that problem starts after some compilations in BigInteger class, I tried to exclude methods one by one from compilation and finally found the cause:

    java -XX:CompileCommand=exclude,java/math/BigInteger,multiplyToLen -XX:+PrintCompilation Tests
    

    For large arrays this method could work long, and problem might really be in safepoints. For some reason they are not inserted, but should be even in compiled code. Looks like a bug. The next step should be to analyze assembly code, I did not do it yet.

    0 讨论(0)
  • 2020-12-24 15:06

    It's not a bug, it's a performance feature. JVM eliminates safepoint check from counted loops, making them run faster. It expects that either

    • you care about STW pauses and don't have extra long loops
    • or you have extra long loops, but fine with safepoints being eventual

    If it doesn't fit you, it can be switched off with this flag: -XX:+UseCountedLoopSafepoints

    And answering the title question, you can still stop and explore a program with gdb, but the stack traces wouldn't be so nice.

    0 讨论(0)
  • 2020-12-24 15:12

    Perhaps that's what the "-F" option of jstack is good for:

    OPTIONS
      -F
         Force a stack dump when 'jstack [-l] pid' does not respond.
    

    I always wondered when an why that could help.

    0 讨论(0)
提交回复
热议问题