Skip to content

Use monotonic clock for relative timed waits - #17

Merged
guillerodriguez merged 4 commits into
masterfrom
feat/use-monotonic-clock-v4
Aug 12, 2026
Merged

Use monotonic clock for relative timed waits#17
guillerodriguez merged 4 commits into
masterfrom
feat/use-monotonic-clock-v4

Conversation

@guillerodriguez

Copy link
Copy Markdown
Contributor

No description provided.

@guillerodriguez
guillerodriguez requested a review from phvega July 20, 2026 11:21
@guillerodriguez guillerodriguez changed the title Feat/use monotonic clock v4 Feat/use monotonic clock Jul 20, 2026
@guillerodriguez guillerodriguez changed the title Feat/use monotonic clock Use monotonic clock for relative timed waits Jul 20, 2026
phvega
phvega previously approved these changes Jul 24, 2026
@guillerodriguez

Copy link
Copy Markdown
Contributor Author

CI is failing for the OpenJDK builds. It seems to be an unrelated issue (a blocked signals test). Will have a look.

@guillerodriguez

Copy link
Copy Markdown
Contributor Author

See #18.

@guillerodriguez

Copy link
Copy Markdown
Contributor Author

Must rebase on top of master to get the fix from #19.

The timedWaitVMWaitLock macro duplicates the deadline calculation
already implemented by getTimeoutRelative(). Make the macro defer to
the function instead, so relative timeout deadlines are computed in
a single place.

Signed-off-by: Guillermo Rodríguez <grodriguez@ingelabs.com>
The OpenJDK class library code probes CLOCK_MONOTONIC availability
at runtime for use by JVM_NanoTime. Move the probe to common code
(time.c), run it early in the VM initialisation sequence, and expose
it as haveMonotonicClock().

Signed-off-by: Guillermo Rodríguez <grodriguez@ingelabs.com>
Introduce initReltimeCondVar() for initialising condition variables
used with relative timeouts, and use it for all such condvars (the
per-thread wait and park condvars, and VM-internal wait locks).

A timed park (threadPark) can take either a relative timeout or an
absolute wall-clock deadline, but currently both waits share the
per-thread park condvar, and a condvar can only be bound to one clock.
Split it in two: park_cv (relative and untimed parks) and park_cv_abs
(absolute deadlines), choosing the right one when parking. Unparking
signals both; signalling a condvar nobody waits on is harmless and
cheap.

All condvars are still bound to the default realtime clock, so no
change in behaviour; this puts the infrastructure in place for
switching relative timeouts to the monotonic clock.

Signed-off-by: Guillermo Rodríguez <grodriguez@ingelabs.com>
All relative timeouts were computed against the wall clock, so
stepping the system time backward stretched them and stepping it
forward truncated them.

Fix this by binding the condvars used for relative timed waits to
CLOCK_MONOTONIC, if available, and make getTimeoutRelative() use
the same clock when computing the deadline.

If the monotonic clock cannot be used, behaviour is unchanged and
a warning is printed at startup.

Signed-off-by: Guillermo Rodríguez <grodriguez@ingelabs.com>
@guillerodriguez
guillerodriguez force-pushed the feat/use-monotonic-clock-v4 branch from d2166e6 to a6d0f6a Compare August 12, 2026 12:25
@guillerodriguez guillerodriguez linked an issue Aug 12, 2026 that may be closed by this pull request
@guillerodriguez
guillerodriguez merged commit a03c33d into master Aug 12, 2026
5 checks passed
@guillerodriguez
guillerodriguez deleted the feat/use-monotonic-clock-v4 branch August 12, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JamVM relative timed waits are affected by clock changes

2 participants