Class PlatformDependent
java.lang.Object
io.netty.util.internal.PlatformDependent
Utility that detects various properties specific to the current runtime
environment, such as Java version and the availability of the
sun.misc.Unsafe object.
You can disable the use of sun.misc.Unsafe if you specify
the system property io.netty.noUnsafe.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intstatic final booleanprivate static final intprivate static final longprivate static final booleanprivate static final Cleanerprivate static final booleanprivate static final AtomicLongprivate static final longprivate static final booleanprivate static final booleanprivate static final booleanprivate static final booleanprivate static final booleanprivate static final booleanprivate static final booleanprivate static final booleanprivate static final Cleanerprivate static final Stringprivate static final Stringprivate static final InternalLoggerprivate static final intprivate static final longprivate static Patternprivate static final booleanprivate static final intprivate static final intprivate static final Cleanerprivate static final Stringprivate static final Stringprivate static final Fileprivate static final Throwableprivate static final boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ByteBufferabsolutePut(ByteBuffer dst, int dstOffset, byte[] src, int srcOffset, int length) static ByteBufferabsolutePut(ByteBuffer dst, int dstOffset, ByteBuffer src, int srcOffset, int length) private static voidaddClassifier(Set<String> dest, String... maybeClassifiers) Adds only those classifier strings to dest which are present in allowed.(package private) static voidaddFilesystemOsClassifiers(Set<String> availableClassifiers) (package private) static booleanaddPropertyOsClassifiers(Set<String> availableClassifiers) static intReturn the address size of the OS.private static intstatic longalign(long value, int alignment) static ByteBufferalignDirectBuffer(ByteBuffer buffer, int alignment) static CleanableDirectBufferallocateDirect(int capacity) Allocate a directByteBufferof the given capacity, and return it alongside its deallocation mechanism.static CleanableDirectBufferallocateDirect(int capacity, boolean permitExpensiveClean) Allocate a directByteBufferof the given capacity, and return it alongside its deallocation mechanism.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()static longprivate static longstatic booleanReturnstrueif and only if it is fine to enable TCP_NODELAY socket option by default.static booleanReturntrueif the selected cleaner can free direct buffers in a controlled way.static booleantrueif multi-byte access at arbitrary offsets is possible, either natively throughUnsafeor viaVarHandlewhere the JVM handles alignment and byte ordering internally.static booleancompareAndSwapInt(Object object, long fieldOffset, int expected, int value) static voidcopyMemory(byte[] src, int srcIndex, byte[] dst, int dstIndex, long length) 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) static FilecreateTempFile(String prefix, String suffix, File directory) (package private) static voiddecrementMemoryCounter(int capacity) static ByteBufferdirectBuffer(long memoryAddress, int size) static longdirectBufferAddress(ByteBuffer buffer) Obtain the native memory address of the given direct byte buffer, or throw an exception if it's not possible.static booleanReturnstrueif 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 longCompute an estimate of the maximum amount of direct memory available to this JVM.static VarHandlefindVarHandleOfIntField(MethodHandles.Lookup lookup, Class<?> type, String fieldName) static voidfreeDirectBuffer(ByteBuffer buffer) Deprecated.static voidfreeMemory(long address) static intgetAndAddInt(Object object, long fieldOffset, int delta) static bytegetByte(byte[] data, int index) static bytegetByte(byte[] data, long index) static bytegetByte(long address) static ClassLoadergetClassLoader(Class<?> clazz) Return theClassLoaderfor the givenClass.static ClassLoaderReturn the contextClassLoaderfor the currentThread.static intgetInt(byte[] data, int index) static intgetInt(int[] data, long index) static intgetInt(long address) static intprivate 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) private static Patternstatic Objectstatic shortgetShort(byte[] data, int index) static shortgetShort(long address) private static shortgetShortSafe(byte[] bytes, int offset) static ClassLoaderReturn the systemClassLoader.static ThrowableReturn the reason (if any) whysun.misc.Unsafewas not available.static intgetVolatileInt(Object object, long fieldOffset) static booleanstatic booleanstatic booleanhasDirectByteBufferAddress(ByteBuffer buffer) Check if it is possible to calldirectBufferAddress(ByteBuffer)on the given buffer.static inthashCodeAscii(byte[] bytes, int startPos, int length) Calculate a hash code of a byte array assuming ASCII character encoding.static inthashCodeAscii(CharSequence bytes) Calculate a hash code of a byte array assuming ASCII character encoding.private static inthashCodeAsciiCompute(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(CharSequence value, int offset) Identical toPlatformDependent0.hashCodeAsciiSanitize(int)but forCharSequence.private static inthashCodeAsciiSanitizeShort(CharSequence value, int offset) Identical toPlatformDependent0.hashCodeAsciiSanitize(short)but forCharSequence.(package private) static booleanstatic booleanReturntrueifsun.misc.Unsafewas found on the classpath and can be used for accelerated direct memory access.static boolean(package private) static voidincrementMemoryCounter(int capacity) private static booleanstatic VarHandlestatic VarHandlestatic VarHandlestatic VarHandleprivate static booleanisAllowedClassifier(String classifier) static booleanReturnstrueif and only if the current platform is Androidstatic booleanReturnstrueif user has specified-Dio.netty.noPreferDirect=trueoption.static booleanprivate static booleanstatic booleanisJ9Jvm()private static booleanisJ9Jvm0()static booleanCheck if JFR events are supported on this platform.static booleanisOsx()Returntrueif the JVM is running on OSX / MacOSprivate static booleanisOsx0()static booleantrueif and only if the platform supports unaligned access.static booleanisVirtualThread(Thread thread) static booleanReturntrueif the JVM is running on Windowsprivate static booleanstatic 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 intReturn the version of Java under which this library is used.static VarHandlestatic VarHandlestatic VarHandlestatic VarHandlestatic longReturns the maximum memory reserved for direct buffer allocation.static booleanReturntrueif the current user may be a super-user.private static booleanstatic <C> Deque<C> Returns a new concurrentDeque.static <K,V> ConcurrentMap <K, V> Deprecated.please use new ConcurrentHashMapinvalid input: '<'K, V>() directly.static <K,V> ConcurrentMap <K, V> newConcurrentHashMap(int initialCapacity) Deprecated.please use new ConcurrentHashMapinvalid input: '<'K, V>() directly.static <K,V> ConcurrentMap <K, V> newConcurrentHashMap(int initialCapacity, float loadFactor) Deprecated.please use new ConcurrentHashMapinvalid input: '<'K, V>() directly.static <K,V> ConcurrentMap <K, V> newConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel) Deprecated.please use new ConcurrentHashMapinvalid input: '<'K, V>() directly.static <K,V> ConcurrentMap <K, V> newConcurrentHashMap(Map<? extends K, ? extends V> map) Deprecated.please use new ConcurrentHashMapinvalid input: '<'K, V>() directly.static <T> Queue<T> newFixedMpmcQueue(int capacity) Create a newQueuewhich is safe to use for multiple producers (different threads) and multiple consumers with the given fixescapacity.static <T> 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 <T> Queue<T> newFixedMpscUnpaddedQueue(int capacity) Create a new un-paddedQueuewhich is safe to use for multiple producers (different threads) and a single consumer (one thread!) with the given fixescapacity.
This should be preferred tonewFixedMpscQueue(int)when the queue is not to be heavily contended.static LongCounterDeprecated.please useLongAdderinstead.static <T> Queue<T> Create a newQueuewhich is safe to use for multiple producers (different threads) and a single consumer (one thread!).static <T> 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> Queue<T> newMpscQueue(int chunkSize, int maxCapacity) Create a newQueuewhich is safe to use for multiple producers (different threads) and a single consumer (one thread!).static <T> Queue<T> Create a newQueuewhich is safe to use for single producer (one thread!) and a single consumer (one thread!).private static Stringprivate static StringnormalizeArch(String value) static Stringstatic Stringprivate static StringnormalizeOs(String value) private static Stringstatic longobjectFieldOffset(Field field) static ByteBufferoffsetSlice(ByteBuffer buffer, int index, int length) private static booleanprocessOsReleaseFile(String osReleaseFileName, Set<String> availableClassifiers) static voidputByte(byte[] data, int index, byte value) static voidputByte(long address, byte value) static voidstatic 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 voidstatic voidputOrderedInt(Object object, long fieldOffset, int value) static voidputShort(byte[] data, int index, short value) static voidputShort(long address, short value) static CleanableDirectBufferreallocateDirect(CleanableDirectBuffer buffer, int newCapacity) Reallocate a direct buffer with the given new capacity.static longreallocateMemory(long address, long newSize) (package private) static voidsafeConstructPutInt(Object object, long fieldOffset, int value) static voidsetMemory(byte[] dst, int dstIndex, long bytes, byte value) static voidsetMemory(long address, long bytes, byte value) static VarHandlestatic VarHandlestatic VarHandlestatic VarHandlestatic voidsplittableRandomNextBytes(SplittableRandom rng, byte[] data) static RandomDeprecated.Use ThreadLocalRandom.current() instead.static voidRaises an exception bypassing compiler checks for checked exceptions.static Filetmpdir()Returns the temporary directory.private static Filetmpdir0()private static FiletoDirectory(String path) private static inttoIntExact(long value) private static Throwablestatic longReturns the current memory reserved for direct buffer allocation.static booleanstatic booleantrueifVarHandleshould be used for multi-byte access.
-
Field Details
-
logger
-
MAX_DIRECT_MEMORY_SIZE_ARG_PATTERN
-
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
-
DIRECT_BUFFER_PREFERRED
private static final boolean DIRECT_BUFFER_PREFERRED -
EXPLICIT_NO_PREFER_DIRECT
private static final boolean EXPLICIT_NO_PREFER_DIRECT -
MAX_DIRECT_MEMORY
private static final long MAX_DIRECT_MEMORY -
MPSC_CHUNK_SIZE
private static final int MPSC_CHUNK_SIZE- See Also:
-
MIN_MAX_MPSC_CAPACITY
private static final int MIN_MAX_MPSC_CAPACITY- See Also:
-
MAX_ALLOWED_MPSC_CAPACITY
private static final int MAX_ALLOWED_MPSC_CAPACITY- See Also:
-
BYTE_ARRAY_BASE_OFFSET
private static final long BYTE_ARRAY_BASE_OFFSET -
TMPDIR
-
BIT_MODE
private static final int BIT_MODE -
NORMALIZED_ARCH
-
NORMALIZED_OS
-
LINUX_OS_CLASSIFIERS
-
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 -
ADDRESS_SIZE
private static final int ADDRESS_SIZE -
DIRECT_MEMORY_COUNTER
-
DIRECT_MEMORY_LIMIT
private static final long DIRECT_MEMORY_LIMIT -
CLEANER
-
LEGACY_CLEANER
-
HAS_ALLOCATE_UNINIT_ARRAY
private static final boolean HAS_ALLOCATE_UNINIT_ARRAY -
LINUX_ID_PREFIX
- See Also:
-
LINUX_ID_LIKE_PREFIX
- See Also:
-
BIG_ENDIAN_NATIVE_ORDER
public static final boolean BIG_ENDIAN_NATIVE_ORDER -
IGNORE_EXPENSIVE_CLEAN
private static final boolean IGNORE_EXPENSIVE_CLEAN -
JFR
private static final boolean JFR -
VAR_HANDLE
private static final boolean VAR_HANDLE -
NOOP
-
-
Constructor Details
-
PlatformDependent
private PlatformDependent()
-
-
Method Details
-
initializeVarHandle
private static boolean initializeVarHandle() -
addFilesystemOsClassifiers
-
processOsReleaseFile
-
addPropertyOsClassifiers
-
byteArrayBaseOffset
public static long byteArrayBaseOffset() -
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. -
isVirtualThread
-
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. -
isUnaligned
public static boolean isUnaligned()trueif and only if the platform supports unaligned access.- See Also:
-
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. -
isExplicitNoPreferDirect
public static boolean isExplicitNoPreferDirect()Returnstrueif user has specified-Dio.netty.noPreferDirect=trueoption. -
canReliabilyFreeDirectBuffers
public static boolean canReliabilyFreeDirectBuffers()Returntrueif the selected cleaner can free direct buffers in a controlled way. This guarantee only applies for buffers allocated viaallocateDirect(int)and when using thecleanmethod of the returnedCleanableDirectBuffer. -
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:
-
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
Raises an exception bypassing compiler checks for checked exceptions. -
newConcurrentHashMap
Deprecated.please use new ConcurrentHashMapinvalid input: '<'K, V>() directly.Creates a new fastestConcurrentMapimplementation for the current platform. -
newLongCounter
Deprecated.please useLongAdderinstead.Creates a new fastestLongCounterimplementation for the current platform. -
newConcurrentHashMap
Deprecated.please use new ConcurrentHashMapinvalid input: '<'K, V>() directly.Creates a new fastestConcurrentMapimplementation for the current platform. -
newConcurrentHashMap
@Deprecated public static <K,V> ConcurrentMap<K,V> newConcurrentHashMap(int initialCapacity, float loadFactor) Deprecated.please use new ConcurrentHashMapinvalid input: '<'K, V>() directly.Creates a new fastestConcurrentMapimplementation for the current platform. -
newConcurrentHashMap
@Deprecated public static <K,V> ConcurrentMap<K,V> newConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel) Deprecated.please use new ConcurrentHashMapinvalid input: '<'K, V>() directly.Creates a new fastestConcurrentMapimplementation for the current platform. -
newConcurrentHashMap
@Deprecated public static <K,V> ConcurrentMap<K,V> newConcurrentHashMap(Map<? extends K, ? extends V> map) Deprecated.please use new ConcurrentHashMapinvalid input: '<'K, V>() directly.Creates a new fastestConcurrentMapimplementation for the current platform. -
allocateDirect
Allocate a directByteBufferof the given capacity, and return it alongside its deallocation mechanism.- Parameters:
capacity- The desired capacity of the direct byte buffer.- Returns:
- The
CleanableDirectBufferinstance that contain the buffer and its deallocation mechanism.
-
allocateDirect
Allocate a directByteBufferof the given capacity, and return it alongside its deallocation mechanism.- Parameters:
capacity- The desired capacity of the direct byte buffer.permitExpensiveClean- Whether to allow expensive clean operations or not. If expensive clean operations are not permitted (false), then the buffer cleaning may instead be delegated to the GC and reference processing. Pooling allocators would typically permit expensive clean operations, while unpooled buffers would not.- Returns:
- The
CleanableDirectBufferinstance that contain the buffer and its deallocation mechanism.
-
reallocateDirect
Reallocate a direct buffer with the given new capacity. The old buffer is invalidated and must not be used after this call.- Parameters:
buffer- The old buffer to reallocate.newCapacity- The desired new capacity.- Returns:
- The new
CleanableDirectBufferwith the given capacity.
-
freeDirectBuffer
Deprecated.Use theCleanableDirectBuffer.clean()fromallocateDirect(int)instead.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. -
hasDirectByteBufferAddress
Check if it is possible to calldirectBufferAddress(ByteBuffer)on the given buffer.- Parameters:
buffer- The specific buffer instance to check for.- Returns:
trueifdirectBufferAddress(ByteBuffer)can be called on the given buffer, otherwisefalse.
-
directBufferAddress
Obtain the native memory address of the given direct byte buffer, or throw an exception if it's not possible.- Parameters:
buffer- The buffer to get the native memory address for.- Returns:
- The native memory address of the give buffer.
-
directBuffer
-
hasVarHandle
public static boolean hasVarHandle() -
hasJctoolsVarHandle
static boolean hasJctoolsVarHandle() -
useVarHandleForMultiByteAccess
public static boolean useVarHandleForMultiByteAccess()trueifVarHandleshould be used for multi-byte access. The multi-byte access strategy is determined as follows: 1) If the platform supports unaligned access natively, useUnsafeas the fastest option. 2) Otherwise, ifVarHandleis available, use it as a fallback. 3) Otherwise, fall back to manual byte-by-byte access. -
canUnalignedAccess
public static boolean canUnalignedAccess()trueif multi-byte access at arbitrary offsets is possible, either natively throughUnsafeor viaVarHandlewhere the JVM handles alignment and byte ordering internally. -
findVarHandleOfIntField
public static VarHandle findVarHandleOfIntField(MethodHandles.Lookup lookup, Class<?> type, String fieldName) -
intBeArrayView
-
intLeArrayView
-
longBeArrayView
-
longLeArrayView
-
shortBeArrayView
-
shortLeArrayView
-
longBeByteBufferView
-
longLeByteBufferView
-
intBeByteBufferView
-
intLeByteBufferView
-
shortBeByteBufferView
-
shortLeByteBufferView
-
getObject
-
getVolatileInt
-
getInt
-
putOrderedInt
-
getAndAddInt
-
compareAndSwapInt
-
safeConstructPutInt
-
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) -
toIntExact
private static int toIntExact(long value) -
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
Identical toPlatformDependent0.hashCodeAsciiCompute(long, int)but forCharSequence. -
hashCodeAsciiSanitizeInt
Identical toPlatformDependent0.hashCodeAsciiSanitize(int)but forCharSequence. -
hashCodeAsciiSanitizeShort
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) -
putByte
-
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
-
objectFieldOffset
-
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(byte[] src, int srcIndex, byte[] dst, int dstIndex, 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) -
hasAlignDirectByteBuffer
public static boolean hasAlignDirectByteBuffer() -
alignDirectBuffer
-
align
public static long align(long value, int alignment) -
offsetSlice
-
absolutePut
public static ByteBuffer absolutePut(ByteBuffer dst, int dstOffset, byte[] src, int srcOffset, int length) -
absolutePut
public static ByteBuffer absolutePut(ByteBuffer dst, int dstOffset, ByteBuffer src, int srcOffset, int length) -
incrementMemoryCounter
static void incrementMemoryCounter(int capacity) -
decrementMemoryCounter
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) invalid input: '&' 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
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
-
newMpscQueue
-
newMpscQueue
-
newSpscQueue
-
newFixedMpscQueue
-
newFixedMpscUnpaddedQueue
Create a new un-paddedQueuewhich is safe to use for multiple producers (different threads) and a single consumer (one thread!) with the given fixescapacity.
This should be preferred tonewFixedMpscQueue(int)when the queue is not to be heavily contended. -
newFixedMpmcQueue
-
getClassLoader
Return theClassLoaderfor the givenClass. -
getContextClassLoader
Return the contextClassLoaderfor the currentThread. -
getSystemClassLoader
Return the systemClassLoader. -
newConcurrentDeque
-
threadLocalRandom
Deprecated.Use ThreadLocalRandom.current() instead.Return aRandomwhich is not-threadsafe and so can only be used from the same thread. -
splittableRandomNextBytes
-
isWindows0
private static boolean isWindows0() -
isOsx0
private static boolean isOsx0() -
maybeSuperUser0
private static boolean maybeSuperUser0() -
isJ9Jvm
public static boolean isJ9Jvm() -
isJ9Jvm0
private static boolean isJ9Jvm0() -
isIkvmDotNet
public static boolean isIkvmDotNet() -
isIkvmDotNet0
private static boolean isIkvmDotNet0() -
getMaxDirectMemorySizeArgPattern
-
estimateMaxDirectMemory
public static long estimateMaxDirectMemory()Compute an estimate of the maximum amount of direct memory available to this JVM.The computation is not cached, so you probably want to use
maxDirectMemory()instead.This will produce debug log output when called.
- Returns:
- The estimated max direct memory, in bytes.
-
tmpdir0
-
toDirectory
-
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
-
normalizedOs
-
normalizedLinuxClassifiers
-
createTempFile
- Throws:
IOException
-
addClassifier
-
isAllowedClassifier
-
normalizeOsReleaseVariableValue
-
normalize
-
normalizeArch
-
normalizeOs
-
isJfrEnabled
public static boolean isJfrEnabled()Check if JFR events are supported on this platform.
-
CleanableDirectBuffer.clean()fromallocateDirect(int)instead.