United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6491083 ThreadMXBean.getCurrentThreadCpuTime() should use the posix clock implementation on Linux
JDK-6491083 : ThreadMXBean.getCurrentThreadCpuTime() should use the posix clock implementation on Linux

Details
Type:
Bug
Submit Date:
2006-11-07
Status:
Resolved
Updated Date:
2011-09-22
Project Name:
JDK
Resolved Date:
2006-12-02
Component:
hotspot
OS:
generic
Sub-Component:
svc
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:
hs10 (b03)

Related Reports
Backport:
Backport:
Relates:

Sub Tasks

Description
In JDK 6 b91, we fixed 6200022 to provide a way to use the Linux Posix thread CPU clock. The CPU time implementation is shared by both JVM TI and java.lang.management.  The fix was only made to JVM TI but not java.lang.management.  We should make the ise of the Linux Posix thread CPU clock for java.lang.management too.

The NetBeans profiler is currently using ThreadMXBean (Java API) to get the CPU time.

                                    

Comments
EVALUATION

Fast thread CPU on Linux can be used when os::current_thread_cpu_time(bool user_sys_cpu_time) is called with user_sys_cpu_time == true.
                                     
2006-11-07
EVALUATION

I have some doubt that maybe we need to use the posix clock implementation
on Linux for ThreadMXBean.getThreadCpuTime() as well.
Then fast posix clock implementation can be used for any thread, not for current only.
                                     
2006-11-15
SUGGESTED FIX

The suggested fix is to update the src/os/linux/vm/os_linux.cpp as follows:

% sccs sccsdiff -c -r1.242 -r1.243 os_linux.cpp

------- os_linux.cpp -------
*** /tmp/geta8042	Wed Nov 15 02:23:50 2006
--- /tmp/getb8042	Wed Nov 15 02:23:50 2006
***************
*** 3627,3633 ****
  }
  
  jlong os::current_thread_cpu_time(bool user_sys_cpu_time) {
!   return os::thread_cpu_time(Thread::current(), user_sys_cpu_time);
  }
  
  //
--- 3627,3637 ----
  }
  
  jlong os::current_thread_cpu_time(bool user_sys_cpu_time) {
!   if (user_sys_cpu_time && os::Linux::supports_fast_thread_cpu_time()) {
!     return os::Linux::fast_thread_cpu_time(CLOCK_THREAD_CPUTIME_ID);
!   } else {
!     return os::thread_cpu_time(Thread::current(), user_sys_cpu_time);
!   }
  }
  
  //

*** (#1 of 1): [ UNSAVED ] ###@###.###
                                     
2006-11-15
SUGGESTED FIX

Finally, we decided to use fast posix clock implementation for "other" threads
as well, not for current thread only.
Please, see the webrev hs_mm.Nov16.tar.gz in attachmnets.
                                     
2006-11-17



Hardware and Software, Engineered to Work Together