Finalizer being run while class still in use (escape analysis bug)
Andrew Haley
aph at redhat.com
Wed Oct 10 09:54:39 UTC 2018
On 10/10/2018 10:48 AM, Luke Hutchison wrote:
> Another case: given the class
>
> class A {
> A someMethod1() {
> // ...
> return this;
> }
>
> A someMethod2() {
> // ...
> return this;
> }
>
> public void finalize() { /* ... */ }
> }
>
> will the call
>
> new A().someMethod1().someMethod2();
>
> never run the finalizer early, because "this" is returned for method
> chaining?
It might. If those methods have no visible side effects then they may
be elided altogether.
The easiest way to think about it is to consider that every method
my be inlined, and all references to "this" elided.
> i.e. does any sort of reference to "this" that cannot be trivially
> optimized away by the compiler serve the same purpose as
> Reference.reachabilityFence(this) ?
If it were so we would not have had to provide reachabilityFence.
> Or will the finalizer never be run while someMethod1() is running, but may
> be run while someMethod2() is running, since the return value of
> someMethod2() is being discarded?
It doesn't help because the bodies of someMethod1 and someMethod2 may
be inlined in the caller. The only thing that matters is the last access
of a field of Class A.
--
Andrew Haley
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671
More information about the hotspot-dev
mailing list