Over a million developers have joined DZone.
Platinum Partner

VisualVM: Free and Open Source Java Troubleshooter

Trying to troubleshoot Java? VisualVM is a great, free, open source tool.

· Java Zone

The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.

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:


 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.

The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}