Section 12.6.1 in the JLS states:
"A reachable object is any object that can be accessed in any potential
continuing computation from any live thread. Optimizing transformations of
a program can be designed that reduce the number of objects that are
reachable to be less than those which would naively be considered
reachable." I think that's pretty much all that's said about reachability.
I don't think that implies than object passed as a parameter to the
currently executing method, or equivalently the "this" object for the
currently executing method, is necessarily reachable, unless the object may
actually be accessed, e.g. with a load or store instruction. Yes, the
"this" object can sometimes be reclaimed while one of its methods is still
running, provided that method no longer needs to load from or store into the
object. In the absence of finalizers this is invisible to the client.
I believe that it's actually quite common to generate code that allows this
kind of reclammation of an object whose method is still running. On
machines that pass arguments and the "this" pointer in registers, the
register holding it is fairly likely to be reused once the "this" pointer is
dead. If the object is also dead in the caller, there is no reason to keep
a reference to it around. I suspect that if you wanted a compiler to
guarantee reasonable space bounds, along the lines of what Appel suggests,
you would be required to ensure that such objects are viewed as unreachable.
I believe that none of this actually matters if finalizers are correctly
synchronized. But they usually do need synchronization.
> -----Original Message-----
> From: David Holmes [mailto:firstname.lastname@example.org]
> Sent: Tuesday, January 01, 2002 6:19 PM
> To: Boehm, Hans
> Cc: jmm
> Subject: RE: JavaMemoryModel: Finalization, again
> > It seems to be common to assume that an object is live as long as
> > one of its methods is executing. I don't believe that's
> guaranteed to be
> > true.
> While a method of an object is executing, the current thread
> has a reference
> to that object via the "this" reference. So from a language
> perspective I
> would say that there is an implicit guarantee that an object
> is live while
> one of its methods is executing - even if the method never explicitly
> references "this".
> An implementation that allows a live object (in the above sense) to be
> finalized is broken IMHO. Would it also allow the live object to be
> reclaimed? ;-)
> David Holmes
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:36 EDT