Package io.netty.util.internal
Class PlatformDependent
- java.lang.Object
-
- io.netty.util.internal.PlatformDependent
-
public final class PlatformDependent extends java.lang.ObjectUtility that detects various properties specific to the current runtime environment, such as Java version and the availability of thesun.misc.Unsafeobject.You can disable the use of
sun.misc.Unsafeif you specify the system property io.netty.noUnsafe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classPlatformDependent.AtomicLongCounterprivate static classPlatformDependent.Mpscprivate static interfacePlatformDependent.ThreadLocalRandomProvider
-
Field Summary
Fields Modifier and Type Field Description private static intADDRESS_SIZEprivate static java.lang.String[]ALLOWED_LINUX_OS_CLASSIFIERSstatic booleanBIG_ENDIAN_NATIVE_ORDERprivate static intBIT_MODEprivate static longBYTE_ARRAY_BASE_OFFSETprivate static booleanCAN_ENABLE_TCP_NODELAY_BY_DEFAULTprivate static CleanerCLEANERprivate static booleanDIRECT_BUFFER_PREFERREDprivate static java.util.concurrent.atomic.AtomicLongDIRECT_MEMORY_COUNTERprivate static longDIRECT_MEMORY_LIMITprivate static booleanIS_IVKVM_DOT_NETprivate static booleanIS_J9_JVMprivate static booleanIS_OSXprivate static booleanIS_WINDOWSprivate static java.lang.StringLINUX_ID_LIKE_PREFIXprivate static java.lang.StringLINUX_ID_PREFIXprivate static java.util.Set<java.lang.String>LINUX_OS_CLASSIFIERSprivate static InternalLoggerloggerprivate static intMAX_ALLOWED_MPSC_CAPACITYprivate static longMAX_DIRECT_MEMORYprivate static java.util.regex.PatternMAX_DIRECT_MEMORY_SIZE_ARG_PATTERNprivate static booleanMAYBE_SUPER_USERprivate static intMIN_MAX_MPSC_CAPACITYprivate static intMPSC_CHUNK_SIZEprivate static CleanerNOOPprivate static java.lang.StringNORMALIZED_ARCHprivate static java.lang.StringNORMALIZED_OSprivate static java.lang.String[]OS_RELEASE_FILESprivate static PlatformDependent.ThreadLocalRandomProviderRANDOM_PROVIDERprivate static java.io.FileTMPDIRprivate static intUNINITIALIZED_ARRAY_ALLOCATION_THRESHOLDprivate static java.lang.ThrowableUNSAFE_UNAVAILABILITY_CAUSEprivate static booleanUSE_DIRECT_BUFFER_NO_CLEANER
-
Constructor Summary
Constructors Modifier Constructor Description privatePlatformDependent()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static voidaddClassifier(java.util.Set<java.lang.String> allowed, java.util.Set<java.lang.String> dest, java.lang.String... maybeClassifiers)Adds only those classifier strings to dest which are present in allowed.static intaddressSize()Return the address size of the OS.private static intaddressSize0()static java.nio.ByteBufferallocateDirectNoCleaner(int capacity)Allocate a newByteBufferwith the givencapacity.static longallocateMemory(long size)static byte[]allocateUninitializedArray(int size)static intbitMode()Returns the bit mode of the current VM (usually 32 or 64.)private static intbitMode0()private static longbyteArrayBaseOffset0()static booleancanEnableTcpNoDelayByDefault()Returnstrueif and only if it is fine to enable TCP_NODELAY socket option by default.static voidcopyMemory(byte[] src, int srcIndex, long dstAddr, long length)static voidcopyMemory(long srcAddr, byte[] dst, int dstIndex, long length)static voidcopyMemory(long srcAddr, long dstAddr, long length)private static voiddecrementMemoryCounter(int capacity)static java.nio.ByteBufferdirectBuffer(long memoryAddress, int size)static longdirectBufferAddress(java.nio.ByteBuffer buffer)static booleandirectBufferPreferred()Returnstrueif the platform has reliable low-level direct buffer access API and a user has not specified-Dio.netty.noPreferDirectoption.static booleanequals(byte[] bytes1, int startPos1, byte[] bytes2, int startPos2, int length)Compare twobytearrays for equality.static intequalsConstantTime(byte[] bytes1, int startPos1, byte[] bytes2, int startPos2, int length)Compare twobytearrays for equality without leaking timing information.private static booleanequalsSafe(byte[] bytes1, int startPos1, byte[] bytes2, int startPos2, int length)static voidfreeDirectBuffer(java.nio.ByteBuffer buffer)Try to deallocate the specified directByteBuffer.static voidfreeDirectNoCleaner(java.nio.ByteBuffer buffer)This method MUST only be called forByteBuffers that were allocated viaallocateDirectNoCleaner(int).static voidfreeMemory(long address)static bytegetByte(byte[] data, int index)static bytegetByte(byte[] data, long index)static bytegetByte(long address)static java.lang.ClassLoadergetClassLoader(java.lang.Class<?> clazz)Return theClassLoaderfor the givenClass.static java.lang.ClassLoadergetContextClassLoader()Return the contextClassLoaderfor the currentThread.static intgetInt(byte[] data, int index)static intgetInt(int[] data, long index)static intgetInt(long address)static intgetInt(java.lang.Object object, long fieldOffset)private static intgetIntSafe(byte[] bytes, int offset)static longgetLong(byte[] data, int index)static longgetLong(long address)static longgetLong(long[] data, long index)private static longgetLongSafe(byte[] bytes, int offset)static java.lang.ObjectgetObject(java.lang.Object object, long fieldOffset)static shortgetShort(byte[] data, int index)static shortgetShort(long address)private static shortgetShortSafe(byte[] bytes, int offset)static java.lang.ClassLoadergetSystemClassLoader()Return the systemClassLoader.static java.lang.ThrowablegetUnsafeUnavailabilityCause()Return the reason (if any) whysun.misc.Unsafewas not available.static booleanhasDirectBufferNoCleanerConstructor()static inthashCodeAscii(byte[] bytes, int startPos, int length)Calculate a hash code of a byte array assuming ASCII character encoding.static inthashCodeAscii(java.lang.CharSequence bytes)Calculate a hash code of a byte array assuming ASCII character encoding.private static inthashCodeAsciiCompute(java.lang.CharSequence value, int offset, int hash)Identical toPlatformDependent0.hashCodeAsciiCompute(long, int)but forCharSequence.(package private) static inthashCodeAsciiSafe(byte[] bytes, int startPos, int length)Package private for testing purposes only!private static inthashCodeAsciiSanitizeByte(char value)Identical toPlatformDependent0.hashCodeAsciiSanitize(byte)but forCharSequence.private static inthashCodeAsciiSanitizeInt(java.lang.CharSequence value, int offset)Identical toPlatformDependent0.hashCodeAsciiSanitize(int)but forCharSequence.private static inthashCodeAsciiSanitizeShort(java.lang.CharSequence value, int offset)Identical toPlatformDependent0.hashCodeAsciiSanitize(short)but forCharSequence.static booleanhasUnsafe()Returntrueifsun.misc.Unsafewas found on the classpath and can be used for accelerated direct memory access.private static voidincrementMemoryCounter(int capacity)static booleanisAndroid()Returnstrueif and only if the current platform is Androidstatic booleanisIkvmDotNet()private static booleanisIkvmDotNet0()static booleanisJ9Jvm()private static booleanisJ9Jvm0()static booleanisOsx()Returntrueif the JVM is running on OSX / MacOSprivate static booleanisOsx0()static booleanisUnaligned()trueif and only if the platform supports unaligned access.static booleanisWindows()Returntrueif the JVM is running on Windowsprivate static booleanisWindows0()static booleanisZero(byte[] bytes, int startPos, int length)Determine if a subsection of an array is zero.private static booleanisZeroSafe(byte[] bytes, int startPos, int length)static intjavaVersion()Return the version of Java under which this library is used.static longmaxDirectMemory()Returns the maximum memory reserved for direct buffer allocation.private static longmaxDirectMemory0()static booleanmaybeSuperUser()Returntrueif the current user may be a super-user.private static booleanmaybeSuperUser0()static <C> java.util.Deque<C>newConcurrentDeque()Returns a new concurrentDeque.static <K,V>
java.util.concurrent.ConcurrentMap<K,V>newConcurrentHashMap()Creates a new fastestConcurrentMapimplementation for the current platform.static <K,V>
java.util.concurrent.ConcurrentMap<K,V>newConcurrentHashMap(int initialCapacity)Creates a new fastestConcurrentMapimplementation for the current platform.static <K,V>
java.util.concurrent.ConcurrentMap<K,V>newConcurrentHashMap(int initialCapacity, float loadFactor)Creates a new fastestConcurrentMapimplementation for the current platform.static <K,V>
java.util.concurrent.ConcurrentMap<K,V>newConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)Creates a new fastestConcurrentMapimplementation for the current platform.static <K,V>
java.util.concurrent.ConcurrentMap<K,V>newConcurrentHashMap(java.util.Map<? extends K,? extends V> map)Creates a new fastestConcurrentMapimplementation for the current platform.static <T> java.util.Queue<T>newFixedMpscQueue(int capacity)Create a newQueuewhich is safe to use for multiple producers (different threads) and a single consumer (one thread!) with the given fixescapacity.static LongCounternewLongCounter()Creates a new fastestLongCounterimplementation for the current platform.static <T> java.util.Queue<T>newMpscQueue()Create a newQueuewhich is safe to use for multiple producers (different threads) and a single consumer (one thread!).static <T> java.util.Queue<T>newMpscQueue(int maxCapacity)Create a newQueuewhich is safe to use for multiple producers (different threads) and a single consumer (one thread!).static <T> java.util.Queue<T>newSpscQueue()Create a newQueuewhich is safe to use for single producer (one thread!) and a single consumer (one thread!).private static java.lang.Stringnormalize(java.lang.String value)private static java.lang.StringnormalizeArch(java.lang.String value)static java.lang.StringnormalizedArch()static java.util.Set<java.lang.String>normalizedLinuxClassifiers()static java.lang.StringnormalizedOs()private static java.lang.StringnormalizeOs(java.lang.String value)private static java.lang.StringnormalizeOsReleaseVariableValue(java.lang.String value)static longobjectFieldOffset(java.lang.reflect.Field field)static voidputByte(byte[] data, int index, byte value)static voidputByte(long address, byte value)static voidputInt(byte[] data, int index, int value)static voidputInt(long address, int value)static voidputLong(byte[] data, int index, long value)static voidputLong(long address, long value)static voidputObject(java.lang.Object o, long offset, java.lang.Object x)static voidputShort(byte[] data, int index, short value)static voidputShort(long address, short value)static java.nio.ByteBufferreallocateDirectNoCleaner(java.nio.ByteBuffer buffer, int capacity)Reallocate a newByteBufferwith the givencapacity.static longreallocateMemory(long address, long newSize)static voidsetMemory(byte[] dst, int dstIndex, long bytes, byte value)static voidsetMemory(long address, long bytes, byte value)static java.util.RandomthreadLocalRandom()Return aRandomwhich is not-threadsafe and so can only be used from the same thread.static voidthrowException(java.lang.Throwable t)Raises an exception bypassing compiler checks for checked exceptions.private static <E extends java.lang.Throwable>
voidthrowException0(java.lang.Throwable t)static java.io.Filetmpdir()Returns the temporary directory.private static java.io.Filetmpdir0()private static java.io.FiletoDirectory(java.lang.String path)private static java.lang.ThrowableunsafeUnavailabilityCause0()static longusedDirectMemory()Returns the current memory reserved for direct buffer allocation.static booleanuseDirectBufferNoCleaner()
-
-
-
Field Detail
-
logger
private static final InternalLogger logger
-
MAX_DIRECT_MEMORY_SIZE_ARG_PATTERN
private static final java.util.regex.Pattern MAX_DIRECT_MEMORY_SIZE_ARG_PATTERN
-
IS_WINDOWS
private static final boolean IS_WINDOWS
-
IS_OSX
private static final boolean IS_OSX
-
IS_J9_JVM
private static final boolean IS_J9_JVM
-
IS_IVKVM_DOT_NET
private static final boolean IS_IVKVM_DOT_NET
-
MAYBE_SUPER_USER
private static final boolean MAYBE_SUPER_USER
-
CAN_ENABLE_TCP_NODELAY_BY_DEFAULT
private static final boolean CAN_ENABLE_TCP_NODELAY_BY_DEFAULT
-
UNSAFE_UNAVAILABILITY_CAUSE
private static final java.lang.Throwable UNSAFE_UNAVAILABILITY_CAUSE
-
DIRECT_BUFFER_PREFERRED
private static final boolean DIRECT_BUFFER_PREFERRED
-
MAX_DIRECT_MEMORY
private static final long MAX_DIRECT_MEMORY
-
MPSC_CHUNK_SIZE
private static final int MPSC_CHUNK_SIZE
- See Also:
- Constant Field Values
-
MIN_MAX_MPSC_CAPACITY
private static final int MIN_MAX_MPSC_CAPACITY
- See Also:
- Constant Field Values
-
MAX_ALLOWED_MPSC_CAPACITY
private static final int MAX_ALLOWED_MPSC_CAPACITY
- See Also:
- Constant Field Values
-
BYTE_ARRAY_BASE_OFFSET
private static final long BYTE_ARRAY_BASE_OFFSET
-
TMPDIR
private static final java.io.File TMPDIR
-
BIT_MODE
private static final int BIT_MODE
-
NORMALIZED_ARCH
private static final java.lang.String NORMALIZED_ARCH
-
NORMALIZED_OS
private static final java.lang.String NORMALIZED_OS
-
ALLOWED_LINUX_OS_CLASSIFIERS
private static final java.lang.String[] ALLOWED_LINUX_OS_CLASSIFIERS
-
LINUX_OS_CLASSIFIERS
private static final java.util.Set<java.lang.String> LINUX_OS_CLASSIFIERS
-
ADDRESS_SIZE
private static final int ADDRESS_SIZE
-
USE_DIRECT_BUFFER_NO_CLEANER
private static final boolean USE_DIRECT_BUFFER_NO_CLEANER
-
DIRECT_MEMORY_COUNTER
private static final java.util.concurrent.atomic.AtomicLong DIRECT_MEMORY_COUNTER
-
DIRECT_MEMORY_LIMIT
private static final long DIRECT_MEMORY_LIMIT
-
RANDOM_PROVIDER
private static final PlatformDependent.ThreadLocalRandomProvider RANDOM_PROVIDER
-
CLEANER
private static final Cleaner CLEANER
-
UNINITIALIZED_ARRAY_ALLOCATION_THRESHOLD
private static final int UNINITIALIZED_ARRAY_ALLOCATION_THRESHOLD
-
OS_RELEASE_FILES
private static final java.lang.String[] OS_RELEASE_FILES
-
LINUX_ID_PREFIX
private static final java.lang.String LINUX_ID_PREFIX
- See Also:
- Constant Field Values
-
LINUX_ID_LIKE_PREFIX
private static final java.lang.String LINUX_ID_LIKE_PREFIX
- See Also:
- Constant Field Values
-
BIG_ENDIAN_NATIVE_ORDER
public static final boolean BIG_ENDIAN_NATIVE_ORDER
-
NOOP
private static final Cleaner NOOP
-
-
Method Detail
-
hasDirectBufferNoCleanerConstructor
public static boolean hasDirectBufferNoCleanerConstructor()
-
allocateUninitializedArray
public static byte[] allocateUninitializedArray(int size)
-
isAndroid
public static boolean isAndroid()
Returnstrueif and only if the current platform is Android
-
isWindows
public static boolean isWindows()
Returntrueif the JVM is running on Windows
-
isOsx
public static boolean isOsx()
Returntrueif the JVM is running on OSX / MacOS
-
maybeSuperUser
public static boolean maybeSuperUser()
Returntrueif the current user may be a super-user. Be aware that this is just an hint and so it may return false-positives.
-
javaVersion
public static int javaVersion()
Return the version of Java under which this library is used.
-
canEnableTcpNoDelayByDefault
public static boolean canEnableTcpNoDelayByDefault()
Returnstrueif and only if it is fine to enable TCP_NODELAY socket option by default.
-
hasUnsafe
public static boolean hasUnsafe()
Returntrueifsun.misc.Unsafewas found on the classpath and can be used for accelerated direct memory access.
-
getUnsafeUnavailabilityCause
public static java.lang.Throwable getUnsafeUnavailabilityCause()
Return the reason (if any) whysun.misc.Unsafewas not available.
-
isUnaligned
public static boolean isUnaligned()
trueif and only if the platform supports unaligned access.- See Also:
- Wikipedia on segfault
-
directBufferPreferred
public static boolean directBufferPreferred()
Returnstrueif the platform has reliable low-level direct buffer access API and a user has not specified-Dio.netty.noPreferDirectoption.
-
maxDirectMemory
public static long maxDirectMemory()
Returns the maximum memory reserved for direct buffer allocation.
-
usedDirectMemory
public static long usedDirectMemory()
Returns the current memory reserved for direct buffer allocation. This method returns -1 in case that a value is not available.- See Also:
maxDirectMemory()
-
tmpdir
public static java.io.File tmpdir()
Returns the temporary directory.
-
bitMode
public static int bitMode()
Returns the bit mode of the current VM (usually 32 or 64.)
-
addressSize
public static int addressSize()
Return the address size of the OS. 4 (for 32 bits systems ) and 8 (for 64 bits systems).
-
allocateMemory
public static long allocateMemory(long size)
-
freeMemory
public static void freeMemory(long address)
-
reallocateMemory
public static long reallocateMemory(long address, long newSize)
-
throwException
public static void throwException(java.lang.Throwable t)
Raises an exception bypassing compiler checks for checked exceptions.
-
throwException0
private static <E extends java.lang.Throwable> void throwException0(java.lang.Throwable t) throws E extends java.lang.Throwable- Throws:
E extends java.lang.Throwable
-
newConcurrentHashMap
public static <K,V> java.util.concurrent.ConcurrentMap<K,V> newConcurrentHashMap()
Creates a new fastestConcurrentMapimplementation for the current platform.
-
newLongCounter
public static LongCounter newLongCounter()
Creates a new fastestLongCounterimplementation for the current platform.
-
newConcurrentHashMap
public static <K,V> java.util.concurrent.ConcurrentMap<K,V> newConcurrentHashMap(int initialCapacity)
Creates a new fastestConcurrentMapimplementation for the current platform.
-
newConcurrentHashMap
public static <K,V> java.util.concurrent.ConcurrentMap<K,V> newConcurrentHashMap(int initialCapacity, float loadFactor)Creates a new fastestConcurrentMapimplementation for the current platform.
-
newConcurrentHashMap
public static <K,V> java.util.concurrent.ConcurrentMap<K,V> newConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)Creates a new fastestConcurrentMapimplementation for the current platform.
-
newConcurrentHashMap
public static <K,V> java.util.concurrent.ConcurrentMap<K,V> newConcurrentHashMap(java.util.Map<? extends K,? extends V> map)
Creates a new fastestConcurrentMapimplementation for the current platform.
-
freeDirectBuffer
public static void freeDirectBuffer(java.nio.ByteBuffer buffer)
Try to deallocate the specified directByteBuffer. Please note this method does nothing if the current platform does not support this operation or the specified buffer is not a direct buffer.
-
directBufferAddress
public static long directBufferAddress(java.nio.ByteBuffer buffer)
-
directBuffer
public static java.nio.ByteBuffer directBuffer(long memoryAddress, int size)
-
getObject
public static java.lang.Object getObject(java.lang.Object object, long fieldOffset)
-
getInt
public static int getInt(java.lang.Object object, long fieldOffset)
-
getByte
public static byte getByte(long address)
-
getShort
public static short getShort(long address)
-
getInt
public static int getInt(long address)
-
getLong
public static long getLong(long address)
-
getByte
public static byte getByte(byte[] data, int index)
-
getByte
public static byte getByte(byte[] data, long index)
-
getShort
public static short getShort(byte[] data, int index)
-
getInt
public static int getInt(byte[] data, int index)
-
getInt
public static int getInt(int[] data, long index)
-
getLong
public static long getLong(byte[] data, int index)
-
getLong
public static long getLong(long[] data, long index)
-
getLongSafe
private static long getLongSafe(byte[] bytes, int offset)
-
getIntSafe
private static int getIntSafe(byte[] bytes, int offset)
-
getShortSafe
private static short getShortSafe(byte[] bytes, int offset)
-
hashCodeAsciiCompute
private static int hashCodeAsciiCompute(java.lang.CharSequence value, int offset, int hash)Identical toPlatformDependent0.hashCodeAsciiCompute(long, int)but forCharSequence.
-
hashCodeAsciiSanitizeInt
private static int hashCodeAsciiSanitizeInt(java.lang.CharSequence value, int offset)Identical toPlatformDependent0.hashCodeAsciiSanitize(int)but forCharSequence.
-
hashCodeAsciiSanitizeShort
private static int hashCodeAsciiSanitizeShort(java.lang.CharSequence value, int offset)Identical toPlatformDependent0.hashCodeAsciiSanitize(short)but forCharSequence.
-
hashCodeAsciiSanitizeByte
private static int hashCodeAsciiSanitizeByte(char value)
Identical toPlatformDependent0.hashCodeAsciiSanitize(byte)but forCharSequence.
-
putByte
public static void putByte(long address, byte value)
-
putShort
public static void putShort(long address, short value)
-
putInt
public static void putInt(long address, int value)
-
putLong
public static void putLong(long address, long value)
-
putByte
public static void putByte(byte[] data, int index, byte value)
-
putShort
public static void putShort(byte[] data, int index, short value)
-
putInt
public static void putInt(byte[] data, int index, int value)
-
putLong
public static void putLong(byte[] data, int index, long value)
-
putObject
public static void putObject(java.lang.Object o, long offset, java.lang.Object x)
-
objectFieldOffset
public static long objectFieldOffset(java.lang.reflect.Field field)
-
copyMemory
public static void copyMemory(long srcAddr, long dstAddr, long length)
-
copyMemory
public static void copyMemory(byte[] src, int srcIndex, long dstAddr, long length)
-
copyMemory
public static void copyMemory(long srcAddr, byte[] dst, int dstIndex, long length)
-
setMemory
public static void setMemory(byte[] dst, int dstIndex, long bytes, byte value)
-
setMemory
public static void setMemory(long address, long bytes, byte value)
-
allocateDirectNoCleaner
public static java.nio.ByteBuffer allocateDirectNoCleaner(int capacity)
Allocate a newByteBufferwith the givencapacity.ByteBuffers allocated with this method MUST be deallocated viafreeDirectNoCleaner(ByteBuffer).
-
reallocateDirectNoCleaner
public static java.nio.ByteBuffer reallocateDirectNoCleaner(java.nio.ByteBuffer buffer, int capacity)Reallocate a newByteBufferwith the givencapacity.ByteBuffers reallocated with this method MUST be deallocated viafreeDirectNoCleaner(ByteBuffer).
-
freeDirectNoCleaner
public static void freeDirectNoCleaner(java.nio.ByteBuffer buffer)
This method MUST only be called forByteBuffers that were allocated viaallocateDirectNoCleaner(int).
-
incrementMemoryCounter
private static void incrementMemoryCounter(int capacity)
-
decrementMemoryCounter
private static void decrementMemoryCounter(int capacity)
-
useDirectBufferNoCleaner
public static boolean useDirectBufferNoCleaner()
-
equals
public static boolean equals(byte[] bytes1, int startPos1, byte[] bytes2, int startPos2, int length)Compare twobytearrays for equality. For performance reasons no bounds checking on the parameters is performed.- Parameters:
bytes1- the first byte array.startPos1- the position (inclusive) to start comparing inbytes1.bytes2- the second byte array.startPos2- the position (inclusive) to start comparing inbytes2.length- the amount of bytes to compare. This is assumed to be validated as not going out of bounds by the caller.
-
isZero
public static boolean isZero(byte[] bytes, int startPos, int length)Determine if a subsection of an array is zero.- Parameters:
bytes- The byte array.startPos- The starting index (inclusive) inbytes.length- The amount of bytes to check for zero.- Returns:
falseifbytes[startPos:startsPos+length)contains a value other than zero.
-
equalsConstantTime
public static int equalsConstantTime(byte[] bytes1, int startPos1, byte[] bytes2, int startPos2, int length)Compare twobytearrays for equality without leaking timing information. For performance reasons no bounds checking on the parameters is performed.The
intreturn type is intentional and is designed to allow cascading of constant time operations:byte[] s1 = new {1, 2, 3}; byte[] s2 = new {1, 2, 3}; byte[] s3 = new {1, 2, 3}; byte[] s4 = new {4, 5, 6}; boolean equals = (equalsConstantTime(s1, 0, s2, 0, s1.length) & equalsConstantTime(s3, 0, s4, 0, s3.length)) != 0;- Parameters:
bytes1- the first byte array.startPos1- the position (inclusive) to start comparing inbytes1.bytes2- the second byte array.startPos2- the position (inclusive) to start comparing inbytes2.length- the amount of bytes to compare. This is assumed to be validated as not going out of bounds by the caller.- Returns:
0if not equal.1if equal.
-
hashCodeAscii
public static int hashCodeAscii(byte[] bytes, int startPos, int length)Calculate a hash code of a byte array assuming ASCII character encoding. The resulting hash code will be case insensitive.- Parameters:
bytes- The array which contains the data to hash.startPos- What index to start generating a hash code inbyteslength- The amount of bytes that should be accounted for in the computation.- Returns:
- The hash code of
bytesassuming ASCII character encoding. The resulting hash code will be case insensitive.
-
hashCodeAscii
public static int hashCodeAscii(java.lang.CharSequence bytes)
Calculate a hash code of a byte array assuming ASCII character encoding. The resulting hash code will be case insensitive.This method assumes that
bytesis equivalent to abyte[]but just usingCharSequencefor storage. The upper most byte of eachcharfrombytesis ignored.- Parameters:
bytes- The array which contains the data to hash (assumed to be equivalent to abyte[]).- Returns:
- The hash code of
bytesassuming ASCII character encoding. The resulting hash code will be case insensitive.
-
newMpscQueue
public static <T> java.util.Queue<T> newMpscQueue()
Create a newQueuewhich is safe to use for multiple producers (different threads) and a single consumer (one thread!).- Returns:
- A MPSC queue which may be unbounded.
-
newMpscQueue
public static <T> java.util.Queue<T> newMpscQueue(int maxCapacity)
Create a newQueuewhich is safe to use for multiple producers (different threads) and a single consumer (one thread!).
-
newSpscQueue
public static <T> java.util.Queue<T> newSpscQueue()
Create a newQueuewhich is safe to use for single producer (one thread!) and a single consumer (one thread!).
-
newFixedMpscQueue
public static <T> java.util.Queue<T> newFixedMpscQueue(int capacity)
Create a newQueuewhich is safe to use for multiple producers (different threads) and a single consumer (one thread!) with the given fixescapacity.
-
getClassLoader
public static java.lang.ClassLoader getClassLoader(java.lang.Class<?> clazz)
Return theClassLoaderfor the givenClass.
-
getContextClassLoader
public static java.lang.ClassLoader getContextClassLoader()
Return the contextClassLoaderfor the currentThread.
-
getSystemClassLoader
public static java.lang.ClassLoader getSystemClassLoader()
Return the systemClassLoader.
-
newConcurrentDeque
public static <C> java.util.Deque<C> newConcurrentDeque()
Returns a new concurrentDeque.
-
threadLocalRandom
public static java.util.Random threadLocalRandom()
Return aRandomwhich is not-threadsafe and so can only be used from the same thread.
-
isWindows0
private static boolean isWindows0()
-
isOsx0
private static boolean isOsx0()
-
maybeSuperUser0
private static boolean maybeSuperUser0()
-
unsafeUnavailabilityCause0
private static java.lang.Throwable unsafeUnavailabilityCause0()
-
isJ9Jvm
public static boolean isJ9Jvm()
-
isJ9Jvm0
private static boolean isJ9Jvm0()
-
isIkvmDotNet
public static boolean isIkvmDotNet()
-
isIkvmDotNet0
private static boolean isIkvmDotNet0()
-
maxDirectMemory0
private static long maxDirectMemory0()
-
tmpdir0
private static java.io.File tmpdir0()
-
toDirectory
private static java.io.File toDirectory(java.lang.String path)
-
bitMode0
private static int bitMode0()
-
addressSize0
private static int addressSize0()
-
byteArrayBaseOffset0
private static long byteArrayBaseOffset0()
-
equalsSafe
private static boolean equalsSafe(byte[] bytes1, int startPos1, byte[] bytes2, int startPos2, int length)
-
isZeroSafe
private static boolean isZeroSafe(byte[] bytes, int startPos, int length)
-
hashCodeAsciiSafe
static int hashCodeAsciiSafe(byte[] bytes, int startPos, int length)Package private for testing purposes only!
-
normalizedArch
public static java.lang.String normalizedArch()
-
normalizedOs
public static java.lang.String normalizedOs()
-
normalizedLinuxClassifiers
public static java.util.Set<java.lang.String> normalizedLinuxClassifiers()
-
addClassifier
private static void addClassifier(java.util.Set<java.lang.String> allowed, java.util.Set<java.lang.String> dest, java.lang.String... maybeClassifiers)Adds only those classifier strings to dest which are present in allowed.- Parameters:
allowed- allowed classifiersdest- destination setmaybeClassifiers- potential classifiers to add
-
normalizeOsReleaseVariableValue
private static java.lang.String normalizeOsReleaseVariableValue(java.lang.String value)
-
normalize
private static java.lang.String normalize(java.lang.String value)
-
normalizeArch
private static java.lang.String normalizeArch(java.lang.String value)
-
normalizeOs
private static java.lang.String normalizeOs(java.lang.String value)
-
-