memory profiling with jvisualvm

Main menu:


Recent Posts


RSS Feed RSS - Posts

August 2009
« Jul   Sep »

Past Posts

Java/Java EE



memory profiling with jvisualvm

August 24th, 2009 by Jeanne Boyarsky

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]


Comment from aschwin
Posted: October 15, 2009 at 4:55 am

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

Comment from aschwin
Posted: October 15, 2009 at 5:38 am

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

Comment from aschwin
Posted: October 15, 2009 at 7:20 am

here is again-Sam agian, however JMAP runs forever. What’s wrong?

Comment from Jeanne Boyarsky
Posted: October 18, 2009 at 3:20 pm

“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.

Comment from Jeanne Boyarsky
Posted: September 8, 2012 at 11:48 pm

It opened very quickly on my newer/better computer. So the 30 minutes was frequent paging in 2009 because I was pushing my computer too heard.

Pingback from Eclipse Memory Analyzer | Down Home Country Coding With Scott Selikoff and Jeanne Boyarsky
Posted: September 16, 2012 at 3:19 pm

[…] Jeanne Boyarsky Last time CodeRanch has a memory leak, a teammate ran Eclipse Memory Analyzer and I ran JVisual VM.  This time, I did both.  I took the heap dump as described here.  JVisual VM told me hibernate […]

Write a comment