Can't fork VM if option value contains space
Dmitry Vyazelenko
vyazelenko at yahoo.com
Mon Aug 11 21:48:25 UTC 2014
Hi all,
Just got into some trouble passing JVM options to forked VMs when values have a space, i.e.
I want to pass the following option (via -jmvArgs) when executing benchmarks:
-Dmy.option=“A B C”
What I get is the following error:
java -jar target/benchmarks.jar -jvmArgs -Dmy.property="A B C"
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/bin/java
# VM options: -Dmy.property=A B C
# Warmup: 20 iterations, 1 s each
# Measurement: 20 iterations, 1 s each
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: test.jmh.DummyBench.baseline
# Run progress: 0.00% complete, ETA 00:06:40
# Fork: 1 of 10
Error: Could not find or load main class B
<forked VM failed with exit code 1>
<stdout last='10 lines'>
</stdout>
<stderr last='10 lines'>
Error: Could not find or load main class B
</stderr>
OK, it seems that quotes were removed. Thus I try to force them which also fails:
java -jar target/benchmarks.jar -jvmArgs -Dmy.property="\"A B C\""
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/bin/java
# VM options: -Dmy.property="A B C"
# Warmup: 20 iterations, 1 s each
# Measurement: 20 iterations, 1 s each
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: test.jmh.DummyBench.baseline
# Run progress: 0.00% complete, ETA 00:06:40
# Fork: 1 of 10
Error: Could not find or load main class B
<forked VM failed with exit code 1>
<stdout last='10 lines'>
</stdout>
<stderr last='10 lines'>
Error: Could not find or load main class B
</stderr>
Note that this time “VM options” shows command correctly but execution fails anyway.
The only workaround I’ve found is to use Java API:
public class DummyBench {
@Benchmark
public void baseline() {
}
public static void main(String[] args) throws Exception {
Options options = new OptionsBuilder().jvmArgs("-Dmy.property=\"A B C\"").build();
new Runner(options).run();
}
}
When I run it via main method then it works:
java -cp target/benchmarks.jar test.jmh.DummyBench
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/bin/java
# VM options: -Dmy.property="A B C"
# Warmup: 20 iterations, 1 s each
# Measurement: 20 iterations, 1 s each
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: test.jmh.DummyBench.baseline
# Run progress: 0.00% complete, ETA 00:06:40
# Fork: 1 of 10
# Warmup Iteration 1: 3513969661.351 ops/s
…
Best regards,
Dmitry Vyazelenko
More information about the jmh-dev
mailing list