instantsetsuna
instantsetsuna

Reputation: 9603

JVM option -Xss - What does it do exactly?

It says here that -Xss is used to "set thread stack size", what does it mean exactly? Could anyone help me understand this?

Upvotes: 293

Views: 299720

Answers (5)

Eugene
Eugene

Reputation: 11055

Add my two cents here, besides what mentioned, we can write a simple demo to show the effect of setting Xss.

Generally speaking, it controls the stack size arranged to each thread.

    public static void main(String[] args) {
        try{
            recur();
        }catch (StackOverflowError e){
            System.out.println(depth);
        }
    }

    static int depth = 1;

    public static void recur(){
        depth++;
        recur();
    }

After compiling above code, you will see the depth (the invoke hierachy) grows together with the passed Xss settings.

The output of java -Xss1m com.eugene.Main is 21638 and the output of java -Xss2m com.eugene.Main is 48325 at my local machine.

Upvotes: 7

Kellindil
Kellindil

Reputation: 4533

If I am not mistaken, this is what tells the JVM how much successive calls it will accept before issuing a StackOverflowError. Not something you wish to change generally.

Upvotes: 5

Adam Adamaszek
Adam Adamaszek

Reputation: 4044

It indeed sets the stack size on a JVM.

You should touch it in either of these two situations:

  • StackOverflowError (the stack size is greater than the limit), increase the value
  • OutOfMemoryError: unable to create new native thread (too many threads, each thread has a large stack), decrease it.

The latter usually comes when your Xss is set too large - then you need to balance it (testing!)

Upvotes: 206

T.J. Crowder
T.J. Crowder

Reputation: 1074008

Each thread in a Java application has its own stack. The stack is used to hold return addresses, function/method call arguments, etc. So if a thread tends to process large structures via recursive algorithms, it may need a large stack for all those return addresses and such. With the Sun JVM, you can set that size via that parameter.

Upvotes: 312

Peter Lawrey
Peter Lawrey

Reputation: 533442

Each thread has a stack which used for local variables and internal values. The stack size limits how deep your calls can be. Generally this is not something you need to change.

Upvotes: 9

Related Questions