[concurrency-interest] DirectByteBuffers and reachabilityFence

Andrew Haley aph at redhat.com
Tue Dec 8 09:33:44 EST 2015


On 12/08/2015 12:07 PM, Vitaly Davidovich wrote:
>>> I think the reasoning here is similar to the above.
>>> ByteBuffer.get() is invoked on a DBB instance, compiler sees a call
>>> to Unsafe.getXXX at some point.  The "natural" lifetime of the
>>> instance survives until the instance method returns.
>>
>> No, this is completely wrong.

> Same here

The lifetime, natural or otherwise, of an instance does not survive
until an instance method returns because, a lot of the time, that
instance method is inlined.

> It's speculation based on observing a real compiler and looking at
> its code generation in various scenarios.  The bottom line is that
> it plays conservative a lot of the time, and that is the sentiment
> I've picked up from various conversations on the compiler list over
> the years.  Yes, it's speculation and a Sufficiently Smart Compiler
> can do things differently.

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.

> But keep in mind if hotspot started scheduling operations more
> aggressively around Unsafe usage a lot of code would break

It's already broken.

Andrew.


More information about the Concurrency-interest mailing list