Finalizer being run while class still in use (escape analysis bug)
Luke Hutchison
luke.hutch at gmail.com
Wed Oct 10 09:48:26 UTC 2018
On Wed, Oct 10, 2018 at 3:39 AM Luke Hutchison <luke.hutch at gmail.com> wrote:
> So given a class
>
> class A {
> void someMethod() {
> try {
> // ...
> } finally {
> Reference.reachabilityFence(this);
> }
> }
> }
>
(Sorry, that should have a finalizer too..)
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?
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) ?
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?
More information about the hotspot-dev
mailing list