RFR: 8357539: TimeSource.now() is not monotonic

Daniel Fuchs dfuchs at openjdk.org
Thu May 22 10:55:03 UTC 2025


On Thu, 22 May 2025 10:35:57 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:

>> src/java.net.http/share/classes/jdk/internal/net/http/common/TimeSource.java line 97:
>> 
>>> 95:         // use localSource if possible to avoid a volatile read
>>> 96:         if (source.isInWindow(delay)) {
>>> 97:             return source.instant(nanos);
>> 
>> I would keep the two args intant() method which avoids computing the delay twice. Using a local variable `source` in this method should be enough to solve the bug.
>
> Hello Daniel, with this proposed change, is there any reason to have the `localSource` field in this `TimeSource` anymore?

Yes. It avoids the volatile read on nanoSource.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25390#discussion_r2102262966


More information about the net-dev mailing list