4

I have a Java application, and I'd like to monitor it using Java VisualVM (jvisualvm).

However, in the VisualVM window very little data can be seen. Also, I can't take a heap dump.

Here is a screenshot of what it looks like, with another test app I wrote:

screenshot

I can monitor memory usage, classes loaded and threads. Heap dumps, performing GC as well as sampling is disabled.

I have tried adding -Dcom.sun.management.jxmremote to VM arguments, as described here. This is showing up in the Installation Details window. However, it does not appear in the Java process arguments. (should it?)

screenshots

I also tried to click the button in my test app until an OutOfMemoryError occurred. No heap dump; that is not weird as Heap Dump on OOME is disabled.

What could I do to solve this?

Community
  • 1
  • 1
PurkkaKoodari
  • 6,703
  • 6
  • 37
  • 58
  • You can take a heap dump in visual VM. – assylias Dec 14 '13 at 13:53
  • What I'm saying is that the Heap Dump button works. Note however that for large heaps (say > 500MB/1GB) it will take some time. You can try it with a small heap to confirm that it works. – assylias Dec 14 '13 at 18:04
  • @assylias As you can probably see from the picture the button is disabled, greyed out, not enabled, what ever you want to call it. You can not even click it, so I don't get how it is working. – PurkkaKoodari Dec 14 '13 at 19:12
  • Oh I see. It's enabled when I try - stupid question but: your program is still running when you try to take a heap dump, right? What version of jdk are you using? – assylias Dec 14 '13 at 19:20
  • @assylias The program is running (in the picture there is the frame :D). I am using Java 7 update 45. – PurkkaKoodari Dec 14 '13 at 19:25
  • You are also missing the CPU usage analysis. Could it be because you run your app from eclipse? Maybe worth trying to run your app from the command line to see if it makes a difference. If not then I don't know what's going on - never had that issue. – assylias Dec 14 '13 at 19:55
  • @assylias Tried running from command line, no effect. – PurkkaKoodari Dec 14 '13 at 20:06

2 Answers2

6

I had this problem because I was running JVisualVM from a different JRE/JDK installation than the target process. It seems that the two must be coming from the same place or it grays out the Heap Dump button.

asgs
  • 3,928
  • 6
  • 39
  • 54
Dobes Vandermeer
  • 8,463
  • 5
  • 43
  • 46
2

It seems there was a problem with different Java versions.

A long story short: If JDK is outdated re-install it, and delete Java executables from C:\Windows\System32 and C:\Windows\SysWOW64.

Firstly, I want to tell you that I have multiple versions of Java on my computer. My JDK is 32-bit because of some drivers not running with 64-bit Java. Also, I have both 32-bit and 64-bit JRE installed, the latter for better performance for Java games.

My JDK was version 7, update 40. The VisualVM was so also that version. However, my JRE with auto updates was version 7, update 45.

java -version told me it was version 45 (which it was), so I didn't think the problem was there.

Then, I checked the versions via Control Panel. I now knew my JDK was outdated, so I uninstalled it and redownloaded it.

Uninstalling removed Java from the system path, so jvisualvm wouldn't run. I added it to the path. Now both the app and VisualVM ran normally, but still the problem persisted.

The final problem was that the system was using the java.exe from C:\Windows\System32 instead of the JDK one. By the date it seemed to be the latest one, but maybe it was that the JRE was installed in a different location that the VisualVM (= the JDK).

Finally, I just deleted the Java executables in both C:\Windows\System32 and C:\Windows\SysWOW64.

PurkkaKoodari
  • 6,703
  • 6
  • 37
  • 58
  • 6
    I think this can be summarized as follows: you were running visualvm using a jre, when you should've been using a jdk (the same one where visualvm is installed into). – eis Dec 15 '13 at 14:35