jmx-dev RFR: 8351359: OperatingSystemMXBean: values from getCpuLoad and getProcessCpuLoad are stale after 24.8 days (Windows)

Alex Menkov amenkov at openjdk.org
Wed May 7 00:41:18 UTC 2025


On Tue, 6 May 2025 10:20:22 GMT, Kevin Walls <kevinw at openjdk.org> wrote:

> OperatingSystemImpl.c on Windows is limited by its use of clock(), which hits its limit with longer process uptimes.
> 
> https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/clock?view=msvc-170
> "maximum clock function return value of 2147483.647 seconds, or about 24.8 days"
> 
> The linked alternative, time(), gives 64-bit time but only seconds.  In the example code for time(), there is use of _ftime() to retrieve milliseconds.
> 
> The example code also notes that _ftime is deprecated, so _ftime_s is used here.

I'm not sure use current system time here is a good idea. system time may be updated (manually or automatically) and this will break the logic (if you change system time 1 hour back, there will be no updates for the next hour..)
May be use `GetTickCount`? it's low-res (10ms IIRC), but it's ok for the case.
It overflows in 50 days, but there is no problem is you use DWORD arithmetic. Or newer `GetTickCount64` (available from Vista) may be used instead.

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

PR Comment: https://git.openjdk.org/jdk/pull/25062#issuecomment-2856684373


More information about the jmx-dev mailing list