[concurrency-interest] DirectByteBuffers and reachabilityFence

David Holmes davidcholmes at aapt.net.au
Wed Dec 9 04:21:26 EST 2015


JLS 12.6.1 establishes a minimum requirement for an object to be finalizable
- it ensures that the object has the minimalist form for a valid object: it
has been allocated and Object's constructor has succeeded. If something goes
wrong prior to that point then the object can not be finalized.

The happens-before requirement was deliberately set the way it is to show
that an object can not be finalized before its construction has completed
(whether normally or abnormally). So I would agree with Justin that it
should not be possible for an object to be finalized before construction has
completed - regardless of potential compiler optimizations etc.

David

> -----Original Message-----
> From: concurrency-interest-bounces at cs.oswego.edu [mailto:concurrency-
> interest-bounces at cs.oswego.edu] On Behalf Of Peter Levart
> Sent: Wednesday, December 9, 2015 7:03 PM
> To: Justin Sampson; Andrew Haley; Vitaly Davidovich
> Cc: concurrency-interest at cs.oswego.edu
> Subject: Re: [concurrency-interest] DirectByteBuffers and
> reachabilityFence
> 
> 
> 
> On 12/09/2015 04:25 AM, Justin Sampson wrote:
> > Andrew Haley wrote:
> >
> >> It's not just HotSpot, though: some VMs are even more aggressive,
> >> and we have seen finalizers executed even before constructors have
> >> completed. And that is allowed by the specification.
> > How so? I mean, I understand that an object may become unreachable
> > before the completion of its constructor due to inlining, but the
> > finalizer is not allowed to run at that point:
> >
> > "The completion of an object's constructor happens-before the
> > execution of its finalize method (in the formal sense of
> > happens-before)."
> >
> > https://docs.oracle.com/javase/specs/jls/se8/html/jls-12.html#jls-
> 12.6
> >
> > Cheers,
> > Justin
> 
> A little later down in "12.6.1. Implementing Finalization" JLS also
> writes:
> 
> "An object o is not finalizable until its constructor has invoked the
> constructor for Object on o and that invocation has completed
> successfully (that is, without throwing an exception)."
> 
> So we have two seemingly contradictive definitions using: object's
> constructor vs. Object's constructor
> 
> I think the definition that uses "object's constructor" is not precise.
> A general object may have many costructors which are invoked in chain.
> While java.lang.Object only has a single constructor. So I would trust
> the later definition. Besides, this is how it is implemented in
> Hotspot/JDK.
> 
> Regards, Peter
> 
> >
> > _______________________________________________
> > Concurrency-interest mailing list
> > Concurrency-interest at cs.oswego.edu
> > http://cs.oswego.edu/mailman/listinfo/concurrency-interest
> 
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest



More information about the Concurrency-interest mailing list