X

Topics and trends related to the Java ecosystem with occasional random rants.

  • Sun
    September 8, 2015

Using Java Flight Recorder with Compact Profiles

James Connors
Principal Solutions Consultant

Like it's big brother Java SE, the Java SE-Embedded 8 platform provides support for Java Flight Recorder, an invaluable profiling and event collection framework built into the Java Runtime Environment.  However, Flight Recorder is only available with the Java SE Embedded 8 Full JRE, not with the smaller Compact Profiles.  So the question becomes, is there anything that can be done to use Java Flight Recorder with Compact Profiles?

At the current time, the smaller Compact1 and Compact2 profiles cannot realistically support Java Flight Recorder without substantial changes.  Hence we'll avoid discussing their prospects for inclusion here.  What we will focus on is Compact3 as its specification includes among others, the javax.management APIs, making for a more reasonable match.  As it turns out, all that is required to enable Flight Recorder use with the Compact3 profile is to copy over a few files over from the Full JRE.  The instructions that follow should aid in creating a Flight Recorder enabled instance:

1. Download a Java SE-Embedded EJRE for your platform.  You can do so here.  For this example, we'll do this on a Linux host and choose the ARMv6/v7 Hard Float option (suitable for the venerable Raspberry Pi).

2. Extract the EJRE.

$ tar xvf ejdk-8u51-linux-armv6-vfp-hflt.tar.gz

3. Use the EJRE's jrecreate.sh script to create a full JRE:

$ ./ejdk1.8.0_51/bin/jrecreate.sh --dest full_jre -g -k
Building JRE using Options {
    ejdk-home: /home/pi/ejdk1.8.0_51
    dest: /home/pi/full_jre
    target: linux_armv6_vfp_hflt
    vm: all
    runtime: jre
    debug: true
    keep-debug-info: true
    no-compression: false
    dry-run: false
    verbose: false
    extension: []
}


Target JRE Size is 59,389 KB (on disk usage may be greater).
Embedded JRE created successfully

4. Create a Compact3 JRE:

$ ./ejdk1.8.0_51/bin/jrecreate.sh --profile compact3 --dest compact3 -g -k
Building JRE using Options {
    ejdk-home: /home/pi/ejdk1.8.0_51
    dest: /home/pi/compact3
    target: linux_armv6_vfp_hflt
    vm: client
    runtime: compact3 profile
    debug: true
    keep-debug-info: true
    no-compression: false
    dry-run: false
    verbose: false
    extension: []
}


Target JRE Size is 24,336 KB (on disk usage may be greater).
Embedded JRE created successfully

5.  Check the size of the compact3 JRE.  We'll use this to see how much space was needed to add support for Flight Recorder.

$ du -sk compact3
24480   compact3

6.  Create the compact3/lib/jfr/ directory

$ mkdir compact3/lib/jfr

7.  Copy the following files over from the full JRE to the compact3 instance with these commands:

$ cd full_jre/

$ cp ./lib/jfr.jar ../compact3/lib

$ cp ./lib/arm/libjfr.so ../compact3/lib/arm

$ cp ./lib/arm/libbci.so ../compact3/lib/arm
$ cp ./lib/jfr/default.jfc ../compact3/lib/jfr

$ cp ./lib/jfr/profile.jfc ../compact3/lib/jfr

8. That's all that is required.  You can compare the disk usage of the compact3/ directory before and after these modifications to get an idea of the additional space required to utilize Java Flight Recorder.

$ du -sk ../compact3
24824   ../compact3

So comparing the disk usage of step (5), we see that less than 400KB is added in order to enable usage of Java Flight Recorder. To better understand how you might remotely connect to a Flight Recorder enabled instance in a secure fashion, check out this article.

Join the discussion

Comments ( 2 )
  • lasealwin Tuesday, September 8, 2015

    Good share. I will apply in my device. Thanks


  • Ingo Wassink Tuesday, March 22, 2016

    Nicely done! Sadly, it works not in jdk 1.8.0_71:

    https://bugs.openjdk.java.net/browse/JDK-8152000

    At the moment we stick to 1.8.0_51


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.