memory profiling with jvisualvm

I’ve been meaning to blog about jmap/jvisualvm for a while, but this JavaRanch question finally prompted me to do so.

My goal was to see where the memory was going in our JForum installation at JavaRanch. This was a one time thing, so I decided to see if I could do so without JProbe.   A colleague had already used Eclipse’s Memory Analyzer.  (Awesome tool by the way – it clues you right in to what it suspects are leaks.)  I decided to use jvisualvm.  Which was interesting.  While I was off exploring, someone else solved the problem and I put writing this up on the side.

I tried this locally on my machine to make sure I knew what to do before trying it on the production UNIX/Linux box.

How to run jvisualvm

  1. Get your process id:
    • Windows: JPS can be used to find your process id on windows.  At the DOS prompt, type “jps”.  My Tomcat process is called “bootstrap”  [I figured this out by stopping the process, running jps and then restarting the process running jps again.  I also had an unnamed process (Eclipse maybe?) and for jps itself.]  The JavaDoc says jps may not be supported in the future, but it works right now on Windows XP.
    • UNIX: You can simply use ps -ef | grep <whatever makes your process name identifiable>.  In my case, it was “ps -ef | grep coderanch”
  2. Run “jmap -dump:file=heap.bin.hprof 1234” [if your process was 1234].  Note this requires Java 6.
  3. Run “jvisualvm”
  4. file –> load –> choose hprof file from jmap
  5. Filter by classname – I used the package name net.jforum to narrow things down.  Which turned out to be a mistake as the memory leak was in Lucene.

or – Run” jhat -J-mx512m heap.bin.hprof”.  Thanks to this blog for helping with the jmap/jhat command.

[edited to fix typos]

7 thoughts on “memory profiling with jvisualvm

  1. Hi there ,

    Nice article! I hoped it could help me any further. When I run JMAP locally then Windows gives me a “permission denied” . Bg WTF of course . Where can I get these rights I am running a DOS cmd box for christ sake

  2. Seems that run an CMD box “as administrator” does the trick. Now I follow your instructions

  3. “JMAP runs forever” – How long did you wait? It ran about 5 minutes for me on a server and about 15 minutes on my machine. (I suspect I could use some more memory.) I recommend seeing what resources are maxed out when JMAP is running to see if is is RAM, disk space, processing, etc.

    You are likely to have a problem later though. Loading the hprof file did take “forever” (somewhere over 30 minutes) for me due to the memory limitation. I don’t know how long it actually took because after 30 minutes, I left it and went out. It was done when I got back – 4 hours later. Telling me it took somewhere between 30 minutes and 4 hours.

  4. Pingback: Eclipse Memory Analyzer | Down Home Country Coding With Scott Selikoff and Jeanne Boyarsky

  5. i want to see in jvisualvm how much memory my Fun will take while execution like i can see for our Class

Leave a Reply

Your email address will not be published. Required fields are marked *