If default stack size is not 0 or if user has specified stack size with -Xss, JVM will pass the stack size value through "stack_size" argument to _beginthreadex() when creating a new thread. However, on Windows "stack_size" refers to the initially committed space. It does not affect total (reserved) stack size at all if it's smaller than the default value specified in PE header. If the "stack_size" value is larger than default value, Windows will round up stack size to the nearest multiple of 1MB. Since b49 the default stack size in JVM has been changed to 320k, while the value in PE header remains 256k. This can cause OOM errors and/or performance degradation if the application has many threads, because each thread will take 1MB real memory. We should use STACK_SIZE_PARAM_IS_A_RESERVATION when creating new threads.
|