Eugene
Eugene

Reputation: 120978

Failure to run a jmh test under java9

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

Upvotes: 6

Views: 1722

Answers (1)

Aleksey Shipilev
Aleksey Shipilev

Reputation: 18857

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.

Upvotes: 6

Related Questions