[concurrency-interest] DirectByteBuffers and reachabilityFence

Peter Levart peter.levart at gmail.com
Wed Dec 9 04:03:04 EST 2015

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

More information about the Concurrency-interest mailing list