org.jikesrvm.mm.mminterface
Class MemoryManager

java.lang.Object
  extended by org.jikesrvm.mm.mminterface.MemoryManager
All Implemented Interfaces:
HeapLayoutConstants, Constants

public final class MemoryManager
extends Object
implements HeapLayoutConstants, Constants

The interface that the MMTk memory manager presents to Jikes RVM


Field Summary
private static boolean booted
          Has the interface been booted yet?
private static boolean CHECK_MEMORY_IS_ZEROED
          true if checking of allocated memory to ensure it is zeroed is desired.
private static boolean collectionEnabled
          Has garbage collection been enabled yet?
private static boolean traceAllocator
           
 
Fields inherited from interface org.jikesrvm.HeapLayoutConstants
BAD_MAP_COMPRESSION, BOOT_IMAGE_CODE_END, BOOT_IMAGE_CODE_SIZE, BOOT_IMAGE_CODE_START, BOOT_IMAGE_DATA_END, BOOT_IMAGE_DATA_SIZE, BOOT_IMAGE_DATA_START, BOOT_IMAGE_END, BOOT_IMAGE_RMAP_END, BOOT_IMAGE_RMAP_START, MAX_BOOT_IMAGE_RMAP_SIZE, MAXIMUM_MAPPABLE
 
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
private MemoryManager()
          Suppress default constructor to enforce noninstantiability.
 
Method Summary
static void addFinalizer(Object object)
          Adds an object to the list of objects to have their finalize method called when they are reclaimed.
static void addPhantomReference(PhantomReference<?> obj, Object referent)
          Add a phantom reference to the list of phantom references.
static boolean addressInVM(Address address)
          Checks if an address refers to an in-use area of memory.
static void addSoftReference(SoftReference<?> obj, Object referent)
          Add a soft reference to the list of soft references.
static void addWeakReference(WeakReference<?> obj, Object referent)
          Add a weak reference to the list of weak references.
static Offset alignAllocation(Offset initialOffset, int align, int offset)
          Align an allocation using some modulo arithmetic to guarantee the following property:
(region + offset) % alignment == 0
static Object allocateArray(int numElements, int logElementSize, int headerSize, TIB tib, int allocator, int align, int offset, int site)
          Allocate an array object.
private static Object allocateArrayInternal(int numElements, int size, TIB tib, int allocator, int align, int offset, int site)
          Allocate an array object.
static ArchitectureSpecific.CodeArray allocateCode(int numInstrs, boolean isHot)
          Allocate a CodeArray into a code space.
static Object allocateScalar(int size, TIB tib, int allocator, int align, int offset, int site)
          Allocate a scalar object.
static Address allocateSpace(CollectorContext context, int bytes, int align, int offset, int allocator, ObjectReference from)
          Allocate space for GC-time copying of an object
private static Address allocateSpace(Selected.Mutator mutator, int bytes, int align, int offset, int allocator, int site)
          Allocate space for runtime allocation of an object
static void boot(BootRecord theBootRecord)
          Initialization that occurs at boot time (runtime initialization).
static Word bootTimeWriteBarrier(Word value)
          Install a reference into the boot image.
static boolean collectionEnabled()
          Is collection enabled?
static SpecializedMethod createSpecializedMethod(int id)
          Initialize a specified specialized method.
static void dumpRef(ObjectReference ref)
          Logs information about a reference to the error output.
static void enableCollection()
          Allow collection (assumes threads can be created).
static void flushMutatorContext()
          Flush the mutator context.
static Extent freeMemory()
          Returns the amount of free memory.
static void fullyBootedVM()
          Notify the MM that the host VM is now fully booted.
static void gc()
          External call to force a garbage collection.
static boolean gcInProgress()
          Returns true if GC is in progress.
static int getAllocationSite(boolean compileTime)
          Return an allocation site upon request.
static Object getFinalizedObject()
          Gets an object from the list of objects that are to be reclaimed and need to have their finalize method called.
static int getMaxHeaps()
          Returns the maximum number of heaps that can be managed.
