JDK using gettimeofday and not clock_gettime?

David Holmes david.holmes at oracle.com
Fri Jul 23 13:40:21 UTC 2021


Hi Rohit,

On 23/07/2021 10:16 pm, Rohit Mohta wrote:
> Hello,
> 
>    While developing an in-house tool on system time related manipulation, we
> learnt Java uses gettimeofday() on linux-x86_64 system call for fetching
> System.currentTimeMillis().

It doesn't in the latest release. Historically we had issues with 
clock_gettime being available at runtime so we used gettimeofday() when 
necessary. That eventually got cleaned up and we assume clock_gettime is 
always available on supported build and runtime platforms. I'm not sure 
if this was fixed for 16 or 17 ... but not backported to 11u.

Cheers,
David

> I was wondering if we thought of using clock_gettime() system call on
> Linux? Or if there are plans to update them to align with the POSIX
> recommendation. From what I can see Golang, Rust are using clock_gettime().
> 
> https://github.com/openjdk/jdk11u/blob/master/src/hotspot/os/linux/os_linux.cpp#L1295-L1300
> int status = gettimeofday(&time, NULL);
> 
> Per https://man7.org/linux/man-pages/man2/settimeofday.2.html
> 
> POSIX.1-2008 marks *gettimeofday*() as obsolete,
>> recommending the use of clock_gettime(2)
>> <https://man7.org/linux/man-pages/man2/clock_gettime.2.html> instead
> 
> 
> Thanks!
> 


More information about the jdk-dev mailing list