I just want to control the stack size for all of my threads in a Java (groovy) application. For the Hotspot Oracle VM, I know that there are two parameters doing that (-Xss and
The Oracle Java SE 8 docs suggest that -Xss and -XX:ThreadStackSize=size are equivalent. However this not correct. Try eg.
java -XX:ThreadStackSize=1024 -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
java -Xss1024 -version
The stack size specified is too small, Specify at least 160k
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
This is fixed e.g. in the Java 14 documentation:
-XX:ThreadStackSize=size Sets the Java thread stack size (in kilobytes). Use of a scaling suffix, such as k, results in the scaling of the kilobytes value so that -XX:ThreadStackSize=1k sets the Java thread stack size to 1024*1024 bytes or 1 megabyte.
and
-Xss size Sets the thread stack size (in bytes).
-Xss
works only on main
Java thead, but -XX:ThreadStackSize
works on all Java thread.
If -Xss (or -ss) were passed on the command line, it gets picked up directly by the launcher and is used later to create the "main" Java thread, without asking the VM for the preferred thread stack size. That where inconsistency comes from: if -Xss is given after -XX:ThreadStackSize, then things are still good; otherwise, the "main" Java thread would have a stack size specified by -Xss where as other Java threads' stack size would still follow that of ThreadStackSize.
Inconsistency between -Xss and -XX:ThreadStackSize in the java launcher
-Xss
is an alias for -XX:ThreadStackSize
both for OpenJDK and Oracle JDK.
Though they parse arguments differently:
-Xss
may accept a number with K, M or G suffix;
-XX:ThreadStackSize=
expects an integer (without suffix) - the stack size in kilobytes.
-Xss
is standard options recognized by the Java HotSpot VM.
-XX:ThreadStackSize
as other -XX
options are not stable and are subject to change without notice.
See Java HotSpot VM Options
Current Oracle Java SE 8 docs suggest that -Xss
and -XX:ThreadStackSize=size
are equivalent. See
https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
-Xss
:-Xsssize
Sets the thread stack size (in bytes). Append the
letter k or K to indicate KB, m or M to indicate MB, g or G to
indicate GB. The default value depends on the platform:
Linux/ARM (32-bit): 320 KB
Linux/i386 (32-bit): 320 KB
Linux/x64 (64-bit): 1024 KB
OS X (64-bit): 1024 KB
Oracle Solaris/i386 (32-bit): 320 KB
Oracle Solaris/x64 (64-bit): 1024 KB
The following examples set the thread stack size to 1024 KB in different units:
-Xss1m
-Xss1024k
-Xss1048576
This option is equivalent to -XX:ThreadStackSize.
-XX:ThreadStackSize=size
-XX:ThreadStackSize=size
Sets the thread stack size (in bytes). Append the
letter k or K to indicate kilobytes, m or M to indicate
megabytes, g or G to indicate gigabytes. The default
value depends on the platform:
Linux/ARM (32-bit): 320 KB
Linux/i386 (32-bit): 320 KB
Linux/x64 (64-bit): 1024 KB
OS X (64-bit): 1024 KB
Oracle Solaris/i386 (32-bit): 320 KB
Oracle Solaris/x64 (64-bit): 1024 KB
The following examples show how to set the thread stack size to 1024 KB in different units:
-XX:ThreadStackSize=1m
-XX:ThreadStackSize=1024k
-XX:ThreadStackSize=1048576
This option is equivalent to -Xss.