public final class GenericFreeList extends BaseGenericFreeList
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.
Modifier and Type | Field and Description |
---|---|
private static int |
COALESC_MASK |
private static int |
FREE_MASK |
static int |
MAX_UNITS |
private static int |
MULTI_MASK |
private static int |
NEXT_MASK |
private GenericFreeList |
parent |
private static int |
PREV_MASK |
private static int |
SIZE_MASK |
private int[] |
table |
private static int |
TOTAL_BITS |
private static int |
UNIT_BITS |
Constructor and Description |
---|
GenericFreeList(GenericFreeList parent,
int ordinal)
Constructor
|
GenericFreeList(int units)
Constructor
|
GenericFreeList(int units,
int grain)
Constructor
|
GenericFreeList(int units,
int grain,
int heads)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
clearUncoalescable(int unit)
Clear the uncoalescable bit associated with this unit.
|
protected boolean |
getFree(int unit)
Establish whether a lump of units is free
|
(package private) int |
getHeads() |
private int |
getHiEntry(int unit) |
protected int |
getLeft(int unit)
Get the lump to the "left" of the current lump (i.e.
|
private int |
getLoEntry(int unit)
Get the contents of an entry
|
protected int |
getNext(int unit)
Get the next lump in the doubly linked free list
|
protected int |
getPrev(int unit)
Get the previous lump in the doubly linked free list
|
protected int |
getSize(int unit)
Get the size of a lump of units
|
(package private) int[] |
getTable() |
boolean |
isCoalescable(int unit)
Return true if this unit may be coalesced with the unit below it.
|
void |
resizeFreeList()
Resize the free list for a child free list.
|
void |
resizeFreeList(int units,
int grain)
Resize the free list for a parent free list.
|
protected void |
setFree(int unit,
boolean isFree)
Set the "free" flag for a lump of units (both the first and last
units in the lump are set.
|
private void |
setHiEntry(int unit,
int value) |
private void |
setLoEntry(int unit,
int value)
Set the contents of an entry
|
protected void |
setNext(int unit,
int next)
Set the next lump in the doubly linked free list
|
protected void |
setPrev(int unit,
int prev)
Set the previous lump in the doubly linked free list
|
protected void |
setSentinel(int unit)
Initialize a unit as a sentinel
|
protected void |
setSize(int unit,
int size)
Set the size of lump of units
|
void |
setUncoalescable(int unit)
Set the uncoalescable bit associated with this unit.
|
alloc, alloc, couldAlloc, dbgPrintFree, free, free, initializeHeap, initializeHeap, size
private static final int TOTAL_BITS
private static final int UNIT_BITS
public static final int MAX_UNITS
private static final int NEXT_MASK
private static final int PREV_MASK
private static final int FREE_MASK
private static final int MULTI_MASK
private static final int COALESC_MASK
private static final int SIZE_MASK
private int[] table
private final GenericFreeList parent
public GenericFreeList(int units)
units
- The number of allocatable units for this free listpublic GenericFreeList(int units, int grain)
units
- The number of allocatable units for this free listgrain
- Units are allocated such that they will never cross this granularity boundarypublic GenericFreeList(int units, int grain, int heads)
units
- The number of allocatable units for this free listgrain
- Units are allocated such that they will never cross this granularity boundaryheads
- The number of free lists which will share this instancepublic GenericFreeList(GenericFreeList parent, int ordinal)
parent
- The parent, owning the data structures this instance will shareordinal
- The ordinal number of this childpublic void resizeFreeList(int units, int grain)
units
- The number of allocatable units for this free listgrain
- Units are allocated such that they will never cross this granularity boundarypublic void resizeFreeList()
int[] getTable()
int getHeads()
protected void setSentinel(int unit)
setSentinel
in class BaseGenericFreeList
unit
- The unit to be initializedprotected int getSize(int unit)
getSize
in class BaseGenericFreeList
unit
- The first unit in the lump of unitsprotected void setSize(int unit, int size)
setSize
in class BaseGenericFreeList
unit
- The first unit in the lump of unitssize
- The size of the lump of unitsprotected boolean getFree(int unit)
getFree
in class BaseGenericFreeList
unit
- The first or last unit in the lumptrue
if the lump is freeprotected void setFree(int unit, boolean isFree)
setFree
in class BaseGenericFreeList
unit
- The first unit in the lumpisFree
- true
if the lump is to be marked as freeprotected int getNext(int unit)
getNext
in class BaseGenericFreeList
unit
- The index of the first unit in the current lumpprotected void setNext(int unit, int next)
setNext
in class BaseGenericFreeList
unit
- The index of the first unit in the lump to be setnext
- The value to be set.protected int getPrev(int unit)
getPrev
in class BaseGenericFreeList
unit
- The index of the first unit in the current lumpprotected void setPrev(int unit, int prev)
setPrev
in class BaseGenericFreeList
unit
- The index of the first unit in the lump to be setprev
- The value to be set.public void setUncoalescable(int unit)
unit
- The unit whose uncoalescable bit is to be setpublic void clearUncoalescable(int unit)
unit
- The unit whose uncoalescable bit is to be clearedpublic boolean isCoalescable(int unit)
isCoalescable
in class BaseGenericFreeList
unit
- The unit in questiontrue
if this unit may be coalesced with the unit below it.protected int getLeft(int unit)
getLeft
in class BaseGenericFreeList
unit
- The index of the first unit in the lump in questionprivate int getLoEntry(int unit)
unit
- The index of the unitprivate int getHiEntry(int unit)
private void setLoEntry(int unit, int value)
unit
- The index of the unitvalue
- The contents of the unitprivate void setHiEntry(int unit, int value)