Re: JavaMemoryModel: References

From: Sylvia Else (
Date: Wed May 19 2004 - 19:13:56 EDT

At 11:51 AM 19/05/2004 -0400, Bill Pugh wrote:
>OK, we've reviewed the stuff on references.
>I think most of this stuff can go into the java.lang.ref JavaDoc rather
>than the jsr133 spec. After all, references are not mentioned in the JLS.
>Within the Reference class, there should be an hb edge
> from creation of the Reference or call to clear()

I too wondered about having the hb edge from the creation of the Reference,
but these classes can be subclassed. It seems to me that the reference can
be cleared while the subclass constructor is still being executed. This
would arise where the only strong reference remaining was the one passed to
the Reference constructor. So putting the hb edge from the creation of the
reference means one has to pay very close attention to exactly what
"creating a Reference" actually means.

Maybe it's sufficient to clarify it as:

     There is an happens-before edge from the completion of the
WeakReference, SoftReference or PhantomReference constructor....

That said, if subclasses are being used, it seems more than likely that
fields set by the subclasses will be used by the code that retrieves the
Reference object once the reference has been cleared. At best such code
would contain a data race in the absence of synchronization, and even with
synchronization the code could still easily be executed in the wrong order
from the programmer's perspective.

Suddenly this seems like a minefield.


JavaMemoryModel mailing list -

This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:01:07 EDT