-Xss JVM Option for Stack Size

This section describes the -Xss option to specify JVM stack size. Changing stack size can help to estimate frame size. The frame size is 32 bytes for a simple method call.

What Is the -Xss JVM Option? The -Xss JVM option allows us to specify the size of the frame stack used by each thread to store local variable, partial results and method calling information.

With this -Xss option, we can now rerun StackOverflowTest.java presented in the previous tutorial to estimate what is the frame size of my thread and the default JVM stack size:

C:\>\progra~1\Java\jdk1.8.0\bin\java StackOverflowTest 2> output.txt
java.lang.StackOverflowError
Maximum nested calls: 8331

C:\>\progra~1\Java\jdk1.8.0\bin\java StackOverflowTest 2> output.txt
java.lang.StackOverflowError
Maximum nested calls: 8299

C:\>\progra~1\Java\jdk1.8.0\bin\ava -Xss128k 
   StackOverflowTest 2> output.txt
java.lang.StackOverflowError
Maximum nested calls: 2499

C:\>\progra~1\Java\jdk1.8.0\bin\java -Xss128k 
   StackOverflowTest 2> output.txt
java.lang.StackOverflowError
Maximum nested calls: 2511

C:\>\progra~1\Java\jdk1.8.0\bin\java -Xss256k 
   StackOverflowTest 2> output.txt
java.lang.StackOverflowError
Maximum nested calls: 6305

C:\>\progra~1\Java\jdk1.8.0\bin\java -Xss256k 
   StackOverflowTest 2> output.txt
java.lang.StackOverflowError
Maximum nested calls: 6348

C:\>\progra~1\Java\jdk1.8.0\bin\java -Xss304k 
   StackOverflowTest 2> output.txt
java.lang.StackOverflowError
Maximum nested calls: 8238

C:\>\progra~1\Java\jdk1.8.0\bin\java -Xss304k 
   StackOverflowTest 2> output.txt
java.lang.StackOverflowError
Maximum nested calls: 8351

C:\>\progra~1\Java\jdk1.8.0\bin\java -Xss512k 
   StackOverflowTest 2> output.txt
java.lang.StackOverflowError
Maximum nested calls: 14359

C:\>\progra~1\Java\jdk1.8.0\bin\java -Xss512k 
   StackOverflowTest 2> output.txt
java.lang.StackOverflowError
Maximum nested calls: 14318

So far the output tells us that:

To estimate the size of the frame created for each recursive call on the sub() method, I did more tests with a wide range of stack sizes. The results are summarized below:

 -Xss
Stack   Frames   Frame
 Size             Size
128k      2505   52.32
256k      6327   41.44
304k      8295   37.53
512k     14339   36.57
  1m     30738   34.11
 64m   2095152   32.03
128m   4192607   32.01

This result clearly indicates that the frame size is 32 bytes for executing the following method:

   private static void sub() {
      n++;
      sub();
   }

Last update: 2014.

Table of Contents

 About This Book

 Downloading and Installing JDK 1.8.0 on Windows

 Downloading and Installing JDK 1.7.0 on Windows

 java.lang.Runtime Class - The JVM Instance

 java.lang.System Class - The Operating System

 ClassLoader Class - Class Loaders

 Class Class - Class Reflections

 Sun's JVM - Java HotSpot VM

 JRockit JVM 28.2.7 by Oracle Corporation

 JVM Runtime Data Areas

 Memory Management and Garbage Collectors

 Garbage Collection Tests

JVM Stack, Frame and Stack Overflow

 What Is JVM Stack?

 StackOverflowError Exception Test

-Xss JVM Option for Stack Size

 Frame Impact of Extra Statements

 JVM Stack Expansion and Footprint

 JVM Stack Expansion and OutOfMemoryError

 Largest Stack Size for HotSpot on Windows

 Default Stack Sizes of HotSpot and JRockit

 JRockit Frame Size Smaller than HotSpot

 JRockit Expanding Stacks in Bigger Chunks

 JRockit Running Out Of Memory Quicker

 Largest Stack Size for JRockit on Windows

 Thread Testing Program and Result

 CPU Impact of Multi-Thread Applications

 I/O Impact of Multi-Thread Applications

 CDS (Class Data Sharing)

 Micro Benchmark Runner and JVM Options

 Micro Benchmark Tests on "int" Operations

 Micro Benchmark Tests on "long" Operations

 Micro Benchmark Tests in JIT Compilation Mode

 Micro Benchmark Tests on "float" and "double" Operations

 Outdated Tutorials

 References

 PDF Printing Version