comparison src/os/linux/vm/os_linux.cpp @ 8099:4c1d8002ffb1

8004495: [parfait] False positive Buffer overflow in hotspot/src/os/linux/vm/os_linux.cpp Summary: Delete the questionable source code because it is for no-longer supported versions of Linux. Reviewed-by: mikael, coleenp
author hseigel
date Wed, 20 Feb 2013 07:16:23 -0500
parents 5cd2fac2ae70
children 5fc51c1ecdeb 63e54c37ac64
comparison
equal deleted inserted replaced
8069:1048edb5434a 8099:4c1d8002ffb1
4741 // 4741 //
4742 // -1 on error. 4742 // -1 on error.
4743 // 4743 //
4744 4744
4745 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) {
4746 static bool proc_pid_cpu_avail = true;
4747 static bool proc_task_unchecked = true; 4746 static bool proc_task_unchecked = true;
4748 static const char *proc_stat_path = "/proc/%d/stat"; 4747 static const char *proc_stat_path = "/proc/%d/stat";
4749 pid_t tid = thread->osthread()->thread_id(); 4748 pid_t tid = thread->osthread()->thread_id();
4750 int i;
4751 char *s; 4749 char *s;
4752 char stat[2048]; 4750 char stat[2048];
4753 int statlen; 4751 int statlen;
4754 char proc_name[64]; 4752 char proc_name[64];
4755 int count; 4753 int count;
4756 long sys_time, user_time; 4754 long sys_time, user_time;
4757 char string[64];
4758 char cdummy; 4755 char cdummy;
4759 int idummy; 4756 int idummy;
4760 long ldummy; 4757 long ldummy;
4761 FILE *fp; 4758 FILE *fp;
4762 4759
4763 // We first try accessing /proc/<pid>/cpu since this is faster to
4764 // process. If this file is not present (linux kernels 2.5 and above)
4765 // then we open /proc/<pid>/stat.
4766 if ( proc_pid_cpu_avail ) {
4767 sprintf(proc_name, "/proc/%d/cpu", tid);
4768 fp = fopen(proc_name, "r");
4769 if ( fp != NULL ) {
4770 count = fscanf( fp, "%s %lu %lu\n", string, &user_time, &sys_time);
4771 fclose(fp);
4772 if ( count != 3 ) return -1;
4773
4774 if (user_sys_cpu_time) {
4775 return ((jlong)sys_time + (jlong)user_time) * (1000000000 / clock_tics_per_sec);
4776 } else {
4777 return (jlong)user_time * (1000000000 / clock_tics_per_sec);
4778 }
4779 }
4780 else proc_pid_cpu_avail = false;
4781 }
4782
4783 // The /proc/<tid>/stat aggregates per-process usage on 4760 // The /proc/<tid>/stat aggregates per-process usage on
4784 // new Linux kernels 2.6+ where NPTL is supported. 4761 // new Linux kernels 2.6+ where NPTL is supported.
4785 // 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.
4786 // See bug 6328462. 4763 // See bug 6328462.
4787 // 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
4788 // and possibly in some other cases, so we check its availability. 4765 // /proc/self/task, so we check its availability.
4789 if (proc_task_unchecked && os::Linux::is_NPTL()) { 4766 if (proc_task_unchecked && os::Linux::is_NPTL()) {
4790 // This is executed only once 4767 // This is executed only once
4791 proc_task_unchecked = false; 4768 proc_task_unchecked = false;
4792 fp = fopen("/proc/self/task", "r"); 4769 fp = fopen("/proc/self/task", "r");
4793 if (fp != NULL) { 4770 if (fp != NULL) {
4808 // 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
4809 // 1234 (java 1.4.2 :)) R ... ... 4786 // 1234 (java 1.4.2 :)) R ... ...
4810 // 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
4811 // occurrence of ")" and then start parsing from there. See bug 4726580. 4788 // occurrence of ")" and then start parsing from there. See bug 4726580.
4812 s = strrchr(stat, ')'); 4789 s = strrchr(stat, ')');
4813 i = 0;
4814 if (s == NULL ) return -1; 4790 if (s == NULL ) return -1;
4815 4791
4816 // Skip blank chars 4792 // Skip blank chars
4817 do s++; while (isspace(*s)); 4793 do s++; while (isspace(*s));
4818 4794