comparison src/os/linux/vm/os_linux.cpp @ 8124:5fc51c1ecdeb

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 05 Mar 2013 23:44:54 +0100
parents 3ac7d10a6572 4c1d8002ffb1
children b8f261ba79c6
comparison
equal deleted inserted replaced
7943:a413bcd552a4 8124:5fc51c1ecdeb
1153 // 4466587: glibc 2.2.x compiled w/o "--enable-kernel=2.4.0" (RH 7.0, 1153 // 4466587: glibc 2.2.x compiled w/o "--enable-kernel=2.4.0" (RH 7.0,
1154 // SuSE 7.2, Debian) can not handle alternate signal stack correctly 1154 // SuSE 7.2, Debian) can not handle alternate signal stack correctly
1155 // for initial thread if its stack size exceeds 6M. Cap it at 2M, 1155 // for initial thread if its stack size exceeds 6M. Cap it at 2M,
1156 // in case other parts in glibc still assumes 2M max stack size. 1156 // in case other parts in glibc still assumes 2M max stack size.
1157 // FIXME: alt signal stack is gone, maybe we can relax this constraint? 1157 // FIXME: alt signal stack is gone, maybe we can relax this constraint?
1158 #ifndef IA64
1159 if (stack_size > 2 * K * K) stack_size = 2 * K * K;
1160 #else
1161 // Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small 1158 // Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small
1162 if (stack_size > 4 * K * K) stack_size = 4 * K * K; 1159 if (stack_size > 2 * K * K IA64_ONLY(*2))
1163 #endif 1160 stack_size = 2 * K * K IA64_ONLY(*2);
1164
1165 // Try to figure out where the stack base (top) is. This is harder. 1161 // Try to figure out where the stack base (top) is. This is harder.
1166 // 1162 //
1167 // When an application is started, glibc saves the initial stack pointer in 1163 // When an application is started, glibc saves the initial stack pointer in
1168 // a global variable "__libc_stack_end", which is then used by system 1164 // a global variable "__libc_stack_end", which is then used by system
1169 // libraries. __libc_stack_end should be pretty close to stack top. The 1165 // libraries. __libc_stack_end should be pretty close to stack top. The
3655 JVM_handle_linux_signal(int signo, siginfo_t* siginfo, 3651 JVM_handle_linux_signal(int signo, siginfo_t* siginfo,
3656 void* ucontext, int abort_if_unrecognized); 3652 void* ucontext, int abort_if_unrecognized);
3657 3653
3658 void signalHandler(int sig, siginfo_t* info, void* uc) { 3654 void signalHandler(int sig, siginfo_t* info, void* uc) {
3659 assert(info != NULL && uc != NULL, "it must be old kernel"); 3655 assert(info != NULL && uc != NULL, "it must be old kernel");
3660 ResourceMark rm; 3656 int orig_errno = errno; // Preserve errno value over signal handler.
3661 if (TraceSignals) {
3662 tty->print_cr(err_msg("signal received: code=%d errno=%d signo=%d thread=%s address=%x", info->si_code, info->si_errno, info->si_signo, Thread::current()->name(), info->si_addr));
3663 }
3664 JVM_handle_linux_signal(sig, info, uc, true); 3657 JVM_handle_linux_signal(sig, info, uc, true);
3665 if (TraceSignals) { 3658 errno = orig_errno;
3666 tty->print_cr("signal handled");
3667 }
3668 } 3659 }
3669 3660
3670 3661
3671 // This boolean allows users to forward their own non-matching signals 3662 // This boolean allows users to forward their own non-matching signals
3672 // to JVM_handle_linux_signal, harmlessly. 3663 // to JVM_handle_linux_signal, harmlessly.
4372 int os::Linux::safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime) 4363 int os::Linux::safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime)
4373 { 4364 {
4374 if (is_NPTL()) { 4365 if (is_NPTL()) {
4375 return pthread_cond_timedwait(_cond, _mutex, _abstime); 4366 return pthread_cond_timedwait(_cond, _mutex, _abstime);
4376 } else { 4367 } else {
4377 #ifndef IA64
4378 // 6292965: LinuxThreads pthread_cond_timedwait() resets FPU control 4368 // 6292965: LinuxThreads pthread_cond_timedwait() resets FPU control
4379 // word back to default 64bit precision if condvar is signaled. Java 4369 // word back to default 64bit precision if condvar is signaled. Java
4380 // wants 53bit precision. Save and restore current value. 4370 // wants 53bit precision. Save and restore current value.
4381 int fpu = get_fpu_control_word(); 4371 int fpu = get_fpu_control_word();
4382 #endif // IA64
4383 int status = pthread_cond_timedwait(_cond, _mutex, _abstime); 4372 int status = pthread_cond_timedwait(_cond, _mutex, _abstime);
4384 #ifndef IA64
4385 set_fpu_control_word(fpu); 4373 set_fpu_control_word(fpu);
4386 #endif // IA64
4387 return status; 4374 return status;
4388 } 4375 }
4389 } 4376 }
4390 4377
4391 //////////////////////////////////////////////////////////////////////////////// 4378 ////////////////////////////////////////////////////////////////////////////////
4754 // 4741 //
4755 // -1 on error. 4742 // -1 on error.
4756 // 4743 //
4757 4744
4758 static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) { 4745 static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
4759 static bool proc_pid_cpu_avail = true;
4760 static bool proc_task_unchecked = true; 4746 static bool proc_task_unchecked = true;
4761 static const char *proc_stat_path = "/proc/%d/stat"; 4747 static const char *proc_stat_path = "/proc/%d/stat";
4762 pid_t tid = thread->osthread()->thread_id(); 4748 pid_t tid = thread->osthread()->thread_id();
4763 int i;
4764 char *s; 4749 char *s;
4765 char stat[2048]; 4750 char stat[2048];
4766 int statlen; 4751 int statlen;
4767 char proc_name[64]; 4752 char proc_name[64];
4768 int count; 4753 int count;
4769 long sys_time, user_time; 4754 long sys_time, user_time;
4770 char string[64];
4771 char cdummy; 4755 char cdummy;
4772 int idummy; 4756 int idummy;
4773 long ldummy; 4757 long ldummy;
4774 FILE *fp; 4758 FILE *fp;
4775 4759
4776 // We first try accessing /proc/<pid>/cpu since this is faster to
4777 // process. If this file is not present (linux kernels 2.5 and above)
4778 // then we open /proc/<pid>/stat.
4779 if ( proc_pid_cpu_avail ) {
4780 sprintf(proc_name, "/proc/%d/cpu", tid);
4781 fp = fopen(proc_name, "r");
4782 if ( fp != NULL ) {
4783 count = fscanf( fp, "%s %lu %lu\n", string, &user_time, &sys_time);
4784 fclose(fp);
4785 if ( count != 3 ) return -1;
4786
4787 if (user_sys_cpu_time) {
4788 return ((jlong)sys_time + (jlong)user_time) * (1000000000 / clock_tics_per_sec);
4789 } else {
4790 return (jlong)user_time * (1000000000 / clock_tics_per_sec);
4791 }
4792 }
4793 else proc_pid_cpu_avail = false;
4794 }
4795
4796 // The /proc/<tid>/stat aggregates per-process usage on 4760 // The /proc/<tid>/stat aggregates per-process usage on
4797 // new Linux kernels 2.6+ where NPTL is supported. 4761 // new Linux kernels 2.6+ where NPTL is supported.
4798 // The /proc/self/task/<tid>/stat still has the per-thread usage. 4762 // The /proc/self/task/<tid>/stat still has the per-thread usage.
4799 // See bug 6328462. 4763 // See bug 6328462.
4800 // There can be no directory /proc/self/task on kernels 2.4 with NPTL 4764 // There possibly can be cases where there is no directory
4801 // and possibly in some other cases, so we check its availability. 4765 // /proc/self/task, so we check its availability.
4802 if (proc_task_unchecked && os::Linux::is_NPTL()) { 4766 if (proc_task_unchecked && os::Linux::is_NPTL()) {
4803 // This is executed only once 4767 // This is executed only once
4804 proc_task_unchecked = false; 4768 proc_task_unchecked = false;
4805 fp = fopen("/proc/self/task", "r"); 4769 fp = fopen("/proc/self/task", "r");
4806 if (fp != NULL) { 4770 if (fp != NULL) {
4821 // to "java 1.4.2 :)", then the stat file would look like 4785 // to "java 1.4.2 :)", then the stat file would look like
4822 // 1234 (java 1.4.2 :)) R ... ... 4786 // 1234 (java 1.4.2 :)) R ... ...
4823 // We don't really need to know the command string, just find the last 4787 // We don't really need to know the command string, just find the last
4824 // occurrence of ")" and then start parsing from there. See bug 4726580. 4788 // occurrence of ")" and then start parsing from there. See bug 4726580.
4825 s = strrchr(stat, ')'); 4789 s = strrchr(stat, ')');
4826 i = 0;
4827 if (s == NULL ) return -1; 4790 if (s == NULL ) return -1;
4828 4791
4829 // Skip blank chars 4792 // Skip blank chars
4830 do s++; while (isspace(*s)); 4793 do s++; while (isspace(*s));
4831 4794