Passing jvmArgs with spaces?
Aleksey Shipilev
aleksey.shipilev at oracle.com
Tue Mar 31 11:07:34 UTC 2015
Hi Trask,
On 03/24/2015 06:42 AM, Trask Stalnaker wrote:
> While on Linux:
>
> # JMH 1.7 (released 3 days ago)
> # VM invoker: /usr/lib/jvm/java-8-oracle/jre/bin/java
> # VM options: -Dx=12 "-Dy=one two"
>
> and the benchmark fails with
>
> Error: Could not find or load main class "-Dy=one
The real cause for this issue is that JMH splits the single jvmArg
argument into multiple arguments with naive split("[ ]+"), that also
splits by space between "one" and "two".
There are two ways to address this:
a) Accept multiple -jvmArgs, each for a single argument. This seems to
be a proper fix, that is also coherent with .jvmArgs() in API. The
drawback for users: requires a tedious listing when multiple options are
required.
b) Make -jvmArgs splitter to be resilient for quotes. The ambigous
part about this: how to handle nested quotes. Trivially, we may just
ignore the issue and treat the quotes as non-nested.
With:
https://bugs.openjdk.java.net/browse/CODETOOLS-7901362
...we have implemented both. Therefore, two proper ways emerged:
$ java -jar benchmarks.jar -jvmArgs "-Dx=12 -Dy=\"one two\""
$ java -jar benchmarks.jar -jvmArgs "-Dx=12" -jvmArgs "-Dy=one two"
Both work fine on Linux and Windows. Please confirm.
Thanks,
-Aleksey.
P.S. I believe it worked "fine" on Windows, because Java launcher there
intervened and "fixed" some quirks.
More information about the jmh-dev
mailing list