public final class BlockAllocator extends Object
Blocks are a non-shared (thread-local) coarse-grained unit of storage. Blocks are available in power-of-two sizes.
Virtual memory space is taken from a VM resource, and pages consumed by blocks are accounted for by a memory resource.
Modifier and Type | Field and Description |
---|---|
private static int |
BLOCK_PAGE_OFFSET_SHIFT |
private static byte |
BLOCK_SC_MASK |
static int |
BLOCK_SIZE_CLASSES |
private static Offset |
BMD_OFFSET |
private static Offset |
CSC_OFFSET |
private static Offset |
FL_META_OFFSET |
private static Offset |
IU_OFFSET |
private static int |
LOG_BYTE_COVERAGE |
private static int |
LOG_BYTES_IN_BLOCK_META |
static int |
LOG_MAX_BLOCK |
static int |
LOG_MIN_BLOCK |
private static int |
MAX_BLOCK_PAGE_OFFSET |
static byte |
MAX_BLOCK_SIZE_CLASS |
static int |
META_DATA_BYTES_PER_REGION |
static Extent |
META_DATA_EXTENT |
private static Offset |
NEXT_OFFSET |
Constructor and Description |
---|
BlockAllocator() |
Modifier and Type | Method and Description |
---|---|
static Address |
alloc(Space space,
int blockSizeClass)
Allocate a block, returning the address of the first usable byte
in the block.
|
static int |
blockSize(int blockSizeClass)
Return the size in bytes of a block of a given size class
|
static boolean |
checkBlockMeta(Address block)
Return true if the metadata for this block was set.
|
static void |
clearBlockMeta(Address block)
Clear the metadata for this block
|
static void |
free(Space space,
Address block)
Free a block.
|
private static byte |
getBlkSizeClass(Address address)
Get the block size class meta data field for a given page
(all blocks on a given page are homogeneous with respect to block
size class).
|
static Address |
getBlkStart(Address address)
Get the address of the start of a block size class a given page
within the block.
|
static byte |
getClientSizeClass(Address address)
Get the client size class meta data field for a given page
(all blocks on a given page are homogeneous with respect to block
size class).
|
static Address |
getFreeListMeta(Address address)
Get the free list meta data field for a given address (this is
per-block meta data that is stored along with the block metadata
but not used by the block allocator).
|
private static Address |
getMetaAddress(Address address)
Get the address of some metadata given the address for which the
metadata is required and the offset into the metadata that is of
interest.
|
private static Address |
getMetaAddress(Address address,
Offset offset)
Get the address of some metadata given the address for which the
metadata is required and the offset into the metadata that is of
interest.
|
static Address |
getNext(Address address)
Get the prev meta data field for a given address
|
static void |
markBlockMeta(Address block)
Mark the metadata for this block.
|
static void |
markBlockMeta(ObjectReference ref)
Marks the metadata for this block.
|
private static int |
pagesForSizeClass(int blockSizeClass)
Return the number of pages required when allocating space for
this size class.
|
static void |
setAllClientSizeClass(Address block,
int blocksc,
byte sc)
Set the client size class meta data field for a given
address (all blocks on a given page are homogeneous with respect
to block size class).
|
private static void |
setBlkSizeMetaData(Address block,
byte sc)
Set the block size class meta data field for a given
address (all blocks on a given page are homogeneous with respect
to block size class).
|
static void |
setFreeListMeta(Address address,
Address value)
Set the free list meta data field for a given address (this is
per-block meta data that is stored along with the block metadata
but not used by the block allocator).
|
static void |
setNext(Address address,
Address prev)
Set the prev meta data field for a given address
|
public static final int LOG_MIN_BLOCK
public static final int LOG_MAX_BLOCK
public static final byte MAX_BLOCK_SIZE_CLASS
public static final int BLOCK_SIZE_CLASSES
private static final Offset NEXT_OFFSET
private static final Offset BMD_OFFSET
private static final Offset CSC_OFFSET
private static final Offset FL_META_OFFSET
private static final byte BLOCK_SC_MASK
private static final int BLOCK_PAGE_OFFSET_SHIFT
private static final int MAX_BLOCK_PAGE_OFFSET
private static final int LOG_BYTES_IN_BLOCK_META
private static final int LOG_BYTE_COVERAGE
public static final int META_DATA_BYTES_PER_REGION
public static final Extent META_DATA_EXTENT
public BlockAllocator()
public static Address alloc(Space space, int blockSizeClass)
space
- the space to request the memory fromblockSizeClass
- The size class for the block to be allocated.public static void free(Space space, Address block)
space
- the space that contains the blockblock
- The address of the block to be freedpublic static int blockSize(int blockSizeClass)
blockSizeClass
- The size class in questionprivate static int pagesForSizeClass(int blockSizeClass)
blockSizeClass
- The size class in questionprivate static void setBlkSizeMetaData(Address block, byte sc)
block
- The address of interestsc
- The value to which this field is to be setprivate static byte getBlkSizeClass(Address address)
address
- The address of interestpublic static Address getBlkStart(Address address)
address
- The address of interestpublic static void setAllClientSizeClass(Address block, int blocksc, byte sc)
block
- The address of interestblocksc
- the block's size classsc
- The value to which this field is to be setpublic static byte getClientSizeClass(Address address)
address
- The address of interestpublic static void setFreeListMeta(Address address, Address value)
address
- The address of interestvalue
- The value to which this field is to be setpublic static Address getFreeListMeta(Address address)
address
- The address of interestpublic static void setNext(Address address, Address prev)
address
- The address of interestprev
- The value to which this field is to be setpublic static Address getNext(Address address)
address
- The address of interestprivate static Address getMetaAddress(Address address)
address
- The address for which the metadata is requiredprivate static Address getMetaAddress(Address address, Offset offset)
address
- The address for which the metadata is requiredoffset
- The offset (in bytes) into the metadata block (eg
for the prev pointer, or next pointer)public static void markBlockMeta(ObjectReference ref)
ref
- the block's referencepublic static void markBlockMeta(Address block)
block
- The block addresspublic static boolean checkBlockMeta(Address block)
block
- The block addresspublic static void clearBlockMeta(Address block)
block
- The block address