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.
This commit is contained in:
Norman Maurer 2016-12-09 15:51:14 +01:00 committed by Norman Maurer
parent 5fec897ef7
commit 89e93968ac
19 changed files with 37 additions and 441 deletions

View File

@ -17,7 +17,6 @@
package io.netty.buffer; package io.netty.buffer;
import io.netty.util.IllegalReferenceCountException; import io.netty.util.IllegalReferenceCountException;
import io.netty.util.internal.PlatformDependent;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
@ -28,16 +27,8 @@ import static io.netty.util.internal.ObjectUtil.checkPositive;
*/ */
public abstract class AbstractReferenceCountedByteBuf extends AbstractByteBuf { public abstract class AbstractReferenceCountedByteBuf extends AbstractByteBuf {
private static final AtomicIntegerFieldUpdater<AbstractReferenceCountedByteBuf> refCntUpdater; private static final AtomicIntegerFieldUpdater<AbstractReferenceCountedByteBuf> refCntUpdater =
AtomicIntegerFieldUpdater.newUpdater(AbstractReferenceCountedByteBuf.class, "refCnt");
static {
AtomicIntegerFieldUpdater<AbstractReferenceCountedByteBuf> updater =
PlatformDependent.newAtomicIntegerFieldUpdater(AbstractReferenceCountedByteBuf.class, "refCnt");
if (updater == null) {
updater = AtomicIntegerFieldUpdater.newUpdater(AbstractReferenceCountedByteBuf.class, "refCnt");
}
refCntUpdater = updater;
}
private volatile int refCnt = 1; private volatile int refCnt = 1;

View File

@ -15,8 +15,6 @@
*/ */
package io.netty.util; package io.netty.util;
import io.netty.util.internal.PlatformDependent;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import static io.netty.util.internal.ObjectUtil.checkPositive; 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 { public abstract class AbstractReferenceCounted implements ReferenceCounted {
private static final AtomicIntegerFieldUpdater<AbstractReferenceCounted> refCntUpdater; private static final AtomicIntegerFieldUpdater<AbstractReferenceCounted> refCntUpdater =
AtomicIntegerFieldUpdater.newUpdater(AbstractReferenceCounted.class, "refCnt");
static {
AtomicIntegerFieldUpdater<AbstractReferenceCounted> updater =
PlatformDependent.newAtomicIntegerFieldUpdater(AbstractReferenceCounted.class, "refCnt");
if (updater == null) {
updater = AtomicIntegerFieldUpdater.newUpdater(AbstractReferenceCounted.class, "refCnt");
}
refCntUpdater = updater;
}
private volatile int refCnt = 1; private volatile int refCnt = 1;

View File

@ -15,8 +15,6 @@
*/ */
package io.netty.util; package io.netty.util;
import io.netty.util.internal.PlatformDependent;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReferenceArray; import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
@ -28,18 +26,8 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
public class DefaultAttributeMap implements AttributeMap { public class DefaultAttributeMap implements AttributeMap {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static final AtomicReferenceFieldUpdater<DefaultAttributeMap, AtomicReferenceArray> updater; private static final AtomicReferenceFieldUpdater<DefaultAttributeMap, AtomicReferenceArray> updater =
AtomicReferenceFieldUpdater.newUpdater(DefaultAttributeMap.class, AtomicReferenceArray.class, "attributes");
static {
@SuppressWarnings("rawtypes")
AtomicReferenceFieldUpdater<DefaultAttributeMap, AtomicReferenceArray> referenceFieldUpdater =
PlatformDependent.newAtomicReferenceFieldUpdater(DefaultAttributeMap.class, "attributes");
if (referenceFieldUpdater == null) {
referenceFieldUpdater = AtomicReferenceFieldUpdater
.newUpdater(DefaultAttributeMap.class, AtomicReferenceArray.class, "attributes");
}
updater = referenceFieldUpdater;
}
private static final int BUCKET_SIZE = 4; private static final int BUCKET_SIZE = 4;
private static final int MASK = BUCKET_SIZE - 1; private static final int MASK = BUCKET_SIZE - 1;

View File

@ -81,15 +81,8 @@ public class HashedWheelTimer implements Timer {
private static final ResourceLeakDetector<HashedWheelTimer> leakDetector = ResourceLeakDetectorFactory.instance() private static final ResourceLeakDetector<HashedWheelTimer> leakDetector = ResourceLeakDetectorFactory.instance()
.newResourceLeakDetector(HashedWheelTimer.class, 1, Runtime.getRuntime().availableProcessors() * 4L); .newResourceLeakDetector(HashedWheelTimer.class, 1, Runtime.getRuntime().availableProcessors() * 4L);
private static final AtomicIntegerFieldUpdater<HashedWheelTimer> WORKER_STATE_UPDATER; private static final AtomicIntegerFieldUpdater<HashedWheelTimer> WORKER_STATE_UPDATER =
static { AtomicIntegerFieldUpdater.newUpdater(HashedWheelTimer.class, "workerState");
AtomicIntegerFieldUpdater<HashedWheelTimer> workerStateUpdater =
PlatformDependent.newAtomicIntegerFieldUpdater(HashedWheelTimer.class, "workerState");
if (workerStateUpdater == null) {
workerStateUpdater = AtomicIntegerFieldUpdater.newUpdater(HashedWheelTimer.class, "workerState");
}
WORKER_STATE_UPDATER = workerStateUpdater;
}
private final ResourceLeakTracker<HashedWheelTimer> leak; private final ResourceLeakTracker<HashedWheelTimer> leak;
private final Worker worker = new Worker(); 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_INIT = 0;
private static final int ST_CANCELLED = 1; private static final int ST_CANCELLED = 1;
private static final int ST_EXPIRED = 2; private static final int ST_EXPIRED = 2;
private static final AtomicIntegerFieldUpdater<HashedWheelTimeout> STATE_UPDATER; private static final AtomicIntegerFieldUpdater<HashedWheelTimeout> STATE_UPDATER =
AtomicIntegerFieldUpdater.newUpdater(HashedWheelTimeout.class, "state");
static {
AtomicIntegerFieldUpdater<HashedWheelTimeout> updater =
PlatformDependent.newAtomicIntegerFieldUpdater(HashedWheelTimeout.class, "state");
if (updater == null) {
updater = AtomicIntegerFieldUpdater.newUpdater(HashedWheelTimeout.class, "state");
}
STATE_UPDATER = updater;
}
private final HashedWheelTimer timer; private final HashedWheelTimer timer;
private final TimerTask task; private final TimerTask task;

View File

@ -38,20 +38,13 @@ public class DefaultPromise<V> extends AbstractFuture<V> implements Promise<V> {
private static final int MAX_LISTENER_STACK_DEPTH = Math.min(8, private static final int MAX_LISTENER_STACK_DEPTH = Math.min(8,
SystemPropertyUtil.getInt("io.netty.defaultPromise.maxListenerStackDepth", 8)); SystemPropertyUtil.getInt("io.netty.defaultPromise.maxListenerStackDepth", 8));
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static final AtomicReferenceFieldUpdater<DefaultPromise, Object> RESULT_UPDATER; private static final AtomicReferenceFieldUpdater<DefaultPromise, Object> RESULT_UPDATER =
AtomicReferenceFieldUpdater.newUpdater(DefaultPromise.class, Object.class, "result");
private static final Signal SUCCESS = Signal.valueOf(DefaultPromise.class, "SUCCESS"); private static final Signal SUCCESS = Signal.valueOf(DefaultPromise.class, "SUCCESS");
private static final Signal UNCANCELLABLE = Signal.valueOf(DefaultPromise.class, "UNCANCELLABLE"); private static final Signal UNCANCELLABLE = Signal.valueOf(DefaultPromise.class, "UNCANCELLABLE");
private static final CauseHolder CANCELLATION_CAUSE_HOLDER = new CauseHolder(ThrowableUtil.unknownStackTrace( private static final CauseHolder CANCELLATION_CAUSE_HOLDER = new CauseHolder(ThrowableUtil.unknownStackTrace(
new CancellationException(), DefaultPromise.class, "cancel(...)")); new CancellationException(), DefaultPromise.class, "cancel(...)"));
static {
@SuppressWarnings("rawtypes")
AtomicReferenceFieldUpdater<DefaultPromise, Object> updater =
PlatformDependent.newAtomicReferenceFieldUpdater(DefaultPromise.class, "result");
RESULT_UPDATER = updater == null ? AtomicReferenceFieldUpdater.newUpdater(DefaultPromise.class,
Object.class, "result") : updater;
}
private volatile Object result; private volatile Object result;
private final EventExecutor executor; private final EventExecutor executor;
/** /**

View File

@ -16,7 +16,6 @@
package io.netty.util.concurrent; package io.netty.util.concurrent;
import io.netty.util.internal.ObjectUtil; import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.SystemPropertyUtil; import io.netty.util.internal.SystemPropertyUtil;
import io.netty.util.internal.UnstableApi; import io.netty.util.internal.UnstableApi;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
@ -73,25 +72,11 @@ public abstract class SingleThreadEventExecutor extends AbstractScheduledEventEx
} }
}; };
private static final AtomicIntegerFieldUpdater<SingleThreadEventExecutor> STATE_UPDATER; private static final AtomicIntegerFieldUpdater<SingleThreadEventExecutor> STATE_UPDATER =
private static final AtomicReferenceFieldUpdater<SingleThreadEventExecutor, ThreadProperties> PROPERTIES_UPDATER; AtomicIntegerFieldUpdater.newUpdater(SingleThreadEventExecutor.class, "state");
private static final AtomicReferenceFieldUpdater<SingleThreadEventExecutor, ThreadProperties> PROPERTIES_UPDATER =
static { AtomicReferenceFieldUpdater.newUpdater(
AtomicIntegerFieldUpdater<SingleThreadEventExecutor> updater = SingleThreadEventExecutor.class, ThreadProperties.class, "threadProperties");
PlatformDependent.newAtomicIntegerFieldUpdater(SingleThreadEventExecutor.class, "state");
if (updater == null) {
updater = AtomicIntegerFieldUpdater.newUpdater(SingleThreadEventExecutor.class, "state");
}
STATE_UPDATER = updater;
AtomicReferenceFieldUpdater<SingleThreadEventExecutor, ThreadProperties> propertiesUpdater =
PlatformDependent.newAtomicReferenceFieldUpdater(SingleThreadEventExecutor.class, "threadProperties");
if (propertiesUpdater == null) {
propertiesUpdater = AtomicReferenceFieldUpdater.newUpdater(SingleThreadEventExecutor.class,
ThreadProperties.class, "threadProperties");
}
PROPERTIES_UPDATER = propertiesUpdater;
}
private final Queue<Runnable> taskQueue; private final Queue<Runnable> taskQueue;

View File

@ -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 <U, W> AtomicReferenceFieldUpdater<U, W> newAtomicReferenceFieldUpdater(
Class<? super U> 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 <T> AtomicIntegerFieldUpdater<T> newAtomicIntegerFieldUpdater(
Class<? super T> 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 <T> AtomicLongFieldUpdater<T> newAtomicLongFieldUpdater(
Class<? super T> 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 class Mpsc {
private static final boolean USE_MPSC_CHUNKED_ARRAY_QUEUE; private static final boolean USE_MPSC_CHUNKED_ARRAY_QUEUE;

View File

@ -559,21 +559,6 @@ final class PlatformDependent0 {
return value & 0x1f; return value & 0x1f;
} }
static <U, W> AtomicReferenceFieldUpdater<U, W> newAtomicReferenceFieldUpdater(
Class<? super U> tclass, String fieldName) throws Exception {
return new UnsafeAtomicReferenceFieldUpdater<U, W>(UNSAFE, tclass, fieldName);
}
static <T> AtomicIntegerFieldUpdater<T> newAtomicIntegerFieldUpdater(
Class<? super T> tclass, String fieldName) throws Exception {
return new UnsafeAtomicIntegerFieldUpdater<T>(UNSAFE, tclass, fieldName);
}
static <T> AtomicLongFieldUpdater<T> newAtomicLongFieldUpdater(
Class<? super T> tclass, String fieldName) throws Exception {
return new UnsafeAtomicLongFieldUpdater<T>(UNSAFE, tclass, fieldName);
}
static ClassLoader getClassLoader(final Class<?> clazz) { static ClassLoader getClassLoader(final Class<?> clazz) {
if (System.getSecurityManager() == null) { if (System.getSecurityManager() == null) {
return clazz.getClassLoader(); return clazz.getClassLoader();

View File

@ -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<T> extends AtomicIntegerFieldUpdater<T> {
private final long offset;
private final Unsafe unsafe;
UnsafeAtomicIntegerFieldUpdater(Unsafe unsafe, Class<? super T> 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);
}
}

View File

@ -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<T> extends AtomicLongFieldUpdater<T> {
private final long offset;
private final Unsafe unsafe;
UnsafeAtomicLongFieldUpdater(Unsafe unsafe, Class<? super T> 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);
}
}

View File

@ -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<U, M> extends AtomicReferenceFieldUpdater<U, M> {
private final long offset;
private final Unsafe unsafe;
UnsafeAtomicReferenceFieldUpdater(Unsafe unsafe, Class<? super U> 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);
}
}

View File

@ -102,13 +102,6 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc
ResourceLeakDetectorFactory.instance().newResourceLeakDetector(ReferenceCountedOpenSslEngine.class); ResourceLeakDetectorFactory.instance().newResourceLeakDetector(ReferenceCountedOpenSslEngine.class);
static { static {
AtomicIntegerFieldUpdater<ReferenceCountedOpenSslEngine> destroyedUpdater =
PlatformDependent.newAtomicIntegerFieldUpdater(ReferenceCountedOpenSslEngine.class, "destroyed");
if (destroyedUpdater == null) {
destroyedUpdater = AtomicIntegerFieldUpdater.newUpdater(ReferenceCountedOpenSslEngine.class, "destroyed");
}
DESTROYED_UPDATER = destroyedUpdater;
Method getUseCipherSuitesOrderMethod = null; Method getUseCipherSuitesOrderMethod = null;
Method setUseCipherSuitesOrderMethod = null; Method setUseCipherSuitesOrderMethod = null;
Class<?> sniHostNameClass = 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; static final int MAX_ENCRYPTION_OVERHEAD_LENGTH = MAX_ENCRYPTED_PACKET_LENGTH - MAX_PLAINTEXT_LENGTH;
private static final AtomicIntegerFieldUpdater<ReferenceCountedOpenSslEngine> DESTROYED_UPDATER; private static final AtomicIntegerFieldUpdater<ReferenceCountedOpenSslEngine> DESTROYED_UPDATER =
AtomicIntegerFieldUpdater.newUpdater(ReferenceCountedOpenSslEngine.class, "destroyed");
private static final String INVALID_CIPHER = "SSL_NULL_WITH_NULL_NULL"; private static final String INVALID_CIPHER = "SSL_NULL_WITH_NULL_NULL";

View File

@ -16,25 +16,13 @@
package io.netty.resolver.dns; package io.netty.resolver.dns;
import io.netty.util.internal.PlatformDependent;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
final class RotationalDnsServerAddresses extends DefaultDnsServerAddresses { final class RotationalDnsServerAddresses extends DefaultDnsServerAddresses {
private static final AtomicIntegerFieldUpdater<RotationalDnsServerAddresses> startIdxUpdater; private static final AtomicIntegerFieldUpdater<RotationalDnsServerAddresses> startIdxUpdater =
AtomicIntegerFieldUpdater.newUpdater(RotationalDnsServerAddresses.class, "startIdx");
static {
AtomicIntegerFieldUpdater<RotationalDnsServerAddresses> updater =
PlatformDependent.newAtomicIntegerFieldUpdater(RotationalDnsServerAddresses.class, "startIdx");
if (updater == null) {
updater = AtomicIntegerFieldUpdater.newUpdater(RotationalDnsServerAddresses.class, "startIdx");
}
startIdxUpdater = updater;
}
@SuppressWarnings("UnusedDeclaration") @SuppressWarnings("UnusedDeclaration")
private volatile int startIdx; private volatile int startIdx;

View File

@ -43,16 +43,8 @@ import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
*/ */
final class EpollEventLoop extends SingleThreadEventLoop { final class EpollEventLoop extends SingleThreadEventLoop {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(EpollEventLoop.class); private static final InternalLogger logger = InternalLoggerFactory.getInstance(EpollEventLoop.class);
private static final AtomicIntegerFieldUpdater<EpollEventLoop> WAKEN_UP_UPDATER; private static final AtomicIntegerFieldUpdater<EpollEventLoop> WAKEN_UP_UPDATER =
AtomicIntegerFieldUpdater.newUpdater(EpollEventLoop.class, "wakenUp");
static {
AtomicIntegerFieldUpdater<EpollEventLoop> updater =
PlatformDependent.newAtomicIntegerFieldUpdater(EpollEventLoop.class, "wakenUp");
if (updater == null) {
updater = AtomicIntegerFieldUpdater.newUpdater(EpollEventLoop.class, "wakenUp");
}
WAKEN_UP_UPDATER = updater;
}
private final FileDescriptor epollFd; private final FileDescriptor epollFd;
private final FileDescriptor eventFd; private final FileDescriptor eventFd;

View File

@ -15,7 +15,6 @@
*/ */
package io.netty.channel.unix; package io.netty.channel.unix;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.ThrowableUtil; import io.netty.util.internal.ThrowableUtil;
import java.io.File; import java.io.File;
@ -64,15 +63,8 @@ public class FileDescriptor {
ThrowableUtil.unknownStackTrace(Errors.newConnectionResetException("syscall:read(...)", ThrowableUtil.unknownStackTrace(Errors.newConnectionResetException("syscall:read(...)",
Errors.ERRNO_ECONNRESET_NEGATIVE), FileDescriptor.class, "readAddress(...)"); Errors.ERRNO_ECONNRESET_NEGATIVE), FileDescriptor.class, "readAddress(...)");
private static final AtomicIntegerFieldUpdater<FileDescriptor> stateUpdater; private static final AtomicIntegerFieldUpdater<FileDescriptor> stateUpdater =
static { AtomicIntegerFieldUpdater.newUpdater(FileDescriptor.class, "state");
AtomicIntegerFieldUpdater<FileDescriptor> updater
= PlatformDependent.newAtomicIntegerFieldUpdater(FileDescriptor.class, "state");
if (updater == null) {
updater = AtomicIntegerFieldUpdater.newUpdater(FileDescriptor.class, "state");
}
stateUpdater = updater;
}
private static final int STATE_CLOSED_MASK = 1; private static final int STATE_CLOSED_MASK = 1;
private static final int STATE_INPUT_SHUTDOWN_MASK = 1 << 1; private static final int STATE_INPUT_SHUTDOWN_MASK = 1 << 1;

View File

@ -24,7 +24,6 @@ import io.netty.util.ReferenceCountUtil;
import io.netty.util.ResourceLeakHint; import io.netty.util.ResourceLeakHint;
import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.OrderedEventExecutor; import io.netty.util.concurrent.OrderedEventExecutor;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.PromiseNotificationUtil; import io.netty.util.internal.PromiseNotificationUtil;
import io.netty.util.internal.ThrowableUtil; import io.netty.util.internal.ThrowableUtil;
import io.netty.util.internal.ObjectUtil; import io.netty.util.internal.ObjectUtil;
@ -43,17 +42,8 @@ abstract class AbstractChannelHandlerContext extends DefaultAttributeMap
volatile AbstractChannelHandlerContext next; volatile AbstractChannelHandlerContext next;
volatile AbstractChannelHandlerContext prev; volatile AbstractChannelHandlerContext prev;
private static final AtomicIntegerFieldUpdater<AbstractChannelHandlerContext> HANDLER_STATE_UPDATER; private static final AtomicIntegerFieldUpdater<AbstractChannelHandlerContext> HANDLER_STATE_UPDATER =
AtomicIntegerFieldUpdater.newUpdater(AbstractChannelHandlerContext.class, "handlerState");
static {
AtomicIntegerFieldUpdater<AbstractChannelHandlerContext> handlerStateUpdater = PlatformDependent
.newAtomicIntegerFieldUpdater(AbstractChannelHandlerContext.class, "handlerState");
if (handlerStateUpdater == null) {
handlerStateUpdater = AtomicIntegerFieldUpdater
.newUpdater(AbstractChannelHandlerContext.class, "handlerState");
}
HANDLER_STATE_UPDATER = handlerStateUpdater;
}
/** /**
* {@link ChannelHandler#handlerAdded(ChannelHandlerContext)} is about to be called. * {@link ChannelHandler#handlerAdded(ChannelHandlerContext)} is about to be called.

View File

@ -86,34 +86,20 @@ public final class ChannelOutboundBuffer {
private boolean inFail; private boolean inFail;
private static final AtomicLongFieldUpdater<ChannelOutboundBuffer> TOTAL_PENDING_SIZE_UPDATER; private static final AtomicLongFieldUpdater<ChannelOutboundBuffer> TOTAL_PENDING_SIZE_UPDATER =
AtomicLongFieldUpdater.newUpdater(ChannelOutboundBuffer.class, "totalPendingSize");
@SuppressWarnings("UnusedDeclaration") @SuppressWarnings("UnusedDeclaration")
private volatile long totalPendingSize; private volatile long totalPendingSize;
private static final AtomicIntegerFieldUpdater<ChannelOutboundBuffer> UNWRITABLE_UPDATER; private static final AtomicIntegerFieldUpdater<ChannelOutboundBuffer> UNWRITABLE_UPDATER =
AtomicIntegerFieldUpdater.newUpdater(ChannelOutboundBuffer.class, "unwritable");
@SuppressWarnings("UnusedDeclaration") @SuppressWarnings("UnusedDeclaration")
private volatile int unwritable; private volatile int unwritable;
private volatile Runnable fireChannelWritabilityChangedTask; private volatile Runnable fireChannelWritabilityChangedTask;
static {
AtomicIntegerFieldUpdater<ChannelOutboundBuffer> unwritableUpdater =
PlatformDependent.newAtomicIntegerFieldUpdater(ChannelOutboundBuffer.class, "unwritable");
if (unwritableUpdater == null) {
unwritableUpdater = AtomicIntegerFieldUpdater.newUpdater(ChannelOutboundBuffer.class, "unwritable");
}
UNWRITABLE_UPDATER = unwritableUpdater;
AtomicLongFieldUpdater<ChannelOutboundBuffer> pendingSizeUpdater =
PlatformDependent.newAtomicLongFieldUpdater(ChannelOutboundBuffer.class, "totalPendingSize");
if (pendingSizeUpdater == null) {
pendingSizeUpdater = AtomicLongFieldUpdater.newUpdater(ChannelOutboundBuffer.class, "totalPendingSize");
}
TOTAL_PENDING_SIZE_UPDATER = pendingSizeUpdater;
}
ChannelOutboundBuffer(AbstractChannel channel) { ChannelOutboundBuffer(AbstractChannel channel) {
this.channel = channel; this.channel = channel;
} }

View File

@ -16,7 +16,6 @@
package io.netty.channel; package io.netty.channel;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
import io.netty.util.internal.PlatformDependent;
import java.util.IdentityHashMap; import java.util.IdentityHashMap;
import java.util.Map; import java.util.Map;
@ -46,25 +45,11 @@ public class DefaultChannelConfig implements ChannelConfig {
private static final int DEFAULT_CONNECT_TIMEOUT = 30000; private static final int DEFAULT_CONNECT_TIMEOUT = 30000;
private static final AtomicIntegerFieldUpdater<DefaultChannelConfig> AUTOREAD_UPDATER; private static final AtomicIntegerFieldUpdater<DefaultChannelConfig> AUTOREAD_UPDATER =
private static final AtomicReferenceFieldUpdater<DefaultChannelConfig, WriteBufferWaterMark> WATERMARK_UPDATER; AtomicIntegerFieldUpdater.newUpdater(DefaultChannelConfig.class, "autoRead");
private static final AtomicReferenceFieldUpdater<DefaultChannelConfig, WriteBufferWaterMark> WATERMARK_UPDATER =
static { AtomicReferenceFieldUpdater.newUpdater(
AtomicIntegerFieldUpdater<DefaultChannelConfig> autoReadUpdater =
PlatformDependent.newAtomicIntegerFieldUpdater(DefaultChannelConfig.class, "autoRead");
if (autoReadUpdater == null) {
autoReadUpdater = AtomicIntegerFieldUpdater.newUpdater(DefaultChannelConfig.class, "autoRead");
}
AUTOREAD_UPDATER = autoReadUpdater;
AtomicReferenceFieldUpdater<DefaultChannelConfig, WriteBufferWaterMark> watermarkUpdater =
PlatformDependent.newAtomicReferenceFieldUpdater(DefaultChannelConfig.class, "writeBufferWaterMark");
if (watermarkUpdater == null) {
watermarkUpdater = AtomicReferenceFieldUpdater.newUpdater(
DefaultChannelConfig.class, WriteBufferWaterMark.class, "writeBufferWaterMark"); DefaultChannelConfig.class, WriteBufferWaterMark.class, "writeBufferWaterMark");
}
WATERMARK_UPDATER = watermarkUpdater;
}
protected final Channel channel; protected final Channel channel;

View File

@ -49,7 +49,8 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
public class LocalChannel extends AbstractChannel { public class LocalChannel extends AbstractChannel {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(LocalChannel.class); private static final InternalLogger logger = InternalLoggerFactory.getInstance(LocalChannel.class);
@SuppressWarnings({ "rawtypes" }) @SuppressWarnings({ "rawtypes" })
private static final AtomicReferenceFieldUpdater<LocalChannel, Future> FINISH_READ_FUTURE_UPDATER; private static final AtomicReferenceFieldUpdater<LocalChannel, Future> FINISH_READ_FUTURE_UPDATER =
AtomicReferenceFieldUpdater.newUpdater(LocalChannel.class, Future.class, "finishReadFuture");
private static final ChannelMetadata METADATA = new ChannelMetadata(false); private static final ChannelMetadata METADATA = new ChannelMetadata(false);
private static final int MAX_READER_STACK_DEPTH = 8; private static final int MAX_READER_STACK_DEPTH = 8;
private static final ClosedChannelException DO_WRITE_CLOSED_CHANNEL_EXCEPTION = ThrowableUtil.unknownStackTrace( 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 boolean writeInProgress;
private volatile Future<?> finishReadFuture; private volatile Future<?> finishReadFuture;
static {
@SuppressWarnings({ "rawtypes" })
AtomicReferenceFieldUpdater<LocalChannel, Future> finishReadFutureUpdater =
PlatformDependent.newAtomicReferenceFieldUpdater(LocalChannel.class, "finishReadFuture");
if (finishReadFutureUpdater == null) {
finishReadFutureUpdater =
AtomicReferenceFieldUpdater.newUpdater(LocalChannel.class, Future.class, "finishReadFuture");
}
FINISH_READ_FUTURE_UPDATER = finishReadFutureUpdater;
}
public LocalChannel() { public LocalChannel() {
super(null); super(null);
config().setAllocator(new PreferHeapByteBufAllocator(config.getAllocator())); config().setAllocator(new PreferHeapByteBufAllocator(config.getAllocator()));