Skip to content

Commit 6f53cda

Browse files
johnouslandelle
authored andcommitted
Remove usage of Netty Atomic*FieldUpdater in favor of JDKs (AsyncHttpClient#1317)
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 Netty Atomic*FieldUpdaters. - Use the JDK implementations everywhere. Result: Faster code.
1 parent d1758d6 commit 6f53cda

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

client/src/main/java/org/asynchttpclient/netty/NettyResponseFuture.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
package org.asynchttpclient.netty;
1515

1616
import static org.asynchttpclient.util.DateUtils.unpreciseMillisTime;
17-
import static io.netty.util.internal.PlatformDependent.*;
1817
import io.netty.channel.Channel;
1918

2019
import java.util.concurrent.CancellationException;
@@ -49,8 +48,10 @@ public final class NettyResponseFuture<V> implements ListenableFuture<V> {
4948

5049
private static final Logger LOGGER = LoggerFactory.getLogger(NettyResponseFuture.class);
5150

52-
private static final AtomicIntegerFieldUpdater<NettyResponseFuture<?>> REDIRECT_COUNT_UPDATER = newAtomicIntegerFieldUpdater(NettyResponseFuture.class, "redirectCount");
53-
private static final AtomicIntegerFieldUpdater<NettyResponseFuture<?>> CURRENT_RETRY_UPDATER = newAtomicIntegerFieldUpdater(NettyResponseFuture.class, "currentRetry");
51+
@SuppressWarnings("rawtypes")
52+
private static final AtomicIntegerFieldUpdater<NettyResponseFuture> REDIRECT_COUNT_UPDATER = AtomicIntegerFieldUpdater.newUpdater(NettyResponseFuture.class, "redirectCount");
53+
@SuppressWarnings("rawtypes")
54+
private static final AtomicIntegerFieldUpdater<NettyResponseFuture> CURRENT_RETRY_UPDATER = AtomicIntegerFieldUpdater.newUpdater(NettyResponseFuture.class, "currentRetry");
5455

5556
private final long start = unpreciseMillisTime();
5657
private final ChannelPoolPartitioning connectionPoolPartitioning;
@@ -70,13 +71,20 @@ public final class NettyResponseFuture<V> implements ListenableFuture<V> {
7071
@SuppressWarnings("unused")
7172
private volatile int onThrowableCalled = 0;
7273

73-
private static final AtomicIntegerFieldUpdater<NettyResponseFuture<?>> isDoneField = newAtomicIntegerFieldUpdater(NettyResponseFuture.class, "isDone");
74-
private static final AtomicIntegerFieldUpdater<NettyResponseFuture<?>> isCancelledField = newAtomicIntegerFieldUpdater(NettyResponseFuture.class, "isCancelled");
75-
private static final AtomicIntegerFieldUpdater<NettyResponseFuture<?>> inAuthField = newAtomicIntegerFieldUpdater(NettyResponseFuture.class, "inAuth");
76-
private static final AtomicIntegerFieldUpdater<NettyResponseFuture<?>> inProxyAuthField = newAtomicIntegerFieldUpdater(NettyResponseFuture.class, "inProxyAuth");
77-
private static final AtomicIntegerFieldUpdater<NettyResponseFuture<?>> statusReceivedField = newAtomicIntegerFieldUpdater(NettyResponseFuture.class, "statusReceived");
78-
private static final AtomicIntegerFieldUpdater<NettyResponseFuture<?>> contentProcessedField = newAtomicIntegerFieldUpdater(NettyResponseFuture.class, "contentProcessed");
79-
private static final AtomicIntegerFieldUpdater<NettyResponseFuture<?>> onThrowableCalledField = newAtomicIntegerFieldUpdater(NettyResponseFuture.class, "onThrowableCalled");
74+
@SuppressWarnings("rawtypes")
75+
private static final AtomicIntegerFieldUpdater<NettyResponseFuture> isDoneField = AtomicIntegerFieldUpdater.newUpdater(NettyResponseFuture.class, "isDone");
76+
@SuppressWarnings("rawtypes")
77+
private static final AtomicIntegerFieldUpdater<NettyResponseFuture> isCancelledField = AtomicIntegerFieldUpdater.newUpdater(NettyResponseFuture.class, "isCancelled");
78+
@SuppressWarnings("rawtypes")
79+
private static final AtomicIntegerFieldUpdater<NettyResponseFuture> inAuthField = AtomicIntegerFieldUpdater.newUpdater(NettyResponseFuture.class, "inAuth");
80+
@SuppressWarnings("rawtypes")
81+
private static final AtomicIntegerFieldUpdater<NettyResponseFuture> inProxyAuthField = AtomicIntegerFieldUpdater.newUpdater(NettyResponseFuture.class, "inProxyAuth");
82+
@SuppressWarnings("rawtypes")
83+
private static final AtomicIntegerFieldUpdater<NettyResponseFuture> statusReceivedField = AtomicIntegerFieldUpdater.newUpdater(NettyResponseFuture.class, "statusReceived");
84+
@SuppressWarnings("rawtypes")
85+
private static final AtomicIntegerFieldUpdater<NettyResponseFuture> contentProcessedField = AtomicIntegerFieldUpdater.newUpdater(NettyResponseFuture.class, "contentProcessed");
86+
@SuppressWarnings("rawtypes")
87+
private static final AtomicIntegerFieldUpdater<NettyResponseFuture> onThrowableCalledField = AtomicIntegerFieldUpdater.newUpdater(NettyResponseFuture.class, "onThrowableCalled");
8088

8189
// volatile where we need CAS ops
8290
private volatile int redirectCount = 0;

0 commit comments

Comments
 (0)