|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jikesrvm.objectmodel.ObjectModel
public class ObjectModel
The interface to the object model definition accessible to the virtual machine.
Conceptually each Java object is composed of the following pieces:
JavaHeader
. This portion of the
object supports language-level functions such as locking, hashcodes,
dynamic type checking, virtual function invocation, and array length.
MemoryManager
. This portion
of the object supports allocator-specific requirements such as
mark/barrier bits, reference counts, etc.
MiscHeader
. This portion supports
various other clients that want to add bits/words to all objects.
Typical uses are profiling and instrumentation (basically this is a
way to add an instance field to java.lang.Object).
|<- lo memory hi memory ->| SCALAR LAYOUT: |<---------- scalar header --------->| +----------+------------+------------+------+------+------+--------+ | GCHeader | MiscHeader | JavaHeader | fldO | fld1 | fldx | fldN-1 | +----------+------------+------------+------+------+------+--------+ ^ JHOFF ^objref . ARRAY LAYOUT: . |<---------- array header ----------------->| +----------+------------+------------+------+------+------+------+------+ | GCHeader | MiscHeader | JavaHeader | len | elt0 | elt1 | ... |eltN-1| +----------+------------+------------+------+------+------+------+------+ ^ JHOFF ^objref
Assumptions:
This model allows free null pointer checking for most reads: a small offset from that reference will wrap around to either very high or very low unmapped memory in the case of a null pointer. As long as these segments of memory are not mapped to the current process, loads/stores through such a pointer will cause a trap that we can catch with a unix signal handler.
Note that on AIX we are forced to perform explicit null checks on scalar field accesses as we are unable to protect low memory.
Note the key invariant that all elements of the header are available at the same offset from an objref for both arrays and scalar objects.
Note that this model allows for arbitrary growth of the GC header to the left of the object. A possible TODO item is to modify the necessary interfaces within this class and JavaHeader to allow moveObject, bytesUsed, bytesRequiredWhenCopied, etc. to tell this class how many GC header bytes have been allocated. As these calls would be constant within the constant of the call the optimising compiler should be able to allow this at minimal cost.
Another possible TODO item is to include support for linear scanning, where it is possible to move from one object to the next under contiguous allocation. At the moment this is in conflict with object alignment code for objects with long/double fields. We could possibly include the code anyway but require that the alignment code is switched off, or that all objects are aligned. Linear scanning is used in several GC algorithms including card-marking and compaction.
JavaHeader
,
MiscHeader
,
MemoryManager
Field Summary | |
---|---|
static boolean |
HASH_STATS
Should we gather stats on hash code state transitions for address-based hashing? |
static int |
hashRequests
count number of Object.hashCode() operations |
static int |
hashTransition1
count transitions from UNHASHED to HASHED |
static int |
hashTransition2
count transitions from HASHED to HASHED_AND_MOVED |
private static FieldLayout |
layout
Layout widget |
private static boolean |
PACKED
Whether to pack bytes and shorts into 32bit fields |
Constructor Summary | |
---|---|
ObjectModel()
|
Method Summary | |
---|---|
static Address |
allocateArray(BootImageInterface bootImage,
RVMArray array,
int numElements,
boolean needsIdentityHash,
int identityHashValue,
int alignCode)
Allocate and initialize space in the bootimage (at bootimage writing time) to be an uninitialized instance of the (array) type specified by array. |
static Address |
allocateArray(BootImageInterface bootImage,
RVMArray array,
int numElements,
boolean needsIdentityHash,
int identityHashValue,
int align,
int alignCode)
Allocate and initialize space in the bootimage (at bootimage writing time) to be an uninitialized instance of the (array) type specified by array. |
static Address |
allocateCode(BootImageInterface bootImage,
RVMArray array,
int numElements)
Allocate and initialize space in the bootimage (at bootimage writing time) to be an uninitialized instance of the (array) type specified by array. |
static Address |
allocateScalar(BootImageInterface bootImage,
RVMClass klass,
boolean needsIdentityHash,
int identityHashValue)
Allocate and initialize space in the bootimage (at bootimage writing time) to be an uninitialized instance of the (scalar) type specified by klass. |
static void |
allocateThinLock(RVMType t)
Allocate a thin lock word for instances of the type (if they already have one, then has no effect). |
static boolean |
attemptAvailableBits(Object o,
Word oldVal,
Word newVal)
An attempt on the word containing the available bits |
static void |
baselineEmitLoadTIB(ArchitectureSpecific.Assembler asm,
int dest,
int object)
The following method will emit code that moves a reference to an object's TIB into a destination register. |
static int |
bytesRequiredWhenCopied(Object obj)
how many bytes are required when the object is copied by GC? |
static int |
bytesRequiredWhenCopied(Object fromObj,
RVMArray type,
int numElements)
how many bytes are needed when the array object is copied by GC? |
static int |
bytesRequiredWhenCopied(Object fromObj,
RVMClass type)
how many bytes are needed when the scalar object is copied by GC? |
static int |
bytesUsed(Object obj)
how many bytes are used by the object? |
static int |
bytesUsed(Object obj,
RVMArray type,
int numElements)
how many bytes are used by the array? |
static int |
bytesUsed(Object obj,
RVMClass type)
how many bytes are used by the scalar? |
static int |
computeArrayHeaderSize(RVMArray type)
Compute the header size of an instance of the given type. |
static int |
computeHeaderSize(Object ref)
Compute the header size of an object |
static int |
computeHeaderSize(Object[] tib)
Given a TIB, compute the header size of an instance of the TIB's class |
static int |
computeHeaderSize(RVMType type)
Compute the header size of an instance of the given type. |
static int |
computeScalarHeaderSize(RVMClass type)
Compute the header size of an instance of the given type. |
static Offset |
defaultThinLockOffset()
what is the default offset for a thin lock? |
static void |
describeObject(ObjectReference addr)
For debugging. |
static void |
dumpHeader(Object ref)
For low level debugging of GC subsystem. |
static void |
dumpHeader(ObjectReference ptr)
For low level debugging of GC subsystem. |
static void |
fillAlignmentGap(BootImageInterface bootImage,
Address address,
Extent size)
Fill an alignment gap with the alignment value |
static void |
genericLock(Object o)
Generic lock |
static void |
genericUnlock(Object o)
Generic unlock |
static int |
getAlignment(RVMArray t)
Return the desired alignment of the alignment point returned by getOffsetForAlignment in instances of the argument RVMArray. |
static int |
getAlignment(RVMArray t,
Object obj)
Return the desired alignment of the alignment point returned by getOffsetForAlignment in instances of the argument RVMArray. |
static int |
getAlignment(RVMClass t)
Return the desired aligment of the alignment point in the object returned by getScalarOffsetForAlignment. |
static int |
getAlignment(RVMClass t,
Object obj)
Return the desired alignment of the alignment point returned by getOffsetForAlignment in instances of the argument RVMClass. |
static ObjectReference |
getArrayFromStartAddress(Address start)
Get an object reference from the address the lowest word of the object was allocated. |
static int |
getArrayLength(Object o)
Get the length of an array |
static Offset |
getArrayLengthOffset()
Return the offset of the array length field from an object reference (in bytes) |
static int |
getHeaderEndOffset()
For a reference to an object, what is the offset in bytes to the last word of the header from an out-to-in perspective for the object? |
static Lock |
getHeavyLock(Object o,
boolean create)
Obtains the heavy-weight lock, if there is one, associated with the indicated object. |
static ObjectReference |
getNextObject(ObjectReference obj)
Get the next object in the heap under contiguous allocation. |
static ObjectReference |
getNextObject(ObjectReference obj,
RVMArray type,
int numElements)
Get the next object after this array under contiguous allocation. |
static ObjectReference |
getNextObject(ObjectReference obj,
RVMClass type)
Get the next object after this scalar under contiguous allocation. |
static Address |
getObjectEndAddress(Object obj)
Get the pointer just past an object |
static Address |
getObjectEndAddress(Object object,
RVMArray type,
int elements)
Get the pointer just past an object |
static Address |
getObjectEndAddress(Object object,
RVMClass type)
Get the pointer just past an object |
static ObjectReference |
getObjectFromStartAddress(Address start)
Get an object reference from the address the lowest word of the object was allocated. |
static int |
getObjectHashCode(Object o)
Get the hash code of an object. |
static RVMType |
getObjectType(Object o)
Get the type of an object. |
static int |
getOffsetForAlignment(RVMArray t,
boolean needsIdentityHash)
Return the offset relative to physical beginning of object that must be aligned. |
static int |
getOffsetForAlignment(RVMArray t,
ObjectReference obj)
Return the offset relative to physical beginning of object that must be aligned. |
static int |
getOffsetForAlignment(RVMClass t,
boolean needsIdentityHash)
Return the offset relative to physical beginning of object that must be aligned. |
static int |
getOffsetForAlignment(RVMClass t,
ObjectReference obj)
Return the offset relative to physical beginning of object that must be aligned. |
static Address |
getPointerInMemoryRegion(ObjectReference ref)
Given a reference, return an address which is guaranteed to be inside the memory region allocated to the object. |
static Object |
getReferenceWhenCopiedTo(Object obj,
Address to)
how many bytes are used by the object? |
static Object |
getReferenceWhenCopiedTo(Object obj,
Address region,
RVMArray type)
Get the reference of an object after copying to a specified region. |
static Object |
getReferenceWhenCopiedTo(Object obj,
Address region,
RVMClass type)
Get the reference of an object after copying to a specified region. |
static ObjectReference |
getScalarFromStartAddress(Address start)
Get an object reference from the address the lowest word of the object was allocated. |
static Offset |
getThinLockOffset(Object o)
Get the offset of the thin lock word in this object |
static TIB |
getTIB(Object o)
Get the TIB for an object. |
static TIB |
getTIB(ObjectReference ptr)
Get the TIB for an object. |
static boolean |
holdsLock(Object obj,
RVMThread thread)
|
static Object |
initializeArray(Address ptr,
TIB tib,
int numElems,
int size)
Initialize raw storage with low memory word ptr of size bytes to be an uninitialized instance of the array type specific by tib with numElems elements. |
static void |
initializeAvailableByte(Object o)
Freeze the other bits in the byte containing the available bits so that it is safe to update them using setAvailableBits. |
static Object |
initializeScalar(Address ptr,
TIB tib,
int size)
Initialize raw storage with low memory word ptr of size bytes to be an uninitialized instance of the (scalar) type specified by tib. |
static void |
layoutInstanceFields(RVMClass klass)
Layout the instance fields declared in this class. |
static Address |
maximumObjectRef(Address regionHighAddr)
Given the largest base address in a region, return the largest object reference that could refer to an object in the region. |
static Address |
minimumObjectRef(Address regionBaseAddr)
Given the smallest base address in a region, return the smallest object reference that could refer to an object in the region. |
static Object |
moveObject(Address toAddress,
Object fromObj,
int numBytes,
RVMArray type)
Copy an array object to the given raw storage address |
static Object |
moveObject(Address toAddress,
Object fromObj,
int numBytes,
RVMClass type)
Copy a scalar object to the given raw storage address |
static Object |
moveObject(Object fromObj,
Object toObj,
int numBytes,
RVMArray type)
Copy an array object to the given raw storage address |
static Object |
moveObject(Object fromObj,
Object toObj,
int numBytes,
RVMClass type)
Copy a scalar object to the given raw storage address |
static int |
objectStartOffset(RVMClass t)
For a reference to an object, what is the offset in bytes to the bottom word of the object? |
static Address |
objectStartRef(ObjectReference obj)
Map from the object ref to the lowest address of the storage associated with the object |
static Word |
prepareAvailableBits(Object o)
A prepare on the word containing the available bits |
static Word |
readAvailableBitsWord(Object o)
Non-atomic read of word containing available bits |
static byte |
readAvailableByte(Object o)
Non-atomic read of byte containing available bits |
static void |
setArrayLength(Object o,
int len)
Set the length of an array |
static void |
setAvailableBit(Object o,
int idx,
boolean flag)
Set argument bit to 1 if flag is true, 0 if flag is false |
static void |
setTIB(BootImageInterface bootImage,
Address refAddress,
Address tibAddr,
RVMType type)
Set the TIB for an object. |
static void |
setTIB(ObjectReference ptr,
TIB tib)
Set the TIB for an object. |
static void |
setTIB(Object ref,
TIB tib)
Set the TIB for an object. |
static boolean |
testAvailableBit(Object o,
int idx)
Return true if argument bit is 1, false if it is 0 |
static void |
writeAvailableBitsWord(Object o,
Word val)
Non-atomic write of word containing available bits |
static void |
writeAvailableByte(Object o,
byte val)
Non-atomic write of byte containing available bits |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final boolean HASH_STATS
public static int hashRequests
public static int hashTransition1
public static int hashTransition2
private static final boolean PACKED
private static final FieldLayout layout
Constructor Detail |
---|
public ObjectModel()
Method Detail |
---|
public static void layoutInstanceFields(RVMClass klass)
klass
- the class to layoutpublic static Address getPointerInMemoryRegion(ObjectReference ref)
public static Offset getArrayLengthOffset()
public static TIB getTIB(ObjectReference ptr)
public static TIB getTIB(Object o)
public static void setTIB(ObjectReference ptr, TIB tib)
public static void setTIB(Object ref, TIB tib)
public static void setTIB(BootImageInterface bootImage, Address refAddress, Address tibAddr, RVMType type)
public static Address getObjectEndAddress(Object obj)
public static Address getObjectEndAddress(Object object, RVMClass type)
public static Address getObjectEndAddress(Object object, RVMArray type, int elements)
public static ObjectReference getObjectFromStartAddress(Address start)
public static ObjectReference getScalarFromStartAddress(Address start)
public static ObjectReference getArrayFromStartAddress(Address start)
public static ObjectReference getNextObject(ObjectReference obj)
public static ObjectReference getNextObject(ObjectReference obj, RVMClass type)
public static ObjectReference getNextObject(ObjectReference obj, RVMArray type, int numElements)
public static Object getReferenceWhenCopiedTo(Object obj, Address to)
public static int bytesUsed(Object obj)
public static int bytesUsed(Object obj, RVMClass type)
public static int bytesUsed(Object obj, RVMArray type, int numElements)
public static int bytesRequiredWhenCopied(Object obj)
public static int bytesRequiredWhenCopied(Object fromObj, RVMClass type)
public static int bytesRequiredWhenCopied(Object fromObj, RVMArray type, int numElements)
public static Address objectStartRef(ObjectReference obj)
public static Object getReferenceWhenCopiedTo(Object obj, Address region, RVMClass type)
public static Object getReferenceWhenCopiedTo(Object obj, Address region, RVMArray type)
public static Object moveObject(Object fromObj, Object toObj, int numBytes, RVMClass type)
public static Object moveObject(Object fromObj, Object toObj, int numBytes, RVMArray type)
public static Object moveObject(Address toAddress, Object fromObj, int numBytes, RVMClass type)
public static Object moveObject(Address toAddress, Object fromObj, int numBytes, RVMArray type)
public static RVMType getObjectType(Object o)
public static int getArrayLength(Object o)
public static void setArrayLength(Object o, int len)
public static int getObjectHashCode(Object o)
public static Offset getThinLockOffset(Object o)
public static Offset defaultThinLockOffset()
public static void allocateThinLock(RVMType t)
public static void genericLock(Object o)
public static void genericUnlock(Object o)
public static boolean holdsLock(Object obj, RVMThread thread)
obj
- an objectthread
- a thread
true
if the lock on obj is currently owned
by thread false
if it is not.public static Lock getHeavyLock(Object o, boolean create)
null
, if there is no
heavy-weight lock associated with the object.
o
- the object from which a lock is desiredcreate
- if true, create heavy lock if none found
public static Word readAvailableBitsWord(Object o)
public static byte readAvailableByte(Object o)
public static void writeAvailableBitsWord(Object o, Word val)
public static void writeAvailableByte(Object o, byte val)
public static boolean testAvailableBit(Object o, int idx)
public static void setAvailableBit(Object o, int idx, boolean flag)
public static void initializeAvailableByte(Object o)
public static Word prepareAvailableBits(Object o)
public static boolean attemptAvailableBits(Object o, Word oldVal, Word newVal)
public static Address minimumObjectRef(Address regionBaseAddr)
public static Address maximumObjectRef(Address regionHighAddr)
public static int computeHeaderSize(RVMType type)
public static int computeHeaderSize(Object ref)
public static int computeScalarHeaderSize(RVMClass type)
public static int computeArrayHeaderSize(RVMArray type)
public static int computeHeaderSize(Object[] tib)
public static int getHeaderEndOffset()
public static int objectStartOffset(RVMClass t)
public static int getAlignment(RVMClass t)
t
- RVMClass instance being createdpublic static int getAlignment(RVMClass t, Object obj)
t
- RVMClass instance being copiedobj
- the object being copiedpublic static int getAlignment(RVMArray t)
t
- RVMArray instance being createdpublic static int getAlignment(RVMArray t, Object obj)
t
- RVMArray instance being copiedobj
- the object being copiedpublic static int getOffsetForAlignment(RVMClass t, boolean needsIdentityHash)
t
- RVMClass instance being createdpublic static int getOffsetForAlignment(RVMClass t, ObjectReference obj)
t
- RVMClass instance being copiedobj
- the object being copiedpublic static int getOffsetForAlignment(RVMArray t, boolean needsIdentityHash)
t
- RVMArray instance being createdpublic static int getOffsetForAlignment(RVMArray t, ObjectReference obj)
t
- RVMArray instance being copiedobj
- the object being copiedpublic static Object initializeScalar(Address ptr, TIB tib, int size)
ptr
- address of raw storagetib
- the type information blocksize
- number of bytes of raw storage allocated.public static Address allocateScalar(BootImageInterface bootImage, RVMClass klass, boolean needsIdentityHash, int identityHashValue)
bootImage
- the bootimage to put the object inklass
- the RVMClass object of the instance to create.needsIdentityHash
- needs an identity hash valueidentityHashValue
- the value for the identity hash
public static void fillAlignmentGap(BootImageInterface bootImage, Address address, Extent size)
public static Object initializeArray(Address ptr, TIB tib, int numElems, int size)
ptr
- address of raw storagetib
- the type information blocknumElems
- number of elements in the arraysize
- number of bytes of raw storage allocated.public static Address allocateArray(BootImageInterface bootImage, RVMArray array, int numElements, boolean needsIdentityHash, int identityHashValue, int alignCode)
bootImage
- the bootimage to put the object inarray
- RVMArray object of array being allocated.numElements
- number of elementsneedsIdentityHash
- needs an identity hash valueidentityHashValue
- the value for the identity hashalignCode
- TODO
public static Address allocateArray(BootImageInterface bootImage, RVMArray array, int numElements, boolean needsIdentityHash, int identityHashValue, int align, int alignCode)
bootImage
- the bootimage to put the object inarray
- RVMArray object of array being allocated.numElements
- number of elementsneedsIdentityHash
- needs an identity hash valueidentityHashValue
- the value for the identity hashalignCode
- TODO
public static Address allocateCode(BootImageInterface bootImage, RVMArray array, int numElements)
bootImage
- the bootimage to put the object inarray
- RVMArray object of array being allocated.numElements
- number of elements
public static void dumpHeader(ObjectReference ptr)
ptr
- the object reference whose header should be dumpedpublic static void dumpHeader(Object ref)
ref
- the object reference whose header should be dumpedpublic static void describeObject(ObjectReference addr)
public static void baselineEmitLoadTIB(ArchitectureSpecific.Assembler asm, int dest, int object)
asm
- the assembler object to emit code withdest
- the number of the destination registerobject
- the number of the register holding the object reference
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |