org.mmtk.utility.alloc
Class BlockAllocator

java.lang.Object
  extended by org.mmtk.utility.alloc.BlockAllocator
All Implemented Interfaces:
Constants

public final class BlockAllocator
extends Object
implements Constants

This class implements "block" data structures of various sizes.

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.


Field Summary
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
           
 
Fields inherited from interface org.mmtk.utility.Constants
ALIGNMENT_VALUE, ARRAY_ELEMENT, BITS_IN_ADDRESS, BITS_IN_BYTE, BITS_IN_CHAR, BITS_IN_INT, BITS_IN_PAGE, BITS_IN_SHORT, BITS_IN_WORD, BYTES_IN_ADDRESS, BYTES_IN_BYTE, BYTES_IN_CHAR, BYTES_IN_INT, BYTES_IN_KBYTE, BYTES_IN_MBYTE, BYTES_IN_PAGE, BYTES_IN_SHORT, BYTES_IN_WORD, CARD_MASK, CARD_META_PAGES_PER_REGION, INSTANCE_FIELD, LOG_BITS_IN_ADDRESS, LOG_BITS_IN_BYTE, LOG_BITS_IN_CHAR, LOG_BITS_IN_INT, LOG_BITS_IN_PAGE, LOG_BITS_IN_SHORT, LOG_BITS_IN_WORD, LOG_BYTES_IN_ADDRESS, LOG_BYTES_IN_ADDRESS_SPACE, LOG_BYTES_IN_BYTE, LOG_BYTES_IN_CHAR, LOG_BYTES_IN_INT, LOG_BYTES_IN_KBYTE, LOG_BYTES_IN_MBYTE, LOG_BYTES_IN_PAGE, LOG_BYTES_IN_SHORT, LOG_BYTES_IN_WORD, LOG_CARD_BYTES, LOG_CARD_GRAIN, LOG_CARD_META_BYTES, LOG_CARD_META_PAGES, LOG_CARD_META_SIZE, LOG_CARD_UNITS, LOG_MIN_ALIGNMENT, MAX_ALIGNMENT, MAX_BYTES_PADDING, MAX_INT, MIN_ALIGNMENT, MIN_INT, SUPPORT_CARD_SCANNING
 
Constructor Summary
BlockAllocator()
           
 
Method Summary
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)
          Mark 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_MIN_BLOCK

public static final int LOG_MIN_BLOCK
See Also:
Constant Field Values

LOG_MAX_BLOCK

public static final int LOG_MAX_BLOCK
See Also:
Constant Field Values

MAX_BLOCK_SIZE_CLASS

public static final byte MAX_BLOCK_SIZE_CLASS
See Also:
Constant Field Values

BLOCK_SIZE_CLASSES

public static final int BLOCK_SIZE_CLASSES
See Also:
Constant Field Values

NEXT_OFFSET

private static final Offset NEXT_OFFSET

BMD_OFFSET

private static final Offset BMD_OFFSET

CSC_OFFSET

private static final Offset CSC_OFFSET

IU_OFFSET

private static final Offset IU_OFFSET

FL_META_OFFSET

private static final Offset FL_META_OFFSET

BLOCK_SC_MASK

private static final byte BLOCK_SC_MASK
See Also:
Constant Field Values

BLOCK_PAGE_OFFSET_SHIFT

private static final int BLOCK_PAGE_OFFSET_SHIFT
See Also:
Constant Field Values

MAX_BLOCK_PAGE_OFFSET

private static final int MAX_BLOCK_PAGE_OFFSET
See Also:
Constant Field Values

LOG_BYTES_IN_BLOCK_META

private static final int LOG_BYTES_IN_BLOCK_META

LOG_BYTE_COVERAGE

private static final int LOG_BYTE_COVERAGE

META_DATA_BYTES_PER_REGION

public static final int META_DATA_BYTES_PER_REGION

META_DATA_EXTENT

public static final Extent META_DATA_EXTENT
Constructor Detail

BlockAllocator

public BlockAllocator()
Method Detail

alloc

public static Address alloc(Space space,
                            int blockSizeClass)
Allocate a block, returning the address of the first usable byte in the block.

Parameters:
blockSizeClass - The size class for the block to be allocated.
Returns:
The address of the first usable byte in the block, or zero on failure.

free

public static void free(Space space,
                        Address block)
Free a block. If the block is a sub-page block and the page is not completely free, then the block is added to the free list. Otherwise the block is returned to the virtual memory resource.

Parameters:
block - The address of the block to be freed

blockSize

public static int blockSize(int blockSizeClass)
Return the size in bytes of a block of a given size class

Parameters:
blockSizeClass - The size class in question
Returns:
The size in bytes of a block of this size class

pagesForSizeClass

private static int pagesForSizeClass(int blockSizeClass)
Return the number of pages required when allocating space for this size class.

Parameters:
blockSizeClass - The size class in question
Returns:
The number of pages required when allocating a block (or blocks) of this size class.

setBlkSizeMetaData

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).

Parameters:
block - The address of interest
sc - The value to which this field is to be set

getBlkSizeClass

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).

Parameters:
address - The address of interest
Returns:
The size class field for the block containing the given address

getBlkStart

public static Address getBlkStart(Address address)
Get the address of the start of a block size class a given page within the block.

Parameters:
address - The address of interest
Returns:
The address of the block containing the address

setAllClientSizeClass

public 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).

Parameters:
block - The address of interest
sc - The value to which this field is to be set

getClientSizeClass

public 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).

Parameters:
address - The address of interest
Returns:
The size class field for the block containing the given address

setFreeListMeta

public 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).

Parameters:
address - The address of interest
value - The value to which this field is to be set

getFreeListMeta

public 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).

Parameters:
address - The address of interest
Returns:
The free list meta data field for the block containing the given address

setNext

public static void setNext(Address address,
                           Address prev)
Set the prev meta data field for a given address

Parameters:
address - The address of interest
prev - The value to which this field is to be set

getNext

public static Address getNext(Address address)
Get the prev meta data field for a given address

Parameters:
address - The address of interest
Returns:
The prev field for the block containing the given address

getMetaAddress

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.

Parameters:
address - The address for which the metadata is required
Returns:
The address of the specified meta data

getMetaAddress

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.

Parameters:
address - The address for which the metadata is required
offset - The offset (in bytes) into the metadata block (eg for the prev pointer, or next pointer)
Returns:
The address of the specified meta data

markBlockMeta

public static void markBlockMeta(ObjectReference ref)
Mark the metadata for this block.

Parameters:
ref -

markBlockMeta

public static void markBlockMeta(Address block)
Mark the metadata for this block.

Parameters:
block - The block address

checkBlockMeta

public static boolean checkBlockMeta(Address block)
Return true if the metadata for this block was set.

Parameters:
block - The block address
Returns:
value of the meta data.

clearBlockMeta

public static void clearBlockMeta(Address block)
Clear the metadata for this block

Parameters:
block - The block address