From 89e93968ac601cbe3d6ca105abbefc99adcb56be Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 9 Dec 2016 15:51:14 +0100 Subject: [PATCH] Remove usage of own Atomic*FieldUpdater in favor of JDKs Motivation: In later Java8 versions our Atomic*FieldUpdater are slower then the JDK implementations so we should not use ours anymore. Even worse the JDK implementations provide for example an optimized version of addAndGet(...) using intrinsics which makes it a lot faster for this use-case. Modifications: - Remove methods that return our own Atomic*FieldUpdaters. - Use the JDK implementations everywhere. Result: Faster code. --- .../AbstractReferenceCountedByteBuf.java | 13 +--- .../netty/util/AbstractReferenceCounted.java | 14 +---- .../io/netty/util/DefaultAttributeMap.java | 16 +---- .../java/io/netty/util/HashedWheelTimer.java | 23 ++----- .../netty/util/concurrent/DefaultPromise.java | 11 +--- .../concurrent/SingleThreadEventExecutor.java | 25 ++------ .../util/internal/PlatformDependent.java | 51 --------------- .../util/internal/PlatformDependent0.java | 15 ----- .../UnsafeAtomicIntegerFieldUpdater.java | 62 ------------------ .../UnsafeAtomicLongFieldUpdater.java | 62 ------------------ .../UnsafeAtomicReferenceFieldUpdater.java | 63 ------------------- .../ssl/ReferenceCountedOpenSslEngine.java | 10 +-- .../dns/RotationalDnsServerAddresses.java | 16 +---- .../netty/channel/epoll/EpollEventLoop.java | 12 +--- .../io/netty/channel/unix/FileDescriptor.java | 12 +--- .../AbstractChannelHandlerContext.java | 14 +---- .../netty/channel/ChannelOutboundBuffer.java | 22 ++----- .../netty/channel/DefaultChannelConfig.java | 23 ++----- .../io/netty/channel/local/LocalChannel.java | 14 +---- 19 files changed, 37 insertions(+), 441 deletions(-) delete mode 100644 common/src/main/java/io/netty/util/internal/UnsafeAtomicIntegerFieldUpdater.java delete mode 100644 common/src/main/java/io/netty/util/internal/UnsafeAtomicLongFieldUpdater.java delete mode 100644 common/src/main/java/io/netty/util/internal/UnsafeAtomicReferenceFieldUpdater.java diff --git a/buffer/src/main/java/io/netty/buffer/AbstractReferenceCountedByteBuf.java b/buffer/src/main/java/io/netty/buffer/AbstractReferenceCountedByteBuf.java index defb1c7ea9..99c2670198 100644 --- a/buffer/src/main/java/io/netty/buffer/AbstractReferenceCountedByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/AbstractReferenceCountedByteBuf.java @@ -17,7 +17,6 @@ package io.netty.buffer; import io.netty.util.IllegalReferenceCountException; -import io.netty.util.internal.PlatformDependent; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; @@ -28,16 +27,8 @@ import static io.netty.util.internal.ObjectUtil.checkPositive; */ public abstract class AbstractReferenceCountedByteBuf extends AbstractByteBuf { - private static final AtomicIntegerFieldUpdater refCntUpdater; - - static { - AtomicIntegerFieldUpdater updater = - PlatformDependent.newAtomicIntegerFieldUpdater(AbstractReferenceCountedByteBuf.class, "refCnt"); - if (updater == null) { - updater = AtomicIntegerFieldUpdater.newUpdater(AbstractReferenceCountedByteBuf.class, "refCnt"); - } - refCntUpdater = updater; - } + private static final AtomicIntegerFieldUpdater refCntUpdater = + AtomicIntegerFieldUpdater.newUpdater(AbstractReferenceCountedByteBuf.class, "refCnt"); private volatile int refCnt = 1; diff --git a/common/src/main/java/io/netty/util/AbstractReferenceCounted.java b/common/src/main/java/io/netty/util/AbstractReferenceCounted.java index 30e17b43ae..0669bc3378 100644 --- a/common/src/main/java/io/netty/util/AbstractReferenceCounted.java +++ b/common/src/main/java/io/netty/util/AbstractReferenceCounted.java @@ -15,8 +15,6 @@ */ package io.netty.util; -import io.netty.util.internal.PlatformDependent; - import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import static io.netty.util.internal.ObjectUtil.checkPositive; @@ -26,16 +24,8 @@ import static io.netty.util.internal.ObjectUtil.checkPositive; */ public abstract class AbstractReferenceCounted implements ReferenceCounted { - private static final AtomicIntegerFieldUpdater refCntUpdater; - - static { - AtomicIntegerFieldUpdater updater = - PlatformDependent.newAtomicIntegerFieldUpdater(AbstractReferenceCounted.class, "refCnt"); - if (updater == null) { - updater = AtomicIntegerFieldUpdater.newUpdater(AbstractReferenceCounted.class, "refCnt"); - } - refCntUpdater = updater; - } + private static final AtomicIntegerFieldUpdater refCntUpdater = + AtomicIntegerFieldUpdater.newUpdater(AbstractReferenceCounted.class, "refCnt"); private volatile int refCnt = 1; diff --git a/common/src/main/java/io/netty/util/DefaultAttributeMap.java b/common/src/main/java/io/netty/util/DefaultAttributeMap.java index 5db03c6844..541a341c2b 100644 --- a/common/src/main/java/io/netty/util/DefaultAttributeMap.java +++ b/common/src/main/java/io/netty/util/DefaultAttributeMap.java @@ -15,8 +15,6 @@ */ package io.netty.util; -import io.netty.util.internal.PlatformDependent; - import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReferenceArray; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; @@ -28,18 +26,8 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; public class DefaultAttributeMap implements AttributeMap { @SuppressWarnings("rawtypes") - private static final AtomicReferenceFieldUpdater updater; - - static { - @SuppressWarnings("rawtypes") - AtomicReferenceFieldUpdater referenceFieldUpdater = - PlatformDependent.newAtomicReferenceFieldUpdater(DefaultAttributeMap.class, "attributes"); - if (referenceFieldUpdater == null) { - referenceFieldUpdater = AtomicReferenceFieldUpdater - .newUpdater(DefaultAttributeMap.class, AtomicReferenceArray.class, "attributes"); - } - updater = referenceFieldUpdater; - } + private static final AtomicReferenceFieldUpdater updater = + AtomicReferenceFieldUpdater.newUpdater(DefaultAttributeMap.class, AtomicReferenceArray.class, "attributes"); private static final int BUCKET_SIZE = 4; private static final int MASK = BUCKET_SIZE - 1; diff --git a/common/src/main/java/io/netty/util/HashedWheelTimer.java b/common/src/main/java/io/netty/util/HashedWheelTimer.java index 0909514df8..9670cae9c6 100644 --- a/common/src/main/java/io/netty/util/HashedWheelTimer.java +++ b/common/src/main/java/io/netty/util/HashedWheelTimer.java @@ -81,15 +81,8 @@ public class HashedWheelTimer implements Timer { private static final ResourceLeakDetector leakDetector = ResourceLeakDetectorFactory.instance() .newResourceLeakDetector(HashedWheelTimer.class, 1, Runtime.getRuntime().availableProcessors() * 4L); - private static final AtomicIntegerFieldUpdater WORKER_STATE_UPDATER; - static { - AtomicIntegerFieldUpdater workerStateUpdater = - PlatformDependent.newAtomicIntegerFieldUpdater(HashedWheelTimer.class, "workerState"); - if (workerStateUpdater == null) { - workerStateUpdater = AtomicIntegerFieldUpdater.newUpdater(HashedWheelTimer.class, "workerState"); - } - WORKER_STATE_UPDATER = workerStateUpdater; - } + private static final AtomicIntegerFieldUpdater WORKER_STATE_UPDATER = + AtomicIntegerFieldUpdater.newUpdater(HashedWheelTimer.class, "workerState"); private final ResourceLeakTracker leak; private final Worker worker = new Worker(); @@ -545,16 +538,8 @@ public class HashedWheelTimer implements Timer { private static final int ST_INIT = 0; private static final int ST_CANCELLED = 1; private static final int ST_EXPIRED = 2; - private static final AtomicIntegerFieldUpdater STATE_UPDATER; - - static { - AtomicIntegerFieldUpdater updater = - PlatformDependent.newAtomicIntegerFieldUpdater(HashedWheelTimeout.class, "state"); - if (updater == null) { - updater = AtomicIntegerFieldUpdater.newUpdater(HashedWheelTimeout.class, "state"); - } - STATE_UPDATER = updater; - } + private static final AtomicIntegerFieldUpdater STATE_UPDATER = + AtomicIntegerFieldUpdater.newUpdater(HashedWheelTimeout.class, "state"); private final HashedWheelTimer timer; private final TimerTask task; diff --git a/common/src/main/java/io/netty/util/concurrent/DefaultPromise.java b/common/src/main/java/io/netty/util/concurrent/DefaultPromise.java index 5b180cc11d..c0941bcf59 100644 --- a/common/src/main/java/io/netty/util/concurrent/DefaultPromise.java +++ b/common/src/main/java/io/netty/util/concurrent/DefaultPromise.java @@ -38,20 +38,13 @@ public class DefaultPromise extends AbstractFuture implements Promise { private static final int MAX_LISTENER_STACK_DEPTH = Math.min(8, SystemPropertyUtil.getInt("io.netty.defaultPromise.maxListenerStackDepth", 8)); @SuppressWarnings("rawtypes") - private static final AtomicReferenceFieldUpdater RESULT_UPDATER; + private static final AtomicReferenceFieldUpdater RESULT_UPDATER = + AtomicReferenceFieldUpdater.newUpdater(DefaultPromise.class, Object.class, "result"); private static final Signal SUCCESS = Signal.valueOf(DefaultPromise.class, "SUCCESS"); private static final Signal UNCANCELLABLE = Signal.valueOf(DefaultPromise.class, "UNCANCELLABLE"); private static final CauseHolder CANCELLATION_CAUSE_HOLDER = new CauseHolder(ThrowableUtil.unknownStackTrace( new CancellationException(), DefaultPromise.class, "cancel(...)")); - static { - @SuppressWarnings("rawtypes") - AtomicReferenceFieldUpdater updater = - PlatformDependent.newAtomicReferenceFieldUpdater(DefaultPromise.class, "result"); - RESULT_UPDATER = updater == null ? AtomicReferenceFieldUpdater.newUpdater(DefaultPromise.class, - Object.class, "result") : updater; - } - private volatile Object result; private final EventExecutor executor; /** diff --git a/common/src/main/java/io/netty/util/concurrent/SingleThreadEventExecutor.java b/common/src/main/java/io/netty/util/concurrent/SingleThreadEventExecutor.java index 0206a2eeab..e90358cffd 100644 --- a/common/src/main/java/io/netty/util/concurrent/SingleThreadEventExecutor.java +++ b/common/src/main/java/io/netty/util/concurrent/SingleThreadEventExecutor.java @@ -16,7 +16,6 @@ package io.netty.util.concurrent; import io.netty.util.internal.ObjectUtil; -import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.SystemPropertyUtil; import io.netty.util.internal.UnstableApi; import io.netty.util.internal.logging.InternalLogger; @@ -73,25 +72,11 @@ public abstract class SingleThreadEventExecutor extends AbstractScheduledEventEx } }; - private static final AtomicIntegerFieldUpdater STATE_UPDATER; - private static final AtomicReferenceFieldUpdater PROPERTIES_UPDATER; - - static { - AtomicIntegerFieldUpdater updater = - PlatformDependent.newAtomicIntegerFieldUpdater(SingleThreadEventExecutor.class, "state"); - if (updater == null) { - updater = AtomicIntegerFieldUpdater.newUpdater(SingleThreadEventExecutor.class, "state"); - } - STATE_UPDATER = updater; - - AtomicReferenceFieldUpdater propertiesUpdater = - PlatformDependent.newAtomicReferenceFieldUpdater(SingleThreadEventExecutor.class, "threadProperties"); - if (propertiesUpdater == null) { - propertiesUpdater = AtomicReferenceFieldUpdater.newUpdater(SingleThreadEventExecutor.class, - ThreadProperties.class, "threadProperties"); - } - PROPERTIES_UPDATER = propertiesUpdater; - } + private static final AtomicIntegerFieldUpdater STATE_UPDATER = + AtomicIntegerFieldUpdater.newUpdater(SingleThreadEventExecutor.class, "state"); + private static final AtomicReferenceFieldUpdater PROPERTIES_UPDATER = + AtomicReferenceFieldUpdater.newUpdater( + SingleThreadEventExecutor.class, ThreadProperties.class, "threadProperties"); private final Queue taskQueue; diff --git a/common/src/main/java/io/netty/util/internal/PlatformDependent.java b/common/src/main/java/io/netty/util/internal/PlatformDependent.java index d9f550de63..600c9e6908 100644 --- a/common/src/main/java/io/netty/util/internal/PlatformDependent.java +++ b/common/src/main/java/io/netty/util/internal/PlatformDependent.java @@ -798,57 +798,6 @@ public final class PlatformDependent { } } - /** - * Create a new optimized {@link AtomicReferenceFieldUpdater} or {@code null} if it - * could not be created. Because of this the caller need to check for {@code null} and if {@code null} is returned - * use {@link AtomicReferenceFieldUpdater#newUpdater(Class, Class, String)} as fallback. - */ - public static AtomicReferenceFieldUpdater newAtomicReferenceFieldUpdater( - Class tclass, String fieldName) { - if (hasUnsafe()) { - try { - return PlatformDependent0.newAtomicReferenceFieldUpdater(tclass, fieldName); - } catch (Throwable ignore) { - // ignore - } - } - return null; - } - - /** - * Create a new optimized {@link AtomicIntegerFieldUpdater} or {@code null} if it - * could not be created. Because of this the caller need to check for {@code null} and if {@code null} is returned - * use {@link AtomicIntegerFieldUpdater#newUpdater(Class, String)} as fallback. - */ - public static AtomicIntegerFieldUpdater newAtomicIntegerFieldUpdater( - Class tclass, String fieldName) { - if (hasUnsafe()) { - try { - return PlatformDependent0.newAtomicIntegerFieldUpdater(tclass, fieldName); - } catch (Throwable ignore) { - // ignore - } - } - return null; - } - - /** - * Create a new optimized {@link AtomicLongFieldUpdater} or {@code null} if it - * could not be created. Because of this the caller need to check for {@code null} and if {@code null} is returned - * use {@link AtomicLongFieldUpdater#newUpdater(Class, String)} as fallback. - */ - public static AtomicLongFieldUpdater newAtomicLongFieldUpdater( - Class tclass, String fieldName) { - if (hasUnsafe()) { - try { - return PlatformDependent0.newAtomicLongFieldUpdater(tclass, fieldName); - } catch (Throwable ignore) { - // ignore - } - } - return null; - } - private static final class Mpsc { private static final boolean USE_MPSC_CHUNKED_ARRAY_QUEUE; diff --git a/common/src/main/java/io/netty/util/internal/PlatformDependent0.java b/common/src/main/java/io/netty/util/internal/PlatformDependent0.java index 6f86da9be4..2a47f6be97 100644 --- a/common/src/main/java/io/netty/util/internal/PlatformDependent0.java +++ b/common/src/main/java/io/netty/util/internal/PlatformDependent0.java @@ -559,21 +559,6 @@ final class PlatformDependent0 { return value & 0x1f; } - static AtomicReferenceFieldUpdater newAtomicReferenceFieldUpdater( - Class tclass, String fieldName) throws Exception { - return new UnsafeAtomicReferenceFieldUpdater(UNSAFE, tclass, fieldName); - } - - static AtomicIntegerFieldUpdater newAtomicIntegerFieldUpdater( - Class tclass, String fieldName) throws Exception { - return new UnsafeAtomicIntegerFieldUpdater(UNSAFE, tclass, fieldName); - } - - static AtomicLongFieldUpdater newAtomicLongFieldUpdater( - Class tclass, String fieldName) throws Exception { - return new UnsafeAtomicLongFieldUpdater(UNSAFE, tclass, fieldName); - } - static ClassLoader getClassLoader(final Class clazz) { if (System.getSecurityManager() == null) { return clazz.getClassLoader(); diff --git a/common/src/main/java/io/netty/util/internal/UnsafeAtomicIntegerFieldUpdater.java b/common/src/main/java/io/netty/util/internal/UnsafeAtomicIntegerFieldUpdater.java deleted file mode 100644 index a9a2bd2a60..0000000000 --- a/common/src/main/java/io/netty/util/internal/UnsafeAtomicIntegerFieldUpdater.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2014 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.util.internal; - -import sun.misc.Unsafe; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; - -final class UnsafeAtomicIntegerFieldUpdater extends AtomicIntegerFieldUpdater { - private final long offset; - private final Unsafe unsafe; - - UnsafeAtomicIntegerFieldUpdater(Unsafe unsafe, Class tClass, String fieldName) - throws NoSuchFieldException { - Field field = tClass.getDeclaredField(fieldName); - if (!Modifier.isVolatile(field.getModifiers())) { - throw new IllegalArgumentException("Must be volatile"); - } - this.unsafe = unsafe; - offset = unsafe.objectFieldOffset(field); - } - - @Override - public boolean compareAndSet(T obj, int expect, int update) { - return unsafe.compareAndSwapInt(obj, offset, expect, update); - } - - @Override - public boolean weakCompareAndSet(T obj, int expect, int update) { - return unsafe.compareAndSwapInt(obj, offset, expect, update); - } - - @Override - public void set(T obj, int newValue) { - unsafe.putIntVolatile(obj, offset, newValue); - } - - @Override - public void lazySet(T obj, int newValue) { - unsafe.putOrderedInt(obj, offset, newValue); - } - - @Override - public int get(T obj) { - return unsafe.getIntVolatile(obj, offset); - } -} diff --git a/common/src/main/java/io/netty/util/internal/UnsafeAtomicLongFieldUpdater.java b/common/src/main/java/io/netty/util/internal/UnsafeAtomicLongFieldUpdater.java deleted file mode 100644 index da630fd95c..0000000000 --- a/common/src/main/java/io/netty/util/internal/UnsafeAtomicLongFieldUpdater.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2014 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.util.internal; - -import sun.misc.Unsafe; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.concurrent.atomic.AtomicLongFieldUpdater; - -final class UnsafeAtomicLongFieldUpdater extends AtomicLongFieldUpdater { - private final long offset; - private final Unsafe unsafe; - - UnsafeAtomicLongFieldUpdater(Unsafe unsafe, Class tClass, String fieldName) - throws NoSuchFieldException { - Field field = tClass.getDeclaredField(fieldName); - if (!Modifier.isVolatile(field.getModifiers())) { - throw new IllegalArgumentException("Must be volatile"); - } - this.unsafe = unsafe; - offset = unsafe.objectFieldOffset(field); - } - - @Override - public boolean compareAndSet(T obj, long expect, long update) { - return unsafe.compareAndSwapLong(obj, offset, expect, update); - } - - @Override - public boolean weakCompareAndSet(T obj, long expect, long update) { - return unsafe.compareAndSwapLong(obj, offset, expect, update); - } - - @Override - public void set(T obj, long newValue) { - unsafe.putLongVolatile(obj, offset, newValue); - } - - @Override - public void lazySet(T obj, long newValue) { - unsafe.putOrderedLong(obj, offset, newValue); - } - - @Override - public long get(T obj) { - return unsafe.getLongVolatile(obj, offset); - } -} diff --git a/common/src/main/java/io/netty/util/internal/UnsafeAtomicReferenceFieldUpdater.java b/common/src/main/java/io/netty/util/internal/UnsafeAtomicReferenceFieldUpdater.java deleted file mode 100644 index d839f669e7..0000000000 --- a/common/src/main/java/io/netty/util/internal/UnsafeAtomicReferenceFieldUpdater.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2014 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.util.internal; - -import sun.misc.Unsafe; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; - -final class UnsafeAtomicReferenceFieldUpdater extends AtomicReferenceFieldUpdater { - private final long offset; - private final Unsafe unsafe; - - UnsafeAtomicReferenceFieldUpdater(Unsafe unsafe, Class tClass, String fieldName) - throws NoSuchFieldException { - Field field = tClass.getDeclaredField(fieldName); - if (!Modifier.isVolatile(field.getModifiers())) { - throw new IllegalArgumentException("Must be volatile"); - } - this.unsafe = unsafe; - offset = unsafe.objectFieldOffset(field); - } - - @Override - public boolean compareAndSet(U obj, M expect, M update) { - return unsafe.compareAndSwapObject(obj, offset, expect, update); - } - - @Override - public boolean weakCompareAndSet(U obj, M expect, M update) { - return unsafe.compareAndSwapObject(obj, offset, expect, update); - } - - @Override - public void set(U obj, M newValue) { - unsafe.putObjectVolatile(obj, offset, newValue); - } - - @Override - public void lazySet(U obj, M newValue) { - unsafe.putOrderedObject(obj, offset, newValue); - } - - @SuppressWarnings("unchecked") - @Override - public M get(U obj) { - return (M) unsafe.getObjectVolatile(obj, offset); - } -} diff --git a/handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.java b/handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.java index 142651429f..5594f3a4e6 100644 --- a/handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.java +++ b/handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.java @@ -102,13 +102,6 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc ResourceLeakDetectorFactory.instance().newResourceLeakDetector(ReferenceCountedOpenSslEngine.class); static { - AtomicIntegerFieldUpdater destroyedUpdater = - PlatformDependent.newAtomicIntegerFieldUpdater(ReferenceCountedOpenSslEngine.class, "destroyed"); - if (destroyedUpdater == null) { - destroyedUpdater = AtomicIntegerFieldUpdater.newUpdater(ReferenceCountedOpenSslEngine.class, "destroyed"); - } - DESTROYED_UPDATER = destroyedUpdater; - Method getUseCipherSuitesOrderMethod = null; Method setUseCipherSuitesOrderMethod = null; Class sniHostNameClass = null; @@ -166,7 +159,8 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc static final int MAX_ENCRYPTION_OVERHEAD_LENGTH = MAX_ENCRYPTED_PACKET_LENGTH - MAX_PLAINTEXT_LENGTH; - private static final AtomicIntegerFieldUpdater DESTROYED_UPDATER; + private static final AtomicIntegerFieldUpdater DESTROYED_UPDATER = + AtomicIntegerFieldUpdater.newUpdater(ReferenceCountedOpenSslEngine.class, "destroyed"); private static final String INVALID_CIPHER = "SSL_NULL_WITH_NULL_NULL"; diff --git a/resolver-dns/src/main/java/io/netty/resolver/dns/RotationalDnsServerAddresses.java b/resolver-dns/src/main/java/io/netty/resolver/dns/RotationalDnsServerAddresses.java index f9613987a1..dfa2a50851 100644 --- a/resolver-dns/src/main/java/io/netty/resolver/dns/RotationalDnsServerAddresses.java +++ b/resolver-dns/src/main/java/io/netty/resolver/dns/RotationalDnsServerAddresses.java @@ -16,25 +16,13 @@ package io.netty.resolver.dns; -import io.netty.util.internal.PlatformDependent; - import java.net.InetSocketAddress; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; final class RotationalDnsServerAddresses extends DefaultDnsServerAddresses { - private static final AtomicIntegerFieldUpdater startIdxUpdater; - - static { - AtomicIntegerFieldUpdater updater = - PlatformDependent.newAtomicIntegerFieldUpdater(RotationalDnsServerAddresses.class, "startIdx"); - - if (updater == null) { - updater = AtomicIntegerFieldUpdater.newUpdater(RotationalDnsServerAddresses.class, "startIdx"); - } - - startIdxUpdater = updater; - } + private static final AtomicIntegerFieldUpdater startIdxUpdater = + AtomicIntegerFieldUpdater.newUpdater(RotationalDnsServerAddresses.class, "startIdx"); @SuppressWarnings("UnusedDeclaration") private volatile int startIdx; diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollEventLoop.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollEventLoop.java index 490caeb105..52abf7a59b 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollEventLoop.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollEventLoop.java @@ -43,16 +43,8 @@ import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; */ final class EpollEventLoop extends SingleThreadEventLoop { private static final InternalLogger logger = InternalLoggerFactory.getInstance(EpollEventLoop.class); - private static final AtomicIntegerFieldUpdater WAKEN_UP_UPDATER; - - static { - AtomicIntegerFieldUpdater updater = - PlatformDependent.newAtomicIntegerFieldUpdater(EpollEventLoop.class, "wakenUp"); - if (updater == null) { - updater = AtomicIntegerFieldUpdater.newUpdater(EpollEventLoop.class, "wakenUp"); - } - WAKEN_UP_UPDATER = updater; - } + private static final AtomicIntegerFieldUpdater WAKEN_UP_UPDATER = + AtomicIntegerFieldUpdater.newUpdater(EpollEventLoop.class, "wakenUp"); private final FileDescriptor epollFd; private final FileDescriptor eventFd; diff --git a/transport-native-epoll/src/main/java/io/netty/channel/unix/FileDescriptor.java b/transport-native-epoll/src/main/java/io/netty/channel/unix/FileDescriptor.java index 80e21512d5..62cc5e5c1a 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/unix/FileDescriptor.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/unix/FileDescriptor.java @@ -15,7 +15,6 @@ */ package io.netty.channel.unix; -import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.ThrowableUtil; import java.io.File; @@ -64,15 +63,8 @@ public class FileDescriptor { ThrowableUtil.unknownStackTrace(Errors.newConnectionResetException("syscall:read(...)", Errors.ERRNO_ECONNRESET_NEGATIVE), FileDescriptor.class, "readAddress(...)"); - private static final AtomicIntegerFieldUpdater stateUpdater; - static { - AtomicIntegerFieldUpdater updater - = PlatformDependent.newAtomicIntegerFieldUpdater(FileDescriptor.class, "state"); - if (updater == null) { - updater = AtomicIntegerFieldUpdater.newUpdater(FileDescriptor.class, "state"); - } - stateUpdater = updater; - } + private static final AtomicIntegerFieldUpdater stateUpdater = + AtomicIntegerFieldUpdater.newUpdater(FileDescriptor.class, "state"); private static final int STATE_CLOSED_MASK = 1; private static final int STATE_INPUT_SHUTDOWN_MASK = 1 << 1; diff --git a/transport/src/main/java/io/netty/channel/AbstractChannelHandlerContext.java b/transport/src/main/java/io/netty/channel/AbstractChannelHandlerContext.java index ae0d7c1c08..bb2fcd01f5 100644 --- a/transport/src/main/java/io/netty/channel/AbstractChannelHandlerContext.java +++ b/transport/src/main/java/io/netty/channel/AbstractChannelHandlerContext.java @@ -24,7 +24,6 @@ import io.netty.util.ReferenceCountUtil; import io.netty.util.ResourceLeakHint; import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.OrderedEventExecutor; -import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PromiseNotificationUtil; import io.netty.util.internal.ThrowableUtil; import io.netty.util.internal.ObjectUtil; @@ -43,17 +42,8 @@ abstract class AbstractChannelHandlerContext extends DefaultAttributeMap volatile AbstractChannelHandlerContext next; volatile AbstractChannelHandlerContext prev; - private static final AtomicIntegerFieldUpdater HANDLER_STATE_UPDATER; - - static { - AtomicIntegerFieldUpdater handlerStateUpdater = PlatformDependent - .newAtomicIntegerFieldUpdater(AbstractChannelHandlerContext.class, "handlerState"); - if (handlerStateUpdater == null) { - handlerStateUpdater = AtomicIntegerFieldUpdater - .newUpdater(AbstractChannelHandlerContext.class, "handlerState"); - } - HANDLER_STATE_UPDATER = handlerStateUpdater; - } + private static final AtomicIntegerFieldUpdater HANDLER_STATE_UPDATER = + AtomicIntegerFieldUpdater.newUpdater(AbstractChannelHandlerContext.class, "handlerState"); /** * {@link ChannelHandler#handlerAdded(ChannelHandlerContext)} is about to be called. diff --git a/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java b/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java index e9ef177b3d..beecf78f3e 100644 --- a/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java +++ b/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java @@ -86,34 +86,20 @@ public final class ChannelOutboundBuffer { private boolean inFail; - private static final AtomicLongFieldUpdater TOTAL_PENDING_SIZE_UPDATER; + private static final AtomicLongFieldUpdater TOTAL_PENDING_SIZE_UPDATER = + AtomicLongFieldUpdater.newUpdater(ChannelOutboundBuffer.class, "totalPendingSize"); @SuppressWarnings("UnusedDeclaration") private volatile long totalPendingSize; - private static final AtomicIntegerFieldUpdater UNWRITABLE_UPDATER; + private static final AtomicIntegerFieldUpdater UNWRITABLE_UPDATER = + AtomicIntegerFieldUpdater.newUpdater(ChannelOutboundBuffer.class, "unwritable"); @SuppressWarnings("UnusedDeclaration") private volatile int unwritable; private volatile Runnable fireChannelWritabilityChangedTask; - static { - AtomicIntegerFieldUpdater unwritableUpdater = - PlatformDependent.newAtomicIntegerFieldUpdater(ChannelOutboundBuffer.class, "unwritable"); - if (unwritableUpdater == null) { - unwritableUpdater = AtomicIntegerFieldUpdater.newUpdater(ChannelOutboundBuffer.class, "unwritable"); - } - UNWRITABLE_UPDATER = unwritableUpdater; - - AtomicLongFieldUpdater pendingSizeUpdater = - PlatformDependent.newAtomicLongFieldUpdater(ChannelOutboundBuffer.class, "totalPendingSize"); - if (pendingSizeUpdater == null) { - pendingSizeUpdater = AtomicLongFieldUpdater.newUpdater(ChannelOutboundBuffer.class, "totalPendingSize"); - } - TOTAL_PENDING_SIZE_UPDATER = pendingSizeUpdater; - } - ChannelOutboundBuffer(AbstractChannel channel) { this.channel = channel; } diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelConfig.java b/transport/src/main/java/io/netty/channel/DefaultChannelConfig.java index 0602a223e6..9311b84c0a 100644 --- a/transport/src/main/java/io/netty/channel/DefaultChannelConfig.java +++ b/transport/src/main/java/io/netty/channel/DefaultChannelConfig.java @@ -16,7 +16,6 @@ package io.netty.channel; import io.netty.buffer.ByteBufAllocator; -import io.netty.util.internal.PlatformDependent; import java.util.IdentityHashMap; import java.util.Map; @@ -46,25 +45,11 @@ public class DefaultChannelConfig implements ChannelConfig { private static final int DEFAULT_CONNECT_TIMEOUT = 30000; - private static final AtomicIntegerFieldUpdater AUTOREAD_UPDATER; - private static final AtomicReferenceFieldUpdater WATERMARK_UPDATER; - - static { - AtomicIntegerFieldUpdater autoReadUpdater = - PlatformDependent.newAtomicIntegerFieldUpdater(DefaultChannelConfig.class, "autoRead"); - if (autoReadUpdater == null) { - autoReadUpdater = AtomicIntegerFieldUpdater.newUpdater(DefaultChannelConfig.class, "autoRead"); - } - AUTOREAD_UPDATER = autoReadUpdater; - - AtomicReferenceFieldUpdater watermarkUpdater = - PlatformDependent.newAtomicReferenceFieldUpdater(DefaultChannelConfig.class, "writeBufferWaterMark"); - if (watermarkUpdater == null) { - watermarkUpdater = AtomicReferenceFieldUpdater.newUpdater( + private static final AtomicIntegerFieldUpdater AUTOREAD_UPDATER = + AtomicIntegerFieldUpdater.newUpdater(DefaultChannelConfig.class, "autoRead"); + private static final AtomicReferenceFieldUpdater WATERMARK_UPDATER = + AtomicReferenceFieldUpdater.newUpdater( DefaultChannelConfig.class, WriteBufferWaterMark.class, "writeBufferWaterMark"); - } - WATERMARK_UPDATER = watermarkUpdater; - } protected final Channel channel; diff --git a/transport/src/main/java/io/netty/channel/local/LocalChannel.java b/transport/src/main/java/io/netty/channel/local/LocalChannel.java index 8b329e3e77..28dee6f9b9 100644 --- a/transport/src/main/java/io/netty/channel/local/LocalChannel.java +++ b/transport/src/main/java/io/netty/channel/local/LocalChannel.java @@ -49,7 +49,8 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; public class LocalChannel extends AbstractChannel { private static final InternalLogger logger = InternalLoggerFactory.getInstance(LocalChannel.class); @SuppressWarnings({ "rawtypes" }) - private static final AtomicReferenceFieldUpdater FINISH_READ_FUTURE_UPDATER; + private static final AtomicReferenceFieldUpdater FINISH_READ_FUTURE_UPDATER = + AtomicReferenceFieldUpdater.newUpdater(LocalChannel.class, Future.class, "finishReadFuture"); private static final ChannelMetadata METADATA = new ChannelMetadata(false); private static final int MAX_READER_STACK_DEPTH = 8; private static final ClosedChannelException DO_WRITE_CLOSED_CHANNEL_EXCEPTION = ThrowableUtil.unknownStackTrace( @@ -93,17 +94,6 @@ public class LocalChannel extends AbstractChannel { private volatile boolean writeInProgress; private volatile Future finishReadFuture; - static { - @SuppressWarnings({ "rawtypes" }) - AtomicReferenceFieldUpdater finishReadFutureUpdater = - PlatformDependent.newAtomicReferenceFieldUpdater(LocalChannel.class, "finishReadFuture"); - if (finishReadFutureUpdater == null) { - finishReadFutureUpdater = - AtomicReferenceFieldUpdater.newUpdater(LocalChannel.class, Future.class, "finishReadFuture"); - } - FINISH_READ_FUTURE_UPDATER = finishReadFutureUpdater; - } - public LocalChannel() { super(null); config().setAllocator(new PreferHeapByteBufAllocator(config.getAllocator()));