Search code examples
javadebuggingjdwp

java: would jdwp slow down the performance?


As known, after jdk 5, no need to specify -Xdebug for debugging, instead, use -agentlib:jdwp, but does it mean debug mode is gone? And does it mean the java program would run in normal mode without any performance trade-off, while you could still attach it anytime you want to debug it?

Compared to C/C++, you could debug the app compiled in optimized mode, as long as you do not strip debug symbols, although, in optimized mode the debugging is not so precised, due to e.g. some function is inline or eliminated. So BTW, does java have the concept of debug symbols/info when you need to take care when building the app?


Solution

  • As known, after jdk 5, no need to specify -Xdebug for debugging, instead, use -agentlib:jdwp, but does it mean debug mode is gone?

    Yes. Old-school debug mode is gone. (The -Xdebug option is ignored by modern JVMs.)

    And does it mean the java program would run in normal mode without any performance trade-off, while you could still attach it anytime you want to debug it?

    See Overhead of enabling JVMTI *capability* to query local variables for example.

    There is some performance tradeoff1, but less than with -Xdebug. A JVMTI agent suppresses some JIT compiler optimizations, not all.

    Does java have the concept of debug symbols/info when you need to take care when building the app?

    Yes it does. See the -g option to javac.


    1 - Most sources say that the cost is small or negligible, but I saw a comment that claimed a 10-fold performance hit. It is not clear if this was the cost of -agentlib:jdwp ... or what the commenter was doing with the agent. For example, if you enable entry / exit tracing, the performance cost is significant. Unfortunately, this is all anecdotal ...