简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM