Reachability of an object when a thread is running one of its methods

Andrew Haley aph at redhat.com
Wed Dec 5 01:59:57 PST 2012


On 12/05/2012 09:00 AM, Carlo de Wolf wrote:

> The example further on shows that an object reference which is on the 
> heap can be optimized away and thus the object can be finalized too 
> early. A reference coming off the stack is allowed to be nullified and 
> it would not trigger finalization. Hence a reference on the stack is a 
> strong one.

Carlo, you are making this very hard work.  You write things like

"A reference coming off the stack is allowed to be nullified and
it would not trigger finalization." but without reference to the
specification.  Does it say anything in the specification to
support this claim?

> Probably the real issue is when the stack of the previous frame is
> cleared, at the start of invoke(virtual) or at the end of
> invoke(virtual)?

I'm looking at the example at https://www.ibm.com/developerworks/forums/message.jspa?messageID=14915477

Is that what you're talking about?

You say

> 1. The current frame holds this in variable #0. While technically it
> is possible to set local variable #0 to null, I find that an
> extremely dirty action.

But the specification explicitly allows it.

And

> 2. The previous frame is also holding a reference to FinalizeBug (or
> at least should be ;-) ) in its stack.

But the specification does not require it to do hold such a reference.

Andrew.


More information about the java-se-8-spec-comments mailing list