diff --git a/buffer/src/main/java/io/netty/buffer/AbstractReferenceCountedByteBuf.java b/buffer/src/main/java/io/netty/buffer/AbstractReferenceCountedByteBuf.java index f87bf4bf39..06df36de74 100644 --- a/buffer/src/main/java/io/netty/buffer/AbstractReferenceCountedByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/AbstractReferenceCountedByteBuf.java @@ -28,20 +28,7 @@ public abstract class AbstractReferenceCountedByteBuf extends AbstractByteBuf { private static final AtomicIntegerFieldUpdater 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 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; } /** diff --git a/common/src/main/java/io/netty/util/AbstractReferenceCounted.java b/common/src/main/java/io/netty/util/AbstractReferenceCounted.java index 6d369ede8d..da152f19d0 100644 --- a/common/src/main/java/io/netty/util/AbstractReferenceCounted.java +++ b/common/src/main/java/io/netty/util/AbstractReferenceCounted.java @@ -26,21 +26,7 @@ public abstract class AbstractReferenceCounted implements ReferenceCounted { private static final AtomicIntegerFieldUpdater 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 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; } /**