Can nanoTime be non-monotonic?

Jaromir Hamala jaromir.hamala at gmail.com
Wed Jun 4 22:16:01 UTC 2025


A few years ago, I was wondering the same, so I did some research and wrote
a blog:
https://www.javaadvent.com/2019/12/measuring-time-from-java-to-kernel-and-back.html

tl;dr: you should be good. tsc is sync'ed across cores since Nehalem

On Wed, Jun 4, 2025 at 7:48 PM Pavel Rappo <pavel.rappo at gmail.com> wrote:

> I was reading a book that refers to this 2015 post claiming that
> nanoTime can be non-monotonic:
>
> https://steveloughran.blogspot.com/2015/09/time-on-multi-core-multi-socket-servers.html
>
> In fact, I'm not sure what the claim actually is, as the author is a
> bit vague. It's unclear whether they say that they have actually
> observed it, or they just strongly suspect that it's possible.
>
> Has non-monotonicity ever been observed by hotspot developers? Can it
> be observed on a modern hardware + JVM?
>
> Thanks,
> -Pavel
>


-- 
“Perfection is achieved, not when there is nothing more to add, but when
there is nothing left to take away.”
Antoine de Saint Exupéry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/hotspot-runtime-dev/attachments/20250605/44ab4d1f/attachment-0001.htm>


More information about the hotspot-runtime-dev mailing list