Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Side Effects of running the JVM in debug mode

Tags:

I'd like to realease a Java application in debug mode to allow for easier debugging when random or hard to reproduce problems occur on the customer side.

However, I want to get a heads up on potential side effects of doing this? From the Java HotSpot Documentation it seems that there should be no performance penalty.

From the link

Full Speed Debugging

The Java HotSpot VM now uses full-speed debugging. In previous version of the VM, when debugging was enabled, the program executed using only the interpreter. Now, the full performance advantage of HotSpot technology is available to programs, even with compiled code. The improved performance allows long-running programs to be more easily debugged. It also allows testing to proceed at full speed. Once there is an exception, the debugger launches with full visibility to code sources.

Is this accurate or are there hidden caveats, what about memory footprint and are there any other hidden gotchas while using debug mode.

PS: I found this article from AMD which confirmed my initial suspiciion that the original article from oricale doesn't show the full story.

like image 514
hhafez Avatar asked Sep 16 '10 00:09

hhafez


People also ask

How does JVM debugging work?

Since in the JVM architecture, the debugging functionality is not found within the JVM itself but is abstracted away into external tools (that are aptly referred to as debuggers), these tools can either reside on the local machine running the JVM being debugged or be run from am external machine.

What is JVM debugger?

The Java™ Debugger (JDB) is included in the SDK. The debugger is started with the jdb command; it attaches to the JVM using JPDA. To debug a Java application: Start the JVM with the following options: java -agentlib:jdwp=transport=dt_socket,server=y,address=<port> <class>

What is debugging an application which runs on another JVM on another machine?

What is debugging an application which runs on another java virtual machine on another machine? Explanation: Remote debugging allows us to debug applications which run on another Java virtual machine or even on another machine.


2 Answers

I can't speak for HotSpot, and won't officially for IBM, but I will say there are certainly legal kinds of optimization that aren't possible to undo fully should a decompilation be required in the middle of them, and thus aren't enabled when debug is being asked for in the production JVMs you are likely to use.

Imagine a situation where the optimizer discovers a part of the program is provably not required and by the various language rules (including JSR 133) is legal to remove, the JVM will want to get rid of it. The one wrinkle is debug: removing the code will look odd to the human stepping through it (variables not updating, possibly not stopping on lines when stepping) so the choice is to disable said optimizations in those cases. The same might also be true for opts like stack allocated objects, etc.. so while the JVM says it's "full speed" it's actually closer to "nearly full speed, with some of the funkier opts that can't quite be undone removed".

like image 69
Trent Gray-Donald Avatar answered Oct 22 '22 15:10

Trent Gray-Donald


This question is old but came up while I was searching for any performance impact if you just leave -agentlib:jdwp... on but are not actively debugging.

Summary: Starting with debugging options but not connecting shouldn't impact the speed now (Java 7+).

Before java 6 (ish) you used -Xdebug and this had a definite impact, it shut off the JIT!

In java 6 they changed it to -agentlib and made it better. there were some bugs though that did cause a performance penalty. Here is one of the bugs that was filed against openjdk, My guess is that there were similar problems with The oracle/sun version: https://bugs.openjdk.java.net/browse/JDK-6902182

Note however that the stated goal is that simply enabling debugging by opening the port should not cause any performance penalty.

It looks like, at least in openjdk, the bugs were cleaned up by java 7. I didn't see anything about performance impacts after that.

If you research this further and find negative results, take note of the java version the testing was done under--everything I saw was referring to versions before 7.

I'd love to hear if anyone encountered performance problems in a recent VM just leaving the port enabled.

like image 33
Bill K Avatar answered Oct 22 '22 16:10

Bill K