VisualVM

GraalVM comes with the VisualVM tool which includes heap analysis features for the supported guest languages. These languages and features are currently available:

Starting VisualVM

To start VisualVM, execute jvisualvm. Immediately after startup, the tool shows all locally running Java processes in the Applications area, including the VisualVM process, itself.

Capture a Heap Dump

To capture a heap dump of, for example, a Ruby application for later analysis, start your application and let it run for a few seconds to warm up. Then right-click its process in VisualVM and invoke the Heap Dump action. A new heap viewer for the Ruby process opens.

Note: GraalVM Enterprise Native Image does not implement the JVMTI agent, so triggering heap dump creation from the Applications area is impossible. Apply the -H:+AllowVMInspection flag with the native-image tool for Native Image processes. This way your application will handle signals and capture a heap dump when it receives the SIGUSR1 signal. The guest language REPL process must be started also with the --jvm flag to monitor it using VisualVM. This functionality is available with GraalVM Enterprise Edition. It is not available in GraalVM Community Edition. See the Generating Native Heap Dumps page for details on capturing heap dumps from a native image process.

Analyzing Objects

Initially the Summary view for the Java heap is displayed. To analyze the Ruby heap, click the leftmost (Summary) dropdown in the Heap Viewer toolbar, choose the Ruby Heap scope and select the Objects view. Now the heap viewer displays all Ruby heap objects, aggregated by their type.

Expand the Proc node in the Results view to see a list of objects of this type. Each object displays its logical value as provided by the underlying implementation. Expand the objects to access their variables and references, where available.

Now enable the Preview, Variables, and References details by clicking the buttons in the toolbar, and select the individual ProcType objects. Where available, the Preview view shows the corresponding source fragment, the Variables view shows variables of the object, and the References view shows objects referring to the selected object.

Last, use the Presets dropdown in the Heap Viewer toolbar to switch the view from All Objects to Dominators or GC Roots. To display the heap dominators, retained sizes must be computed first, which can take a few minutes for the server.rb example. Select the Objects aggregation in the toolbar to view the individual dominators or GC roots.

Analyzing Threads

Click the leftmost dropdown in the Heap Viewer toolbar and select the Threads view for the Ruby heap. The heap viewer now displays the Ruby thread stack trace, including local objects. The stack trace can alternatively be displayed textually by clicking the HTML toolbar button.

Reading JFR Snapshots

The VisualVM tool bundled with GraalVM 19.2.x and later has the ability to read JFR snapshots – snapshots taken with JDK Flight Recorder (previously Java Flight Recorder). JFR is a tool for collecting diagnostic and profiling data about a running Java application. It is integrated into the Java Virtual Machine (JVM) and causes almost no performance overhead, so it can be used even in heavily loaded production environments.

To install the JFR support, released as a plugin:

  1. Run <GRAALVM_HOME>/bin/jvisualvm to start VisualVM;
  2. Navigate to Tools > Plugins > Available Plugins to list all available plugins, then install the VisualVM-JFR and VisualVM-JFR-Generic modules.

The JFR snapshots can be opened using either the File > Load action, or by double-clicking the JFR Snapshots node and adding the snapshot into the JFR repository, permanently. Please follow the documentation for your Java version to create JFR snapshots.

The JFR viewer reads all JFR snapshots created from Java 7 onward, and presents the data in typical VisualVM views familiar to the tool users.

These views and functionality tabs are currently available:

Note: the support of JDK Flight Recorder is currently experimental. Some advanced features like analyzing JVM internals, showing event stack traces, or support for creating JFR snapshots from live processes are not available in this preview version and will be addressed incrementally in the following releases.