[concurrency-interest] DirectByteBuffers and reachabilityFence

Vitaly Davidovich vitalyd at gmail.com
Wed Dec 9 20:36:38 EST 2015


sent from my phone
On Dec 9, 2015 8:23 PM, "Justin Sampson" <jsampson at guidewire.com> wrote:
>
> David Holmes wrote:
>
> > You are right about the intent here. I just found what seems to be
> > a major error in the JLS in regards to JSR-133. Here is the text
> > that was supposed to be included in the JLS update by JSR-133:
> >
> > "An object cannot be considered finalizable until all of its
> > constructors have finished. The constructor for class Object must
> > be invoked and complete normally in order for the object to be
> > finalizable; other constructors may terminate by throwing
> > exceptions."
> >
> > http://www.cs.umd.edu/~pugh/java/memoryModel/jsr133.pdf
> >
> > But that isn't what it says in JLS 12.6.1!
>
> As you pointed out earlier, that's just talking about whether an
> exception during construction prevents finalization. That PDF and
> the JLS both agree that an object can't be finalized at all if its
> capital-O Object constructor didn't complete normally.
>
> The happens-before relationship is stated very explicitly, not once
> but _twice_ in the JLS. It is stated in 12.6, as I quoted earlier,
> and stated again in 17.4.5 as the second bullet point in the very
> definition of happens-before itself! It's stated even earlier than
> the fact that synchronizes-with also implies happens-before:
>
>   "If we have two actions x and y, we write hb(x, y) to indicate
>   that x happens-before y.
>
>   * If x and y are actions of the same thread and x comes before y
>     in program order, then hb(x, y).
>
>   * There is a happens-before edge from the end of a constructor of
>     an object to the start of a finalizer (§12.6) for that object.
>
>   * If an action x synchronizes-with a following action y, then we
>     also have hb(x, y).
>
>   * If hb(x, y) and hb(y, z), then hb(x, z)."
>
> https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.4.5
>
> In summary, we agree that an object can _become finalizable_ before
> completion of its constructor, if the Object constructor completed
> normally and the object is otherwise no longer reachable. But the
> definition of happens-before makes it very clear that whenever the
> finalizer _does_ run, it will see all writes from the remainder of
> the constructor and none of its writes will be visible within the
> constructor.

What about reads in ctor though? Writes in finalizer should not happen -
before reads in ctor either.

>
> Cheers,
> Justin
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20151209/55b57174/attachment.html>


More information about the Concurrency-interest mailing list