Mac OS X System.nanoTime Improvements

Aleksey Shipilev aleksey.shipilev at oracle.com
Tue May 14 13:53:02 PDT 2013


Welcome to OpenJDK, Dennis!

On 05/15/2013 12:44 AM, Денис Ушаков wrote:
> couple of days ago Aleksey Shipilev mentioned that System.nanoTime() 
> is very slow on OS X and is non-monotonic.

Correction: it is monotonic. It's just not monotonically *increasing*,
because the granularity is around 1us.

> OS X provides a monotonic clock function mach_absolute_time(). 
> According to documentation 
> (https://developer.apple.com/library/mac/#qa/qa1398/_index.html) it 
> can be converted to nanoseconds using results of 
> mach_timebase_info().

Any clue how this performs with the CPU power management interventions?

> Here's draft patch that uses mach_absolute_time() to provide fast
> and monotonic System.nanoTime() for OS X: 
> https://gist.github.com/denofevil/db57fa547510b2dd87fd

While others can have the proper review done, there are couple of steps
required to contribute the code to OpenJDK:
  http://openjdk.java.net/contribute/

At least two things:
  a) Signed OCA
  b) Webrev/hg patch for the changeset

> You can find benchmark written by Aleksey Shipilev here: 
> https://github.com/shipilev/jmh-nanotime. Benchmark results with 
> system specs: https://gist.github.com/denofevil/5026294ee6de42699b41

These *are* impressive. These granularities are actually on-par with my
bleeding edge Linux/OpenJDK.

Thanks,
Aleksey.


More information about the hotspot-dev mailing list