RFR: 8329968: os::random should be random

Thomas Stuefe stuefe at openjdk.org
Mon May 27 09:08:26 UTC 2024


Hi,

This change ensures that the random seed of os::random is initialized randomly. Before this patch, every sequence of os::random calls gave the same results. With this patch, a quasi-random seed based on javaTimeNanos is used.

Where this matters the most:

- Random distribution of ihashes. Atm, ihashes are always the same for the same sequence of System.identityHashCode.

- We use os::random to fuzzing gtests. This is the part most important to me. I want gtest tests that use os::random for stress testing data structures to be as efficient as possible in tickling out pathological behavior.

Note that this issue turned out to be much more controversial than I expected. Please see pro- and con-arguments in JBS comment section. I would like a consensus on this issue before pushing the fix (pinging @dholmes). If we cannot agree that this needs fixing, I'd be content with at least the gtests being random. So, a smaller version of this change would be to use a separate random seed for gtests.

--

Interesting side note: Not only does os::random() repeat the random sequences on each run, its RNG is also pretty bad at distribution. I opened https://bugs.openjdk.org/browse/JDK-8332965 to track that problem. These issues affect each other, since if we were to vary the seed, it would at least shuffle the distribution peaks a bit on each run.

---

Tests:
- tested that the regression test fails with Stock JVM, passes with patched JVM
- GHAs
(will do more tests to see if the new randomness shakes lose bugs. However, before investing the work I'd like consensus that this PR can go forward)

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

Commit messages:
 - fixes and simplications
 - Merge branch 'openjdk:master' into JDK-8329968
 - start

Changes: https://git.openjdk.org/jdk/pull/18702/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=18702&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8329968
  Stats: 82 lines in 3 files changed: 82 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/18702.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18702/head:pull/18702

PR: https://git.openjdk.org/jdk/pull/18702


More information about the hotspot-runtime-dev mailing list