[gclist] Question from a newbie

Bakul Shah bakul@bitblocks.com
Wed, 07 May 2003 10:30:05 -0700

> In practice "data which is not reachable" begs the question of what should 
> be  reachable!
> For example:
> void m1() {
> Object obj1 = ...;
> Object obj2 = ...;
>    m2();
>   return obj2;
> }
> void m2() {
>   /* gc gets invoked */
> }
> When m2 is called an the gc is invoked is obj1 reachable?  Well that 
> depends on whether or not the compiler spilled the obj1 variable on the 
> stack or nulled out it's register holding the value. Intuitively obj1 is 
> garbage, because we don't touch it after we return from m2.

Your intuition is different from mine!  The usual language
rules dictate that the extent (i.e. lifetime) of an object
such as obj1 is until the end of m1 (where it goes out of
scope and its value has not escaped to m1's callee).  So my
"intuition" says that if for instance I want to examine
obj1's value in m1 after returning from m2 I should be able
to do that!  Worse, if there are any side-effects associated
with freeing of obj1 they will occur in an incorrect order if
obj1 is freed early.  In general the "as if" rule _limits_
(or ought to limit) what optimizations are allowed but
perhaps agressive optimizations have already lowered people's