org.glassfish.grizzly.memory.slab
Class SlabMemoryManagerBase

java.lang.Object
  extended by org.glassfish.grizzly.memory.ByteBufferManager
      extended by org.glassfish.grizzly.memory.slab.SlabMemoryManagerBase
All Implemented Interfaces:
MemoryManager<ByteBufferWrapper>, WrapperAware<ByteBufferWrapper>
Direct Known Subclasses:
SlabMemoryManagerImpl, SlabPoolMemoryManagerImpl

public abstract class SlabMemoryManagerBase
extends ByteBufferManager

Base class for implementing an SlabMemory Allocator. All subclasses must implement dispose, releaseSlab and obtainSlab, as well as the undefined methods in the Allocator interface: maxAllocationSize, bufferType, and close. For the aim of avoiding contention on allocate() and supporting Buffer.trim() SlabMemoryManagerBase associates each calling Thread with ist own Slab. If calling Thread happens to be WorkerThread Slab is stored in WorkerThread's Attributes otherwise Threadlocal storage is used. The Thread associated Slab serves as a memory depot for allocating BufferWrappers. If a Slab's space is exhausted obtainSlab will provide a empty Slab which will replace the calling Thread's exhausted Slab.

Author:
Ken Cavanaugh, John Vieten

Field Summary
 
Fields inherited from class org.glassfish.grizzly.memory.ByteBufferManager
isDirect
 
Method Summary
 SlabByteBufferWrapper allocate(int size)
          Allocated Buffer of the required size.
 Buffer allocate(int minSize, int maxSize)
           
abstract  void dispose(Slab slab, ByteBuffer store)
           
abstract  int maxAllocationSize()
          Returns the maximum size that can be allocated by an allocate( int ) call.
 ByteBufferWrapper reallocate(ByteBufferWrapper oldBuffer, int newSize)
          Reallocate Buffer to a required size.
 void release(ByteBufferWrapper buffer)
          Lets JVM Garbage collector to release buffer.
 
Methods inherited from class org.glassfish.grizzly.memory.ByteBufferManager
allocate0, isDirect, setDirect, wrap, wrap, wrap, wrap, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

dispose

public abstract void dispose(Slab slab,
                             ByteBuffer store)

maxAllocationSize

public abstract int maxAllocationSize()
Returns the maximum size that can be allocated by an allocate( int ) call.


allocate

public SlabByteBufferWrapper allocate(int size)
Description copied from class: ByteBufferManager
Allocated Buffer of the required size.

Specified by:
allocate in interface MemoryManager<ByteBufferWrapper>
Overrides:
allocate in class ByteBufferManager
Parameters:
size - Buffer size to be allocated.
Returns:
allocated Buffer.

allocate

public final Buffer allocate(int minSize,
                             int maxSize)

release

public void release(ByteBufferWrapper buffer)
Description copied from class: ByteBufferManager
Lets JVM Garbage collector to release buffer.

Specified by:
release in interface MemoryManager<ByteBufferWrapper>
Overrides:
release in class ByteBufferManager
Parameters:
buffer - Buffer to be released.

reallocate

public ByteBufferWrapper reallocate(ByteBufferWrapper oldBuffer,
                                    int newSize)
Description copied from class: ByteBufferManager
Reallocate Buffer to a required size. Implementation may choose the way, how reallocation could be done, either by allocating new Buffer of required size and copying old Buffer content there, or perform more complex logic related to memory pooling etc.

Specified by:
reallocate in interface MemoryManager<ByteBufferWrapper>
Overrides:
reallocate in class ByteBufferManager
Parameters:
oldBuffer - old Buffer to be reallocated.
newSize - new Buffer required size.
Returns:
reallocated Buffer.


Copyright © 2009 SUN Microsystems. All Rights Reserved.