From f23d68b42fd71674fee6623f6779d70b6849da21 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 7 Feb 2014 09:23:16 +0100 Subject: [PATCH] [#2187] Always do a volatile read on the refCnt --- .../AbstractReferenceCountedByteBuf.java | 20 +----------------- .../netty/util/AbstractReferenceCounted.java | 21 +------------------ 2 files changed, 2 insertions(+), 39 deletions(-) diff --git a/buffer/src/main/java/io/netty/buffer/AbstractReferenceCountedByteBuf.java b/buffer/src/main/java/io/netty/buffer/AbstractReferenceCountedByteBuf.java index d881590668..08c498178d 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 5b6131ffb6..80f21d19c7 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; } /**