If people are defining their own subclasses of a Reference class, they
are responsible for proper synchronization, not the VM.
At any rate, so long as people aren't passing pointers to References
around via a data race, we shouldn't have to worry about imposing
a hb-edge from Reference construction to Reference use.
The only cases that we really need to worry about are:
thread 1 calls clear, thread 2 calls get
GC clears reference, thread 2 calls get
which are handled by making the referent field volatile.
On May 19, 2004, at 7:13 PM, Sylvia Else wrote:
> 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
>> than the jsr133 spec. After all, references are not mentioned in the
>> 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
> 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
> Suddenly this seems like a minefield.
> JavaMemoryModel mailing list -
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:01:07 EDT