JDK using gettimeofday and not clock_gettime?

Rohit Mohta rmohta.coder at gmail.com
Fri Jul 23 17:53:47 UTC 2021


Thank you David. I see clock_gettime in JDK 17 branch in os_posix.cpp. 

------
Rohit Mohta

> On Jul 23, 2021, at 06:40, David Holmes <david.holmes at oracle.com> wrote:
> 
> 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