VisualVM – a neat little tool for Java profiling

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:

VisualVM Applications View

The main view included CPU, memory, classes and threads graph as you would expect from a profiler.

VisualVM Main View

The Heap and Thread dump is as easy as right clicking on the application and it was fast and seemed accurate.

VisualVM Thread and Heap Dump

And finally, the Heap Dump showed me the classes taking up the memory, just what I needed…

VisualVM Classes View

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.

4 thoughts on “VisualVM – a neat little tool for Java profiling

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

  2. 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…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s