Reachability of an object when a thread is running one of its methods
Carlo de Wolf
cdewolf at redhat.com
Tue Dec 4 04:12:46 PST 2012
I would like to ask you to clarify the reachability of an object when a
thread is running one of its methods. 
JLS 7 12.6.1:
Optimizing transformations of a program can be designed that reduce the
objects that are reachable to be less than those which would naively be
reachable. For example, a Java compiler or code generator may choose to
variable or parameter that will no longer be used to null to cause the
such an object to be potentially reclaimable sooner.
Based on this the IBM JDK sets 'this' (local variable #0) to null when
it is no longer actively being used by the current method invocation (or
a different implementation with similar effect). Because of their highly
aggressive GC, the object is then immediately finalized.
Personally I find this a bit dirty, as the object is semantically still
JLS 7 12.6.1:
Note that this sort of optimization is only allowed if references are on
the stack, not stored in
This hints to me that an object which is on the stack (of the previous
frame) is actually strong referenced.
Could you please clarify the following behaviors?
1. Is it allowed to nullify 'this' and thus clearing the local variable
reference to 'this'?
2. Is a reference from the stack of the previous frame considered a
More information about the java-se-8-spec-comments