Top Description Inners Fields Constructors Methods
io.netty.util.internal

public final Class PlatformDependent

extends Object
Class Inheritance
Imports
io.netty.util.CharsetUtil, io.netty.util.internal.logging.InternalLogger, .InternalLoggerFactory, io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueue, .MpscChunkedArrayQueue, .MpscUnboundedArrayQueue, .SpscLinkedQueue, io.netty.util.internal.shaded.org.jctools.queues.atomic.MpscAtomicArrayQueue, .MpscChunkedAtomicArrayQueue, .MpscUnboundedAtomicArrayQueue, .SpscLinkedAtomicQueue, io.netty.util.internal.shaded.org.jctools.util.Pow2, .UnsafeAccess, java.io.BufferedReader, .File, .FileInputStream, .IOException, .InputStreamReader, java.lang.reflect.Field, .Method, java.nio.ByteBuffer, .ByteOrder, java.nio.file.Files, java.security.AccessController, .PrivilegedAction, java.util.Arrays, .Collections, .Deque, .HashSet, .LinkedHashSet, .List, .Locale, .Map, .Queue, .Random, .Set, java.util.concurrent.ConcurrentHashMap, .ConcurrentLinkedDeque, .ConcurrentMap, .LinkedBlockingDeque, java.util.concurrent.atomic.AtomicLong, java.util.regex.Matcher, .Pattern

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 and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static interface

Field Summary

Modifier and TypeField and Description
private static final int
private static final String[]
public static final boolean
private static final int
private static final long
private static final boolean
private static final Cleaner
private static final boolean
private static final AtomicLong
private static final long
private static final boolean
private static final boolean
private static final boolean
private static final boolean
private static final String
private static final String
private static final Set<String>
private static final InternalLogger
private static final int
private static final long
private static Pattern
private static final boolean
private static final int
private static final int
private static final Cleaner
private static final String
private static final String
private static final String[]
private static final PlatformDependent.ThreadLocalRandomProvider
private static final File
private static final int
private static final Throwable
private static final boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
addClassifier(Set<String>
allowed classifiers
allowed
,
Set<String>
destination set
dest
,
String...
potential classifiers to add
maybeClassifiers
)

Adds only those classifier strings to dest which are present in allowed.

pack-priv static void
addFilesystemOsClassifiers(final Set<String> allowedClassifiers, final Set<String> availableClassifiers)

pack-priv static boolean
addPropertyOsClassifiers(Set<String> allowedClassifiers, Set<String> availableClassifiers)

public static int
addressSize()

Return the address size of the OS.

private static int
public static long
align(long value, int alignment)

public static ByteBuffer
alignDirectBuffer(ByteBuffer buffer, int alignment)

public static ByteBuffer
allocateDirectNoCleaner(int capacity)

Allocate a new ByteBuffer with the given capacity.

public static long
allocateMemory(long size)

public static byte[]
public static int
bitMode()

Returns the bit mode of the current VM (usually 32 or 64.)

private static int
public static long
private static long
public static boolean
canEnableTcpNoDelayByDefault()

Returns true if and only if it is fine to enable TCP_NODELAY socket option by default.

public static void
copyMemory(long srcAddr, long dstAddr, long length)

public static void
copyMemory(byte[] src, int srcIndex, long dstAddr, long length)

public static void
copyMemory(byte[] src, int srcIndex, byte[] dst, int dstIndex, long length)

public static void
copyMemory(long srcAddr, byte[] dst, int dstIndex, long length)

public static File
createTempFile(String prefix, String suffix, File directory)

private static void
decrementMemoryCounter(int capacity)

public static ByteBuffer
directBuffer(long memoryAddress, int size)

public static long
public static boolean
directBufferPreferred()

Returns true if the platform has reliable low-level direct buffer access API and a user has not specified -Dio.netty.noPreferDirect option.

public static boolean
equals(byte[]
the first byte array.
bytes1
,
int
the position (inclusive) to start comparing in bytes1.
startPos1
,
byte[]
the second byte array.
bytes2
,
int
the position (inclusive) to start comparing in bytes2.
startPos2
,
int
the amount of bytes to compare. This is assumed to be validated as not going out of bounds by the caller.
length
)

Compare two byte arrays for equality.

public static int

Returns:

0 if not equal. 1 if equal.
equalsConstantTime
(byte[]
the first byte array.
bytes1
,
int
the position (inclusive) to start comparing in bytes1.
startPos1
,
byte[]
the second byte array.
bytes2
,
int
the position (inclusive) to start comparing in bytes2.
startPos2
,
int
the amount of bytes to compare. This is assumed to be validated as not going out of bounds by the caller.
length
)

Compare two byte arrays for equality without leaking timing information.

private static boolean
equalsSafe(byte[] bytes1, int startPos1, byte[] bytes2, int startPos2, int length)

public static long

Returns:

The estimated max direct memory, in bytes.
estimateMaxDirectMemory
()

Compute an estimate of the maximum amount of direct memory available to this JVM.

public static void
freeDirectBuffer(ByteBuffer buffer)

Try to deallocate the specified direct ByteBuffer.

public static void
freeDirectNoCleaner(ByteBuffer buffer)

This method MUST only be called for ByteBuffers that were allocated via allocateDirectNoCleaner(int).

public static void
freeMemory(long address)

public static byte
getByte(long address)

public static byte
getByte(byte[] data, int index)

public static byte
getByte(byte[] data, long index)

public static ClassLoader
getClassLoader(final Class<?> clazz)

Return the ClassLoader for the given Class.

public static ClassLoader
getContextClassLoader()

Return the context ClassLoader for the current Thread.

public static int
getInt(Object object, long fieldOffset)

public static int
getInt(long address)

public static int
getInt(byte[] data, int index)

public static int
getInt(int[] data, long index)

private static int
getIntSafe(byte[] bytes, int offset)

public static int
getIntVolatile(long address)

public static long
getLong(long address)

public static long
getLong(byte[] data, int index)

public static long
getLong(long[] data, long index)

private static long
getLongSafe(byte[] bytes, int offset)

private static Pattern
public static Object
getObject(Object object, long fieldOffset)

public static short
getShort(long address)

public static short
getShort(byte[] data, int index)

private static short
getShortSafe(byte[] bytes, int offset)

public static ClassLoader
getSystemClassLoader()

Return the system ClassLoader.

public static Throwable
getUnsafeUnavailabilityCause()

Return the reason (if any) why sun.misc.Unsafe was not available.

public static boolean
public static boolean
public static int

Returns:

The hash code of bytes assuming ASCII character encoding. The resulting hash code will be case insensitive.
hashCodeAscii
(byte[]
The array which contains the data to hash.
bytes
,
int
What index to start generating a hash code in bytes
startPos
,
int
The amount of bytes that should be accounted for in the computation.
length
)

Calculate a hash code of a byte array assuming ASCII character encoding.

public static int

Returns:

The hash code of bytes assuming ASCII character encoding. The resulting hash code will be case insensitive.
hashCodeAscii
(CharSequence
The array which contains the data to hash (assumed to be equivalent to a byte[]).
bytes
)

Calculate a hash code of a byte array assuming ASCII character encoding.

private static int
pack-priv static int
hashCodeAsciiSafe(byte[] bytes, int startPos, int length)

Package private for testing purposes only!

private static int
private static int
private static int
public static boolean
hasUnsafe()

Return true if sun.misc.Unsafe was found on the classpath and can be used for accelerated direct memory access.

private static void
incrementMemoryCounter(int capacity)

public static boolean
isAndroid()

Returns true if and only if the current platform is Android

public static boolean
isIkvmDotNet()

Returns true if the running JVM is IKVM.NET, false otherwise.

private static boolean
public static boolean
isJ9Jvm()

Returns true if the running JVM is either IBM J9 or Eclipse OpenJ9, false otherwise.

private static boolean
public static boolean
isOsx()

Return true if the JVM is running on OSX / MacOS

private static boolean
public static boolean
isUnaligned()

true if and only if the platform supports unaligned access.

public static boolean
isWindows()

Return true if the JVM is running on Windows

private static boolean
public static boolean

Returns:

false if bytes[startPos:startsPos+length) contains a value other than zero.
isZero
(byte[]
The byte array.
bytes
,
int
The starting index (inclusive) in bytes.
startPos
,
int
The amount of bytes to check for zero.
length
)

Determine if a subsection of an array is zero.

private static boolean
isZeroSafe(byte[] bytes, int startPos, int length)

public static int
javaVersion()

Return the version of Java under which this library is used.

public static long
maxDirectMemory()

Returns the maximum memory reserved for direct buffer allocation.

public static boolean
maybeSuperUser()

Return true if the current user may be a super-user.

private static boolean
public static <C> Deque<C>
newConcurrentDeque()

Returns a new concurrent Deque.

public static <K, V> ConcurrentMap<K, V>
newConcurrentHashMap()

Creates a new fastest ConcurrentMap implementation for the current platform.

public static <K, V> ConcurrentMap<K, V>
newConcurrentHashMap(int initialCapacity)

Creates a new fastest ConcurrentMap implementation for the current platform.

public static <K, V> ConcurrentMap<K, V>
newConcurrentHashMap(int initialCapacity, float loadFactor)

Creates a new fastest ConcurrentMap implementation for the current platform.

public static <K, V> ConcurrentMap<K, V>
newConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)

Creates a new fastest ConcurrentMap implementation for the current platform.

public static <K, V> ConcurrentMap<K, V>
newConcurrentHashMap(Map<? extends K, ? extends V> map)

Creates a new fastest ConcurrentMap implementation for the current platform.

public static <T> Queue<T>
newFixedMpscQueue(int capacity)

Create a new Queue which is safe to use for multiple producers (different threads) and a single consumer (one thread!) with the given fixes capacity.

public static LongCounter
newLongCounter()

Creates a new fastest LongCounter implementation for the current platform.

public static <T> Queue<T>

Returns:

A MPSC queue which may be unbounded.
newMpscQueue
()

Create a new Queue which is safe to use for multiple producers (different threads) and a single consumer (one thread!).

public static <T> Queue<T>
newMpscQueue(final int maxCapacity)

Create a new Queue which is safe to use for multiple producers (different threads) and a single consumer (one thread!).

public static <T> Queue<T>
newMpscQueue(final int chunkSize, final int maxCapacity)

Create a new Queue which is safe to use for multiple producers (different threads) and a single consumer (one thread!).

public static <T> Queue<T>
newSpscQueue()

Create a new Queue which is safe to use for single producer (one thread!) and a single consumer (one thread!).

private static String
private static String
public static String
public static Set<String>
public static String
private static String
private static String
public static long
public static void
putByte(long address, byte value)

public static void
putByte(byte[] data, int index, byte value)

public static void
putByte(Object data, long offset, byte value)

public static void
putInt(long address, int value)

public static void
putInt(byte[] data, int index, int value)

public static void
putIntOrdered(long adddress, int newValue)

public static void
putLong(long address, long value)

public static void
putLong(byte[] data, int index, long value)

public static void
putObject(Object o, long offset, Object x)

public static void
putShort(long address, short value)

public static void
putShort(byte[] data, int index, short value)

public static ByteBuffer
reallocateDirectNoCleaner(ByteBuffer buffer, int capacity)

Reallocate a new ByteBuffer with the given capacity.

public static long
reallocateMemory(long address, long newSize)

pack-priv static void
safeConstructPutInt(Object object, long fieldOffset, int value)

public static void
setMemory(byte[] dst, int dstIndex, long bytes, byte value)

public static void
setMemory(long address, long bytes, byte value)

public static Random
threadLocalRandom()

Return a Random which is not-threadsafe and so can only be used from the same thread.

public static void
throwException(Throwable t)

Raises an exception bypassing compiler checks for checked exceptions.

private static <E extends Throwable> void
public static File
tmpdir()

Returns the temporary directory.

private static File
private static File
private static Throwable
public static long
usedDirectMemory()

Returns the current memory reserved for direct buffer allocation.

public static boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait