How to run jmh class in main method
Aleksey Shipilev
aleksey.shipilev at oracle.com
Tue Feb 3 09:23:07 UTC 2015
Hi, 张博文!
On 02/03/2015 08:18 AM, 张博文 wrote:
> When I run the sample class in my eclipse with jmh-core jar(1.5.1) brought in, it also threw such exception as follows:
>
> Caused by: java.io.UnsupportedEncodingException: cp0
> at java.io.PrintStream.toCharset(PrintStream.java:96)
> at java.io.PrintStream.<init>(PrintStream.java:175)
> at org.openjdk.jmh.util.UnCloseablePrintStream.<init>(UnCloseablePrintStream.java:34)
> at org.openjdk.jmh.runner.Runner.createOutputFormat(Runner.java:131)
> ... 2 more
>
>
> I notice that it would call the Utils.guessConsoleEncoding() which return the "cp0" of the encoding which I could not know why.
Ah, an interesting encoding you have there. I wonder how that happened.
The only way I can see for this to happen is if Console.encoding field
was having "cp0", while this Charset is unavailable. We can make JMH a
bit more resilient on this, and try to check if the Charset is actually
available, instead of trusting whatever we got from there:
https://bugs.openjdk.java.net/browse/CODETOOLS-7901287
Can you build JMH from source, and try again with 1.6-SNAPSHOT? You
might just run any JMH sample from command line after the entire JMH
workspace is built.
> by the way, my main function like this:
> public static void main(String[] args) throws Exception {
> Options opt = new OptionsBuilder().include(LocalAtomicLongBenchmark.class.getSimpleName()).jvmArgs("-Dfile.encoding=UTF-8").build();
> new Runner(opt).run();
> }
.jvmArgs() would affect only the forked VM settings. If you need to pass
the option to the JVM that does "new Runner(opt).run()", it's too late
already, and it should be handled elsewhere, like in IDE's Run
Configuration.
Thanks,
-Aleksey.
More information about the jmh-dev
mailing list