static Extent getMaxHeapSize()
          Return the max heap size in bytes (as set by -Xmx).
static void initializeHeader(BootImageInterface bootImage, Address ref, TIB tib, int size, boolean isScalar)
          Override the boot-time initialization method here, so that the core JMTk code doesn't need to know about the BootImageInterface type.
static boolean isImmortal(Object obj)
          Will this object move (allows us to optimize some JNI calls)
private static boolean isPrefix(String a, byte[] b)
          Is string a a prefix of string b.
static Extent maxMemory()
          Returns the maximum amount of memory VM will attempt to use.
static boolean mightBeFP(Address address)
          Return true if address is in a space which may contain stacks
static boolean mightBeTIB(ObjectReference obj)
          Check if object might be a TIB.
static void modifyCheck(Object object)
          Checks that if a garbage collection is in progress then the given object is not movable.
static int[] newContiguousIntArray(int n)
          Allocate a contiguous int array
static IMT newIMT()
          Allocate a new interface method table (IMT).
static ITable newITable(int size)
          Allocate a new ITable
static ITableArray newITableArray(int size)
          Allocate a new ITableArray
static double[] newNonMovingDoubleArray(int size)
          Allocate a non moving double array
static int[] newNonMovingIntArray(int size)
          Allocate a non moving int array
static short[] newNonMovingShortArray(int size)
          Allocate a non moving int array
static WordArray newNonMovingWordArray(int size)
          Allocate a non moving word array
static Object newRuntimeTable(int size, RVMType type)
          Allocate a new runtime table (at runtime)
static byte[] newStack(int bytes)
          Allocate a stack
static TIB newTIB(int numVirtualMethods, int alignCode)
          Allocate a new type information block (TIB).
static void notifyClassResolved(RVMType vmType)
          A new type has been resolved by the VM.
static int numSpecializedMethods()
          Return the number of specialized methods.
static boolean objectInVM(ObjectReference object)
          Checks if a reference refers to an object in an in-use area of memory.
static int pickAllocator(RVMType type)
          Returns the appropriate allocation scheme/area for the given type.
static int pickAllocator(RVMType type, RVMMethod method)
          Returns the appropriate allocation scheme/area for the given type and given method requesting the allocation.
private static int pickAllocatorForType(RVMType type)
          Determine the default allocator to be used for a given type.
static void postBoot()
          Perform postBoot operations such as dealing with command line options (this is called as soon as options have been parsed, which is necessarily after the basic allocator boot).
static void processCommandLineArg(String arg)
          Process GC parameters.
static void startGCspyServer()
          Start the GCspy server
private static void throwLargeArrayOutOfMemoryError()
          Throw an out of memory error due to an array allocation request that is larger than the maximum allowed value.
static Extent totalMemory()
          Returns the amount of total memory.
static boolean validRef(ObjectReference ref)
          Checks if a reference is valid.
static boolean willNeverMove(Object obj)
          Will this object move (allows us to optimize some JNI calls)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHECK_MEMORY_IS_ZEROED

private static final boolean CHECK_MEMORY_IS_ZEROED
true if checking of allocated memory to ensure it is zeroed is desired.

See Also:
Constant Field Values

traceAllocator

private static final boolean traceAllocator
See Also:
Constant Field Values

booted

private static boolean booted
Has the interface been booted yet?


collectionEnabled

private static boolean collectionEnabled
Has garbage collection been enabled yet?

Constructor Detail

MemoryManager

private MemoryManager()
Suppress default constructor to enforce noninstantiability.

Method Detail

boot

public static void boot(BootRecord theBootRecord)
Initialization that occurs at boot time (runtime initialization). This is only executed by one processor (the primordial thread).

Parameters:
theBootRecord - the boot record. Contains information about the heap size.

postBoot

public static void postBoot()
Perform postBoot operations such as dealing with command line options (this is called as soon as options have been parsed, which is necessarily after the basic allocator boot).


enableCollection

