In the last couple of weeks, I had to do lots of profiling of our server code. Normally I use YourKit, easy to setup, and it has all the tools I need to do profiling such as CPU and Heap display graphs, force GC option, display of objects with their instance counts and sizes and so on. This time though I had to do profiling when server was under load and YourKit did not behave as I expected. I could see the memory usage in the main graph but when I took a snapshot of the heap, the snapshot took a while, and it didn’t match with the graph I was observing. I’m guessing that since the server is under load, by the time YourKit could take the snapshot, the data was not relevant anymore. This didn’t help me of course, so I turned to other tools.
Luckily, a coworker recommend Sun’s free VisualVM. I think it comes with JDK on Windows, but not on Mac OS, so I had to download it. I was pleasantly surprised with the VisualVM. First, I didn’t have to do anything special to use it, no JVM options or anything like that to make it detect my running Tomcat, it was just displayed under applications:
The main view included CPU, memory, classes and threads graph as you would expect from a profiler.
The Heap and Thread dump is as easy as right clicking on the application and it was fast and seemed accurate.
And finally, the Heap Dump showed me the classes taking up the memory, just what I needed…
One thing that was missing in VisualVM was the “GC roots” option in YourKit. I also did not see much Thread blocking information displayed but I didn’t spend too much time with VisualVM, maybe it’s there. Overall, I’m glad that there’s another free tool out there for Java profiling.






Jiri Sedlacek
November 30, 2009 at 11:55 am
You can display instances of a class by right-clicking it and selecting ‘Show in Instances View’. In Instances view in the References section there’s a ‘Show Nearest GC Root’ action in each item’s context menu. That’s what you’re looking for.
Detailed thread analysis can be done using the TDA plugin, use Tools | Plugins to download and install it. It’s also available as a separate tool at https://tda.dev.java.net.
Tomas Hurka
November 30, 2009 at 3:14 pm
Java VisualVM is part of Java on Mac OS X. To run it, just open terminal and type ‘jvisualvm’.
Sergey
February 5, 2010 at 5:01 am
> snapshot took a while, and it didn’t match with the graph I was observing
To understand why this happen, please read article which describes JVM memory structure http://www.yourkit.com/docs/kb/sizes.jsp
–serge
Ben Poole
April 7, 2010 at 4:01 am
As Tomas says, it does appear to be included with Java 6 on the Mac, and you can run it from the command line. You can also simply navigate to /Developer/Applications/Utilities — the app’s right there for double-clicking…