41

I want to get a heap dump (suspected memory leak) of a certain Java process. However, when I start the jvisualvm tool, I cannot see any of the running Java processes.

I have Google'd around about this and have already found a couple of articles saying that you have to run the Java processes using the same JDK that you start the jvisualvm tool with in order for it to be able to see them. However, as far as I can see, this is already the case. I'm doing everything locally (I have remote access to the machine).

A couple of things to consider:

  1. The processes are running on a firewalled Windows 2008 server
  2. The processes are running using renamed versions of the JDK java.exe executable
  3. As far as I can see the processes are running using the 1.6.0_18 JDK
  4. One of the running processes starts an RMI registry

I'm waiting on a virtualized copy of the server so I can mess around with it (this is a production server). But in the meanwhile; any ideas as to why I cannot see any of the processes in jvisualvm (or jconsole for that matter)?

tmbrggmn
  • 8,680
  • 10
  • 35
  • 44
  • Why would you rename java.exe? I'm pretty sure VisualVM gets it's process list by looking for all processes running java.exe – Gandalf Feb 17 '11 at 16:19
  • You can't see the comandline arguements easily in windows so you end up renaming/copying the java.exe so you know which process is what. – Peter Lawrey Feb 17 '11 at 16:27
  • 7
    jconsole and visualvm are user specific. If the processes are running as another user, you won't be able to see them, but you can open security to allow them to be managed "remotely" – Peter Lawrey Feb 17 '11 at 16:28
  • Thanks for the tip, that might well be it. The processes are launched by means of a Windows service, so they're probably running under some Windows service account. Can you provide any links to articles about this? Also, feel free to provide that as an answer, Ill approve it in case it's right. – tmbrggmn Feb 17 '11 at 16:40
  • 7
    @Peter if you want to see whats running on a windows machine, with full command line args, tcp/ip sockets etc. then you should use sysinternals process explorer http://technet.microsoft.com/en-us/sysinternals/bb896653 its like task manager on steroids. As a developer once you try it you'll always want it on any windows machine that you use. There are a number of other very useful tools in the sysinternals suite too, I also like junction, which brings real unix like symlinks to windows. – crowne Feb 17 '11 at 16:51

2 Answers2

67

Well after I did a little research, it would appear that Peter's comment was correct. Because the JVM processes were launched by another user (the NETWORK SERVICE account because they were being started by a Windows service) they didn't show up in jvisualvm.

Workaround

Since I have access to the application configuration, I have found the following workaround, which involves explicitly enabling unsecured JMX for the target JVM:

  1. Add the following JVM parameters:

    -Dcom.sun.management.jmxremote.port=3333 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false

  2. Add the remote process to jvisualvm using JMX by click File -> Add JMX Connection. You can connect to the process using port 3333. Obviously you can change the port if you want.

Link to article explaining this in a little more detail: http://download.oracle.com/javase/6/docs/technotes/guides/visualvm/jmx_connections.html

Notes

  1. It's probably not a good idea to keep the JVM settings permanently, as they would allow anyone to connect to the JVM via JMX.
  2. You can also add authentication to the JMX JVM parameters if you want to.
Community
  • 1
  • 1
tmbrggmn
  • 8,680
  • 10
  • 35
  • 44
8

The simplest way is to execute jvisualvm as administrator (win: "run as administrator"). Which is not ideal but works. All java processes are visible then.

Wooff
  • 1,091
  • 12
  • 23