public static void enableCollection()
Allow collection (assumes threads can be created).


collectionEnabled

public static boolean collectionEnabled()
Is collection enabled?


fullyBootedVM

public static void fullyBootedVM()
Notify the MM that the host VM is now fully booted.


processCommandLineArg

public static void processCommandLineArg(String arg)
Process GC parameters.


modifyCheck

public static void modifyCheck(Object object)
Checks that if a garbage collection is in progress then the given object is not movable. If it is movable error messages are logged and the system exits.

Parameters:
object - the object to check

freeMemory

public static Extent freeMemory()
Returns the amount of free memory.

Returns:
The amount of free memory.

totalMemory

public static Extent totalMemory()
Returns the amount of total memory.

Returns:
The amount of total memory.

maxMemory

public static Extent maxMemory()
Returns the maximum amount of memory VM will attempt to use.

Returns:
The maximum amount of memory VM will attempt to use.

gc

public static void gc()
External call to force a garbage collection.


dumpRef

public static void dumpRef(ObjectReference ref)
Logs information about a reference to the error output.

Parameters:
ref - the address to log information about

validRef

public static boolean validRef(ObjectReference ref)
Checks if a reference is valid.

Parameters:
ref - the address to be checked
Returns:
true if the reference is valid

addressInVM

public static boolean addressInVM(Address address)
Checks if an address refers to an in-use area of memory.

Parameters:
address - the address to be checked
Returns:
true if the address refers to an in use area

objectInVM

public static boolean objectInVM(ObjectReference object)
Checks if a reference refers to an object in an in-use area of memory.

References may be addresses just outside the memory region allocated to the object.

Parameters:
object - the reference to be checked
Returns:
true if the object refered to is in an in-use area

mightBeFP

public static boolean mightBeFP(Address address)
Return true if address is in a space which may contain stacks

Parameters:
address - The address to be checked
Returns:
true if the address is within a space which may contain stacks

getAllocationSite

public static int getAllocationSite(boolean compileTime)
Return an allocation site upon request. The request may be made in the context of compilation.

Parameters:
compileTime - true if this request is being made in the context of a compilation.
Returns:
an allocation site

pickAllocator

public static int pickAllocator(RVMType type)
Returns the appropriate allocation scheme/area for the given type. This form is deprecated. Without the RVMMethod argument, it is possible that the wrong allocator is chosen which may affect correctness. The prototypical example is that JMTk meta-data must generally be in immortal or at least non-moving space.

Parameters:
type - the type of the object to be allocated
Returns:
the identifier of the appropriate allocator

isPrefix

private static boolean isPrefix(String a,
                                byte[] b)
Is string a a prefix of string b. String b is encoded as an ASCII byte array.

Parameters:
a - prefix string
b - string which may contain prefix, encoded as an ASCII byte array.
Returns:
true if a is a prefix of b

pickAllocator

public static int pickAllocator(RVMType type,
                                RVMMethod method)
Returns the appropriate allocation scheme/area for the given type and given method requesting the allocation.

Parameters:
type - the type of the object to be allocated
method - the method requesting the allocation
Returns:
the identifier of the appropriate allocator

pickAllocatorForType

private static int pickAllocatorForType(RVMType type)
Determine the default allocator to be used for a given type.

Parameters:
type - The type in question
Returns:
The allocator to use for allocating instances of type type.

allocateScalar

public static Object allocateScalar(int size,
                                    TIB tib,
                                    int allocator,
                                    int align,
                                    int offset,
                                    int site)
Allocate a scalar object.

Parameters:
size - Size in bytes of the object, including any headers that need space.
tib - Type of the object (pointer to TIB).
allocator - Specify which allocation scheme/area JMTk should allocate the memory from.
align - the alignment requested; must be a power of 2.
offset - the offset at which the alignment is desired.
site - allocation site.
Returns:
the initialized Object

allocateArray

public static Object allocateArray(int numElements,
                                   int logElementSize,
                                   int headerSize,
                                   TIB tib,
                                   int allocator,
                                   int align,
                                   int offset,
                                   int site)
