Mac OS X System.nanoTime Improvements

Денис Ушаков dennis.ushakov at
Tue May 14 13:44:05 PDT 2013


couple of days ago Aleksey Shipilev mentioned that System.nanoTime() is very slow on OS X and is non-monotonic. After some research I found that there's no clock_gettime() function in OS X and current implementation falls back to gettimeofday().

OS X provides a monotonic clock function mach_absolute_time(). According to documentation ( it can be converted to nanoseconds using results of mach_timebase_info().

Here's draft patch that uses mach_absolute_time() to provide fast and monotonic System.nanoTime() for OS X:

You can find benchmark written by Aleksey Shipilev here:
Benchmark results with system specs:


More information about the hotspot-dev mailing list