public final class PlatformDependent
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static long |
allocateMemory(long size)
Allocates direct memory.
|
static void |
freeMemory(long address)
Deallocates direct memory.
|
static boolean |
hasUnsafe()
Checks if
sun.misc.Unsafe is available and has not been disabled. |
static java.nio.ByteBuffer |
newDirectBuffer(long address,
long size,
int capacity)
Creates a new
ByteBuffer for the specified pre-allocated direct memory. |
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> |
newMpscQueue(int initialCapacity,
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(int maxCapacity)
Create a new
Queue which is safe to use for single producer (one thread!) and a single
consumer (one thread!). |
static <T> java.util.Queue<T> |
newSpscQueue(int initialCapacity,
int maxCapacity)
Create a new
Queue which is safe to use for single producer (one thread!) and a single
consumer (one thread!). |
static <T> java.util.Queue<T> |
newUnboundedLinkedMpscQueue()
Create a new MPSC
Queue that will use a linked data structure and supports Collection.remove(Object) . |
static <T> java.util.Queue<T> |
newUnboundedMpscQueue()
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> |
newUnboundedMpscQueue(int initialCapacity)
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> |
newUnboundedSpscQueue(int initialCapacity)
Create a new unbounded
Queue which is safe to use for single producer (one thread!) and a single
consumer (one thread!). |
static void |
reserveMemory(long size,
int capacity)
Reserves direct memory for the specified size and capacity.
|
static <T> T |
throwException(java.lang.Throwable t)
Raises an exception bypassing compiler checks for checked exceptions.
|
static void |
unreserveMemory(long size,
int capacity)
Unreserves direct memory for the specified size and capacity.
|
static boolean |
useDirectBufferWithoutZeroing()
Checks if it is possible to create a new direct
ByteBuffer without zeroing the direct memory. |
public static boolean hasUnsafe()
sun.misc.Unsafe
is available and has not been disabled.true
if sun.misc.Unsafe
is available.public static boolean useDirectBufferWithoutZeroing()
ByteBuffer
without zeroing the direct memory.true
if it is possible to create a new direct ByteBuffer
without zeroing the direct
memory; false
otherwise.public static void reserveMemory(long size, int capacity)
size
- The size of direct memory to reserve.capacity
- The capacity of direct memory to reserve.public static void unreserveMemory(long size, int capacity)
size
- The size of direct memory to unreserve.capacity
- The capacity of direct memory to unreserve.public static long allocateMemory(long size)
size
- The size of direct memory to allocate.public static void freeMemory(long address)
address
- The address of direct memory to free.public static java.nio.ByteBuffer newDirectBuffer(long address, long size, int capacity)
ByteBuffer
for the specified pre-allocated direct memory.address
- The address of pre-allocated direct memory.size
- The size of pre-allocated direct memory.capacity
- The capacity of pre-allocated direct memory.ByteBuffer
.public static <T> T throwException(java.lang.Throwable t)
T
- The expected typet
- The Throwable
to throw.public static <T> java.util.Queue<T> newUnboundedMpscQueue()
Queue
which is safe to use for multiple producers (different threads) and a single
consumer (one thread!).T
- Type of items stored in the queue.Queue
.public static <T> java.util.Queue<T> newUnboundedMpscQueue(int initialCapacity)
Queue
which is safe to use for multiple producers (different threads) and a single
consumer (one thread!).T
- Type of items stored in the queue.initialCapacity
- of the returned queue.Queue
.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!).T
- Type of items stored in the queue.maxCapacity
- of the queue.Queue
with max capacity of maxCapacity
.public static <T> java.util.Queue<T> newMpscQueue(int initialCapacity, int maxCapacity)
Queue
which is safe to use for multiple producers (different threads) and a single
consumer (one thread!).T
- Type of items stored in the queue.initialCapacity
- Initial capacity for the queue.maxCapacity
- of the queue.Queue
with max capacity of maxCapacity
.public static <T> java.util.Queue<T> newUnboundedLinkedMpscQueue()
Queue
that will use a linked data structure and supports Collection.remove(Object)
.
Some reasons to use this queue as opposed to newUnboundedMpscQueue()
include the following:
ConcurrentLinkedQueue
only has 24 bytes of initial overhead so
this maybe a viable alternative if memory pressure exists and the size is expected to be small.Collection.remove(Object)
support - Current only the linked variants support this operation.T
- The data type of the queue.Queue
that will use a linked data structure and supports Collection.remove(Object)
.public static <T> java.util.Queue<T> newSpscQueue(int maxCapacity)
Queue
which is safe to use for single producer (one thread!) and a single
consumer (one thread!).T
- Type of items stored in the queue.maxCapacity
- of the queue.Queue
with max capacity of maxCapacity
.public static <T> java.util.Queue<T> newSpscQueue(int initialCapacity, int maxCapacity)
Queue
which is safe to use for single producer (one thread!) and a single
consumer (one thread!).T
- Type of items stored in the queue.initialCapacity
- Initial capacity for the queue.maxCapacity
- of the queue.Queue
with max capacity of maxCapacity
.public static <T> java.util.Queue<T> newUnboundedSpscQueue(int initialCapacity)
Queue
which is safe to use for single producer (one thread!) and a single
consumer (one thread!).T
- Type of items stored in the queue.initialCapacity
- of the returned queue.Queue
.