4

I'm trying to use Java VisualVM on Windows 7 64-bit together with Eclipse Kepler and am experiencing the following issue:

I have a Java application running inside Eclipse, but when I open jVisualVM, the only item showing up in the Applications under Local is VisualVM itself.

Is it possible to have my Java application show up as well? Do I need to launch it with some command line parameter to allow VisualVM to connect? Do I need to run it outside of Eclipse?

Markus A.
  • 12,349
  • 8
  • 52
  • 116

4 Answers4

5

Due to a design peculiarity in the Windows JVM's you need to run JVisualVM in the same kind of JVM as the program you want to connect to (and as the same user)

This mean, use either 32-bit or 64-bit, not one of each.

A simple way to ensure this, is to add the JVM in the JDK installation directory containing the jvisualvm executable you want to use to the JVM's known to Eclipse (in Preferences), and then change the JVM used by your project to the one in the JDK you just added. Now your application should show up in the VisualVM window when launched.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • How can I check what "kind" of JVM I'm running in? I have "jre7" selected as the execution environment for my program and am launching jvisualvm.exe from the jdk1.7.0_11 directory... – Markus A. Oct 06 '14 at 17:54
  • Add the jdk1.7.0._11 directory to the JVM's Eclipse knows (in preferences) and launch your program with that instead. – Thorbjørn Ravn Andersen Oct 06 '14 at 18:53
  • Got it! I needed to add the jdk, choose it as the default, and restart Eclipse. THEN it worked. If you'd like to expand your answer a bit, I'd like to accept it. :) – Markus A. Oct 06 '14 at 19:53
  • Also see this answer from one of the visualvm developers: http://stackoverflow.com/a/14622229/53897 – Thorbjørn Ravn Andersen Oct 06 '14 at 20:12
3

Have you tried using the VisualVM eclipse launcher ? This will automatically launch visual VM for you.

The only change is when you run your main class in eclipse, is to change the configuration to use the VisualVM launcher like this.

enter image description here

dkatzel
  • 31,188
  • 3
  • 63
  • 67
  • That works, yes... I'm just surprised that it doesn't work without the plugin. And it's a bit annoying that I have to chose a different launcher in the run-configuration... – Markus A. Oct 06 '14 at 18:32
  • yes it is annoying. And I think eclipse remembers your configuration for that main class. So if you want to later rerun that main method *without* visualVM, you have to go back and change the configuration again back to JDT. – dkatzel Oct 06 '14 at 18:34
  • 1
    Thorbjørn figured out what it takes to make things work without the plugin. Now I can just work in Eclipse as I always do and if I need to profile something, I can run jVisualVM completely independently from Eclipse and all applications running inside Eclipse show up and I can profile them as needed... I'll accept his answer since it's the more "elegant" solution as far as I'm concerned. But it's good to have yours here also for completeness. Some people might actually prefer to use a plugin, too... Definitely a big thank you and +1 for you also! – Markus A. Oct 07 '14 at 03:33
0

Another possible solution, in case it helps others: Restart Eclipse.

This was the first time I'd tried JVisualVM on a new computer. Eclipse was showing up in JVisualVM, just not any child processes it launched.

I was tearing my hair out, trying all sorts of other things (firewall, different JDKs...) Then this silly restart just fixed it!


Anyway if all is working well, the rules seem to be:

  • JVisualVM can attach to and monitor applications using any JDK / JRE version and the same "bit-ness".
  • For full functionality (like profiling) JVisualVM should be running on an equal or higher version of the JDK than the application

Random tip (while we're discussing bitness):

  • Browsing memory dumps is inexplicably a zillion times fastor in 64-bit. (Shame, as I still like the 32-bit's -client mode for GUI apps to get the lowest memory usage. So I'd like to also profile them that way, but unfortunately it's intolerably slow.)
Luke Usherwood
  • 3,082
  • 1
  • 28
  • 35
0

Just found another, quite obscure thing that can prevent your application from showing up in JVisualVM under Windows:

JVisualVM uses your system's temp-folder (as specified by the environment variable TMP) to communicate with running applications. For security reasons, if this folder is not located on an NTFS partition where Windows can provide strict file access controls, debugging is disabled and applications won't show up in JVisualVM.

If reformatting that partition or moving your entire temp-folder is not something you want or can do, you can simply create a secondary temp-folder just for JVisualVM on an NTFS partition somewhere else and set your launch configurations in Eclipse to set the environment variable TMP to that folder. Then, simply use the following batch file to run JVisualVM and everything should work:

@Echo off
set TMP=F:\temp
start "JVisualVM" /b "C:\Program Files\Java\jdk1.7.0_76\bin\jvisualvm"

Here, you need to replace F:\temp with the location of your new temp-folder just like specified in the launch configurations and C:\Program Files\Java\jdk1.7.0_76 with your JDK install directory.

Markus A.
  • 12,349
  • 8
  • 52
  • 116