public final class MemoryManager extends Object
Modifier and Type | Field and Description |
---|---|
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 |
Modifier | Constructor and Description |
---|---|
private |
MemoryManager()
Suppress default constructor to enforce noninstantiability.
|
Modifier and Type | Method and Description |
---|---|
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 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)
Installs a reference into the boot image.
|
static boolean |
collectionEnabled() |
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 MMTk code doesn't need to know about the
BootImageInterface type.
|
static boolean |
isImmortal(Object obj) |
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)
Allocates a non moving double array.
|
static int[] |
newNonMovingIntArray(int size)
Allocates a non moving int array.
|
static short[] |
newNonMovingShortArray(int size)
Allocates a non moving short array.
|
static WordArray |
newNonMovingWordArray(int size)
Allocates a non moving word array.
|
static Object |
newRuntimeTable(int size,
RVMType type)
Allocates a new runtime table (at runtime).
|
static byte[] |
newStack(int bytes)
Allocate a stack
|
static TIB |
newTIB(int numVirtualMethods,
int alignCode)
Allocates a new type information block (TIB).
|
static void |
notifyClassResolved(RVMType vmType)
A new type has been resolved by the VM.
|
static int |
numSpecializedMethods() |
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) |
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)
Checks if the object can move.
|
private static final boolean CHECK_MEMORY_IS_ZEROED
true
if checking of allocated memory to ensure it is
zeroed is desired.private static final boolean traceAllocator
private static boolean booted
private static boolean collectionEnabled
private MemoryManager()
public static void boot(BootRecord theBootRecord)
theBootRecord
- the boot record. Contains information about
the heap size.public static void postBoot()
public static void enableCollection()
public static boolean collectionEnabled()
public static void fullyBootedVM()
public static void processCommandLineArg(String arg)
public static void modifyCheck(Object object)
object
- the object to checkpublic static Extent freeMemory()
public static Extent totalMemory()
public static Extent maxMemory()
public static void gc()
public static void dumpRef(ObjectReference ref)
ref
- the address to log information aboutpublic static boolean validRef(ObjectReference ref)
ref
- the address to be checkedtrue
if the reference is validpublic static boolean addressInVM(Address address)
address
- the address to be checkedtrue
if the address refers to an in use areapublic static boolean objectInVM(ObjectReference object)
References may be addresses just outside the memory region allocated to the object.
object
- the reference to be checkedtrue
if the object refered to is in an
in-use areapublic static boolean mightBeFP(Address address)
address
- The address to be checkedpublic static int getAllocationSite(boolean compileTime)
compileTime
- true
if this request is being made in the
context of a compilation.public static int pickAllocator(RVMType type)
type
- the type of the object to be allocatedprivate static boolean isPrefix(String a, byte[] b)
a
a prefix of string
b
. String b
is encoded as an ASCII byte
array.a
- prefix stringb
- string which may contain prefix, encoded as an ASCII
byte array.true
if a
is a prefix of
b
public static int pickAllocator(RVMType type, RVMMethod method)
type
- the type of the object to be allocatedmethod
- the method requesting the allocationprivate static int pickAllocatorForType(RVMType type)
type
- The type in questiontype
.public static Object allocateScalar(int size, TIB tib, int allocator, int align, int offset, int site)
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.public static Object allocateArray(int numElements, int logElementSize, int headerSize, TIB tib, int allocator, int align, int offset, int site)
numElements
- number of array elementslogElementSize
- size in bytes of an array element, log base 2.headerSize
- size in bytes of array headertib
- type information block for array objectallocator
- int that encodes which allocator should be usedalign
- the alignment requested; must be a power of 2.offset
- the offset at which the alignment is desired.site
- allocation site.private static void throwLargeArrayOutOfMemoryError()
private static Object allocateArrayInternal(int numElements, int size, TIB tib, int allocator, int align, int offset, int site)
numElements
- The number of element bytessize
- size in bytes of array headertib
- type information block for array objectallocator
- int that encodes which allocator should be usedalign
- the alignment requested; must be a power of 2.offset
- the offset at which the alignment is desired.site
- allocation site.null
See also: bytecode 0xbc ("newarray") and 0xbd ("anewarray")private static Address allocateSpace(Selected.Mutator mutator, int bytes, int align, int offset, int allocator, int site)
mutator
- The mutator instance to be used for this allocationbytes
- The size of the allocation in bytesalign
- 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.public static Address allocateSpace(CollectorContext context, int bytes, int align, int offset, int allocator, ObjectReference from)
context
- The collector context to be used for this allocationbytes
- The size of the allocation in bytesallocator
- the allocator associated with this requestalign
- 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 copiedpublic static Offset alignAllocation(Offset initialOffset, int align, int offset)
(region + offset) % alignment == 0
initialOffset
- The initial (unaligned) start value of the
allocated region of memory.align
- The alignment requested, must be a power of twooffset
- The offset at which the alignment is desiredinitialOffset
plus some delta (possibly 0) such
that the return value is aligned according to the above
constraints.public static CodeArray allocateCode(int numInstrs, boolean isHot)
numInstrs
- number of instructionsisHot
- is this a request for hot code space allocation?public static byte[] newStack(int bytes)
bytes
- The number of bytes to allocatepublic static WordArray newNonMovingWordArray(int size)
size
- The size of the arraypublic static double[] newNonMovingDoubleArray(int size)
size
- The size of the arraypublic static int[] newNonMovingIntArray(int size)
size
- The size of the arraypublic static short[] newNonMovingShortArray(int size)
size
- The size of the arraypublic static TIB newTIB(int numVirtualMethods, int alignCode)
numVirtualMethods
- the number of virtual method slots in the TIBalignCode
- alignment encoding for the TIBAlignmentEncoding
public static ITable newITable(int size)
size
- the number of slots in the ITablepublic static ITableArray newITableArray(int size)
size
- the number of slots in the ITableArraypublic static Object newRuntimeTable(int size, RVMType type)
size
- The size of the tabletype
- the type for the tablepublic static boolean willNeverMove(Object obj)
obj
- the object in questiontrue
if this object can never move, false
if it can move.public static boolean isImmortal(Object obj)
obj
- the object in questionpublic static void addFinalizer(Object object)
finalize
method called when they are reclaimed.object
- the object to be added to the finalizer's listpublic static Object getFinalizedObject()
finalize
method called.public static void addSoftReference(SoftReference<?> obj, Object referent)
obj
- the soft reference to be added to the listreferent
- the object that the reference points topublic static void addWeakReference(WeakReference<?> obj, Object referent)
obj
- the weak reference to be added to the listreferent
- the object that the reference points topublic static void addPhantomReference(PhantomReference<?> obj, Object referent)
obj
- the phantom reference to be added to the listreferent
- the object that the reference points topublic static Extent getMaxHeapSize()
public static void notifyClassResolved(RVMType vmType)
vmType
- The newly resolved typepublic static boolean mightBeTIB(ObjectReference obj)
obj
- address of object to checkfalse
if the object is in the wrong
allocation scheme/area for a TIB, true
otherwisepublic static boolean gcInProgress()
public static void startGCspyServer()
public static void flushMutatorContext()
public static int numSpecializedMethods()
public static SpecializedMethod createSpecializedMethod(int id)
id
- the specializedMethodpublic static void initializeHeader(BootImageInterface bootImage, Address ref, TIB tib, int size, boolean isScalar)
bootImage
- the bootimage instanceref
- the object's addresstib
- the object's TIBsize
- the number of bytes allocated by the GC system for
the objectisScalar
- whether the header belongs to a scalar or an arraypublic static Word bootTimeWriteBarrier(Word value)
value
- the reference to installpublic static int getMaxHeaps()
public static int[] newContiguousIntArray(int n)
n
- The number of ints