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.
Modifier and Type | Class and Description |
---|---|
private static class |
PlatformDependent.AtomicLongCounter |
private static class |
PlatformDependent.Mpsc |
Modifier and Type | Field and Description |
---|---|
private static int |
ADDRESS_SIZE |
private static long |
ARRAY_BASE_OFFSET |
static boolean |
BIG_ENDIAN_NATIVE_ORDER |
private static int |
BIT_MODE |
private static boolean |
CAN_ENABLE_TCP_NODELAY_BY_DEFAULT |
private static boolean |
CAN_USE_CHM_V8 |
private static int |
DEFAULT_MAX_MPSC_CAPACITY |
private static boolean |
DIRECT_BUFFER_PREFERRED |
private static java.util.concurrent.atomic.AtomicLong |
DIRECT_MEMORY_COUNTER |
private static long |
DIRECT_MEMORY_LIMIT |
private static boolean |
HAS_JAVASSIST |
private static boolean |
HAS_UNSAFE |
private static boolean |
IS_ANDROID |
private static boolean |
IS_EXPLICIT_NO_UNSAFE |
private static java.lang.Boolean |
IS_ROOT |
private static boolean |
IS_WINDOWS |
private static int |
JAVA_VERSION |
private static InternalLogger |
logger |
private static int |
MAX_ALLOWED_MPSC_CAPACITY |
private static long |
MAX_DIRECT_MEMORY |
private static java.util.regex.Pattern |
MAX_DIRECT_MEMORY_SIZE_ARG_PATTERN |
private static int |
MIN_MAX_MPSC_CAPACITY |
private static int |
MPSC_CHUNK_SIZE |
private static java.io.File |
TMPDIR |
private static boolean |
USE_DIRECT_BUFFER_NO_CLEANER |
Modifier | Constructor and Description |
---|---|
private |
PlatformDependent() |
Modifier and Type | Method and Description |
---|---|
static int |
addressSize()
Return the address size of the OS.
|
private static int |
addressSize0() |
static java.nio.ByteBuffer |
allocateDirectNoCleaner(int capacity)
Allocate a new
ByteBuffer with the given capacity . |
static long |
allocateMemory(long size) |
private static long |
arrayBaseOffset0() |
static int |
bitMode()
Returns the bit mode of the current VM (usually 32 or 64.)
|
private static int |
bitMode0() |
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) |
private static void |
decrementMemoryCounter(int capacity) |
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. |
private static boolean |
explicitNoUnsafe0() |
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 java.lang.Object |
getObject(java.lang.Object object,
long fieldOffset) |
static java.lang.Object |
getObjectVolatile(java.lang.Object object,
long fieldOffset) |
static short |
getShort(byte[] data,
int index) |
static short |
getShort(long address) |
static java.lang.ClassLoader |
getSystemClassLoader()
Return the system
ClassLoader . |
static boolean |
hasJavassist()
Returns
true if and only if Javassist is available. |
private static boolean |
hasJavassist0() |
static boolean |
hasUnsafe()
Return
true if sun.misc.Unsafe was found on the classpath and can be used for acclerated
direct memory access. |
private static boolean |
hasUnsafe0() |
private static void |
incrementMemoryCounter(int capacity) |
static boolean |
isAndroid()
Returns
true if and only if the current platform is Android |
private static boolean |
isAndroid0() |
static boolean |
isRoot()
Return
true if the current user is root. |
private static boolean |
isRoot0() |
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 |
private static boolean |
isWindows0() |
static int |
javaVersion()
Return the version of Java under which this library is used.
|
private static int |
javaVersion0() |
(package private) static int |
majorVersion(java.lang.String javaSpecVersion) |
(package private) static int |
majorVersionFromJavaSpecificationVersion() |
static long |
maxDirectMemory()
Returns the maximum memory reserved for direct buffer allocation.
|
private static long |
maxDirectMemory0() |
static <T> java.util.concurrent.atomic.AtomicIntegerFieldUpdater<T> |
newAtomicIntegerFieldUpdater(java.lang.Class<? super T> tclass,
java.lang.String fieldName)
Create a new optimized
AtomicIntegerFieldUpdater or null if it
could not be created. |
static <T> java.util.concurrent.atomic.AtomicLongFieldUpdater<T> |
newAtomicLongFieldUpdater(java.lang.Class<? super T> tclass,
java.lang.String fieldName)
Create a new optimized
AtomicLongFieldUpdater or null if it
could not be created. |
static <U,W> java.util.concurrent.atomic.AtomicReferenceFieldUpdater<U,W> |
newAtomicReferenceFieldUpdater(java.lang.Class<? super U> tclass,
java.lang.String fieldName)
Create a new optimized
AtomicReferenceFieldUpdater or null if it
could not be created. |
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 implementaion for the current platform. |
static <K,V> java.util.concurrent.ConcurrentMap<K,V> |
newConcurrentHashMap(int initialCapacity)
Creates a new fastest
ConcurrentMap implementaion for the current platform. |
static <K,V> java.util.concurrent.ConcurrentMap<K,V> |
newConcurrentHashMap(int initialCapacity,
float loadFactor)
Creates a new fastest
ConcurrentMap implementaion 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 implementaion 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 implementaion 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!) with the given fixes capacity . |
static LongCounter |
newLongCounter()
Creates a new fastest
LongCounter implementaion 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!) and a single
consumer (one thread!). |
static long |
objectFieldOffset(java.lang.reflect.Field field) |
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 |
putOrderedObject(java.lang.Object object,
long address,
java.lang.Object 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 void |
throwException(java.lang.Throwable t)
Raises an exception bypassing compiler checks for checked exceptions.
|
private static <E extends java.lang.Throwable> |
throwException0(java.lang.Throwable t) |
static java.io.File |
tmpdir()
Returns the temporary directory.
|
private static java.io.File |
tmpdir0() |
private static java.io.File |
toDirectory(java.lang.String path) |
static boolean |
useDirectBufferNoCleaner() |
private static final InternalLogger logger
private static final java.util.regex.Pattern MAX_DIRECT_MEMORY_SIZE_ARG_PATTERN
private static final boolean IS_ANDROID
private static final boolean IS_WINDOWS
private static volatile java.lang.Boolean IS_ROOT
private static final int JAVA_VERSION
private static final boolean CAN_ENABLE_TCP_NODELAY_BY_DEFAULT
private static final boolean IS_EXPLICIT_NO_UNSAFE
private static final boolean HAS_UNSAFE
private static final boolean CAN_USE_CHM_V8
private static final boolean DIRECT_BUFFER_PREFERRED
private static final long MAX_DIRECT_MEMORY
private static final int MPSC_CHUNK_SIZE
private static final int MIN_MAX_MPSC_CAPACITY
private static final int DEFAULT_MAX_MPSC_CAPACITY
private static final int MAX_ALLOWED_MPSC_CAPACITY
private static final long ARRAY_BASE_OFFSET
private static final boolean HAS_JAVASSIST
private static final java.io.File TMPDIR
private static final int BIT_MODE
private static final int ADDRESS_SIZE
private static final boolean USE_DIRECT_BUFFER_NO_CLEANER
private static final java.util.concurrent.atomic.AtomicLong DIRECT_MEMORY_COUNTER
private static final long DIRECT_MEMORY_LIMIT
public static final boolean BIG_ENDIAN_NATIVE_ORDER
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 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 boolean hasJavassist()
true
if and only if Javassist is available.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)
private static <E extends java.lang.Throwable> void throwException0(java.lang.Throwable t) throws E extends java.lang.Throwable
E extends java.lang.Throwable
public static <K,V> java.util.concurrent.ConcurrentMap<K,V> newConcurrentHashMap()
ConcurrentMap
implementaion for the current platform.public static LongCounter newLongCounter()
LongCounter
implementaion for the current platform.public static <K,V> java.util.concurrent.ConcurrentMap<K,V> newConcurrentHashMap(int initialCapacity)
ConcurrentMap
implementaion for the current platform.public static <K,V> java.util.concurrent.ConcurrentMap<K,V> newConcurrentHashMap(int initialCapacity, float loadFactor)
ConcurrentMap
implementaion for the current platform.public static <K,V> java.util.concurrent.ConcurrentMap<K,V> newConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)
ConcurrentMap
implementaion for the current platform.public static <K,V> java.util.concurrent.ConcurrentMap<K,V> newConcurrentHashMap(java.util.Map<? extends K,? extends V> map)
ConcurrentMap
implementaion 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 java.lang.Object getObject(java.lang.Object object, long fieldOffset)
public static java.lang.Object getObjectVolatile(java.lang.Object object, long fieldOffset)
public static int getInt(java.lang.Object object, long fieldOffset)
public static long objectFieldOffset(java.lang.reflect.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 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 putOrderedObject(java.lang.Object object, long address, java.lang.Object value)
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)
.private static void incrementMemoryCounter(int capacity)
private static void decrementMemoryCounter(int capacity)
public static boolean useDirectBufferNoCleaner()
public static <U,W> java.util.concurrent.atomic.AtomicReferenceFieldUpdater<U,W> newAtomicReferenceFieldUpdater(java.lang.Class<? super U> tclass, java.lang.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> java.util.concurrent.atomic.AtomicIntegerFieldUpdater<T> newAtomicIntegerFieldUpdater(java.lang.Class<? super T> tclass, java.lang.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> java.util.concurrent.atomic.AtomicLongFieldUpdater<T> newAtomicLongFieldUpdater(java.lang.Class<? super T> tclass, java.lang.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> 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
.private static boolean isAndroid0()
private static boolean isWindows0()
private static boolean isRoot0()
private static int javaVersion0()
static int majorVersionFromJavaSpecificationVersion()
static int majorVersion(java.lang.String javaSpecVersion)
private static boolean explicitNoUnsafe0()
private static boolean hasUnsafe0()
private static long arrayBaseOffset0()
private static long maxDirectMemory0()
private static boolean hasJavassist0()
private static java.io.File tmpdir0()
private static java.io.File toDirectory(java.lang.String path)
private static int bitMode0()
private static int addressSize0()