JDK Mission Control (JMC) is now available as a module in Fedora 29. JDK Mission Control is a powerful profiling application for HotSpot JVMs. It has an advanced set of tools that enables efficient and detailed analysis of the extensive data collected by JDK Flight Recorder (JFR). JMC requires JDK 8 or later.
JFR is part of the JVM, and is available in OpenJDK 11 or Oracle JDK 7u4 or later. Therefore, to generate a flight recording to be loaded into JMC for analysis, the target application needs to run on OpenJDK 11 or OracleJDK 7u4 or later.
This article is a guide to install and run JMC on Fedora 29 Workstation. Then you’ll learn how to use it to solve a common problem with Java programs called hot methods.
Installing JMC on Fedora 29
Using Java 11 will allow JMC to record JFR data for itself. Install Java 11 via:
$ sudo dnf install java-11-openjdk
Enable and install the JMC module with the default profile via:
$ sudo dnf module install jmc:latest/default
Run JMC targeting the Java 11 JRE via:
$ jmc -vm /usr/lib/jvm/jre-11/bin
Using JMC and JFR to explore hot methods
JDK Mission Control can be used to deeply analyze Java applications. In this example, we will take a look at hot methods. Hot methods are methods where a high proportion of time is spent during execution. These are good places to start investigating when trying to reduce overall execution time.
To demonstrate, here is a portion of code for a Java application.
In practice, there are multiple methods of analyzing Java applications in JDK Mission Control. As an example, you can run the application with Flight Recording enabled and set to dump on JVM exit. This generates a Flight Recording (.jfr) file when the application exits, which can be opened by JDK Mission Control. Note that Flight Recorder is available in OpenJDK 11+ and OracleJDK 7u4+.
For example, for OpenJDK 11+ use this command to run the class with Flight Recorder:
$ java -XX:+FlightRecorder -XX:StartFlightRecording=dumponexit=true,filename=initiator.jfr Initiator
After the application has completed execution, open the resulting Flight Recording with JMC. Below is the automated analysis results.
The automated Method Profiling analysis already indicates a potential optimization area in the calls to Integer.equals(Object). Going to the Method Profiling tab, select that method and check the Stack Trace for it as shown below.
In this Stack Trace, you can follow the calls to the method Initiator.countIntersection(Initiator). Checking the Initiator class, shown below, note that counting intersections between two Integer collections would be better done using HashSet collections instead of LinkedLists collections.
After making this change, you can see the execution improve in the follow-up Flight Recording.
JDK Mission Control and JDK Flight Recorder gives you a highly detailed view of your Java application behavior. You can use it to diagnose issues with hot methods, deadlocks, lock contention, memory leaks and more. Try it out via the JMC module in Fedora 29!
Yazan Al Monshed
Nice Blog
dcrxnmr
Very interesting, thank you :-).
There is a little problem with the article: the pictures are too small, I have to zoom in to see what’s happening :-(.
jkang
You’re right re. the pictures, sorry about that. I’ll see if I can make them better. Thanks!
jkang
You should be able to click on the pictures to see a larger image now. Thanks for your feedback!
jakfrost
For those who may be interested in trying this on Silverblue, you can from the fedora-toolbox pet container. When you enter the fedora-toolbox container with the apply named command ‘fedora-toolbox enter’, you can start the JMC as directed in the article. Open another terminal and issue the command ‘podman ps’ to get a listing of running containers, you will see the fedora-toolbox container running. Use the command ‘podman attach ‘ substituting the container ID you observed from the ps command, and you are now in the same container at a shell. From there run the java app you created with the options as noted above in the article to get the flight recording of your app.
Dan
Why did it took so long for it to be available in Fedora repos.? Don’t want to be rude, just curious what is the reason. What is simply because there was not enough man power (i.e. someone to package it) or because of some licensing problems?
jkang
For what it’s worth, the module was available in Fedora Jan. 3, 2019, this article I drafted is certainly delayed in comparison. I’m not inclined to write any details on packaging this in a comment box, but manpower is an interesting point to bring up. Now I’m genuinely curious who you think should be responsible for making this free and open source project available in Fedora.
jkang
I guess I can do a few bullet points to assuage curiosity
* there are a lot of dependencies, some of which weren’t packaged in Fedora
* it needs to follow Fedora packaging guidelines (offline build, licenses, no embedded libraries)
* I personally would of preferred a stable release version (also applies to dependencies)
Mario Torre
Dan, as of this writing, JDK Mission Control 7.0 has not been officially released yet, so we wanted to wait for the official release or at least for a reasonably stable version before shipping, this is why we haven’t done the package before January, then it takes the time it takes for the actual packaging, especially regarding the dependencies.