JDK-6491083 : ThreadMXBean.getCurrentThreadCpuTime() should use the posix clock implementation on Linux
  • Type: Bug
  • Component: hotspot
  • Sub-Component: svc
  • Affected Version: 6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-11-07
  • Updated: 2011-09-22
  • Resolved: 2006-12-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7 Other
6u4Fixed 7Fixed hs10Fixed
Related Reports
Relates :  
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.

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.

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.

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 ] ###@###.###

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.