これらは JSR-174 標準のスレッドアカウンティング機能, および HotSpot 独自のアカウンティング機能. このうち HotSpot 独自のメソッド (= com.sun.management.ThreadMXBean で追加されているメソッド) は以下の 2つ.
ただし, どのメソッドも最終的には各 OS が提供しているアカウンティング機能を呼び出すだけ. より具体的に言うと, 各 OS の以下の機能を利用する (See: os::current_thread_cpu_time(), os::thread_cpu_time()).
Solaris
Linux
Windows
((cite: hotspot/src/share/vm/runtime/os.hpp))
// JVMTI & JVM monitoring and management support
// The thread_cpu_time() and current_thread_cpu_time() are only
// supported if is_thread_cpu_time_supported() returns true.
// They are not supported on Solaris T1.
// Thread CPU Time - return the fast estimate on a platform
// On Solaris - call gethrvtime (fast) - user time only
// On Linux - fast clock_gettime where available - user+sys
// - otherwise: very slow /proc fs - user+sys
// On Windows - GetThreadTimes - user+sys
static jlong current_thread_cpu_time();
static jlong thread_cpu_time(Thread* t);
// Thread CPU Time with user_sys_cpu_time parameter.
//
// If user_sys_cpu_time is true, user+sys time is returned.
// Otherwise, only user time is returned
static jlong current_thread_cpu_time(bool user_sys_cpu_time);
static jlong thread_cpu_time(Thread* t, bool user_sys_cpu_time);
Solaris 上での実装について:
((cite: hotspot/src/os/solaris/vm/os_solaris.cpp))
// JVMTI & JVM monitoring and management support
// The thread_cpu_time() and current_thread_cpu_time() are only
// supported if is_thread_cpu_time_supported() returns true.
// They are not supported on Solaris T1.
// current_thread_cpu_time(bool) and thread_cpu_time(Thread*, bool)
// are used by JVM M&M and JVMTI to get user+sys or user CPU time
// of a thread.
//
// current_thread_cpu_time() and thread_cpu_time(Thread *)
// returns the fast estimate available on the platform.
sun.management.ThreadImpl.getCurrentThreadCpuTime() -> sun.management.ThreadImpl.getThreadTotalCpuTime0() -> Java_sun_management_ThreadImpl_getThreadTotalCpuTime0() -> jmm_GetThreadCpuTimeWithKind() 以下のどちらかを呼び出す. -> os::current_thread_cpu_time() -> os::thread_cpu_time()
sun.management.ThreadImpl.getThreadCpuTime(long id) -> sun.management.ThreadImpl.getThreadCpuTime(long[] ids) 以下のどちらかを呼び出す. -> sun.management.ThreadImpl.getThreadTotalCpuTime0() -> (同上) -> sun.management.ThreadImpl.getThreadTotalCpuTime1() -> Java_sun_management_ThreadImpl_getThreadTotalCpuTime1() -> jmm_GetThreadCpuTimesWithKind() -> os::thread_cpu_time()
sun.management.ThreadImpl.getThreadCpuTime(long[] ids) -> (同上)
sun.management.ThreadImpl.getCurrentThreadUserTime() -> sun.management.ThreadImpl.getThreadUserCpuTime0() -> Java_sun_management_ThreadImpl_getThreadUserCpuTime0() -> jmm_GetThreadCpuTimeWithKind() -> (同上)
sun.management.ThreadImpl.getThreadUserTime(long id) -> sun.management.ThreadImpl.getThreadUserTime(long[] ids) 以下のどちらかを呼び出す. -> sun.management.ThreadImpl.getThreadUserCpuTime0() -> (同上) -> sun.management.ThreadImpl.getThreadUserCpuTime1() -> Java_sun_management_ThreadImpl_getThreadUserCpuTime1() -> jmm_GetThreadCpuTimesWithKind() -> (同上)
sun.management.ThreadImpl.getThreadUserTime(long[] ids) -> (同上)
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.