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

Carlo de Wolf cdewolf at redhat.com
Wed Dec 5 01:00:06 PST 2012


On 12/04/2012 08:41 PM, Andrew Haley wrote:
> On 12/04/2012 06:35 PM, Carlo de Wolf wrote:
>> On 12/04/2012 05:05 PM, Andrew Haley wrote:
>>> On 12/04/2012 12:12 PM, Carlo de Wolf wrote:
>>>> JLS 7 12.6.1:
>>>> Note that this sort of optimization is only allowed if references are on
>>>> the stack, not stored in
>>>> the heap.
>>>>
>>>> This hints to me that an object which is on the stack (of the previous
>>>> frame) is actually strong referenced.
>>> What is your reason for believing that references in previous frames
>>> are any stronger than references in the current frame?  I can't see
>>> anything that implies it.
>>>
>> I don't believe that. But it's a reference on the stack of the previous
>> frame, while a local variable reference on the current frame.
> OK, but you said:
>
>>>> This hints to me that an object which is on the stack (of the previous
>>>> frame) is actually strong referenced.
> which is what I don't understand.  Why do you think there is such a hint?
> I can't see any such hint in what you quoted.
>
> Andrew.
>
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.
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)?

Carlo


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