Allocate an array object. This is the interruptible component, including throwing an OutOfMemoryError for arrays that are too large.

Parameters:
numElements - number of array elements
logElementSize - size in bytes of an array element, log base 2.
headerSize - size in bytes of array header
tib - type information block for array object
allocator - int that encodes which allocator should be used
align - the alignment requested; must be a power of 2.
offset - the offset at which the alignment is desired.
site - allocation site.
Returns:
array object with header installed and all elements set to zero/null See also: bytecode 0xbc ("newarray") and 0xbd ("anewarray")

throwLargeArrayOutOfMemoryError

private static void throwLargeArrayOutOfMemoryError()
Throw an out of memory error due to an array allocation request that is larger than the maximum allowed value. This is in a separate method so it can be forced out of line.


allocateArrayInternal

private static Object allocateArrayInternal(int numElements,
                                            int size,
                                            TIB tib,
                                            int allocator,
                                            int align,
                                            int offset,
                                            int site)
Allocate an array object.

Parameters:
numElements - The number of element bytes
size - size in bytes of array header
tib - type information block for array object
allocator - int that encodes which allocator should be used
align - the alignment requested; must be a power of 2.
offset - the offset at which the alignment is desired.
site - allocation site.
Returns:
array object with header installed and all elements set to zero/null See also: bytecode 0xbc ("newarray") and 0xbd ("anewarray")

allocateSpace

private static Address allocateSpace(Selected.Mutator mutator,
                                     int bytes,
                                     int align,
                                     int offset,
                                     int allocator,
                                     int site)
Allocate space for runtime allocation of an object

Parameters:
mutator - The mutator instance to be used for this allocation
bytes - The size of the allocation in bytes
align - The alignment requested; must be a power of 2.
offset - The offset at which the alignment is desired.
allocator - The MMTk allocator to be used (if allocating)
site - Allocation site.
Returns:
The first byte of a suitably sized and aligned region of memory.

allocateSpace

public static Address allocateSpace(CollectorContext context,
                                    int bytes,
                                    int align,
                                    int offset,
                                    int allocator,
                                    ObjectReference from)
Allocate space for GC-time copying of an object

Parameters:
context - The collector context to be used for this allocation
bytes - The size of the allocation in bytes
align - The alignment requested; must be a power of 2.
offset - The offset at which the alignment is desired.
from - The source object from which this is to be copied
Returns:
The first byte of a suitably sized and aligned region of memory.

alignAllocation

public static Offset alignAllocation(Offset initialOffset,
                                     int align,
                                     int offset)
Align an allocation using some modulo arithmetic to guarantee the following property:
(region + offset) % alignment == 0

Parameters:
initialOffset - The initial (unaligned) start value of the allocated region of memory.
align - The alignment requested, must be a power of two
offset - The offset at which the alignment is desired
Returns:
initialOffset plus some delta (possibly 0) such that the return value is aligned according to the above constraints.

allocateCode

public static ArchitectureSpecific.CodeArray allocateCode(int numInstrs,
                                                          boolean isHot)
Allocate a CodeArray into a code space. Currently the interface is fairly primitive; just the number of instructions in the code array and a boolean to indicate hot or cold code.

Parameters:
numInstrs - number of instructions
isHot - is this a request for hot code space allocation?
Returns:
The array

newStack

public static byte[] newStack(int bytes)
Allocate a stack

Parameters:
bytes - The number of bytes to allocate
Returns:
The stack

newNonMovingWordArray

public static WordArray newNonMovingWordArray(int size)
Allocate a non moving word array

Parameters:
size - The size of the array

newNonMovingDoubleArray

public static double[] newNonMovingDoubleArray(int size)
Allocate a non moving double array

Parameters:
size - The size of the array

newNonMovingIntArray

public static int[] newNonMovingIntArray(int size)
Allocate a non moving int array

Parameters:
size - The size of the array

newNonMovingShortArray

public static short[] newNonMovingShortArray(int size)
Allocate a non moving int array

