public final class PlatformDependent extends Object
sun.misc.Unsafe
object.
You can disable the use of sun.misc.Unsafe
if you specify
the system property io.netty.noUnsafe.
Modifier and Type | Method and Description |
---|---|
static int |
addressSize()
Return the address size of the OS.
4 (for 32 bits systems ) and 8 (for 64 bits systems).
|
static long |
allocateMemory(long 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 long |
directBufferAddress(ByteBuffer buffer) |
static boolean |
directBufferPreferred()
Returns
true if the platform has reliable low-level direct buffer access API and a user specified
-Dio.netty.preferDirect option. |
static void |
freeDirectBuffer(ByteBuffer buffer)
Try to deallocate the specified direct
ByteBuffer . |
static void |
freeMemory(long address) |
static byte |
getByte(long address) |
static ClassLoader |
getClassLoader(Class<?> clazz)
Return the
ClassLoader for the given Class . |
static ClassLoader |
getContextClassLoader()
Return the context
ClassLoader for the current Thread . |
static int |
getInt(long address) |
static int |
getInt(Object object,
long fieldOffset) |
static long |
getLong(long address) |
static Object |
getObject(Object object,
long fieldOffset) |
static Object |
getObjectVolatile(Object object,
long fieldOffset) |
static short |
getShort(long address) |
static ClassLoader |
getSystemClassLoader()
Return the system
ClassLoader . |
static boolean |
hasJavassist()
Returns
true if and only if Javassist is available. |
static boolean |
hasUnsafe()
Return
true if sun.misc.Unsafe was found on the classpath and can be used for acclerated
direct memory access. |
static boolean |
isAndroid()
Returns
true if and only if the current platform is Android |
static boolean |
isRoot()
Return
true if the current user is root. |
static boolean |
isWindows()
Return
true if the JVM is running on Windows |
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 <T> AtomicIntegerFieldUpdater<T> |
newAtomicIntegerFieldUpdater(Class<?> tclass,
String fieldName)
Create a new optimized
AtomicIntegerFieldUpdater or null if it
could not be created. |
static <T> AtomicLongFieldUpdater<T> |
newAtomicLongFieldUpdater(Class<?> tclass,
String fieldName)
Create a new optimized
AtomicLongFieldUpdater or null if it
could not be created. |
static <U,W> AtomicReferenceFieldUpdater<U,W> |
newAtomicReferenceFieldUpdater(Class<U> tclass,
String fieldName)
Create a new optimized
AtomicReferenceFieldUpdater or null if it
could not be created. |
static <C> Deque<C> |
newConcurrentDeque()
Returns a new concurrent
Deque . |
static <K,V> ConcurrentMap<K,V> |
newConcurrentHashMap()
Creates a new fastest
ConcurrentMap implementaion for the current platform. |
static <K,V> ConcurrentMap<K,V> |
newConcurrentHashMap(int initialCapacity)
Creates a new fastest
ConcurrentMap implementaion for the current platform. |
static <K,V> ConcurrentMap<K,V> |
newConcurrentHashMap(int initialCapacity,
float loadFactor)
Creates a new fastest
ConcurrentMap implementaion for the current platform. |
static <K,V> ConcurrentMap<K,V> |
newConcurrentHashMap(int initialCapacity,
float loadFactor,
int concurrencyLevel)
Creates a new fastest
ConcurrentMap implementaion for the current platform. |
static <K,V> ConcurrentMap<K,V> |
newConcurrentHashMap(Map<? extends K,? extends V> map)
Creates a new fastest
ConcurrentMap implementaion for the current platform. |
static <T> Queue<T> |
newMpscQueue()
Create a new
Queue which is safe to use for multiple producers (different threads) and a single
consumer (one thread!). |
static long |
objectFieldOffset(Field field) |
static void |
putByte(long address,
byte value) |
static void |
putInt(long address,
int value) |
static void |
putLong(long address,
long value) |
static void |
putOrderedObject(Object object,
long address,
Object value) |
static void |
putShort(long address,
short value) |
static void |
throwException(Throwable t)
Raises an exception bypassing compiler checks for checked exceptions.
|
static File |
tmpdir()
Returns the temporary directory.
|
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 isRoot()
true
if the current user is root. Note that this method returns
false
if on Windows.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 acclerated
direct memory access.public static boolean directBufferPreferred()
true
if the platform has reliable low-level direct buffer access API and a user specified
-Dio.netty.preferDirect
option.public static long maxDirectMemory()
public static boolean hasJavassist()
true
if and only if Javassist is available.public static 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(Throwable t)
public static <K,V> ConcurrentMap<K,V> newConcurrentHashMap()
ConcurrentMap
implementaion for the current platform.public static <K,V> ConcurrentMap<K,V> newConcurrentHashMap(int initialCapacity)
ConcurrentMap
implementaion for the current platform.public static <K,V> ConcurrentMap<K,V> newConcurrentHashMap(int initialCapacity, float loadFactor)
ConcurrentMap
implementaion for the current platform.public static <K,V> ConcurrentMap<K,V> newConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)
ConcurrentMap
implementaion for the current platform.public static <K,V> ConcurrentMap<K,V> newConcurrentHashMap(Map<? extends K,? extends V> map)
ConcurrentMap
implementaion for the current platform.public static void freeDirectBuffer(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(ByteBuffer buffer)
public static int getInt(Object object, long fieldOffset)
public static long objectFieldOffset(Field field)
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 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 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 <U,W> AtomicReferenceFieldUpdater<U,W> newAtomicReferenceFieldUpdater(Class<U> tclass, String fieldName)
AtomicReferenceFieldUpdater
or null
if it
could not be created. Because of this the caller need to check for null
and if null
is returned
use AtomicReferenceFieldUpdater.newUpdater(Class, Class, String)
as fallback.public static <T> AtomicIntegerFieldUpdater<T> newAtomicIntegerFieldUpdater(Class<?> tclass, String fieldName)
AtomicIntegerFieldUpdater
or null
if it
could not be created. Because of this the caller need to check for null
and if null
is returned
use AtomicIntegerFieldUpdater.newUpdater(Class, String)
as fallback.public static <T> AtomicLongFieldUpdater<T> newAtomicLongFieldUpdater(Class<?> tclass, String fieldName)
AtomicLongFieldUpdater
or null
if it
could not be created. Because of this the caller need to check for null
and if null
is returned
use AtomicLongFieldUpdater.newUpdater(Class, String)
as fallback.public static <T> Queue<T> newMpscQueue()
Queue
which is safe to use for multiple producers (different threads) and a single
consumer (one thread!).public static ClassLoader getClassLoader(Class<?> clazz)
ClassLoader
for the given Class
.public static ClassLoader getContextClassLoader()
ClassLoader
for the current Thread
.public static ClassLoader getSystemClassLoader()
ClassLoader
.Copyright © 2008-2016 The Netty Project. All Rights Reserved.