JVM -XSS Option

MD Aminul Islam Jan 30, 2023 Sep 11, 2022
  1. Change the Size of the JVM Stack With -Xss
  2. Alternative Way to Change the Size of the JVM Stack
JVM -XSS Option

A Java Application has a thread, and each thread has its stack. A stack in a virtual machine is mainly used to hold the return addresses, method call arguments, etc.

Now when a thread with a large structure tries to process by using recursive algorithms, it may require a large size stack.

In Java Virtual Machine or JVM, the stack has a default size available. Every JVM thread contains a Private Native Stack that stores Call Stack information, results, and local variables.

Now the size of the JVM stack mainly depends on the Operating System where the JVM is running.

Operating System JVM Stack Default Size
Linux 1 MB
macOS 1 MB
Oracle Solaris 1 MB
Windows JVM stack uses the System-wide stack size

In this article, we will discuss the -Xss in Java, and we will see how we can change the default size of the JVM stack.

The -Xss flag is mainly used to change the size of the JVM stack. Let’s go through the below commands through which we can change the size of the JVM stack.

Change the Size of the JVM Stack With -Xss

To change the current default size of the JVM stack, you can follow the below command.

java -Xss1048576

In the command above, the number 1048576 means 1 MB. But if you don’t like calculation, you can edit the command below.

java -Xss1024k

In the example above, we used 1024k instead of 1048576 as we know that 1024k means 1 MB. But you can directly mention the 1 MB in your command like below.

java -Xss1m

Alternative Way to Change the Size of the JVM Stack

There is also an alternative way to change the JVM stack’s current size by using the flag -XX. To use this, you can follow the command below.

java -XX:ThreadStackSize=1024

Some Important Notes

We need to follow some important rules when working with these commands.

  1. We can’t provide a size greater than the Max Value of 1 GB.
  2. We can’t provide a size less than the Min Value of 1 MB.

Please note that these commands are for the Java Virtual Machine or JVM.

MD Aminul Islam avatar MD Aminul Islam avatar

Aminul Is an Expert Technical Writer and Full-Stack Developer. He has hands-on working experience on numerous Developer Platforms and SAAS startups. He is highly skilled in numerous Programming languages and Frameworks. He can write professional technical articles like Reviews, Programming, Documentation, SOP, User manual, Whitepaper, etc.


Related Article - Java JVM