[Bug 300333] java/openjdk25: getCurrentThreadCpuTime() does not return the actual time in nanoseconds

From: <bugzilla-noreply_at_freebsd.org>
Date: Mon, 02 Nov 2026 13:48:36 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300333

--- Comment #2 from Harald Eilertsen <haraldei@FreeBSD.org> ---
I think the JVM code is correct. It uses the `clock_gettime(2)` call which (at
least on my test system) reports a resolution of 41ns. Which means if the loop
runs faster than 41ns it will result in a delta of 0.

I get comparable results with a small C++ test program running the same test.
I'll attach it here for reference.

Adding a small delay to the loop to slow it down a bit gives more accurate
results.

Also note that while `ThreadMXBean.getCurrentThreadCpuTime()` returns a result
with nanosecond resolution, it does not guarantee nanosecond accuracy.

-- 
You are receiving this mail because:
You are on the CC list for the bug.