Tue, 20 Dec 2016 16:06:10 -0500
8170307: Stack size option -Xss is ignored
Reviewed-by: dcubed, sspitsyn, gtriantafill
src/os/linux/vm/os_linux.cpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/os/linux/vm/os_linux.cpp Tue Dec 20 08:57:29 2016 +0000 1.2 +++ b/src/os/linux/vm/os_linux.cpp Tue Dec 20 16:06:10 2016 -0500 1.3 @@ -1075,29 +1075,30 @@ 1.4 1.5 // Locate initial thread stack. This special handling of initial thread stack 1.6 // is needed because pthread_getattr_np() on most (all?) Linux distros returns 1.7 -// bogus value for initial thread. 1.8 +// bogus value for the primordial process thread. While the launcher has created 1.9 +// the VM in a new thread since JDK 6, we still have to allow for the use of the 1.10 +// JNI invocation API from a primordial thread. 1.11 void os::Linux::capture_initial_stack(size_t max_size) { 1.12 - // stack size is the easy part, get it from RLIMIT_STACK 1.13 - size_t stack_size; 1.14 + 1.15 + // max_size is either 0 (which means accept OS default for thread stacks) or 1.16 + // a user-specified value known to be at least the minimum needed. If we 1.17 + // are actually on the primordial thread we can make it appear that we have a 1.18 + // smaller max_size stack by inserting the guard pages at that location. But we 1.19 + // cannot do anything to emulate a larger stack than what has been provided by 1.20 + // the OS or threading library. In fact if we try to use a stack greater than 1.21 + // what is set by rlimit then we will crash the hosting process. 1.22 + 1.23 + // Maximum stack size is the easy part, get it from RLIMIT_STACK. 1.24 + // If this is "unlimited" then it will be a huge value. 1.25 struct rlimit rlim; 1.26 getrlimit(RLIMIT_STACK, &rlim); 1.27 - stack_size = rlim.rlim_cur; 1.28 + size_t stack_size = rlim.rlim_cur; 1.29 1.30 // 6308388: a bug in ld.so will relocate its own .data section to the 1.31 // lower end of primordial stack; reduce ulimit -s value a little bit 1.32 // so we won't install guard page on ld.so's data section. 1.33 stack_size -= 2 * page_size(); 1.34 1.35 - // 4441425: avoid crash with "unlimited" stack size on SuSE 7.1 or Redhat 1.36 - // 7.1, in both cases we will get 2G in return value. 1.37 - // 4466587: glibc 2.2.x compiled w/o "--enable-kernel=2.4.0" (RH 7.0, 1.38 - // SuSE 7.2, Debian) can not handle alternate signal stack correctly 1.39 - // for initial thread if its stack size exceeds 6M. Cap it at 2M, 1.40 - // in case other parts in glibc still assumes 2M max stack size. 1.41 - // FIXME: alt signal stack is gone, maybe we can relax this constraint? 1.42 - // Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small 1.43 - if (stack_size > 2 * K * K IA64_ONLY(*2)) 1.44 - stack_size = 2 * K * K IA64_ONLY(*2); 1.45 // Try to figure out where the stack base (top) is. This is harder. 1.46 // 1.47 // When an application is started, glibc saves the initial stack pointer in 1.48 @@ -1257,14 +1258,18 @@ 1.49 // stack_top could be partially down the page so align it 1.50 stack_top = align_size_up(stack_top, page_size()); 1.51 1.52 - if (max_size && stack_size > max_size) { 1.53 - _initial_thread_stack_size = max_size; 1.54 + // Allowed stack value is minimum of max_size and what we derived from rlimit 1.55 + if (max_size > 0) { 1.56 + _initial_thread_stack_size = MIN2(max_size, stack_size); 1.57 } else { 1.58 - _initial_thread_stack_size = stack_size; 1.59 + // Accept the rlimit max, but if stack is unlimited then it will be huge, so 1.60 + // clamp it at 8MB as we do on Solaris 1.61 + _initial_thread_stack_size = MIN2(stack_size, 8*M); 1.62 } 1.63 1.64 _initial_thread_stack_size = align_size_down(_initial_thread_stack_size, page_size()); 1.65 _initial_thread_stack_bottom = (address)stack_top - _initial_thread_stack_size; 1.66 + assert(_initial_thread_stack_bottom < (address)stack_top, "overflow!"); 1.67 } 1.68 1.69 ////////////////////////////////////////////////////////////////////////////////