|
|
@ -18,16 +18,16 @@ package io.netty.util.internal; |
|
|
|
import io.netty.util.CharsetUtil; |
|
|
|
import io.netty.util.CharsetUtil; |
|
|
|
import io.netty.util.internal.logging.InternalLogger; |
|
|
|
import io.netty.util.internal.logging.InternalLogger; |
|
|
|
import io.netty.util.internal.logging.InternalLoggerFactory; |
|
|
|
import io.netty.util.internal.logging.InternalLoggerFactory; |
|
|
|
import org.jctools.queues.MpscArrayQueue; |
|
|
|
import io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueue; |
|
|
|
import org.jctools.queues.MpscChunkedArrayQueue; |
|
|
|
import io.netty.util.internal.shaded.org.jctools.queues.MpscChunkedArrayQueue; |
|
|
|
import org.jctools.queues.MpscUnboundedArrayQueue; |
|
|
|
import io.netty.util.internal.shaded.org.jctools.queues.MpscUnboundedArrayQueue; |
|
|
|
import org.jctools.queues.SpscLinkedQueue; |
|
|
|
import io.netty.util.internal.shaded.org.jctools.queues.SpscLinkedQueue; |
|
|
|
import org.jctools.queues.atomic.MpscAtomicArrayQueue; |
|
|
|
import io.netty.util.internal.shaded.org.jctools.queues.atomic.MpscAtomicArrayQueue; |
|
|
|
import org.jctools.queues.atomic.MpscChunkedAtomicArrayQueue; |
|
|
|
import io.netty.util.internal.shaded.org.jctools.queues.atomic.MpscChunkedAtomicArrayQueue; |
|
|
|
import org.jctools.queues.atomic.MpscUnboundedAtomicArrayQueue; |
|
|
|
import io.netty.util.internal.shaded.org.jctools.queues.atomic.MpscUnboundedAtomicArrayQueue; |
|
|
|
import org.jctools.queues.atomic.SpscLinkedAtomicQueue; |
|
|
|
import io.netty.util.internal.shaded.org.jctools.queues.atomic.SpscLinkedAtomicQueue; |
|
|
|
import org.jctools.util.Pow2; |
|
|
|
import io.netty.util.internal.shaded.org.jctools.util.Pow2; |
|
|
|
import org.jctools.util.UnsafeAccess; |
|
|
|
import io.netty.util.internal.shaded.org.jctools.util.UnsafeAccess; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
|
import java.io.BufferedReader; |
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
@ -200,7 +200,7 @@ public final class PlatformDependent { |
|
|
|
|
|
|
|
|
|
|
|
// We should always prefer direct buffers by default if we can use a Cleaner to release direct buffers.
|
|
|
|
// We should always prefer direct buffers by default if we can use a Cleaner to release direct buffers.
|
|
|
|
DIRECT_BUFFER_PREFERRED = CLEANER != NOOP |
|
|
|
DIRECT_BUFFER_PREFERRED = CLEANER != NOOP |
|
|
|
&& !SystemPropertyUtil.getBoolean("io.netty.noPreferDirect", false); |
|
|
|
&& !SystemPropertyUtil.getBoolean("io.netty.noPreferDirect", false); |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
logger.debug("-Dio.netty.noPreferDirect: {}", !DIRECT_BUFFER_PREFERRED); |
|
|
|
logger.debug("-Dio.netty.noPreferDirect: {}", !DIRECT_BUFFER_PREFERRED); |
|
|
|
} |
|
|
|
} |
|
|
@ -212,8 +212,8 @@ public final class PlatformDependent { |
|
|
|
if (CLEANER == NOOP && !PlatformDependent0.isExplicitNoUnsafe()) { |
|
|
|
if (CLEANER == NOOP && !PlatformDependent0.isExplicitNoUnsafe()) { |
|
|
|
logger.info( |
|
|
|
logger.info( |
|
|
|
"Your platform does not provide complete low-level API for accessing direct buffers reliably. " + |
|
|
|
"Your platform does not provide complete low-level API for accessing direct buffers reliably. " + |
|
|
|
"Unless explicitly requested, heap buffer will always be preferred to avoid potential system " + |
|
|
|
"Unless explicitly requested, heap buffer will always be preferred to avoid potential system " + |
|
|
|
"instability."); |
|
|
|
"instability."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final Set<String> allowedClassifiers = Collections.unmodifiableSet( |
|
|
|
final Set<String> allowedClassifiers = Collections.unmodifiableSet( |
|
|
@ -626,14 +626,14 @@ public final class PlatformDependent { |
|
|
|
if (BIG_ENDIAN_NATIVE_ORDER) { |
|
|
|
if (BIG_ENDIAN_NATIVE_ORDER) { |
|
|
|
// mimic a unsafe.getInt call on a big endian machine
|
|
|
|
// mimic a unsafe.getInt call on a big endian machine
|
|
|
|
return (value.charAt(offset + 3) & 0x1f) | |
|
|
|
return (value.charAt(offset + 3) & 0x1f) | |
|
|
|
(value.charAt(offset + 2) & 0x1f) << 8 | |
|
|
|
(value.charAt(offset + 2) & 0x1f) << 8 | |
|
|
|
(value.charAt(offset + 1) & 0x1f) << 16 | |
|
|
|
(value.charAt(offset + 1) & 0x1f) << 16 | |
|
|
|
(value.charAt(offset) & 0x1f) << 24; |
|
|
|
(value.charAt(offset) & 0x1f) << 24; |
|
|
|
} |
|
|
|
} |
|
|
|
return (value.charAt(offset + 3) & 0x1f) << 24 | |
|
|
|
return (value.charAt(offset + 3) & 0x1f) << 24 | |
|
|
|
(value.charAt(offset + 2) & 0x1f) << 16 | |
|
|
|
(value.charAt(offset + 2) & 0x1f) << 16 | |
|
|
|
(value.charAt(offset + 1) & 0x1f) << 8 | |
|
|
|
(value.charAt(offset + 1) & 0x1f) << 8 | |
|
|
|
(value.charAt(offset) & 0x1f); |
|
|
|
(value.charAt(offset) & 0x1f); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -710,7 +710,7 @@ public final class PlatformDependent { |
|
|
|
|
|
|
|
|
|
|
|
public static void copyMemory(byte[] src, int srcIndex, byte[] dst, int dstIndex, long length) { |
|
|
|
public static void copyMemory(byte[] src, int srcIndex, byte[] dst, int dstIndex, long length) { |
|
|
|
PlatformDependent0.copyMemory(src, BYTE_ARRAY_BASE_OFFSET + srcIndex, |
|
|
|
PlatformDependent0.copyMemory(src, BYTE_ARRAY_BASE_OFFSET + srcIndex, |
|
|
|
dst, BYTE_ARRAY_BASE_OFFSET + dstIndex, length); |
|
|
|
dst, BYTE_ARRAY_BASE_OFFSET + dstIndex, length); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void copyMemory(long srcAddr, byte[] dst, int dstIndex, long length) { |
|
|
|
public static void copyMemory(long srcAddr, byte[] dst, int dstIndex, long length) { |
|
|
@ -834,8 +834,8 @@ public final class PlatformDependent { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static boolean equals(byte[] bytes1, int startPos1, byte[] bytes2, int startPos2, int length) { |
|
|
|
public static boolean equals(byte[] bytes1, int startPos1, byte[] bytes2, int startPos2, int length) { |
|
|
|
return !hasUnsafe() || !unalignedAccess() ? |
|
|
|
return !hasUnsafe() || !unalignedAccess() ? |
|
|
|
equalsSafe(bytes1, startPos1, bytes2, startPos2, length) : |
|
|
|
equalsSafe(bytes1, startPos1, bytes2, startPos2, length) : |
|
|
|
PlatformDependent0.equals(bytes1, startPos1, bytes2, startPos2, length); |
|
|
|
PlatformDependent0.equals(bytes1, startPos1, bytes2, startPos2, length); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -874,8 +874,8 @@ public final class PlatformDependent { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static int equalsConstantTime(byte[] bytes1, int startPos1, byte[] bytes2, int startPos2, int length) { |
|
|
|
public static int equalsConstantTime(byte[] bytes1, int startPos1, byte[] bytes2, int startPos2, int length) { |
|
|
|
return !hasUnsafe() || !unalignedAccess() ? |
|
|
|
return !hasUnsafe() || !unalignedAccess() ? |
|
|
|
ConstantTimeUtils.equalsConstantTime(bytes1, startPos1, bytes2, startPos2, length) : |
|
|
|
ConstantTimeUtils.equalsConstantTime(bytes1, startPos1, bytes2, startPos2, length) : |
|
|
|
PlatformDependent0.equalsConstantTime(bytes1, startPos1, bytes2, startPos2, length); |
|
|
|
PlatformDependent0.equalsConstantTime(bytes1, startPos1, bytes2, startPos2, length); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -965,10 +965,10 @@ public final class PlatformDependent { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (unsafe == null) { |
|
|
|
if (unsafe == null) { |
|
|
|
logger.debug("org.jctools-core.MpscChunkedArrayQueue: unavailable"); |
|
|
|
logger.debug("io.netty.util.internal.shaded.org.jctools.core.MpscChunkedArrayQueue: unavailable"); |
|
|
|
USE_MPSC_CHUNKED_ARRAY_QUEUE = false; |
|
|
|
USE_MPSC_CHUNKED_ARRAY_QUEUE = false; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
logger.debug("org.jctools-core.MpscChunkedArrayQueue: available"); |
|
|
|
logger.debug("io.netty.util.internal.shaded.org.jctools.core.MpscChunkedArrayQueue: available"); |
|
|
|
USE_MPSC_CHUNKED_ARRAY_QUEUE = true; |
|
|
|
USE_MPSC_CHUNKED_ARRAY_QUEUE = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -988,7 +988,7 @@ public final class PlatformDependent { |
|
|
|
|
|
|
|
|
|
|
|
static <T> Queue<T> newMpscQueue() { |
|
|
|
static <T> Queue<T> newMpscQueue() { |
|
|
|
return USE_MPSC_CHUNKED_ARRAY_QUEUE ? new MpscUnboundedArrayQueue<T>(MPSC_CHUNK_SIZE) |
|
|
|
return USE_MPSC_CHUNKED_ARRAY_QUEUE ? new MpscUnboundedArrayQueue<T>(MPSC_CHUNK_SIZE) |
|
|
|
: new MpscUnboundedAtomicArrayQueue<T>(MPSC_CHUNK_SIZE); |
|
|
|
: new MpscUnboundedAtomicArrayQueue<T>(MPSC_CHUNK_SIZE); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1403,27 +1403,27 @@ public final class PlatformDependent { |
|
|
|
hash = PlatformDependent0.hashCodeAsciiCompute(getLongSafe(bytes, i), hash); |
|
|
|
hash = PlatformDependent0.hashCodeAsciiCompute(getLongSafe(bytes, i), hash); |
|
|
|
} |
|
|
|
} |
|
|
|
switch(remainingBytes) { |
|
|
|
switch(remainingBytes) { |
|
|
|
case 7: |
|
|
|
case 7: |
|
|
|
return ((hash * HASH_CODE_C1 + hashCodeAsciiSanitize(bytes[startPos])) |
|
|
|
return ((hash * HASH_CODE_C1 + hashCodeAsciiSanitize(bytes[startPos])) |
|
|
|
* HASH_CODE_C2 + hashCodeAsciiSanitize(getShortSafe(bytes, startPos + 1))) |
|
|
|
* HASH_CODE_C2 + hashCodeAsciiSanitize(getShortSafe(bytes, startPos + 1))) |
|
|
|
* HASH_CODE_C1 + hashCodeAsciiSanitize(getIntSafe(bytes, startPos + 3)); |
|
|
|
* HASH_CODE_C1 + hashCodeAsciiSanitize(getIntSafe(bytes, startPos + 3)); |
|
|
|
case 6: |
|
|
|
case 6: |
|
|
|
return (hash * HASH_CODE_C1 + hashCodeAsciiSanitize(getShortSafe(bytes, startPos))) |
|
|
|
return (hash * HASH_CODE_C1 + hashCodeAsciiSanitize(getShortSafe(bytes, startPos))) |
|
|
|
* HASH_CODE_C2 + hashCodeAsciiSanitize(getIntSafe(bytes, startPos + 2)); |
|
|
|
* HASH_CODE_C2 + hashCodeAsciiSanitize(getIntSafe(bytes, startPos + 2)); |
|
|
|
case 5: |
|
|
|
case 5: |
|
|
|
return (hash * HASH_CODE_C1 + hashCodeAsciiSanitize(bytes[startPos])) |
|
|
|
return (hash * HASH_CODE_C1 + hashCodeAsciiSanitize(bytes[startPos])) |
|
|
|
* HASH_CODE_C2 + hashCodeAsciiSanitize(getIntSafe(bytes, startPos + 1)); |
|
|
|
* HASH_CODE_C2 + hashCodeAsciiSanitize(getIntSafe(bytes, startPos + 1)); |
|
|
|
case 4: |
|
|
|
case 4: |
|
|
|
return hash * HASH_CODE_C1 + hashCodeAsciiSanitize(getIntSafe(bytes, startPos)); |
|
|
|
return hash * HASH_CODE_C1 + hashCodeAsciiSanitize(getIntSafe(bytes, startPos)); |
|
|
|
case 3: |
|
|
|
case 3: |
|
|
|
return (hash * HASH_CODE_C1 + hashCodeAsciiSanitize(bytes[startPos])) |
|
|
|
return (hash * HASH_CODE_C1 + hashCodeAsciiSanitize(bytes[startPos])) |
|
|
|
* HASH_CODE_C2 + hashCodeAsciiSanitize(getShortSafe(bytes, startPos + 1)); |
|
|
|
* HASH_CODE_C2 + hashCodeAsciiSanitize(getShortSafe(bytes, startPos + 1)); |
|
|
|
case 2: |
|
|
|
case 2: |
|
|
|
return hash * HASH_CODE_C1 + hashCodeAsciiSanitize(getShortSafe(bytes, startPos)); |
|
|
|
return hash * HASH_CODE_C1 + hashCodeAsciiSanitize(getShortSafe(bytes, startPos)); |
|
|
|
case 1: |
|
|
|
case 1: |
|
|
|
return hash * HASH_CODE_C1 + hashCodeAsciiSanitize(bytes[startPos]); |
|
|
|
return hash * HASH_CODE_C1 + hashCodeAsciiSanitize(bytes[startPos]); |
|
|
|
default: |
|
|
|
default: |
|
|
|
return hash; |
|
|
|
return hash; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|