48 ms·
I'm surprised that Java uses gettimeofday (equivalent to CLOCK_REALTIME in clock_gettime calls) instead of CLOCK_REALTIME_COARSE for os::javaTimeMillis(). IIRC
by lifthrasiir 5y ago
I'm surprised that Java uses gettimeofday (equivalent to CLOCK_REALTIME in clock_gettime calls) instead of CLOCK_REALTIME_COARSE for os::javaTimeMillis(). IIRC the resolution of the coarse clock has been 1 ms since around Linux 3.0 and it can avoid most system calls even if the underlying clock source needs them. Of course it can't be used if you need sub-ms resolution, but the function name clearly suggests that it only needs millisecond resolution (as per System.currentTimeMillis) so using a plain gettimeofday seems inefficient. For the reference, glibc implementation of time() (which has 1 second resolution) internally uses coarse clocks.
- saagarjha 5y agoPerhaps some useful background: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8185891 https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-818... (historically, the blog post triggering this bug report came after this investigation, but I guess before publication.)