This guide assumes Visual VM, version 2.1.5 or later; does not explain usage on OSs other than Linux, macOS and Windows; and is incomplete
Visual VM can be used to profile and otherwise debug running JVM process(es).
See: https://visualvm.github.io/gettingstarted.html?VisualVM_2.1.5 for an in-depth guide to using Visual VM.
VisualVM requires that a JDK be installed in order access a running JVM process.
JDK distributions/installers for your OS can be downloaded from Adoptium.
A reliable way to check whether a JDK is already installed would be to check for the existence of the
javac
executable in the PATH
environment variable's list of search directories:
Windows
cmd.exe
:
C:\> where javac
[example output from where]
Powershell
:
PS C:\> Get-Command javac
[ditto]
Linux / macOS
$ bash -c 'type -P javac'
/usr/bin/javac
-
Download ZIP package from https://visualvm.github.io/download.html
-
Extract downloaded
visualvm_$VERSION.zip file
-
For version 2.1.5, change to extracted
visualvm_215/bin
directory -
Launching
Windows: execute / double-click
visualvm.exe
Linux / macOS: execute / double-click
visualvm
Note: To be sure that Visual VM will see the Java application that you want to interact with, start that application first and wait for it to finish loading, and then finally launch Visual VM.
Note: If you are familiar with Java applications and their entry points, you can probably skip this section.
Visual VM will refer to running JVM processes by their fully-qualified entry point name that might look something
like com.example.Module.ClassName
Some common applications include:
cpw.mods.bootstaplauncher.BootstrapLauncher
(Minecraft)install4j.net.creeperhost.creeperlauncher.CreeperLauncher
(the FTB App)org.multimc.EntryPoint
(MultiMC)
Flesh this out more?
Once launched, Visual VM can attach to JVM processes running locally where the executing user has
sufficient priveleges. JVMs that can be attached to will appear in the Applications
sidebar
shown below.
- Double click the application's entry point name (
install4j.net.creeperhost.creeperlauncher.CreeperLauncher
in the example screenshot below) underLocal
in theApplications
sidebar.
-
In the main application view, click on the
Monitor
tab towards the top of the right-side view. -
Under
Monitor
heading, click on theHeap Dump
button
- To view objects whose sizes dominate in the heap, the
Compute Retained Sizes
button must be clicked first.
- Heap dumps can be saved for later examination by right-clicking the timestamped dump and clicking
Save As...
-
Double click the application's entry point name (
install4j.net.creeperhost.creeperlauncher.CreeperLauncher
in the example screenshot below) underLocal
in theApplications
sidebar. -
In the main application view, click on the
Threads
tab towards the top of the right-side view. -
Under
Threads
heading, click on theThread Dump
button highlighted below.
- As with heap dumps, thread dumps can also be saved to ease sharing by right clicking the timestamped threaddump
TBC
-
Gereralise where possible, e.g. instead of talking about the FTB App, use language and/or instructions that can apply to any of the Java applications referenced in the
ENTRY POINT PRIMER
section. (Done) -
Flesh out the list of application entry points to include older Minecraft versions and perhaps additional launchers.
-
Finish section on profiling Minecraft including CPU/memory-based sampling.
-
Clean up the Markdown source (e.g. proper headings) for this guide and make it easier on the user by adding self-referencing links in place of blockquote references, etc.
-
Get and crop screenshots for the
PREREQUISITES
section. -
Non-sampling based profiling of Minecraft (minimally) need further testing. With Amazon Coretto
build 17.0.3+6-LTS
at least, both Minecraft and Visual VM become unstable with the former unresponsive to keyboard/mouse input responding only toSIGKILL
.
It might be better to start VisualVM after Java process is being started. At least in one case new process was not found automatically.
SCENARIO: CREATING HEAP DUMP OF RUNNING FTB APP
andSCENARIO: CREATING THREAD DUMP OF RUNNING FTB APP
could more more generic:first list well-known java apps
After those changes it would be easier to request e.g. thread dump for game or for FTB App's java parts.