JMH and JDK 22

Jaikiran Pai jai.forums2013 at gmail.com
Tue Oct 31 15:16:05 UTC 2023


Hello Maurizio,

We had this issue in our JDK repo which has micro benchmarks. Running 
those micro benchmarks had run into this issue. We decided to use the 
"-processor org.openjdk.jmh.generators.BenchmarkProcessor" instead of 
-proc:full to get this to work. More details are available here 
https://github.com/openjdk/jdk/pull/16122

-Jaikiran

On 31/10/23 7:44 pm, Maurizio Cimadamore wrote:
>
> 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/1fbc2bae/attachment.htm>


More information about the compiler-dev mailing list