os::javaTimeSystemUTC to call nanosecond precision OS API, so Clock.systemUTC() can give nanosecond precision UTC

Florian Weimer fw at deneb.enyo.de
Wed Apr 15 09:47:27 UTC 2020


* Florian Weimer:

> * Mark Kralj-Taylor:
>
>> The wording of Linux docs suggests that clock_gettime(CLOCK_REALTIME)
>> should be supported if the clock_gettime() API exists. But other clock
>> sources are not mandatory.
>
> Really old glibc emulates clock_gettime (CLOCK_REALTIME) using
> gettimeofday, yes.
>
> clock_gettime was already in Linux 2.12 (and possibly quite a bit

That should have been Linux 2.6.12, sorry.

> earlier, I did not check), so that is not likely to be a limitation.
>
> A tricky question is whether it's possible to avoid loading librt.
> The present code already uses dlopen, but I think it could try a
> little bit harder (try resolving clock_gettime first, and then load
> librt, and try again).  For distribution builds that do not need to be
> compatible with glibc versions before 2.17, directly calling
> clock_gettime would also be an option. (clock_gettime moved to
> libc.so.6 in glibc 2.17, but a lot of software keeps linking against
> librt for the definition of clock_gettime, something that we are
> finally tackling on the glibc side.)
>
> Making a direct system call instead is a bit tricky because it's
> absolutely required to use the vDSO if possible, for performance
> reasons.  But it's possible to obtain the address of the vDSO function
> using dlvsym, so that might be an option as well.


More information about the hotspot-runtime-dev mailing list