[crac] RFR: Correct System.nanotime() value after restore
Radim Vansa
duke at openjdk.org
Thu Mar 23 17:47:12 UTC 2023
On Thu, 23 Mar 2023 17:15:12 GMT, Ashutosh Mehra <duke at openjdk.org> wrote:
>> There are various places both inside JDK and in libraries that rely on monotonicity of `System.nanotime()`. When the process is restored on a different machine the value will likely differ as the implementation provides time since machine boot. This PR records wall clock time before checkpoint and after restore and tries to adjust the value provided by nanotime() to reasonably correct value.
>
> src/hotspot/share/runtime/os.cpp line 2051:
>
>> 2049: diff_millis = 0;
>> 2050: }
>> 2051: javaTimeNanos_offset = checkpoint_nanos - javaTimeNanos() + diff_millis * 1000000L;
>
> Can you please explain why isn't `javaTimeNanos_offset = checkpoint_nanos - javaTimeNanos()` sufficient? What am I missing here?
@ashu-mehra Had we ignored the `diff_millis` part, the diff of nanotime before and after checkpoint would indicate that no time elapsed between checkpoint and restore. With this in place the difference does not have the expected accuracy but at least it's monotonic; wall clock time difference gives us the best possible estimate.
-------------
PR Review Comment: https://git.openjdk.org/crac/pull/53#discussion_r1146570603
More information about the crac-dev
mailing list