Parameters:
size - The size of the array

newTIB

public static TIB newTIB(int numVirtualMethods,
                         int alignCode)
Allocate a new type information block (TIB).

Parameters:
numVirtualMethods - the number of virtual method slots in the TIB
alignCode - TODO
Returns:
the new TIB

newIMT

public static IMT newIMT()
Allocate a new interface method table (IMT).

Returns:
the new IMT

newITable

public static ITable newITable(int size)
Allocate a new ITable

Parameters:
size - the number of slots in the ITable
Returns:
the new ITable

newITableArray

public static ITableArray newITableArray(int size)
Allocate a new ITableArray

Parameters:
size - the number of slots in the ITableArray
Returns:
the new ITableArray

newRuntimeTable

public static Object newRuntimeTable(int size,
                                     RVMType type)
Allocate a new runtime table (at runtime)

Parameters:
size - The size of the table.
Returns:
the newly allocated table

willNeverMove

public static boolean willNeverMove(Object obj)
Will this object move (allows us to optimize some JNI calls)


isImmortal

public static boolean isImmortal(Object obj)
Will this object move (allows us to optimize some JNI calls)


addFinalizer

public static void addFinalizer(Object object)
Adds an object to the list of objects to have their finalize method called when they are reclaimed.

Parameters:
object - the object to be added to the finalizer's list

getFinalizedObject

public static Object getFinalizedObject()
Gets an object from the list of objects that are to be reclaimed and need to have their finalize method called.

Returns:
the object needing to be finialized

addSoftReference

public static void addSoftReference(SoftReference<?> obj,
                                    Object referent)
Add a soft reference to the list of soft references.

Parameters:
obj - the soft reference to be added to the list

addWeakReference

public static void addWeakReference(WeakReference<?> obj,
                                    Object referent)
Add a weak reference to the list of weak references.

Parameters:
obj - the weak reference to be added to the list

addPhantomReference

public static void addPhantomReference(PhantomReference<?> obj,
                                       Object referent)
Add a phantom reference to the list of phantom references.

Parameters:
obj - the phantom reference to be added to the list

getMaxHeapSize

public static Extent getMaxHeapSize()
Return the max heap size in bytes (as set by -Xmx).

Returns:
The max heap size in bytes (as set by -Xmx).

notifyClassResolved

public static void notifyClassResolved(RVMType vmType)
A new type has been resolved by the VM. Create a new MM type to reflect the VM type, and associate the MM type with the VM type.

Parameters:
vmType - The newly resolved type

mightBeTIB

public static boolean mightBeTIB(ObjectReference obj)
Check if object might be a TIB.

Parameters:
obj - address of object to check
Returns:
false if the object is in the wrong allocation scheme/area for a TIB, true otherwise

gcInProgress

public static boolean gcInProgress()
Returns true if GC is in progress.

Returns:
True if GC is in progress.

startGCspyServer

public static void startGCspyServer()
Start the GCspy server


flushMutatorContext

public static void flushMutatorContext()
Flush the mutator context.


numSpecializedMethods

public static int numSpecializedMethods()
Return the number of specialized methods.


createSpecializedMethod

public static SpecializedMethod createSpecializedMethod(int id)
Initialize a specified specialized method.

Parameters:
id - the specializedMethod

initializeHeader

public static void initializeHeader(BootImageInterface bootImage,
                                    Address ref,
                                    TIB tib,
                                    int size,
                                    boolean isScalar)
Override the boot-time initialization method here, so that the core JMTk code doesn't need to know about the BootImageInterface type.


bootTimeWriteBarrier

public static Word bootTimeWriteBarrier(Word value)
Install a reference into the boot image.


getMaxHeaps

public static int getMaxHeaps()
Returns the maximum number of heaps that can be managed.

Returns:
the maximum number of heaps

newContiguousIntArray

public static int[] newContiguousIntArray(int n)
Allocate a contiguous int array

Parameters:
n - The number of ints
Returns:
The contiguous int array