JVM線程的棧默認大小,oracle官網有簡單描述:
In Java SE 6, the default on Sparc is 512k in the 32-bit VM, and 1024k in the 64-bit VM. On x86 Solaris/Linux it is 320k in the 32-bit VM and 1024k in the 64-bit VM.
On Windows, the default thread stack size is read from the binary (java.exe). As of Java SE 6, this value is 320k in the 32-bit VM and 1024k in the 64-bit VM.
You can reduce your stack size by running with the -Xss option. For example:
java -server -Xss64k
Note that on some versions of Windows, the OS may round up thread stack sizes using very coarse granularity. If the requested size is less than the default size by 1K or more,
the stack size is rounded up to the default; otherwise, the stack size is rounded up to a multiple of 1 MB.
64k is the least amount of stack space allowed per thread.
可參考:Frequently Asked Questions About the Java HotSpot VM
實際上:Linux x64 Oracle JDK7u60 64-bit HotSpot VM 下,普通Java線程的默認棧大小怎樣都是1MB。
define_pd_global(intx, ThreadStackSize, 1024); // 0 => use system defaul
http://hg.openjdk.java.net/jdk7u/jdk7u/hotspot/file/2cd3690f644c/src/os_cpu/linux_x86/vm/os_linux_x86.cpp#l654 :
// return default stack size for thr_type
size_t os::Linux::default_stack_size(os::ThreadType thr_type) { // default stack size (compiler thread needs larger stack) #ifdef AMD64 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M); #else size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K); #endif // AMD64 return s; }
不顯式設置-Xss或-XX:ThreadStackSize時,或者把-Xss或者-XX:ThreadStackSize設為0,就是使用“系統默認值”。
可參考大神門的筆記: