public final class PlatformDependent
extends java.lang.Object
sun.misc.Unsafe
object.
You can disable the use of sun.misc.Unsafe
if you specify
the system property io.netty.noUnsafe.
限定符和类型 | 字段和说明 |
---|---|
static boolean |
BIG_ENDIAN_NATIVE_ORDER |
限定符和类型 | 方法和说明 |
---|---|
static int |
addressSize()
Return the address size of the OS.
4 (for 32 bits systems ) and 8 (for 64 bits systems).
|
static java.nio.ByteBuffer |
allocateDirectNoCleaner(int capacity)
Allocate a new
ByteBuffer with the given capacity . |
static long |
allocateMemory(long size) |
static byte[] |
allocateUninitializedArray(int size) |
static int |
bitMode()
Returns the bit mode of the current VM (usually 32 or 64.)
|
static boolean |
canEnableTcpNoDelayByDefault()
Returns
true if and only if it is fine to enable TCP_NODELAY socket option by default. |
static void |
copyMemory(byte[] src,
int srcIndex,
long dstAddr,
long length) |
static void |
copyMemory(long srcAddr,
byte[] dst,
int dstIndex,
long length) |
static void |
copyMemory(long srcAddr,
long dstAddr,
long length) |
static java.nio.ByteBuffer |
directBuffer(long memoryAddress,
int size) |
static long |
directBufferAddress(java.nio.ByteBuffer buffer) |
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. |
static void |
freeDirectBuffer(java.nio.ByteBuffer buffer)
Try to deallocate the specified direct
ByteBuffer . |
static void |
freeDirectNoCleaner(java.nio.ByteBuffer buffer)
This method MUST only be called for
ByteBuffer s that were allocated via
allocateDirectNoCleaner(int) . |
static void |
freeMemory(long address) |
static byte |
getByte(byte[] data,
int index) |
static byte |
getByte(long address) |
static java.lang.ClassLoader |
getClassLoader(java.lang.Class<?> clazz)
Return the
ClassLoader for the given Class . |
static java.lang.ClassLoader |
getContextClassLoader()
Return the context
ClassLoader for the current Thread . |
static int |
getInt(byte[] data,
int index) |
static int |
getInt(long address) |
static int |
getInt(java.lang.Object object,
long fieldOffset) |
static long |
getLong(byte[] data,
int index) |
static long |
getLong(long address) |
static short |
getShort(byte[] data,
int index) |
static short |
getShort(long address) |
static java.lang.ClassLoader |
getSystemClassLoader()
Return the system
ClassLoader . |
static java.lang.Throwable |
getUnsafeUnavailabilityCause()
Return the reason (if any) why
sun.misc.Unsafe was not available. |
static boolean |
hasDirectBufferNoCleanerConstructor() |
static boolean |
hasUnsafe()
Return
true if sun.misc.Unsafe was found on the classpath and can be used for accelerated
direct memory access. |
static boolean |
isAndroid()
Returns
true if and only if the current platform is Android |
static boolean |
isOsx()
Return
true if the JVM is running on OSX / MacOS |
static boolean |
isUnaligned()
true if and only if the platform supports unaligned access. |
static boolean |
isWindows()
Return
true if the JVM is running on Windows |
static boolean |
isZero(byte[] bytes,
int startPos,
int length)
Determine if a subsection of an array is zero.
|
static int |
javaVersion()
Return the version of Java under which this library is used.
|
static long |
maxDirectMemory()
Returns the maximum memory reserved for direct buffer allocation.
|
static boolean |
maybeSuperUser()
Return
true if the current user may be a super-user. |
static <C> java.util.Deque<C> |
newConcurrentDeque()
Returns a new concurrent
Deque . |
static <K,V> java.util.concurrent.ConcurrentMap<K,V> |
newConcurrentHashMap()
Creates a new fastest
ConcurrentMap implementation for the current platform. |
static <K,V> java.util.concurrent.ConcurrentMap<K,V> |
newConcurrentHashMap(int initialCapacity)
Creates a new fastest
ConcurrentMap implementation for the current platform. |
static <K,V> java.util.concurrent.ConcurrentMap<K,V> |
newConcurrentHashMap(int initialCapacity,
float loadFactor)
Creates a new fastest
ConcurrentMap implementation for the current platform. |
static <K,V> java.util.concurrent.ConcurrentMap<K,V> |
newConcurrentHashMap(int initialCapacity,
float loadFactor,
int concurrencyLevel)
Creates a new fastest
ConcurrentMap implementation 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 fastest
ConcurrentMap implementation for the current platform. |
static <T> java.util.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!) |
static LongCounter |
newLongCounter()
Creates a new fastest
LongCounter implementation for the current platform. |
static <T> java.util.Queue<T> |
newMpscQueue()
Create a new
Queue which 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 new
Queue which is safe to use for multiple producers (different threads) and a single
consumer (one thread!). |
static <T> java.util.Queue<T> |
newSpscQueue()
Create a new
Queue which is safe to use for single producer (one thread!) |
static java.lang.String |
normalizedArch() |
static java.lang.String |
normalizedOs() |
static void |
putByte(byte[] data,
int index,
byte value) |
static void |
putByte(long address,
byte value) |
static void |
putInt(byte[] data,
int index,
int value) |
static void |
putInt(long address,
int value) |
static void |
putLong(byte[] data,
int index,
long value) |
static void |
putLong(long address,
long value) |
static void |
putShort(byte[] data,
int index,
short value) |
static void |
putShort(long address,
short value) |
static java.nio.ByteBuffer |
reallocateDirectNoCleaner(java.nio.ByteBuffer buffer,
int capacity)
Reallocate a new
ByteBuffer with the given capacity . |
static void |
setMemory(byte[] dst,
int dstIndex,
long bytes,
byte value) |
static void |
setMemory(long address,
long bytes,
byte value) |
static java.util.Random |
threadLocalRandom()
Return a
Random which is not-threadsafe and so can only be used from the same thread. |
static void |
throwException(java.lang.Throwable t)
Raises an exception bypassing compiler checks for checked exceptions.
|
static java.io.File |
tmpdir()
Returns the temporary directory.
|
static boolean |
useDirectBufferNoCleaner() |
public static boolean hasDirectBufferNoCleanerConstructor()
public static byte[] allocateUninitializedArray(int size)
public static boolean isAndroid()
true
if and only if the current platform is Androidpublic static boolean isWindows()
true
if the JVM is running on Windowspublic static boolean isOsx()
true
if the JVM is running on OSX / MacOSpublic static boolean maybeSuperUser()
true
if the current user may be a super-user. Be aware that this is just an hint and so it may
return false-positives.public static int javaVersion()
public static boolean canEnableTcpNoDelayByDefault()
true
if and only if it is fine to enable TCP_NODELAY socket option by default.public static boolean hasUnsafe()
true
if sun.misc.Unsafe
was found on the classpath and can be used for accelerated
direct memory access.public static java.lang.Throwable getUnsafeUnavailabilityCause()
sun.misc.Unsafe
was not available.public static boolean isUnaligned()
true
if and only if the platform supports unaligned access.public static boolean directBufferPreferred()
true
if the platform has reliable low-level direct buffer access API and a user has not specified
-Dio.netty.noPreferDirect
option.public static long maxDirectMemory()
public static java.io.File tmpdir()
public static int bitMode()
public static int addressSize()
public static long allocateMemory(long size)
public static void freeMemory(long address)
public static void throwException(java.lang.Throwable t)
public static <K,V> java.util.concurrent.ConcurrentMap<K,V> newConcurrentHashMap()
ConcurrentMap
implementation for the current platform.public static LongCounter newLongCounter()
LongCounter
implementation for the current platform.public static <K,V> java.util.concurrent.ConcurrentMap<K,V> newConcurrentHashMap(int initialCapacity)
ConcurrentMap
implementation for the current platform.public static <K,V> java.util.concurrent.ConcurrentMap<K,V> newConcurrentHashMap(int initialCapacity, float loadFactor)
ConcurrentMap
implementation for the current platform.public static <K,V> java.util.concurrent.ConcurrentMap<K,V> newConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)
ConcurrentMap
implementation for the current platform.public static <K,V> java.util.concurrent.ConcurrentMap<K,V> newConcurrentHashMap(java.util.Map<? extends K,? extends V> map)
ConcurrentMap
implementation for the current platform.public static void freeDirectBuffer(java.nio.ByteBuffer buffer)
ByteBuffer
. Please note this method does nothing if
the current platform does not support this operation or the specified buffer is not a direct buffer.public static long directBufferAddress(java.nio.ByteBuffer buffer)
public static java.nio.ByteBuffer directBuffer(long memoryAddress, int size)
public static int getInt(java.lang.Object object, long fieldOffset)
public static byte getByte(long address)
public static short getShort(long address)
public static int getInt(long address)
public static long getLong(long address)
public static byte getByte(byte[] data, int index)
public static short getShort(byte[] data, int index)
public static int getInt(byte[] data, int index)
public static long getLong(byte[] data, int index)
public static void putByte(long address, byte value)
public static void putShort(long address, short value)
public static void putInt(long address, int value)
public static void putLong(long address, long value)
public static void putByte(byte[] data, int index, byte value)
public static void putShort(byte[] data, int index, short value)
public static void putInt(byte[] data, int index, int value)
public static void putLong(byte[] data, int index, long value)
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(long srcAddr, byte[] dst, int dstIndex, long length)
public static void setMemory(byte[] dst, int dstIndex, long bytes, byte value)
public static void setMemory(long address, long bytes, byte value)
public static java.nio.ByteBuffer allocateDirectNoCleaner(int capacity)
ByteBuffer
with the given capacity
. ByteBuffer
s allocated with
this method MUST be deallocated via freeDirectNoCleaner(ByteBuffer)
.public static java.nio.ByteBuffer reallocateDirectNoCleaner(java.nio.ByteBuffer buffer, int capacity)
ByteBuffer
with the given capacity
. ByteBuffer
s reallocated with
this method MUST be deallocated via freeDirectNoCleaner(ByteBuffer)
.public static void freeDirectNoCleaner(java.nio.ByteBuffer buffer)
ByteBuffer
s that were allocated via
allocateDirectNoCleaner(int)
.public static boolean useDirectBufferNoCleaner()
public static boolean isZero(byte[] bytes, int startPos, int length)
bytes
- The byte array.startPos
- The starting index (inclusive) in bytes
.length
- The amount of bytes to check for zero.false
if bytes[startPos:startsPos+length)
contains a value other than zero.public static <T> java.util.Queue<T> newMpscQueue()
Queue
which is safe to use for multiple producers (different threads) and a single
consumer (one thread!).public static <T> java.util.Queue<T> newMpscQueue(int maxCapacity)
Queue
which is safe to use for multiple producers (different threads) and a single
consumer (one thread!).public static <T> java.util.Queue<T> newSpscQueue()
Queue
which is safe to use for single producer (one thread!) and a single
consumer (one thread!).public static <T> java.util.Queue<T> newFixedMpscQueue(int capacity)
Queue
which is safe to use for multiple producers (different threads) and a single
consumer (one thread!) with the given fixes capacity
.public static java.lang.ClassLoader getClassLoader(java.lang.Class<?> clazz)
ClassLoader
for the given Class
.public static java.lang.ClassLoader getContextClassLoader()
ClassLoader
for the current Thread
.public static java.lang.ClassLoader getSystemClassLoader()
ClassLoader
.public static <C> java.util.Deque<C> newConcurrentDeque()
Deque
.public static java.util.Random threadLocalRandom()
Random
which is not-threadsafe and so can only be used from the same thread.public static java.lang.String normalizedArch()
public static java.lang.String normalizedOs()