On Thu, 18 Nov 2021 14:53:38 GMT, Peter Levart <plev...@openjdk.org> wrote:

>> I think @shipilev asks a good question. This could be done completely in the 
>> VM without the changes to j.l.ref.Finalizer. The CLI option is for 
>> experimenting, at least in the short term, and should be benign to have the 
>> Finalizer thread running, it just won't do anything.
>
> Or, you could move the static initialization block that statrts the finalizer 
> thread into the Finalizer.FinalizerThread class itself and then arrange for 
> that class to be initialized explicitly immediately after the Finalizer 
> class, but conditionally, only if the option to disable finalization was not 
> specified...
> This way the Finalizer class could still be initialized early, but the thread 
> would not be started if it is not needed.

If you then need this "flag" in the assert of registerFinalizer and 
runFinalization, you could use 
unsafe.shouldBeInitialized(Finalizer.FinalizerThread.class) as a means to find 
out whether the flag was set or not...

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

PR: https://git.openjdk.java.net/jdk/pull/6442

Reply via email to