Mercurial > hg > graal-jvmci-8
comparison src/os/linux/vm/os_linux.cpp @ 24179:75021e6fe108
8170307: Stack size option -Xss is ignored
Reviewed-by: dcubed, sspitsyn, gtriantafill
author | dholmes |
---|---|
date | Tue, 20 Dec 2016 16:06:10 -0500 |
parents | e21dd2c95cf0 |
children | 719853999215 |
comparison
equal
deleted
inserted
replaced
24178:ab892d05b029 | 24179:75021e6fe108 |
---|---|
1073 return false; | 1073 return false; |
1074 } | 1074 } |
1075 | 1075 |
1076 // Locate initial thread stack. This special handling of initial thread stack | 1076 // Locate initial thread stack. This special handling of initial thread stack |
1077 // is needed because pthread_getattr_np() on most (all?) Linux distros returns | 1077 // is needed because pthread_getattr_np() on most (all?) Linux distros returns |
1078 // bogus value for initial thread. | 1078 // bogus value for the primordial process thread. While the launcher has created |
1079 // the VM in a new thread since JDK 6, we still have to allow for the use of the | |
1080 // JNI invocation API from a primordial thread. | |
1079 void os::Linux::capture_initial_stack(size_t max_size) { | 1081 void os::Linux::capture_initial_stack(size_t max_size) { |
1080 // stack size is the easy part, get it from RLIMIT_STACK | 1082 |
1081 size_t stack_size; | 1083 // max_size is either 0 (which means accept OS default for thread stacks) or |
1084 // a user-specified value known to be at least the minimum needed. If we | |
1085 // are actually on the primordial thread we can make it appear that we have a | |
1086 // smaller max_size stack by inserting the guard pages at that location. But we | |
1087 // cannot do anything to emulate a larger stack than what has been provided by | |
1088 // the OS or threading library. In fact if we try to use a stack greater than | |
1089 // what is set by rlimit then we will crash the hosting process. | |
1090 | |
1091 // Maximum stack size is the easy part, get it from RLIMIT_STACK. | |
1092 // If this is "unlimited" then it will be a huge value. | |
1082 struct rlimit rlim; | 1093 struct rlimit rlim; |
1083 getrlimit(RLIMIT_STACK, &rlim); | 1094 getrlimit(RLIMIT_STACK, &rlim); |
1084 stack_size = rlim.rlim_cur; | 1095 size_t stack_size = rlim.rlim_cur; |
1085 | 1096 |
1086 // 6308388: a bug in ld.so will relocate its own .data section to the | 1097 // 6308388: a bug in ld.so will relocate its own .data section to the |
1087 // lower end of primordial stack; reduce ulimit -s value a little bit | 1098 // lower end of primordial stack; reduce ulimit -s value a little bit |
1088 // so we won't install guard page on ld.so's data section. | 1099 // so we won't install guard page on ld.so's data section. |
1089 stack_size -= 2 * page_size(); | 1100 stack_size -= 2 * page_size(); |
1090 | 1101 |
1091 // 4441425: avoid crash with "unlimited" stack size on SuSE 7.1 or Redhat | |
1092 // 7.1, in both cases we will get 2G in return value. | |
1093 // 4466587: glibc 2.2.x compiled w/o "--enable-kernel=2.4.0" (RH 7.0, | |
1094 // SuSE 7.2, Debian) can not handle alternate signal stack correctly | |
1095 // for initial thread if its stack size exceeds 6M. Cap it at 2M, | |
1096 // in case other parts in glibc still assumes 2M max stack size. | |
1097 // FIXME: alt signal stack is gone, maybe we can relax this constraint? | |
1098 // Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small | |
1099 if (stack_size > 2 * K * K IA64_ONLY(*2)) | |
1100 stack_size = 2 * K * K IA64_ONLY(*2); | |
1101 // Try to figure out where the stack base (top) is. This is harder. | 1102 // Try to figure out where the stack base (top) is. This is harder. |
1102 // | 1103 // |
1103 // When an application is started, glibc saves the initial stack pointer in | 1104 // When an application is started, glibc saves the initial stack pointer in |
1104 // a global variable "__libc_stack_end", which is then used by system | 1105 // a global variable "__libc_stack_end", which is then used by system |
1105 // libraries. __libc_stack_end should be pretty close to stack top. The | 1106 // libraries. __libc_stack_end should be pretty close to stack top. The |
1255 } | 1256 } |
1256 | 1257 |
1257 // stack_top could be partially down the page so align it | 1258 // stack_top could be partially down the page so align it |
1258 stack_top = align_size_up(stack_top, page_size()); | 1259 stack_top = align_size_up(stack_top, page_size()); |
1259 | 1260 |
1260 if (max_size && stack_size > max_size) { | 1261 // Allowed stack value is minimum of max_size and what we derived from rlimit |
1261 _initial_thread_stack_size = max_size; | 1262 if (max_size > 0) { |
1263 _initial_thread_stack_size = MIN2(max_size, stack_size); | |
1262 } else { | 1264 } else { |
1263 _initial_thread_stack_size = stack_size; | 1265 // Accept the rlimit max, but if stack is unlimited then it will be huge, so |
1266 // clamp it at 8MB as we do on Solaris | |
1267 _initial_thread_stack_size = MIN2(stack_size, 8*M); | |
1264 } | 1268 } |
1265 | 1269 |
1266 _initial_thread_stack_size = align_size_down(_initial_thread_stack_size, page_size()); | 1270 _initial_thread_stack_size = align_size_down(_initial_thread_stack_size, page_size()); |
1267 _initial_thread_stack_bottom = (address)stack_top - _initial_thread_stack_size; | 1271 _initial_thread_stack_bottom = (address)stack_top - _initial_thread_stack_size; |
1272 assert(_initial_thread_stack_bottom < (address)stack_top, "overflow!"); | |
1268 } | 1273 } |
1269 | 1274 |
1270 //////////////////////////////////////////////////////////////////////////////// | 1275 //////////////////////////////////////////////////////////////////////////////// |
1271 // time support | 1276 // time support |
1272 | 1277 |