RFR: 8329968: os::random should be random

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


On Tue, 9 Apr 2024 16:55:07 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

> 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)

CDS errors will be addressed separately by https://github.com/openjdk/jdk/pull/18735

Linux build error unrelated.

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

PR Comment: https://git.openjdk.org/jdk/pull/18702#issuecomment-2049284714
PR Comment: https://git.openjdk.org/jdk/pull/18702#issuecomment-2133013844


More information about the hotspot-runtime-dev mailing list