RFR: JDK-8276422 Add command-line option to disable finalization [v2]

Peter Levart plevart at openjdk.java.net
Thu Nov 18 14:56:50 UTC 2021


On Thu, 18 Nov 2021 08:39:52 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> Yeah, "flag" is `Holder.ENABLED` here. I mean, are Java methods `registerFinalizer` and `runFinalization` called only by VM? If so, can VM check the whole thing on VM side, without going to Java and asking back from there?
>
> 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.

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

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


More information about the core-libs-dev mailing list