[concurrency-interest] DirectByteBuffers and reachabilityFence

David Holmes davidcholmes at aapt.net.au
Thu Dec 10 19:08:27 EST 2015

Justin Sampson writes:
> David Holmes wrote:
> > > > No! The object should not be able to become finalizable until
> > > > after all its constructors have completed, and then it becomes
> > > > unreachable.
> > >
> > > Is this your view of the existing world, or what you are
> > > proposing be changed? I'm losing track of what's what in this
> > > discussion. :-)
> >
> > This is how the existing world should have been if the JLS update
> > had not been snafu'd. Justin would argue it should be the current
> > state regardless due to happens-before definition. Regardless the
> > JVM does not currently implement this.
> Jeremy Manson seemed to think it had been implemented this way,
> based on the happens-before wording, back in 2010:
> http://jeremymanson.blogspot.com/2010/01/garbage-collection-
> references.html

He certainly believed it was implemented this way - see the comments:

"@Sanjay - that is the right concept, although the VM has to do some magic
to prevent the finalizer from running before the constructor finishes."

But only Jeremy can answer whether that was based on the happens-before
wording or the explicit statement that got dropped from the JLS.


> I'm having trouble finding any other concrete references to how it's
> actually implemented, but I suppose it's not worth trying to nail it
> down unless someone has a legitimate piece of code that's failing.
> To summarize the thread again, there have been several questions:
> 1. Does the spec allow an object's memory to be freed in the middle
> of one of its own instance methods?
> Everyone seems to agree that the answer is Yes, but there is still
> ongoing discussion of whether the spec could be changed, or whether
> reachabilityFence() is the best we can hope for.
> 2. Does any JVM actually do #1?
> Yes, Alexandre provided a working example with a segfault.
> 3. Does the spec allow a finalizer to be run concurrently with the
> same object's own constructor?
> I say No, David says Maybe, but everyone agrees that the intent was
> to forbid it and it's probably worth clarifying in the spec.
> 4. Does any JVM actually do #3?
> A few people say Yes, but we haven't looked at any running examples
> in this particular discussion.
> Cheers,
> Justin

More information about the Concurrency-interest mailing list