javajvmjvm-hotspotjdi

Can breakpoints be placed in JITed code in the Hotspot JVM?


I've read that that this was possible, in the (now retired) Harmony JVM, but what about the Hotspot JVM? Is this possible? If not, do breakpoints prevent the code from being JITed, which means that breakpoints come at an even greater cost?


Solution

  • What happens is that the JVM deoptimizes the method to allow the breakpoint to be added to it.

    Deoptimization doesn't necessarily mean that the method is returned to bytecode form and only interpreted. But it may undo optimizations that reorder code, inline methods and so on. These make it difficult for the debugger relate the execution state to the source code ... which is what the programmer is looking at.

    But, yes, running your code in debug mode does make it slower.


    Think of it this way, when you are debugging a C executable in a symbolic debugger, the C code has been (statically) compiled to native code and linked. And yet, the debugger is able to insert breakpoints, single-step the code, look at the variables on the stack, and so on.

    If anything, it is easier for a JVM to do this ... because >>it<< controls the compilation to native code.