RFR: 8338566: Lazy creation of exception instances is not thread safe

Tobias Hartmann thartmann at openjdk.org
Mon Sep 16 12:43:04 UTC 2024


On Thu, 12 Sep 2024 09:48:28 GMT, Dean Long <dlong at openjdk.org> wrote:

>> Thanks for looking into this, David and Dean. Good points, I agree that we would need to make this completely thread-safe to prevent a leak. Looking at the code again, I wonder why we even do all this lazily, especially since we already create `NullPointerException` and `ArithmeticException` eagerly at VM startup:
>> https://github.com/openjdk/jdk/blob/438121be6bdb085fa13ad14ec53b09ecdbd4757d/src/hotspot/share/memory/universe.cpp#L1086-L1089
>> 
>> Couldn't we do the same for `ArrayIndexOutOfBoundsException`, `ArrayStoreException` and `ClassCastException`? This would save us quite some complexity and I think the startup / footprint overhead is negligible.
>
> @TobiHartmann Yes, that seems like the best idea.  I was going to suggest moving the fields into the CompilerThread, which gets rid of the race and limits the redundant objects, but I like your idea better.

@dean-long, @vnkozlov please (re-)approve. Thanks!

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

PR Comment: https://git.openjdk.org/jdk/pull/20950#issuecomment-2352807733


More information about the hotspot-compiler-dev mailing list