RFR: 8273000: Remove WeakReference-based class initialisation barrier implementation
Vladimir Ivanov
vlivanov at openjdk.java.net
Thu Aug 26 08:20:29 UTC 2021
On Thu, 26 Aug 2021 02:48:38 GMT, David Holmes <dholmes at openjdk.org> wrote:
> I'm unclear exactly what that statement is meant to indicate.
`DirectMethodHandle::checkInitialized()` is dual-purpose: it implements class initialization barrier and reports whether the class is fully initialized, so the barrier can be safely elided.
The call to `Unsafe::ensureClassInitialized()` blocks until initialization is over when the current thread is not the initializing one.
But when call to `Unsafe::ensureClassInitialized()` finished, there are 2 cases possible:
* the class is fully initialized;
* the class is being initialized and the current thread is the initializing one.
In the former case, it's safe to remove the barrier while in the latter the barrier is still required.
Original implementation implemented that in an explicit manner by using `WeakReference`s to record the initializing thread.
But a pair of `Unsafe::ensureClassInitialized()` and `Unsafe::shouldBeInitialized()` calls provides equivalent functionality and is much simpler at the same time.
-------------
PR: https://git.openjdk.java.net/jdk/pull/5258
More information about the core-libs-dev
mailing list