JDK-8226219 : [Linux] Park(millis) can use the wrong clock if pthread_condattr_setclock failed
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 8
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: linux
  • Submitted: 2019-06-17
  • Updated: 2019-08-19
  • Resolved: 2019-08-19
Related Reports
Relates :  
Description
In  JDK-6900441 we fixed the park implementation on Linux to use CLOCK_MONOTONIC  using pthread_condattr_setclock, which is now required to be available on all supported Linux platforms. However we also allowed for it to fail at runtime:

+  // Only set the clock if CLOCK_MONOTONIC is available
+  if (Linux::supports_monotonic_clock()) {
+    if ((status = pthread_condattr_setclock(_condattr, CLOCK_MONOTONIC)) != 0) {
+      if (status == EINVAL) {
+        warning("Unable to use monotonic clock with relative timed-waits" \
+                " - changes to the time-of-day clock may have adverse affects");
+      } else {
+        fatal(err_msg("pthread_condattr_setclock: %s", strerror(status)));
+      }
+    }
+  }

If we do hit the EINVAL case we simply print the warning, but computeAbsTime and unpackTime will still calculate relative timeouts using CLOCK_MONOTONIC, which is wrong if the pthread_cond_timedwait is actually going to use CLOCK_REALTIME.
Comments
No plans to address in JDK 8 at this time. Please reopen if require and outline your requirements.
19-08-2019

This problem does not exist in JDK 10+ as the refactoring done by JDK-8174231 addresses this oversight.
17-06-2019