|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.mmtk.utility.BaseGenericFreeList
abstract class BaseGenericFreeList
This is a very simple, generic malloc-free allocator. It works
abstractly, in "units", which the user may associate with some
other allocatable resource (e.g. heap blocks). The user issues
requests for N units and the allocator returns the index of the
first of a contiguous set of N units or fails, returning -1. The
user frees the block of N units by calling free()
with
the index of the first unit as the argument.
Properties/Constraints:
+-+-+-----------+-----------+ |f|m| prev | next/size | +-+-+-----------+-----------+ - single free unit: "free", "single", "prev", "next" - single used unit: "used", "single" - contiguous free units . first unit: "free", "multi", "prev", "next" . second unit: "free", "multi", "size" . last unit: "free", "multi", "size" - contiguous used units . first unit: "used", "multi", "prev", "next" . second unit: "used", "multi", "size" . last unit: "used", "multi", "size" - any other unit: undefined +-+-+-----------+-----------+ top sentinel |0|0| tail | head | [-1] +-+-+-----------+-----------+ .... /-------- +-+-+-----------+-----------+ | |1|1| prev | next | [j] | +-+-+-----------+-----------+ | |1|1| | size | [j+1] free multi +-+-+-----------+-----------+ unit block | ... | ... | +-+-+-----------+-----------+ | |1|1| | size | >-------- +-+-+-----------+-----------+ single free unit |1|0| prev | next | >-------- +-+-+-----------+-----------+ single used unit |0|0| | >-------- +-+-+-----------------------+ | |0|1| | | +-+-+-----------+-----------+ | |0|1| | size | used multi +-+-+-----------+-----------+ unit block | ... | | +-+-+-----------+-----------+ | |0|1| | size | \-------- +-+-+-----------+-----------+ .... +-+-+-----------------------+ bottom sentinel |0|0| | [N] +-+-+-----------------------+The sentinels serve as guards against out of range coalescing because they both appear as "used" blocks and so will never coalesce. The top sentinel also serves as the head and tail of the doubly linked list of free blocks.
Field Summary | |
---|---|
protected static boolean |
DEBUG
|
static int |
FAILURE
|
protected int |
head
|
protected int |
heads
|
protected static int |
MAX_HEADS
|
Constructor Summary | |
---|---|
BaseGenericFreeList()
|
Method Summary | |
---|---|
private void |
addToFree(int unit)
Add a lump of units to the free list |
int |
alloc(int size)
Allocate size units. |
int |
alloc(int size,
int unit)
Allocate size units. |
private int |
alloc(int size,
int unit,
int unitSize)
Allocate size units. |
private void |
coalesce(int start,
int end)
Coalesce two or three contiguous lumps of units, removing start and end lumps from the free list as necessary. |
boolean |
couldAlloc(int size)
Would an allocation of size units succeed? |
(package private) void |
dbgPrintFree()
Print the free list (for debugging purposes) |
int |
free(int unit)
Free a previously allocated contiguous lump of units. |
int |
free(int unit,
boolean returnCoalescedSize)
Free a previously allocated contiguous lump of units. |
(package private) abstract boolean |
getFree(int unit)
|
(package private) abstract int |
getLeft(int unit)
|
(package private) abstract int |
getNext(int unit)
|
(package private) abstract int |
getPrev(int unit)
|
private int |
getRight(int unit)
Get the lump to the "right" of the current lump (i.e. |
(package private) abstract int |
getSize(int unit)
|
protected void |
initializeHeap(int units)
Initialize a new heap. |
protected void |
initializeHeap(int units,
int grain)
Initialize a new heap. |
(package private) abstract boolean |
isCoalescable(int unit)
|
private void |
removeFromFree(int unit)
Remove a lump of units from the free list |
(package private) abstract void |
setFree(int unit,
boolean isFree)
|
(package private) abstract void |
setNext(int unit,
int next)
|
(package private) abstract void |
setPrev(int unit,
int prev)
|
(package private) abstract void |
setSentinel(int unit)
|
(package private) abstract void |
setSize(int unit,
int size)
|
int |
size(int unit)
Return the size of the specified lump of units |
private void |
split(int unit,
int size)
Reduce a lump of units to size, freeing any excess. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final boolean DEBUG
public static final int FAILURE
protected static final int MAX_HEADS
protected int heads
protected int head
Constructor Detail |
---|
BaseGenericFreeList()
Method Detail |
---|
public final int alloc(int size)
size
units. Return the unit ID
size
- The number of units to be allocated
size
contiguous units, or -1 if the request can't be satisfiedpublic final boolean couldAlloc(int size)
size
units succeed?
size
- The number of units to test for
public final int alloc(int size, int unit)
size
units. Return the unit ID
size
- The number of units to be allocated
size
contiguous units, or -1 if the request can't be satisfiedprivate int alloc(int size, int unit, int unitSize)
size
units. Return the unit ID
size
- The number of units to be allocated
size
contiguous units, or -1 if the request can't be satisfiedpublic final int free(int unit)
unit
- The index of the first unit.
public final int free(int unit, boolean returnCoalescedSize)
unit
- The index of the first unit.returnCoalescedSize
- if true, return the coalesced size
public final int size(int unit)
unit
- The index of the first unit in the lump.
protected final void initializeHeap(int units)
units
- The number of units in the heapprotected final void initializeHeap(int units, int grain)
units
- The number of units in the heapprivate void split(int unit, int size)
unit
- The index of the first unitsize
- The size of the first partprivate void coalesce(int start, int end)
start
- The index of the start of the first lumpend
- The index of the start of the last lumpprivate void addToFree(int unit)
unit
- The first unit in the lump of units to be addedprivate void removeFromFree(int unit)
unit
- The first unit in the lump of units to be removedprivate int getRight(int unit)
unit
- The index of the first unit in the lump in question
void dbgPrintFree()
abstract void setSentinel(int unit)
abstract int getSize(int unit)
abstract void setSize(int unit, int size)
abstract boolean getFree(int unit)
abstract void setFree(int unit, boolean isFree)
abstract int getNext(int unit)
abstract void setNext(int unit, int next)
abstract int getPrev(int unit)
abstract void setPrev(int unit, int prev)
abstract int getLeft(int unit)
abstract boolean isCoalescable(int unit)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |