[#2187] Always do a volatile read on the refCnt

This commit is contained in:
Norman Maurer 2014-02-07 09:23:16 +01:00
parent 103a08e6c6
commit f23d68b42f
2 changed files with 2 additions and 39 deletions

View File

@ -28,20 +28,7 @@ public abstract class AbstractReferenceCountedByteBuf extends AbstractByteBuf {
private static final AtomicIntegerFieldUpdater<AbstractReferenceCountedByteBuf> refCntUpdater;
private static final long REFCNT_FIELD_OFFSET;
static {
long refCntFieldOffset = -1;
try {
if (PlatformDependent.hasUnsafe()) {
refCntFieldOffset = PlatformDependent.objectFieldOffset(
AbstractReferenceCountedByteBuf.class.getDeclaredField("refCnt"));
}
} catch (Throwable t) {
// Ignored
}
REFCNT_FIELD_OFFSET = refCntFieldOffset;
AtomicIntegerFieldUpdater<AbstractReferenceCountedByteBuf> updater =
PlatformDependent.newAtomicIntegerFieldUpdater(AbstractReferenceCountedByteBuf.class, "refCnt");
if (updater == null) {
@ -59,12 +46,7 @@ public abstract class AbstractReferenceCountedByteBuf extends AbstractByteBuf {
@Override
public final int refCnt() {
if (REFCNT_FIELD_OFFSET >= 0) {
// Try to do non-volatile read for performance.
return PlatformDependent.getInt(this, REFCNT_FIELD_OFFSET);
} else {
return refCnt;
}
return refCnt;
}
/**

View File

@ -26,21 +26,7 @@ public abstract class AbstractReferenceCounted implements ReferenceCounted {
private static final AtomicIntegerFieldUpdater<AbstractReferenceCounted> refCntUpdater;
private static final long REFCNT_FIELD_OFFSET;
static {
long refCntFieldOffset = -1;
try {
if (PlatformDependent.hasUnsafe()) {
refCntFieldOffset = PlatformDependent.objectFieldOffset(
AbstractReferenceCounted.class.getDeclaredField("refCnt"));
}
} catch (Throwable t) {
// Ignored
}
REFCNT_FIELD_OFFSET = refCntFieldOffset;
AtomicIntegerFieldUpdater<AbstractReferenceCounted> updater =
PlatformDependent.newAtomicIntegerFieldUpdater(AbstractReferenceCounted.class, "refCnt");
if (updater == null) {
@ -54,12 +40,7 @@ public abstract class AbstractReferenceCounted implements ReferenceCounted {
@Override
public final int refCnt() {
if (REFCNT_FIELD_OFFSET >= 0) {
// Try to do non-volatile read for performance.
return PlatformDependent.getInt(this, REFCNT_FIELD_OFFSET);
} else {
return refCnt;
}
return refCnt;
}
/**