A small test to check for JFR support in the different JDKs. This is not an exhaustive list, but the check can be easily adapted to test additional versions.
Background: JFR was introduced in Oracle JDK 9, and was open sourced with OpenJDK 11, and later on backported to OpenJDK 8_262. It was not backported to the not-lts releases 9 and 10.
JFR is supported in
-
adoptopenjdk-8.0.262+10
-
adoptopenjdk-8.0.292+10
-
adoptopenjdk-11.0.9+11
-
adoptopenjdk-openj9-11.0.1+13.openj9-0.11.0
-
corretto-8.262.10.1
-
corretto-8.302.08.1
-
corretto-11.0.12.7.2
-
liberica-8u302+8
-
liberica-11.0.12+7
-
openjdk-11.0.2
-
zulu-8.48.0.51
-
zulu-8.56.0.21
-
zulu-11.2.3
-
zulu-11.50.19
Doesn’t work with
-
adoptopenjdk-openj9-8.0.292+10.openj9-0.26.0
-
adoptopenjdk-9.0.0+181
-
adoptopenjdk-10.0.2+13.1
-
liberica-8u262+10
-
openjdk-9.0.4
-
openjdk-10.0.2
Install JDKs
for jdk in "adoptopenjdk-8.0.262+10" "adoptopenjdk-8.0.292+10" "adoptopenjdk-9.0.0+181" "adoptopenjdk-10.0.2+13.1" "adoptopenjdk-11.0.9+11" "adoptopenjdk-openj9-8.0.292+10.openj9-0.26.0" "adoptopenjdk-openj9-11.0.1+13.openj9-0.11.0" "corretto-8.262.10.1" "corretto-8.302.08.1" "corretto-11.0.12.7.2" "liberica-8u262+10" "liberica-8u302+8" "liberica-11.0.12+7" "openjdk-9.0.4" "openjdk-10.0.2" "openjdk-11.0.2" "zulu-8.48.0.51" "zulu-8.56.0.21" "zulu-11.2.3" "zulu-11.50.19"
do
asdf install java $jdk
done
Create HelloWorld.java
and compile with adoptopenjdk-8.0.292+10
.
import jdk.jfr.*;
@Category("HelloWorld")
@Name("HelloWorldEvent")
@StackTrace(true)
@Description("Say Hello")
@Label("Hello World")
public class HelloWorld extends Event {
@Label("Greeting")
String greeting;
public static void main(String... args) {
HelloWorld event = new HelloWorld();
event.begin();
String greeting = args.length > 0 ? args[0] : "World";
System.out.println("Hello " + greeting);
event.greeting = greeting;
event.commit();
}
}
Execute with different JDKs using this snippet
for jdk in "adoptopenjdk-8.0.262+10" "adoptopenjdk-8.0.292+10" "adoptopenjdk-9.0.0+181" "adoptopenjdk-10.0.2+13.1" "adoptopenjdk-11.0.9+11" "adoptopenjdk-openj9-8.0.292+10.openj9-0.26.0" "adoptopenjdk-openj9-11.0.1+13.openj9-0.11.0" "corretto-8.262.10.1" "corretto-8.302.08.1" "corretto-11.0.12.7.2" "liberica-8u262+10" "liberica-8u302+8" "liberica-11.0.12+7" "openjdk-9.0.4" "openjdk-10.0.2" "openjdk-11.0.2" "zulu-8.48.0.51" "zulu-8.56.0.21" "zulu-11.2.3" "zulu-11.50.19"
do
echo "Using ${jdk}"
asdf shell java $jdk
java -version
java HelloWorld
echo "-------------------"
done
Using adoptopenjdk-8.0.262+10 openjdk version "1.8.0_262" OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_262-b10) OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.262-b10, mixed mode) Hello World ------------------- Using adoptopenjdk-8.0.292+10 openjdk version "1.8.0_292" OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_292-b10) OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.292-b10, mixed mode) Hello World ------------------- Using adoptopenjdk-9.0.0+181 openjdk version "9" OpenJDK Runtime Environment (build 9+181) OpenJDK 64-Bit Server VM (build 9+181, mixed mode) Error: Could not find or load main class HelloWorld Caused by: java.lang.NoClassDefFoundError: jdk/jfr/Event ------------------- Using adoptopenjdk-10.0.2+13.1 openjdk version "10.0.2" 2018-07-17 OpenJDK Runtime Environment AdoptOpenJDK (build 10.0.2+13) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 10.0.2+13, mixed mode) Error: Could not find or load main class HelloWorld Caused by: java.lang.NoClassDefFoundError: jdk/jfr/Event ------------------- Using adoptopenjdk-11.0.9+11 openjdk version "11.0.9" 2020-10-20 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9+11) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.9+11, mixed mode) Hello World ------------------- Using adoptopenjdk-openj9-8.0.292+10.openj9-0.26.0 openjdk version "1.8.0_292" OpenJDK Runtime Environment (build 1.8.0_292-b10) Eclipse OpenJ9 VM (build openj9-0.26.0, JRE 1.8.0 Mac OS X amd64-64-Bit Compressed References 20210421_909 (JIT enabled, AOT enabled) OpenJ9 - b4cc246d9 OMR - 162e6f729 JCL - 2a5e268814 based on jdk8u292-b10) Error: Could not find or load main class HelloWorld ------------------- Using adoptopenjdk-openj9-11.0.1+13.openj9-0.11.0 openjdk version "11.0.1" 2018-10-16 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.1+13) Eclipse OpenJ9 VM AdoptOpenJDK (build openj9-0.11.0, JRE 11 Mac OS X amd64-64-Bit 20181115_16 (JIT enabled, AOT enabled) OpenJ9 - 090ff9dcd OMR - ea548a66 JCL - d4455071ce based on jdk-11.0.1+13) Hello World ------------------- Using corretto-8.262.10.1 openjdk version "1.8.0_262" OpenJDK Runtime Environment Corretto-8.262.10.1 (build 1.8.0_262-b10) OpenJDK 64-Bit Server VM Corretto-8.262.10.1 (build 25.262-b10, mixed mode) Hello World ------------------- Using corretto-8.302.08.1 openjdk version "1.8.0_302" OpenJDK Runtime Environment Corretto-8.302.08.1 (build 1.8.0_302-b08) OpenJDK 64-Bit Server VM Corretto-8.302.08.1 (build 25.302-b08, mixed mode) Hello World ------------------- Using corretto-11.0.12.7.2 openjdk version "11.0.12" 2021-07-20 LTS OpenJDK Runtime Environment Corretto-11.0.12.7.2 (build 11.0.12+7-LTS) OpenJDK 64-Bit Server VM Corretto-11.0.12.7.2 (build 11.0.12+7-LTS, mixed mode) Hello World ------------------- Using liberica-8u262+10 openjdk version "1.8.0_262" OpenJDK Runtime Environment (build 1.8.0_262-b10) OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode) Error: Could not find or load main class HelloWorld ------------------- Using liberica-8u302+8 openjdk version "1.8.0_302" OpenJDK Runtime Environment (build 1.8.0_302-b08) OpenJDK 64-Bit Server VM (build 25.302-b08, mixed mode) Hello World ------------------- Using liberica-11.0.12+7 openjdk version "11.0.12" 2021-07-20 LTS OpenJDK Runtime Environment (build 11.0.12+7-LTS) OpenJDK 64-Bit Server VM (build 11.0.12+7-LTS, mixed mode) Hello World ------------------- Using openjdk-9.0.4 openjdk version "9.0.4" OpenJDK Runtime Environment (build 9.0.4+11) OpenJDK 64-Bit Server VM (build 9.0.4+11, mixed mode) Error: Could not find or load main class HelloWorld Caused by: java.lang.NoClassDefFoundError: jdk/jfr/Event ------------------- Using openjdk-10.0.2 openjdk version "10.0.2" 2018-07-17 OpenJDK Runtime Environment 18.3 (build 10.0.2+13) OpenJDK 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode) Error: Could not find or load main class HelloWorld Caused by: java.lang.NoClassDefFoundError: jdk/jfr/Event ------------------- Using openjdk-11.0.2 openjdk version "11.0.2" 2019-01-15 OpenJDK Runtime Environment 18.9 (build 11.0.2+9) OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode) Hello World ------------------- Using zulu-8.48.0.51 openjdk version "1.8.0_262" OpenJDK Runtime Environment (Zulu 8.48.0.51-CA-macosx) (build 1.8.0_262-b19) OpenJDK 64-Bit Server VM (Zulu 8.48.0.51-CA-macosx) (build 25.262-b19, mixed mode) Hello World ------------------- Using zulu-8.56.0.21 openjdk version "1.8.0_302" OpenJDK Runtime Environment (Zulu 8.56.0.21-CA-macosx) (build 1.8.0_302-b08) OpenJDK 64-Bit Server VM (Zulu 8.56.0.21-CA-macosx) (build 25.302-b08, mixed mode) Hello World ------------------- Using zulu-11.2.3 openjdk version "11.0.1" 2018-10-16 LTS OpenJDK Runtime Environment Zulu11.2+3 (build 11.0.1+13-LTS) OpenJDK 64-Bit Server VM Zulu11.2+3 (build 11.0.1+13-LTS, mixed mode) Hello World ------------------- Using zulu-11.50.19 openjdk version "11.0.12" 2021-07-20 LTS OpenJDK Runtime Environment Zulu11.50+19-CA (build 11.0.12+7-LTS) OpenJDK 64-Bit Server VM Zulu11.50+19-CA (build 11.0.12+7-LTS, mixed mode) Hello World -------------------