src/os/linux/vm/os_linux.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 6518907 Sdiff src/os/linux/vm

src/os/linux/vm/os_linux.cpp

Print this page




1157 // bogus value for initial thread.
1158 void os::Linux::capture_initial_stack(size_t max_size) {
1159   // stack size is the easy part, get it from RLIMIT_STACK
1160   size_t stack_size;
1161   struct rlimit rlim;
1162   getrlimit(RLIMIT_STACK, &rlim);
1163   stack_size = rlim.rlim_cur;
1164 
1165   // 6308388: a bug in ld.so will relocate its own .data section to the
1166   //   lower end of primordial stack; reduce ulimit -s value a little bit
1167   //   so we won't install guard page on ld.so's data section.
1168   stack_size -= 2 * page_size();
1169 
1170   // 4441425: avoid crash with "unlimited" stack size on SuSE 7.1 or Redhat
1171   //   7.1, in both cases we will get 2G in return value.
1172   // 4466587: glibc 2.2.x compiled w/o "--enable-kernel=2.4.0" (RH 7.0,
1173   //   SuSE 7.2, Debian) can not handle alternate signal stack correctly
1174   //   for initial thread if its stack size exceeds 6M. Cap it at 2M,
1175   //   in case other parts in glibc still assumes 2M max stack size.
1176   // FIXME: alt signal stack is gone, maybe we can relax this constraint?
1177 #ifndef IA64
1178   if (stack_size > 2 * K * K) stack_size = 2 * K * K;
1179 #else
1180   // Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small
1181   if (stack_size > 4 * K * K) stack_size = 4 * K * K;
1182 #endif
1183 
1184   // Try to figure out where the stack base (top) is. This is harder.
1185   //
1186   // When an application is started, glibc saves the initial stack pointer in
1187   // a global variable "__libc_stack_end", which is then used by system
1188   // libraries. __libc_stack_end should be pretty close to stack top. The
1189   // variable is available since the very early days. However, because it is
1190   // a private interface, it could disappear in the future.
1191   //
1192   // Linux kernel saves start_stack information in /proc/<pid>/stat. Similar
1193   // to __libc_stack_end, it is very close to stack top, but isn't the real
1194   // stack top. Note that /proc may not exist if VM is running as a chroot
1195   // program, so reading /proc/<pid>/stat could fail. Also the contents of
1196   // /proc/<pid>/stat could change in the future (though unlikely).
1197   //
1198   // We try __libc_stack_end first. If that doesn't work, look for
1199   // /proc/<pid>/stat. If neither of them works, we use current stack pointer
1200   // as a hint, which should work well in most cases.
1201 
1202   uintptr_t stack_start;
1203 


4372   if (do_suspend(osthread)) {
4373     if (osthread->ucontext() != NULL) {
4374       epc = os::Linux::ucontext_get_pc(osthread->ucontext());
4375     } else {
4376       // NULL context is unexpected, double-check this is the VMThread
4377       guarantee(thread->is_VM_thread(), "can only be called for VMThread");
4378     }
4379     do_resume(osthread);
4380   }
4381   // failure means pthread_kill failed for some reason - arguably this is
4382   // a fatal problem, but such problems are ignored elsewhere
4383 
4384   return epc;
4385 }
4386 
4387 int os::Linux::safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime)
4388 {
4389    if (is_NPTL()) {
4390       return pthread_cond_timedwait(_cond, _mutex, _abstime);
4391    } else {
4392 #ifndef IA64
4393       // 6292965: LinuxThreads pthread_cond_timedwait() resets FPU control
4394       // word back to default 64bit precision if condvar is signaled. Java
4395       // wants 53bit precision.  Save and restore current value.
4396       int fpu = get_fpu_control_word();
4397 #endif // IA64
4398       int status = pthread_cond_timedwait(_cond, _mutex, _abstime);
4399 #ifndef IA64
4400       set_fpu_control_word(fpu);
4401 #endif // IA64
4402       return status;
4403    }
4404 }
4405 
4406 ////////////////////////////////////////////////////////////////////////////////
4407 // debug support
4408 
4409 static address same_page(address x, address y) {
4410   int page_bits = -os::vm_page_size();
4411   if ((intptr_t(x) & page_bits) == (intptr_t(y) & page_bits))
4412     return x;
4413   else if (x > y)
4414     return (address)(intptr_t(y) | ~page_bits) + 1;
4415   else
4416     return (address)(intptr_t(y) & page_bits);
4417 }
4418 
4419 bool os::find(address addr, outputStream* st) {
4420   Dl_info dlinfo;
4421   memset(&dlinfo, 0, sizeof(dlinfo));




1157 // bogus value for initial thread.
1158 void os::Linux::capture_initial_stack(size_t max_size) {
1159   // stack size is the easy part, get it from RLIMIT_STACK
1160   size_t stack_size;
1161   struct rlimit rlim;
1162   getrlimit(RLIMIT_STACK, &rlim);
1163   stack_size = rlim.rlim_cur;
1164 
1165   // 6308388: a bug in ld.so will relocate its own .data section to the
1166   //   lower end of primordial stack; reduce ulimit -s value a little bit
1167   //   so we won't install guard page on ld.so's data section.
1168   stack_size -= 2 * page_size();
1169 
1170   // 4441425: avoid crash with "unlimited" stack size on SuSE 7.1 or Redhat
1171   //   7.1, in both cases we will get 2G in return value.
1172   // 4466587: glibc 2.2.x compiled w/o "--enable-kernel=2.4.0" (RH 7.0,
1173   //   SuSE 7.2, Debian) can not handle alternate signal stack correctly
1174   //   for initial thread if its stack size exceeds 6M. Cap it at 2M,
1175   //   in case other parts in glibc still assumes 2M max stack size.
1176   // FIXME: alt signal stack is gone, maybe we can relax this constraint?



1177   // Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small
1178   if (stack_size > 2 * K * K IA64_ONLY(*2))
1179       stack_size = 2 * K * K IA64_ONLY(*2);

1180   // Try to figure out where the stack base (top) is. This is harder.
1181   //
1182   // When an application is started, glibc saves the initial stack pointer in
1183   // a global variable "__libc_stack_end", which is then used by system
1184   // libraries. __libc_stack_end should be pretty close to stack top. The
1185   // variable is available since the very early days. However, because it is
1186   // a private interface, it could disappear in the future.
1187   //
1188   // Linux kernel saves start_stack information in /proc/<pid>/stat. Similar
1189   // to __libc_stack_end, it is very close to stack top, but isn't the real
1190   // stack top. Note that /proc may not exist if VM is running as a chroot
1191   // program, so reading /proc/<pid>/stat could fail. Also the contents of
1192   // /proc/<pid>/stat could change in the future (though unlikely).
1193   //
1194   // We try __libc_stack_end first. If that doesn't work, look for
1195   // /proc/<pid>/stat. If neither of them works, we use current stack pointer
1196   // as a hint, which should work well in most cases.
1197 
1198   uintptr_t stack_start;
1199 


4368   if (do_suspend(osthread)) {
4369     if (osthread->ucontext() != NULL) {
4370       epc = os::Linux::ucontext_get_pc(osthread->ucontext());
4371     } else {
4372       // NULL context is unexpected, double-check this is the VMThread
4373       guarantee(thread->is_VM_thread(), "can only be called for VMThread");
4374     }
4375     do_resume(osthread);
4376   }
4377   // failure means pthread_kill failed for some reason - arguably this is
4378   // a fatal problem, but such problems are ignored elsewhere
4379 
4380   return epc;
4381 }
4382 
4383 int os::Linux::safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime)
4384 {
4385    if (is_NPTL()) {
4386       return pthread_cond_timedwait(_cond, _mutex, _abstime);
4387    } else {

4388       // 6292965: LinuxThreads pthread_cond_timedwait() resets FPU control
4389       // word back to default 64bit precision if condvar is signaled. Java
4390       // wants 53bit precision.  Save and restore current value.
4391       int fpu = get_fpu_control_word();

4392       int status = pthread_cond_timedwait(_cond, _mutex, _abstime);

4393       set_fpu_control_word(fpu);

4394       return status;
4395    }
4396 }
4397 
4398 ////////////////////////////////////////////////////////////////////////////////
4399 // debug support
4400 
4401 static address same_page(address x, address y) {
4402   int page_bits = -os::vm_page_size();
4403   if ((intptr_t(x) & page_bits) == (intptr_t(y) & page_bits))
4404     return x;
4405   else if (x > y)
4406     return (address)(intptr_t(y) | ~page_bits) + 1;
4407   else
4408     return (address)(intptr_t(y) & page_bits);
4409 }
4410 
4411 bool os::find(address addr, outputStream* st) {
4412   Dl_info dlinfo;
4413   memset(&dlinfo, 0, sizeof(dlinfo));


src/os/linux/vm/os_linux.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File