JMH and JDK 22
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Tue Oct 31 14:14:18 UTC 2023
Hi,
earlier today I ran into an issue when trying to run a JMH benchmark on
a 3rd party maven project.
It seems like the issue is caused by the change in javac’s default
annotation processing policy [1].
Here are the steps to reproduce the issue:
* set JAVA_HOME to point to a recent JDK 22 build
* generate a JMH sample pom file using the following command (this is
what is advertised in the JMH github page [2]):
|$ mvn archetype:generate \ -DinteractiveMode=false \
-DarchetypeGroupId=org.openjdk.jmh \
-DarchetypeArtifactId=jmh-java-benchmark-archetype \
-DgroupId=org.sample \ -DartifactId=test \ -Dversion=1.0 |
* build the project using |mvn clean package|
* run the benchmark as follows:
|$ $JAVA_HOME/bin/java -jar target/benchmarks.jar MyBenchmark Exception
in thread "main" java.lang.RuntimeException: ERROR: Unable to find the
resource: /META-INF/BenchmarkList at
org.openjdk.jmh.runner.AbstractResourceReader.getReaders(AbstractResourceReader.java:98)
at org.openjdk.jmh.runner.BenchmarkList.find(BenchmarkList.java:124) at
org.openjdk.jmh.runner.Runner.internalRun(Runner.java:252) at
org.openjdk.jmh.runner.Runner.run(Runner.java:208) at
org.openjdk.jmh.Main.main(Main.java:71) |
As you can see, there is a problem here, as the META-INF folder does not
contain the list of benchmarks. This is due to the fact that annotations
are no longer processed using processors available in the classpath.
Using JDK 21 to build and run the same pom file works fine.
Adding the following lines to the compiler plugin configuration
addresses the issue in JDK 22:
|<compilerArgs> <arg>-proc:full</arg> </compilerArgs> |
While this is understandable, I’m afraid that not many users will have
gotten the memo - I don’t seem to get any notes when building this
project using JDK 21 (probably the notes are swallowed by maven?). And,
sadly, the lack of a proper JMH plugin means that all the JMH poms out
there will need some manual tweaking to keep working in 22.
At the very least, I think that JMH’s maven archetype should be updated
to include the lines above?
Cheers
Maurizio
[1] - https://github.com/openjdk/jdk/pull/14432
[2] - https://github.com/openjdk/jmh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20231031/5e4173a1/attachment-0001.htm>
More information about the compiler-dev
mailing list