public class DefaultMemoryManager extends Object implements MemoryManager
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_PAGE_SIZE
The default memory page size.
|
static int |
MIN_PAGE_SIZE
The minimal memory page size.
|
| Constructor and Description |
|---|
DefaultMemoryManager(long memorySize,
int numberOfSlots)
Creates a memory manager with the given capacity, using the default page size.
|
DefaultMemoryManager(long memorySize,
int numberOfSlots,
int pageSize)
Creates a memory manager with the given capacity and given page size.
|
| Modifier and Type | Method and Description |
|---|---|
List<MemorySegment> |
allocatePages(AbstractInvokable owner,
int numPages) |
void |
allocatePages(AbstractInvokable owner,
List<MemorySegment> target,
int numPages) |
long |
computeMemorySize(double fraction)
Computes the memory size of the fraction per slot.
|
int |
computeNumberOfPages(double fraction)
Computes to how many pages the given number of bytes corresponds.
|
long |
getMemorySize()
Returns the total size of memory.
|
int |
getPageSize()
Gets the size of the pages handled by the memory manager.
|
<T extends MemorySegment> |
release(Collection<T> segments)
Tries to release the memory for the specified collection of segments.
|
void |
release(MemorySegment segment)
Tries to release the memory for the specified segment.
|
void |
releaseAll(AbstractInvokable owner)
Releases all memory segments for the given task.
|
long |
roundDownToPageSizeMultiple(long numBytes)
Rounds the given value down to a multiple of the memory manager's page size.
|
void |
shutdown()
Shuts the memory manager down, trying to release all the memory it managed.
|
boolean |
verifyEmpty()
Checks if the memory manager all memory available and the descriptors of the free segments
describe a contiguous memory layout.
|
public static final int DEFAULT_PAGE_SIZE
public static final int MIN_PAGE_SIZE
public DefaultMemoryManager(long memorySize,
int numberOfSlots)
memorySize - The total size of the memory to be managed by this memory manager.public DefaultMemoryManager(long memorySize,
int numberOfSlots,
int pageSize)
memorySize - The total size of the memory to be managed by this memory manager.pageSize - The size of the pages handed out by the memory manager.public void shutdown()
MemoryManagershutdown in interface MemoryManagerpublic boolean verifyEmpty()
MemoryManagerverifyEmpty in interface MemoryManagerpublic List<MemorySegment> allocatePages(AbstractInvokable owner, int numPages) throws MemoryAllocationException
allocatePages in interface MemoryManagerMemoryAllocationExceptionpublic void allocatePages(AbstractInvokable owner, List<MemorySegment> target, int numPages) throws MemoryAllocationException
allocatePages in interface MemoryManagerMemoryAllocationExceptionpublic void release(MemorySegment segment)
MemoryManagersegment has already been released or
is null, the request is simply ignored. If the segment is not from the expected
MemorySegment implementation type, an IllegalArgumentException is thrown.release in interface MemoryManagersegment - The segment to be released.public <T extends MemorySegment> void release(Collection<T> segments)
MemoryManagerrelease in interface MemoryManagerT - The type of memory segment.segments - The segments to be released.public void releaseAll(AbstractInvokable owner)
MemoryManagerreleaseAll in interface MemoryManagerowner - The task whose memory segments are to be released.public int getPageSize()
MemoryManagergetPageSize in interface MemoryManagerpublic long getMemorySize()
MemoryManagergetMemorySize in interface MemoryManagerpublic int computeNumberOfPages(double fraction)
MemoryManagercomputeNumberOfPages in interface MemoryManagerfraction - the fraction of the total memory per slotpublic long computeMemorySize(double fraction)
MemoryManagercomputeMemorySize in interface MemoryManagerfraction - The fraction of the memory of the task slot.public long roundDownToPageSizeMultiple(long numBytes)
MemoryManagerroundDownToPageSizeMultiple in interface MemoryManagerCopyright © 2015 The Apache Software Foundation. All rights reserved.