Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.memory

public Class PooledMemoryManager

extends Object
implements MemoryManager<Buffer>, WrapperAware
Class Inheritance
All Implemented Interfaces
org.glassfish.grizzly.memory.WrapperAware, org.glassfish.grizzly.memory.MemoryManager, org.glassfish.grizzly.monitoring.MonitoringAware
Imports
java.nio.ByteBuffer, java.nio.charset.Charset, java.util.Arrays, java.util.concurrent.ThreadLocalRandom, java.util.concurrent.atomic.AtomicInteger, .AtomicReferenceArray, java.util.concurrent.locks.LockSupport, org.glassfish.grizzly.Buffer, org.glassfish.grizzly.monitoring.DefaultMonitoringConfig, .MonitoringConfig, .MonitoringUtils

A MemoryManager implementation based on a series of shared memory pools. Each pool contains multiple buffers of the fixed length specific for this pool. There are several tuning options for this MemoryManager implementation. If no explicit configuration is provided, the following defaults will be used: The main advantage of this manager over org.glassfish.grizzly.memory.HeapMemoryManager or org.glassfish.grizzly.memory.ByteBufferManager is that this implementation doesn't use ThreadLocal pools and as such, doesn't suffer from the memory fragmentation/reallocation cycle that can impact the ThreadLocal versions.
Since
2.3.11

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static interface
private static class
private static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final long
public static final int
public static final int
public static final float
public static final int
public static final float
private static final boolean
private final int
protected final DefaultMonitoringConfig<MemoryProbe>
monitoringConfig

Basic monitoring support.

private final PooledMemoryManager.Pool[]

Constructor Summary

AccessConstructor and Description
public
PooledMemoryManager()

Creates a new PooledMemoryManager using the following defaults:

  • 4 KiB base buffer size
  • 3 pools
  • 2 growth factor, which means 1st pool will contain buffers of size 4KiB, the 2nd - 16KiB, the 3rd - 64KiB
  • Number of pool slices based on Runtime.getRuntime().availableProcessors()
  • The initial allocation will use 3% of the heap
  • The percentage of buffers to be pre-allocated during MemoryManager initialization
public
PooledMemoryManager(final boolean
flag, indicating whether direct or heap based Buffers will be allocated
isDirect
)

Creates a new PooledMemoryManager using the specified parameters for configuration.

public
PooledMemoryManager(final int
the base size of the buffer for the 1st pool, every next pool n will have buffer size equal to bufferSize(n-1) * 2^growthFactor
baseBufferSize
,
final int
the number of pools, responsible for allocation of buffers of a pool-specific size
numberOfPools
,
final int
the buffer size growth factor, that defines 2^x multiplier, used to calculate buffer size for next allocated pool
growthFactor
,
final int
the number of pool slices that every pool will stripe allocation requests across
numberOfPoolSlices
,
final float
percentage of the heap that will be used when populating the pools
percentOfHeap
,
final float
percentage of buffers to be pre-allocated during MemoryManager initialization
percentPreallocated
,
final boolean
flag, indicating whether direct or heap based Buffers will be allocated
isDirect
)

Creates a new PooledMemoryManager using the specified parameters for configuration.

Method Summary

Modifier and TypeMethod and Description
public Buffer
allocate(final int size)

Implements org.glassfish.grizzly.memory.MemoryManager.allocate.

For this implementation, this method simply calls through to allocateAtLeast(int);

public Buffer

Returns:

a buffer with a limit of the specified size.
allocateAtLeast
(int
the min Buffer size to be allocated.
size
)

Implements org.glassfish.grizzly.memory.MemoryManager.allocateAtLeast.

Allocates a buffer of at least the size requested.

private CompositeBuffer
protected Object
private static int
public MonitoringConfig<MemoryProbe>
private PooledMemoryManager.Pool
getPoolFor(final int size)

pack-priv PooledMemoryManager.Pool[]
private static boolean
isPowerOfTwo(final int valueToCheck)

private CompositeBuffer
public Buffer

Returns:

potentially a new buffer of at least the specified size.
reallocate
(final Buffer
old Buffer to be reallocated.
oldBuffer
,
final int
new Buffer required size.
newSize
)

Implements org.glassfish.grizzly.memory.MemoryManager.reallocate.

Reallocates an existing buffer to at least the specified size.

public void
public boolean
willAllocateDirect(final int size)

Implements org.glassfish.grizzly.memory.MemoryManager.willAllocateDirect.

Return true if next allocate(int) or allocateAtLeast(int) call, made in the current thread for the given memory size, going to return a Buffer based on direct java.nio.ByteBuffer, or false otherwise.

public Buffer
wrap(final byte[] data)

Implements org.glassfish.grizzly.memory.WrapperAware.wrap.

Returns Buffer, which wraps the byte array.

public Buffer
wrap(byte[] data, int offset, int length)

Implements org.glassfish.grizzly.memory.WrapperAware.wrap.

Returns Buffer, which wraps the part of byte array with specific offset and length.

public Buffer
wrap(final String s)

Implements org.glassfish.grizzly.memory.WrapperAware.wrap.

Returns Buffer, which wraps the String.

public Buffer
wrap(final String s, final Charset charset)

Implements org.glassfish.grizzly.memory.WrapperAware.wrap.

Returns Buffer, which wraps the String with the specific Charset.

public Buffer
wrap(final ByteBuffer byteBuffer)

Implements org.glassfish.grizzly.memory.WrapperAware.wrap.

Returns Buffer, which wraps the ByteBuffer.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait