Finalizer being run while class still in use (escape analysis bug)

Andrew Haley aph at
Thu Oct 11 09:29:11 UTC 2018

On Wed, Oct 10, 2018 at 9:53 AM Kim Barrett <kim.barrett at> wrote:
> Finalization was deprecated in JDK 9 (*).  There's an ongoing (though
> progressing slowly) process of eliminating its usage in the JDK.
> Sometime after that it may go away entirely, or perhaps require some
> sort of explicit opt-in, making it possible to eliminate various GC
> overheads associated with it.
> (*) Use PhantomReference, or a helper like java.lang.ref.Cleaner.
> Though that change the liveness question in this thread.

It doesn't matter whether finalization is used or PhantomReferences,
or whatever. The problem of "early" collection remains the same on
every possible mechanism which relies on the GC to trigger cleanup, so
reachabilityFence still has to be used to prevent early collectiona
from happening.

The existence of PhantomReference does show, however, why treating
classes with finalizers in a special way is pointless. Hans Boehm's
proposal for an annotation such as @Cleaned on the class makes the
most sense, IMO. But we can probably live with reachabilityFence,
although it's a horrible name.

Andrew Haley
Java Platform Lead Engineer
Red Hat UK Ltd. <>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671

More information about the jdk-dev mailing list