RFR: 8372652: Re-enable LocalRandom clinit after monitor pinning improvements

Patricio Chilano Mateo pchilanomate at openjdk.org
Mon Dec 1 22:33:47 UTC 2025


On Thu, 27 Nov 2025 23:33:56 GMT, Vishal Chand <duke at openjdk.org> wrote:

> This PR re-enables LocalRandom clinit after monitor pinning improvements.
> Enabling this one would start printing random seeds, which is useful for test debugging.

Some comments on this. I think the TODO was inaccurate because JEP491 doesn't help prevent deadlock scenarios involving class initializers. If anything, it introduced additional unmount points, making them more likely. Although this issue has now been mostly fixed with JDK-8369238, there are still some initialization paths where a thread waiting for a class to be initialized might remain pinned (besides the thread executing the class initializer which can never be unmounted). So if we want to be certain that calling `Utils.getRandomInstance` will not lead to a deadlock we need to check for possible unmount points.
The unmount points in [1] and [2] are fine because we implemented a timed-park mechanism for pinned vthreads when there are unmounted vthreads ahead in the monitor queue. This ensures that even if an unmounted vthread is selected as the successor and we run out of carriers, we will not deadlock. So the real problem is with unmount points inside the critical section, since in that case the owner of the monitor could be unmounted and might be unable to run again. For [1] I don't see any, but for [2] I see that we call `Locale.getDefault(Locale.Category.FORMAT)` which calls synchronized method `getFormatLocale()` if `defaultFormatLocale` is not initialized (which I see it's not initialized at startup so we do end up calling it at the `PrintStream.format` call).
We'll probably never encounter this issue in our testing, especially now that 8369238 has been integrated, but I thought it was worth mentioning.

[1] https://github.com/openjdk/jdk/blob/a1cc8f4e4107e361f64cf51ff73985e471cdde03/test/lib/jdk/test/lib/Utils.java#L515
[2] https://github.com/openjdk/jdk/blob/a1cc8f4e4107e361f64cf51ff73985e471cdde03/src/java.base/share/classes/java/io/PrintStream.java#L1159

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

PR Comment: https://git.openjdk.org/jdk/pull/28547#issuecomment-3599239977


More information about the hotspot-dev mailing list