JMH: invalid initial heap size
10,914
JMH uses Runtime.exec(String[]) to launch a forked VM. This method assumes a single command-line token per array item, and it will properly escape spaces inside tokens.
It means that when you pass a "-Xms2048m -Xmx2048m -XX:MaxDirectMemorySize=512M"
string as an argument it is treated as a single argument that happens to contain spaces inside instead of three separate space-separated arguments.
Thus the proper way to specify multiple JVM arguments in JMH is to use a separate string value for each separate argument:
Options opt = new OptionsBuilder()
...
.jvmArgs("-Xms2048m", "-Xmx2048m", "-XX:MaxDirectMemorySize=512M")
...
Author by
VB_
Updated on June 26, 2022Comments
-
VB_ almost 2 years
I test my program performance with JMH. And fail to configure heap size. I wondering why it doesn't work.
Questions:
- Why JMH doesn't accept heap size configs?
- Does JMH absorb idea heap size settings without
jvmArgs
method?
Error:
# Run progress: 0.00% complete, ETA 00:04:30 # VM invoker: /usr/lib/jvm/java-8-oracle/jre/bin/java # VM options: -Xms2048m -Xmx2048m -XX:MaxDirectMemorySize=512M # Fork: 1 of 1 Invalid initial heap size: -Xms2048m -Xmx2048m -XX:MaxDirectMemorySize=512M Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. <forked VM failed with exit code 1>
Main Method:
public static void main(String... args) throws RunnerException, IOException { Options opt = new OptionsBuilder() .include(".*" + ArraySummatorBenchmarking.class.getSimpleName() + ".*") .warmupIterations(5) .measurementIterations(5) .forks(1) .jvmArgs("-Xms2048m -Xmx2048m -XX:MaxDirectMemorySize=512M") .build(); new Runner(opt).run(); }
idea.vmoptions
-server -Xms2056m -Xmx2056m -XX:MaxPermSize=1024m -XX:ReservedCodeCacheSize=256m -ea -Dsun.io.useCanonCaches=false -Djava.net.preferIPv4Stack=true -Djsse.enableSNIExtension=false -XX:+UseCodeCacheFlushing -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -Dawt.useSystemAAFontSettings=lcd
Main method options:
-Xms2048m -Xmx2048m -XX:MaxDirectMemorySize=512M