Fetching and Building OpenJDK Mission Control

(Please note that an updated version of this article, for JMC 8+, is available here: https://hirt.se/blog/?p=1196.)

Since people keep asking me, I thought I’d put together this quick primer on how to get started with OpenJDK Mission Control. Now, once the early access builds of JMC 7 is out, that will probably be the easiest way to get started for people who don’t want to change stuff. This blog, however, will be for the ones of you who would like to build JMC from source.

Getting Mercurial

First step is to get Mercurial, the SCM used for OpenJDK. JMC (being an OpenJDK project) is available through a Mercurial repository. Installing Mercurial is different for different platforms:

Mac OS X

Easiest is to install through Homebrew:

brew install mercurial

That said, dmg packages can also be downloaded from here: https://www.mercurial-scm.org/wiki/Download.

Windows

Go to https://www.mercurial-scm.org/wiki/Download. Download the InnoSetup based installer and run it. Ensure that the “add to path” checkbox is checked. Verify that the install went fine by opening a command prompt and typing hg and enter. A list of the available commands should be printed.

Linux

For Debian based distributions, you can install using the package manager:

sudo apt-get install mercurial

That said, you can also get rpms and other installation packages from here: https://www.mercurial-scm.org/wiki/Download.

Cloning the Source

Once Mercurial is installed properly, getting the source is as easy as cloning the jmc repo. First change into the directory where you want to check out jmc. Then run:

hg clone http://hg.openjdk.java.net/jmc/jmc/

Getting Maven

Since you probably have some Java experience, you probably already have Maven installed on your system. If you do not, you now need to install it. Simply follow the instructions here:

https://maven.apache.org/install.html

Building Mission Control

First we need to ensure that Java 8 is on our path. Some of the build components still use JDK 8, so this is important.

java –version

This will show the Java version in use. If this is not a Java 8 JDK, change your path. Once done, we are now ready to build Mission Control. Open up two terminals. Yep, two!

In the first one, go to where your cloned JMC resides and type in and execute the following commands (for Windows, replace the dash (/) with a backslash (\)):

cd releng/third-party
mvn p2:site
mvn jetty:run

Now, leave that terminal open with the jetty running. Do not touch.

In the second terminal, go to your cloned jmc directory. First we will need to build and install the core libraries:

cd core
mvn install

Next run maven in the jmc root:

mvn clean package

JMC should now be building. The first time you build Maven will download all of the third party dependencies. This will take some time. Subsequent builds will be less painful. On my system, the first build took 6:01 min. The subsequent clean package build took 2:38.

Running Mission Control

To start your recently built Mission Control, run:

Windows

target\products\org.openjdk.jmc\win32\win32\x86_64\jmc.exe -vm %JAVA_HOME%\bin

Mac OS X

target/products/org.openjdk.jmc/macosx/cocoa/x86_64/JDK\ Mission\ Control.app/Contents/MacOS/jmc -vm $JAVA_HOME/bin

Contributing to JDK Mission Control

To contribute to JDK Mission Control, you need to have signed an Oracle Contributor Agreement. More information can be found here:

http://openjdk.java.net/contribute/

Don’t forget to join the dev list:

http://mail.openjdk.java.net/mailman/listinfo/jmc-dev

If there is interest, I will add a more detailed blog post on this later.

More Info

For more information on how to run tests, use APIs etc, there is a README.md file in the root of the mercurial repo. Let me know in the comments section if there is something you think I should add to this blog post and/or the README!

40 Responses to "Fetching and Building OpenJDK Mission Control"

  1. And here we go with JDK 11…

    org.openjdk.jmc.flightrecorder.internal.InvalidJfrFileException
    at org.openjdk.jmc.flightrecorder.internal.FlightRecordingLoader.createChunkInput(FlightRecordingLoader.java:155)
    at org.openjdk.jmc.flightrecorder.internal.FlightRecordingLoader.access$0(FlightRecordingLoader.java:146)
    at org.openjdk.jmc.flightrecorder.internal.FlightRecordingLoader$1.getNextChunk(FlightRecordingLoader.java:108)
    at org.openjdk.jmc.flightrecorder.internal.FlightRecordingLoader.createChunkLoader(FlightRecordingLoader.java:293)
    at org.openjdk.jmc.flightrecorder.internal.FlightRecordingLoader.readChunks(FlightRecordingLoader.java:216)
    at org.openjdk.jmc.flightrecorder.internal.FlightRecordingLoader.loadStream(FlightRecordingLoader.java:95)
    at org.openjdk.jmc.flightrecorder.internal.FlightRecordingLoader.loadStream(FlightRecordingLoader.java:76)
    at org.openjdk.jmc.flightrecorder.ui.RecordingLoader.doCreateRecording(RecordingLoader.java:173)
    at org.openjdk.jmc.flightrecorder.ui.RecordingLoader.run(RecordingLoader.java:96)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:60)

  2. […] last blog (about Fetching and Building OpenJDK Mission Control) earned me questions on how to get the source into Eclipse to start playing around with it. This […]

  3. Suresh says:

    Nice for the write-up. One small suggestion I have is to use Maven wrapper https://github.com/takari/maven-wrapper, so that we can remove the getting maven step.

  4. Marcus says:

    Thanks! Well, JMC is open source, so anyone with an Oracle Contributor Agreement can go ahead and propose a change to add the wrapper. Since it is Apache licensed, I am sure it will be an acceptable third-party dependency.

    Join the dev-list here:
    http://mail.openjdk.java.net/mailman/listinfo/jmc-dev

    Looking forward to seeing you there! 😉

  5. Gary Morrison says:

    This is really excellent! Thanks.

    However, does the JMC build work under JDK11? “mvn p2:site” keeps giving me:
    [INFO] ————————————————————————
    [INFO] BUILD FAILURE
    [INFO] ————————————————————————
    [INFO] Total time: 18.993 s
    [INFO] Finished at: 2018-10-04T17:54:08-05:00
    [INFO] ————————————————————————
    [ERROR] Failed to execute goal org.reficio:p2-maven-plugin:1.2.0-SNAPSHOT:site (default-cli) on project external-dependencies: Execution default-cli of goal org.reficio:p2-maven-plugin:1.2.0-SNAPSHOT:site failed: org.apache.maven.plugin.MojoExecutionException: Unable to execute mojo: P2 publisher return code was 13 -> [Help 1]

  6. Marcus says:

    Nope, not yet, but we’re working on it. As the readme states, the build currently requires a JDK 8.

  7. Ravikumar Sivaraj says:

    Hi Marcus,
    I’m new to jmc.exe at my work, I get an error saying that the config.ini is non writable. I worked out to it using the user.home variable to go to a directory and first look for config.ini that is writable there. Is there a way to override this as my work has given a non writable directory for this.
    My main goal is to analyse a process to see which methods it calls and how much time per method. I’ve already used the Flight recorder to record the process. But now want some system to unravel the output and give me this information.

  8. Marcus says:

    Hi Gary!

    I should have taken a closer look at the error message – that is an actually error. Seems org.reficio is no longer available. I have a patch open for review.

    Here is the Jira issue:
    https://bugs.openjdk.java.net/browse/JMC-6161

    That said, you do need JDK 8 to build the application. Core you can build with JDK 11 as well.

  9. Will Sargent says:

    Where would I download a pre-built binary of JMC now?

  10. Marcus says:

    Hi there!

    You can reach them through the project page (where you can also see the status for releases).

    Or directly at http://jdk.java.net/jmc/.

    Kind regards,
    Marcus

  11. Martin Skarsaune says:

    p2:site fails for me as well building on JDK8:

    [ERROR] Failed to execute goal org.reficio:p2-maven-plugin:1.2.0:site (default-cli) on project external-dependencies: Execution default-cli of goal org.reficio:p2-maven-plugin:1.2.0:site failed: A required class was missing while executing org.reficio:p2-maven-plugin:1.2.0:site: org/apache/felix/bundleplugin/BundlePlugi

    Maven setup:
    Martins-MacBook-Pro-2:third-party marska$ mvn -version
    Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T11:33:14-07:00)
    Maven home: /usr/local/Cellar/maven/3.5.4/libexec
    Java version: 1.8.0_152-ea, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/jre
    Default locale: nb_GB, platform encoding: UTF-8
    OS name: “mac os x”, version: “10.13.6”, arch: “x86_64”, family: “mac”

    Revision:
    Martins-MacBook-Pro-2:third-party marska$ hg log
    changeset: 60:bd0c0065130b
    tag: tip
    user: hirt
    date: Sun Oct 21 13:50:15 2018 -0700
    summary: JMC-6174: Document how to use ide update site

  12. Josef says:

    Hi Marcus,

    it seams the build process has changed. I had to first execute

    1) cd core && mvn clean install
    2) cd .. && mvn package

    As stated in the README.md

    “`bash

    cd core

    mvn clean install

    cd ..

    mvn package

    “`

    It would be great if you could update your blog post (section “In the second terminal, go to your cloned jmc directory and simply run maven:”).

    Kind regards,
    Josef

  13. Marcus says:

    Hi Josef,

    Indeed it has. The blog is now updated!

    Kind regards,
    Marcus

  14. Andrew Kew says:

    Hi Marcus
    Great project!
    I am trying to build it and getting missing dependency failure when running p2:site

    [info] Resolving artifact=[javax.mail:dsn:1.4] transitive=[true] source=[false]
    Downloading: http://*.*.*.*/nexus/content/groups/public/javax/mail/dsn/1.4/dsn-1.4.pom
    [WARNING] The POM for javax.mail:dsn:jar:1.4 is missing, no dependency information available
    Downloading: http://*.*.*.*/nexus/content/groups/public/javax/mail/dsn/1.4/dsn-1.4.jar
    [INFO] ————————————————————————
    [INFO] BUILD FAILURE
    [INFO] ————————————————————————
    [INFO] Total time: 18.426 s
    [INFO] Finished at: 2018-12-06T11:48:13+00:00
    [INFO] Final Memory: 20M/211M
    [INFO] ————————————————————————
    [ERROR] Failed to execute goal org.reficio:p2-maven-plugin:1.2.0:site (default-cli) on project external-dependencies: Execution default-cli of goal org.reficio:p2-maven-plugin:1.2.0:site failed: org.eclipse.aether.resolution.DependencyResolutionException: Could not find artifact javax.mail:dsn:jar:1.4 in nexus (http://*.*.*.*/nexus/content/groups/public) -> [Help 1]

    ~$ java -version
    java version “1.8.0_161”
    Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

    ~$ mvn –version
    Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)

  15. Marcus says:

    Looks like you have old code there. Try getting the latest version, and do mvn clean before doing mvn p2:site and mvn jetty:run.

  16. Ivan says:

    Hi Marcus,

    I’ve been using Oracle and BEA JMC for years, but I can’t find any plug-in for free version of JMC (7.1 version which is in early access build).

    With Oracle there are plug-ins for WebLogic, DTrace…

    Can you help to find plug-ins?

    Are there some plans for plug-ins for Tomcat, WildFly (JBoss) and other application servers?

    Thanks

  17. Marcus says:

    Hi Ivan,

    The plug-ins for WLDF and Coherence will be released at the same date as JMC 7.0.0 is released. Plug-ins for other application servers and frameworks depends on the various communities. First useful JFR events would need to be generated. It will probably be a little while, but I am sure it will eventually happen.

    Kind regards,
    Marcus

  18. @Andrew Kew I solved the “Failed to execute goal org.reficio:p2-maven-plugin:1.2.0:site (default-cli)” error by cloning from source ( `hg clone https://hg.openjdk.java.net/jmc/jmc7/` ) and in releng/third-party/pom.xml updating the version of p2-maven-plugin from 1.2.0 to 1.3.0.

    Hope this helps folks.

  19. Marcus says:

    Hi Jay,

    That error only occurs if you try to build the third-party libraries using JDK 11. As the instructions say, you need a JDK 8 to build for now. That said, in the jmc (not jmc7) repo (which is now 7.1.0 EA), we’ve already upgraded to 1.3.0.

  20. anonymous says:

    Is my understanding correct that this is not compatible with openjdk 8 at runtime since flight recorder has only be integrated into openjdk in 11 (https://openjdk.java.net/jeps/328) ?
    > …/target/products/org.openjdk.jmc/linux/gtk/x86_64$ ./jmc -vm $JAVA_HOME/bin
    > Unrecognized VM option ‘FlightRecorderOptions=stackdepth=128’
    > Error: Could not create the Java Virtual Machine.

    So it needs to be run with openjdk 11+ and will only connect to a openjdk 11+ JVM (or Oracle JVMs) ?

  21. Marcus says:

    That is correct. You currently need either an Oracle JDK (7u40 or later), or an OpenJDK 11+.

  22. Felix Yang says:

    A good news is that openjdk community is working on backporting JFR to JDK 8u. I have experimented with openjdk 8 + current patches, and it works well
    https://mail.openjdk.java.net/pipermail/jdk8u-dev/2019-January/008466.html

  23. Soner says:

    When I try to run the last step, app wants me to install Java SE 6 runtime with the message:

    “`To open “JDK Mission Control” you need to install the legacy Java SE 6 runtime.
    Click “More Info…” to visit the legacy Java SE 6 download website.“`

    Shall I install it?

  24. Marcus says:

    W00t! No, you don’t need a Java SE 6 runtime to run the built JDK Mission Control. You must use a JDK 8 and above – you can use an OpenJDK 11. Did you give the vm parameter properly, and did you make sure that your JAVA_HOME variable points to the JDK you wish to run with?

    Which platform was this?

  25. mike says:

    I get the same:

    `To open “JDK Mission Control” you need to install the legacy Java SE 6 runtime.
    Click “More Info…” to visit the legacy Java SE 6 download website.“`

    Your suggestion – ” Did you give the vm parameter properly, and did you make sure that your JAVA_HOME variable points to the JDK you wish to run with?” does not work

    This is on a Mac

    Darwin macbook-pro.local 18.5.0 Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64

    java -version

    openjdk version “1.8.0_212”
    OpenJDK Runtime Environment Corretto-8.212.04.1 (build 1.8.0_212-b04)
    OpenJDK 64-Bit Server VM Corretto-8.212.04.1 (build 25.212-b04, mixed mode)

    ${JAVA_HOME}/bin/ is a valid JRE

  26. Marcus says:

    I think most of us are running on Mac. I haven’t tried running on Coretto myself, but I can’t imagine why it would not work. The way I am starting the build on my Mac is (as stated in the README.md):
    target/products/org.openjdk.jmc/macosx/cocoa/x86_64/JDK\ Mission\ Control.app/Contents/MacOS/jmc -vm $JAVA_HOME/bin

    You can also set up the -vm section in the jmc.ini file directly.

  27. mike says:

    I tried the instructions exactly as stated above (and am using the same command that you are running). Perhaps when you try it on Corretto you can post a fix if you find one. I cannot make it work.

  28. Marcus says:

    First built entire JMC (first core, then started the p2 site, then built from the root) with Corretto. Here is some version info:
    COMP11057:jmc marcus.hirt$ java -version
    openjdk version “1.8.0_212”
    OpenJDK Runtime Environment Corretto-8.212.04.2 (build 1.8.0_212-b04)
    OpenJDK 64-Bit Server VM Corretto-8.212.04.2 (build 25.212-b04, mixed mode)
    COMP11057:jmc marcus.hirt$ uname -a
    Darwin COMP11057.local 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64 i386 MacBookPro15,1 Darwin

    Then ran the thing on Corretto:
    COMP11057:jmc marcus.hirt$ echo $JAVA_HOME
    /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/
    COMP11057:jmc marcus.hirt$ target/products/org.openjdk.jmc/macosx/cocoa/x86_64/JDK\ Mission\ Control.app/Contents/MacOS/jmc -vm $JAVA_HOME/bin

    This is what it looks like on my Mac (just using the JMX console to verify the vendor):

    JMC running on Corretto (image)

  29. […] how to fetch and build OpenJDK Mission Control, this is an updated version of my old post on how to fetch and build JMC from version 8 and […]

  30. David Leonhartsberger says:

    I am on Mac OSX, I followed the instructions (using -vm arg) but I always get “No Java runtime present, requesting install”.
    I have installed OpenJDK8 and JAVA_HOME correctly points to it.

  31. Bruce says:

    When I run the mvn clean package command, mvn tries to access the repository at the jetty server started by the mvn jetty:run command. However, it is giving me a ClassCastException:
    Is anyone else seeing this?
    [INFO] Adding repository http://localhost:8080/site

    !ENTRY org.eclipse.equinox.p2.metadata.repository 4 0 2020-01-03 19:21:58.330
    !MESSAGE Unexpected error loading extension: org.eclipse.equinox.p2.updatesite.metadataRepository
    !STACK 0
    java.lang.ClassCastException: org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager cannot be cast to org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager
    at org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository.setProperty(LocalMetadataRepository.java:303)
    at org.eclipse.equinox.p2.repository.spi.AbstractRepository.setProperty(AbstractRepository.java:192)
    at org.eclipse.equinox.internal.p2.updatesite.metadata.UpdateSiteMetadataRepositoryFactory.resetCache(UpdateSiteMetadataRepositoryFactory.java:83)
    at org.eclipse.equinox.internal.p2.updatesite.metadata.UpdateSiteMetadataRepositoryFactory.load(UpdateSiteMetadataRepositoryFactory.java:63)

  32. Marcus says:

    Hi Bruce,

    Try getting and building JMC 8 instead:
    http://hirt.se/blog/?p=1196

    Way better version – and also on GitHub! 🙂

  33. Brice says:

    Hi Marcus,

    I just downloaded the JMC 7 build 14 (from here https://jdk.java.net/jmc/), and running it with this vm, leads to an Alert popup with this message :

    Failed to create the Java Virtual Machine.

    The terminal shows this message :

    “`
    ❯ JDK\ Mission\ Control.app/Contents/MacOS/jmc -vm /Library/Java/JavaVirtualMachines/openjdk-14.jdk/Contents/Home/bin

    Error: could not find libjava.dylib
    Failed to GetJREPath()
    “`

    I supposed it was due to Java 14, so I defined a java 11 (also corretto), this gets a bit further, but the app crashes almost immediately with this message

    To open “JDK Mission Control” you need to install the legacy Java SE 6 runtime.

    And the in the terminal.

    “`
    ❯ JDK\ Mission\ Control.app/Contents/MacOS/jmc -vm $HOME/.asdf/installs/java/amazon-corretto-11.0.6.10.1-2/bin
    Started recording 1.

    Use jcmd 59688 JFR.dump name=JMC_Default filename=FILEPATH to copy recording data to file.
    No Java runtime present, requesting install.
    “`

    I’ll try what is possible on github.

  34. Marcus says:

    Have you tried any of the 8.0 EA builds, or the 7.1.0 builds? For example https://www.azul.com/products/zulu-mission-control/ (7.1.0) or https://adoptopenjdk.net/jmc (8.0.0 EA)?

  35. Brice says:

    @Marcus Nope I tried those as well with the same issue, but this morning I found the issue:

    What’s happening is that the JDK I use to run java graphical apps is installed with `brew cask install java` and is auto updated to the latest version (right now Oracle’s openjdk 14), however I manage older specific versions via asdf-vm.

    Knowing that I expected that passing the -vm $JAVA_11_HOME/bin argument would have worked, but it did not, somehow the app use the latest version that is available in /Library/Java/JavaVirtualMachines/

    I had to uninstall the java formula and hence the Java 14 version and install the java11 formula that install Oracle’s openjdk11 to make the Mission Control work.

    Also I noticed that only Oracle’s openjdk 11 (11.0.2) or zulu 11 (11.0.6) allows the app to start, using adoptopenjdk 11.0.6, jdk mission control does not start (whatever the version).
    I noticed it affects other Java graphical apps that don’t ship with the java runtime.

    By the way macOs it is now recommanded to ship the jdk runtime as well.

    So the tl;dr is removing all java related brew formula that are greater that 11, and use zulu11 brew formula, and I didn’t have to change the jmc.ini file

  36. Brice says:

    FYI I just submitted two cask formula

    => https://github.com/Homebrew/homebrew-cask/pull/79124
    => https://github.com/Homebrew/homebrew-cask-versions/pull/8777

    Hopefully one of them will be merged.

  37. Marcus says:

    Nice! 🙂

  38. Volodymyr says:

    I’ve had exactly the same problem with running JMC as @Brice
    The following helped me:
    1. brew install java11
    2. sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk

    It looks like JMC looks in /Library/Java/JavaVirtualMachines to find appropriate jdk

Leave a Reply

Your email address will not be published. Required fields are marked *