Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failure to run a jmh test under java9

Tags:

java

java-9

jmh

So basically I am trying to run a test in the form of:

@Benchmark
@Fork(jvmArgsAppend = "-Djava.lang.invoke.stringConcat=java.lang.invoke.StringConcatFactory.Strategy.BC_SB", value = 1)
public String java9StringBuilder(ThreadState state) {
    // some implementation here
}

Running it with:

java -jar benchmarks.jar MyFullClassNameHere -v extra

Unfortunately it fails with forked VM failed with exit code 1 and no more "verbose" output.

What I am doing wrong?

I do get these warnings:

WARNING: Unknown module: org.openjdk specified to --add-exports

WARNING: An illegal reflective access operation has occurred

WARNING: Illegal reflective access by org.openjdk.jmh.util.Utils (file:/Path/Here/benchmarks.jar) to field java.io.Console.cs

WARNING: Please consider reporting this to the maintainers of org.openjdk.jmh.util.Utils

WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations

WARNING: All illegal access operations will be denied in a future release

like image 513
Eugene Avatar asked Nov 27 '17 14:11

Eugene


1 Answers

Nothing is wrong with Java 9 in this example. You are supplying JVM options to the forked VM, have you tried running with that option without JMH first? Then you would notice the command is incorrect, and the correct form is:

- @Fork(jvmArgs = "-Djava.lang.invoke.stringConcat=java.lang.invoke.StringConcatFactory.Strategy.BC_SB")
+ @Fork(jvmArgs = "-Djava.lang.invoke.stringConcat=BC_SB")

...because BC_SB is the enum constant in java.lang.invoke.StringConcatFactory.Strategy enum.

like image 133
Aleksey Shipilev Avatar answered Sep 28 '22 00:09

Aleksey Shipilev