2

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?

kingluo
  • 1,679
  • 1
  • 13
  • 31

1 Answers1

1

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 ...

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • what happen if debug info is not compiled in? And it seems that the debug info could be generated in separate files? – kingluo Jul 04 '18 at 11:36
  • 1) Then you don't get line numbers in stack traces, and the symbolic debugger will give you less info, etc. 2) AFAIK not in Java. The debug info is part of the ".class" file. – Stephen C Jul 04 '18 at 11:38
  • As a side question, from your opinion, what's the most recommended tool (standalone, not ide specific) to debug java program (of modern version, like jdk 8 or later)? No matter free or commercial. – kingluo Jul 04 '18 at 11:43
  • Requests for recommendations are off-topic. – Stephen C Jul 04 '18 at 11:48