[concurrency-interest] DirectByteBuffers and reachabilityFence

Justin Sampson jsampson at guidewire.com
Wed Dec 9 21:24:56 EST 2015


Vitaly Davidovich wrote:

> The sane and intuitive thing is to say all reads/writes in ctor
> happen-before all reads/writes in finalizer. That just about
> enforces the temporal aspect but is also the model that all
> developers would intuit.

That's exactly what the JLS says! Twice! It's central to the very
definition of the happens-before ordering that the completion of a
constructor happens-before the execution of a finalizer on the same
object. That means _nothing but_ the fact that all reads and writes
in the constructor happen-before all reads and writes in the
finalizer. It doesn't say "_if_ the finalizer _doesn't_ execute
concurrently with the constructor..." -- that would be meaningless,
because the whole point of defining the happens-before ordering is
to define the semantics of "concurrently." If one program action
happens-before another, then they are by definition _not_ concurrent
actions. Therefore the JLS explicitly states that no finalizer may
ever be executed concurrently with any constructor for the same
object. If by "temporal ordering" David means the order of actual
instructions on a physical processor, that's an implementation
detail -- all the JLS has to say is that the physical operation of
the program must behave _as if_ all of the above is true. If a JVM
does _not_ behave as if all of the above is true, then it is not
implementing the JLS correctly.

Cheers,
Justin



More information about the Concurrency-interest mailing list