Not use InternalThreadLocalMap where access may be done from outside the EventLoop.

Motivation:

We should not use the InternalThreadLocalMap where access may be done from outside the EventLoop as this may create a lot of memory usage while not be reused anyway.

Modifications:

Not use InternalThreadLocalMap in places where the code-path will likely be executed from outside the EventLoop.

Result:

Less memory bloat.
This commit is contained in:
Norman Maurer 2016-10-31 07:23:22 +01:00 committed by Norman Maurer
parent 29c7a7609e
commit de4692e6e0
4 changed files with 10 additions and 12 deletions

View File

@ -15,8 +15,7 @@
*/
package io.netty.handler.ssl;
import io.netty.util.internal.InternalThreadLocalMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@ -34,7 +33,7 @@ public final class IdentityCipherSuiteFilter implements CipherSuiteFilter {
if (ciphers == null) {
return defaultCiphers.toArray(new String[defaultCiphers.size()]);
} else {
List<String> newCiphers = InternalThreadLocalMap.get().arrayList(supportedCiphers.size());
List<String> newCiphers = new ArrayList<String>(supportedCiphers.size());
for (String c : ciphers) {
if (c == null) {
break;

View File

@ -24,7 +24,6 @@ import io.netty.util.ResourceLeak;
import io.netty.util.ResourceLeakDetector;
import io.netty.util.ResourceLeakDetectorFactory;
import io.netty.util.internal.EmptyArrays;
import io.netty.util.internal.InternalThreadLocalMap;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.ThrowableUtil;
@ -39,6 +38,7 @@ import java.nio.ByteBuffer;
import java.nio.ReadOnlyBufferException;
import java.security.Principal;
import java.security.cert.Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@ -1128,7 +1128,7 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc
@Override
public final String[] getEnabledProtocols() {
List<String> enabled = InternalThreadLocalMap.get().arrayList();
List<String> enabled = new ArrayList<String>(6);
// Seems like there is no way to explict disable SSLv2Hello in openssl so it is always enabled
enabled.add(OpenSsl.PROTOCOL_SSL_V2_HELLO);

View File

@ -15,9 +15,8 @@
*/
package io.netty.handler.ssl;
import io.netty.util.internal.InternalThreadLocalMap;
import javax.net.ssl.SSLEngine;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@ -41,10 +40,10 @@ public final class SupportedCipherSuiteFilter implements CipherSuiteFilter {
final List<String> newCiphers;
if (ciphers == null) {
newCiphers = InternalThreadLocalMap.get().arrayList(defaultCiphers.size());
newCiphers = new ArrayList<String>(defaultCiphers.size());
ciphers = defaultCiphers;
} else {
newCiphers = InternalThreadLocalMap.get().arrayList(supportedCiphers.size());
newCiphers = new ArrayList<String>(supportedCiphers.size());
}
for (String c : ciphers) {
if (c == null) {

View File

@ -20,7 +20,6 @@ import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.util.internal.EmptyArrays;
import io.netty.util.concurrent.FastThreadLocal;
import io.netty.util.internal.InternalThreadLocalMap;
import javax.net.ssl.ManagerFactoryParameters;
import javax.net.ssl.TrustManager;
@ -32,6 +31,7 @@ import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
@ -159,7 +159,7 @@ public final class FingerprintTrustManagerFactory extends SimpleTrustManagerFact
throw new NullPointerException("fingerprints");
}
List<byte[]> list = InternalThreadLocalMap.get().arrayList();
List<byte[]> list = new ArrayList<byte[]>(fingerprints.length);
for (byte[] f: fingerprints) {
if (f == null) {
break;
@ -179,7 +179,7 @@ public final class FingerprintTrustManagerFactory extends SimpleTrustManagerFact
throw new NullPointerException("fingerprints");
}
List<byte[]> list = InternalThreadLocalMap.get().arrayList();
List<byte[]> list = new ArrayList<byte[]>();
for (String f: fingerprints) {
if (f == null) {
break;