JVM Tutorials - Herong's Tutorial Examples - Version 4.23, by Dr. Herong Yang
Largest Stack Size for HotSpot on Windows
This section provides a tutorial example on how to find out the largest stack size supported by HotSpot on Windows systems. The highest safe stack size is about 160 MB on Windows.
Another way to test the JVM behavior is to keep increasing the stack size using the -Xss option on MultiStackThread.java. Here is the first run with -Xss1m and 1 thread:
C:\>\progra~1\java\jdk1.8.0\bin\java -Xss1m MultiStackThread 1 20000 Number of threads started: 1 Stack overflow at 17939 for thread: 8 Stack overflow at 17939 for thread: 8 Stack overflow at 17939 for thread: 8 Stack overflow at 17939 for thread: 8 Stack overflow at 17939 for thread: 8 Time, heap total, free and used: 1, 2031616, 1483888, 547728 Time, heap total, free and used: 2, 2031616, 1483888, 547728 Time, heap total, free and used: 3, 2031616, 1465488, 566128 ...
The JVM was able to create 17,939 frames within the 1MB stack. But the StackOverflow exception was thrown 5 times. I am not sure why.
Note the heap usage is very low, only about 566KB. I also collected the JVM footprint using the tasklist command in another command window:
C:\herong>tasklist Image Name PID Session Name Session# Mem Usage ============= ======== ================ =========== ============ ... java.exe 7188 Console 1 15,064 K ...
I did more runs and compiled the result shown below:
-Xss Frames Mem Usage Heap Usage (1 Thread) 1m 17939 15,064 K 566128 2m 27970 16,256 K 547728 4m 50763 18,260 K 584744 8m 94906 18,680 K 570872 16m 182579 26,896 K 570872 32m 356072 43,300 K 570872 64m 704467 76,112 K 552088 128m 1403726 141,768 K 570808 160m 1754577 174,620 K 552200 176m 1929494 191,028 K 552248 (Unable to stop with Ctrl-C) 200m (java.lang.OutOfMemoryError) 256m (Error occurred during initialization of VM)
Some notes on the test result:
Conclusion: Do not specify large stack size, unless your application requires very deep nested method calls.
Last update: 2014.
Table of Contents
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
JRockit JVM 28.2.7 by Oracle Corporation
Memory Management and Garbage Collectors
►JVM Stack, Frame and Stack Overflow
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
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