[concurrency-interest] Is Reference.reachabilityFence() needed in Reference constructor?

Andrew Haley aph at redhat.com
Wed Oct 21 09:28:09 EDT 2015


On 10/21/2015 01:34 PM, Peter Levart wrote:
> Is it possible that the newly constructed Object is found 
> weakly-reachable before the 'queue' is assigned to the Reference.queue 
> field or is there something in the JVM that prevents this happening 
> (like all the constructor parameters are reachable at least until the 
> constructor is finished)?

No, there's nothing like that.

I think you're right: from the point where the reference is assigned
to the referent field of the WeakReference it is only reachable by
traversing a weak reference, therefore it is weakly reachable.

Adding the reachabilityFence would not hurt anything, and if it did
make a difference to generated code it'd eliminate a bug.

There may be a few more of these.

Andrew.



More information about the Concurrency-interest mailing list