[concurrency-interest] DirectByteBuffers and reachabilityFence

Justin Sampson jsampson at guidewire.com
Tue Dec 8 22:40:19 EST 2015


Vitaly Davidovich wrote:

> > public ByteBuffer put(int i, byte x) {
> >     try {
> >         unsafe.putByte(ix(checkIndex(i)), ((x)));
> >         return this;
> >     } finally {
> >         Fences.reachabilityFence(this);
> >     }
> > }
>
> Yes. This also reminds me that default inlining size needs to be
> reconsidered in light of changes like the above. Putting
> try/finally {reachabilityFence(this)} adds about 14 bytes of
> bytecode alone, which may make some methods go over the default
> MaxInlineSize threshold.

Is the try/finally necessary? How about instead:

public ByteBuffer put(int i, byte x) {
    unsafe.putByte(ix(checkIndex(i)), x);
    Fences.reachabilityFence(this);
    return this;
}

public int get(int i) {
    int result = unsafe.getByte(ix(checkIndex(i)));
    Fences.reachabilityFence(this);
    return result;
}

Cheers,
Justin



More information about the Concurrency-interest mailing list