Getting per-thread CPU time on *BSD

Thomas Schatzl thomas.schatzl at oracle.com
Fri Jun 13 13:06:23 UTC 2025


Hi all,

   I am currently looking into making os::get_thread_cpu_time() usable 
on *BSD because we in the gc team would like to use this functionality 
in the future.

The idea is to get an accurate measurement of how much CPU time the GC 
threads take to do heap sizing.

For this reason, for some time there is that 
os::get_thread_cpu_time(Thread*) that returns the user+sys time the 
given thread (id) took since creation API that is unimplemented on *BSD 
except OSX.

Is there something on *BSD that would satisfy the requirements?

I only could find getrusage(RUSAGE_THREAD), that only gets this 
information for the calling thread, which is not enough and too 
complicated/expensive to start the threads themselves. Also it only 
seems to be supported on OpenBSD and FreeBSD.

The method seems also required for JVMTI, JFR, some management API and 
some collectors (Shenandoah uses it), so these are already not working 
optimally or not at all on *BSD.

This would add G1, the default collector, not working as well (or not 
optimally).

Thanks,
   Thomas

(I'm aware that this mailing list might be dead, the last message was 
from 2019, but maybe....)


More information about the bsd-port-dev mailing list