VisualVM: Free and Open Source Java Troubleshooter
The 3rd milestone of VisualVM was released a few days ago. That release marks the open sourcing of this troubleshooting tool, together with the further polishing of its API. Perhaps this is therefore an opportune moment to spend some time exploring its main features. The key to understanding VisualVM is to see it as a bundling of a number of JDK tools, such as JConsole, jstack, and jinfo, combined with several new and advanced profiling capabilities. The tool is designed for both production and development use and further enhances the capabilities of monitoring and performance analysis for the Java SE platform.
All Java applications running on the same system as the VisualVM are listed in the "Applications" tab on the left side of the tool. Java applications on remote systems are also shown, under the "Remote" node. Information specific to each of the applications, which includes VisualVM itself, is displayed in the main part of the tool. For each application, there is an "Overview" tab showing general information, such as process ID and the Java version used to run the application.
The "Monitor" tab shows graphs for the application's heap, permanent generation, threads, and classes. The total heap space is shown in one color and the amount of heap space in use is shown in another. Below, you see the "Threads" tab, shwoing thread visualization for VisualVM itself:
VisualVM can read and interpret binary heap dump files. You can either generate a heap dump from within the VisualVM or you can open one, via the "Profile" menu at the top of the tool. The heapwalker part of the tool can then provide information about the dump, as shown in the next two screenshots:
The heapwalker can help you track down memory leaks. The instances view, shown above, shows all object instances of a class, from where you can find the nearest garbage collection root points.
VisualVM is pluggable. It comes with a Plugin Manager which already contains three plugins:
The VisualVM-MBeans plugin gives you an MBean Browser. It does the same as JConsole's MBeans tab: "The MBeans tab allows you to access the full set of the platform MXBean instrumentation. In addition, you can monitor and manage your application's MBeans using the MBeans tab." It lets you get and set MBean attributes and invoke MBean operations as well as subscribing for MBean notifications. Here's how it looks, once you've installed the plugin:
The Visual GC plugin gives you a graphic overview of information relevant to garbage collection:
Finally, your investment in JConsole plugins is protected, because they can be loaded into the VisualVM, in the same way as how they were loaded into the JConsole. First, you'd need to install "VisualVM-JConsole" plugin that is shown in the 4th pic above. Then, VisualVM is receptive to any JConsole plugin. For example, let's take the JTop plugin. JTop is a JDK demo that shows the thread CPU usage of all threads running in the application. This demo is helpful in identifying the threads that have high CPU consumption. This is how it is installed in the JConsole:
<JDK6>/bin/jconsole -pluginpath <JDK6>/demo/management/JTop/JTop.jar
And, to install that same plugin into VisualVM, you simply open the etc/visualvm.conf file and then add the following to the "default_options" setting:
-J-Djconsole.plugin.path=<JDK6>/demo/management/JTop/JTop.jar
For JTop, you'd then end up with the following, in a new tab, that is, the JConsole tab, provided by the aforementioned VisualVM-JConsole plugin:

With the release of the 3rd milestone, you can try out the APIs and create your own plugins. When you go to the download page for VisualVM, you'll see a link for the VisualVM binary as well as a Milestone 3 API Docs link. That gives you access to the Javadoc, as well as an overview of the entrypoints to VisualVM. However, note that the API is still in progress and cannot be considered stable yet.
You are welcome to join the mailing list and provide your feedback there.
- Login or register to post comments
- 8100 reads
- Flag as offensive
- Email this Story
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)







Comments
Mike P replied on Thu, 2008/02/21 - 1:09pm
Very cool. This will definitely come in handy. I just downloaded it and it just starts up, without no need for an installer. Just unzip and run.
I couldn't immediately find a way to see a stack trace of the waiting threads, but I haven't looked very hard yet.
I'm especially looking forward to using it for hunting memory leaks. I take it, you run the app, do a heap dump, run it some more, heap dump again, and visualvm shows the differences between the two heap dumps?
Luis-Miguel Alv... replied on Thu, 2008/02/21 - 6:10pm
Hi Mike,
You can get thread dumps either by selecting an application node in the tree and right-clicking on the Thread dump action or by clicking on the Thread dump button in the Threads view.
The tool provides a lightweight memory profiler that you can use to take memory snapshots at different intervals and compare them later on.
Regards,
Luis-Miguel Alventosa - VisualVM dev team - http://blogs.sun.com/lmalventosa
ivan_memruk replied on Tue, 2008/02/26 - 12:24pm
this post was so much more useful than the tons of "10 tips how to become a senior engineer overnight" post bullshit that dzone is full of :)
Mark Ashworth replied on Thu, 2008/02/28 - 4:59am
Hi,
I was looking at the source code to see how other developer design NB 6.0 applications and I noticed that Visual VM does not make use of the Nodes API, is there a specific reason for this?
Regards,
Mark P Ashworth
Geertjan Wielenga replied on Tue, 2008/03/04 - 7:37am
atticcat replied on Mon, 2008/06/16 - 11:11am
Hi, mark.
Have you tried visual vm on windows to monitor tomcat6 which run on service mode?
When I running tomcat on service mode, I got a 'not supported for this JVM' message in the JVM arguments tab.
But when tomccat running on console mode, it has no probelm.
My JDK is 1.6
Regards.
Dennis