public class JavaHeader extends Object
One word holds a TIB pointer.
The other word ("status word") contains an inline thin lock,
either the hash code or hash code state, and a few unallocated
bits that can be used for other purposes.
If JavaHeaderConstants.ADDRESS_BASED_HASHING
is false,
then to implement default hashcodes, Jikes RVM uses a 10 bit hash code
that is completely stored in the status word, which is laid out as
shown below:
TTTT TTTT TTTT TTTT TTTT HHHH HHHH HHAA T = thin lock bits H = hash code A = available for use by GCHeader and/or MiscHeader.If
ADDRESS_BASED_HASHING
is true,
then Jikes RVM uses two bits of the status word to record the hash code state in
a typical three state scheme (JavaHeaderConstants.HASH_STATE_UNHASHED
,
JavaHeaderConstants.HASH_STATE_HASHED
, and
JavaHeaderConstants.HASH_STATE_HASHED_AND_MOVED
). In this case, the status
word is laid out as shown below:
TTTT TTTT TTTT TTTT TTTT TTHH AAAA AAAA T = thin lock bits H = hash code state bits A = available for use by GCHeader and/or MiscHeader.
Modifier and Type | Field and Description |
---|---|
static int |
ALIGNMENT_VALUE
The alignment value
|
protected static int |
ARRAY_HEADER_SIZE |
protected static Offset |
AVAILABLE_BITS_OFFSET |
protected static Word |
HASH_CODE_MASK |
protected static int |
HASH_CODE_SHIFT |
protected static Word |
hashCodeGenerator |
static int |
LOG_MIN_ALIGNMENT |
static int |
NUM_THIN_LOCK_BITS
How many bits are allocated to a thin lock?
|
static int |
OBJECT_REF_OFFSET
offset of object reference from the lowest memory word
|
protected static int |
SCALAR_HEADER_SIZE |
protected static Offset |
STATUS_OFFSET |
static int |
THIN_LOCK_DEDICATED_U16_OFFSET
How many bytes do we have to offset to get to the high locking bits
|
static int |
THIN_LOCK_DEDICATED_U16_SHIFT
How many bits do we have to shift to only hold the high locking bits
|
static int |
THIN_LOCK_SHIFT
How many bits to shift to get the thin lock?
|
protected static Offset |
TIB_OFFSET |
Constructor and Description |
---|
JavaHeader() |
Modifier and Type | Method and Description |
---|---|
static void |
allocateThinLock(RVMType t)
Allocates 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 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) |
static int |
bytesUsed(Object obj,
RVMArray type,
int numElements)
how many bytes are used by the array object?
|
static int |
bytesUsed(Object obj,
RVMClass type) |
static int |
computeArrayHeaderSize(RVMArray type)
Computes the header size of an instance of the given type.
|
static int |
computeScalarHeaderSize(RVMClass type)
Computes the header size of an instance of the given type.
|
static Offset |
defaultThinLockOffset() |
static void |
dumpHeader(Object ref)
For low level debugging of GC subsystem.
|
static void |
genericLock(Object o) |
static void |
genericUnlock(Object o) |
static int |
getAlignment(RVMArray t) |
static int |
getAlignment(RVMArray t,
Object obj) |
static int |
getAlignment(RVMClass t) |
static int |
getAlignment(RVMClass t,
Object obj) |
static ObjectReference |
getArrayFromStartAddress(Address start)
Gets an object reference from the address the lowest word of the
object was allocated.
|
static int |
getHeaderEndOffset() |
static Lock |
getHeavyLock(Object o,
boolean create)
Obtains the heavy-weight lock, if there is one, associated with the
indicated object.
|
protected static ObjectReference |
getNextObject(ObjectReference obj,
int size)
Get the next object in the heap under contiguous
allocation.
|
static ObjectReference |
getNextObject(ObjectReference obj,
RVMArray type,
int numElements)
Get the next array in the heap under contiguous
allocation.
|
static ObjectReference |
getNextObject(ObjectReference obj,
RVMClass type)
Get the next object in the heap under contiguous
allocation.
|
static Address |
getObjectEndAddress(Object obj,
RVMArray type,
int numElements)
What is the first word after the array?
|
static Address |
getObjectEndAddress(Object obj,
RVMClass type)
What is the first word after the class?
|
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) |
static int |
getOffsetForAlignment(RVMArray t,
boolean needsIdentityHash) |
static int |
getOffsetForAlignment(RVMArray t,
ObjectReference obj) |
static int |
getOffsetForAlignment(RVMClass t,
boolean needsIdentityHash) |
static int |
getOffsetForAlignment(RVMClass t,
ObjectReference obj) |
static Address |
getPointerInMemoryRegion(ObjectReference ref)
Given a reference, return an address which is guaranteed to be inside
the memory region allocated to the object.
|
protected static Object |
getReferenceWhenCopiedTo(Object obj,
Address to) |
static Object |
getReferenceWhenCopiedTo(Object obj,
Address to,
RVMArray type)
Gets the reference of an array when copied to the specified region.
|
static Object |
getReferenceWhenCopiedTo(Object obj,
Address to,
RVMClass type)
Get the reference of a scalar when copied to the specified region.
|
static ObjectReference |
getScalarFromStartAddress(Address start)
Gets an object reference from the address the lowest word of the
object was allocated.
|
static Offset |
getThinLockOffset(Object o) |
static TIB |
getTIB(Object o) |
static Offset |
getTibOffset() |
static boolean |
holdsLock(Object obj,
RVMThread thread) |
static Object |
initializeArrayHeader(Address ptr,
TIB tib,
int size)
Perform any required initialization of the JAVA portion of the header.
|
static Address |
initializeArrayHeader(BootImageInterface bootImage,
Address ptr,
TIB tib,
int size,
int numElements,
boolean needsIdentityHash,
int identityHashValue)
Perform any required initialization of the JAVA portion of the header.
|
static void |
initializeAvailableByte(Object o)
Freezes the other bits in the byte containing the available bits
so that it is safe to update them using setAvailableBits.
|
static Object |
initializeScalarHeader(Address ptr,
TIB tib,
int size)
Perform any required initialization of the JAVA portion of the header.
|
static Address |
initializeScalarHeader(BootImageInterface bootImage,
Address ptr,
TIB tib,
int size,
boolean needsIdentityHash,
int identityHashValue)
Perform any required initialization of the JAVA portion of the header.
|
protected static int |
installHashCode(Object o) |
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 int |
minimumObjectSize()
How small is the minimum object header size?
|
static Object |
moveObject(Address toAddress,
Object fromObj,
int numBytes,
RVMArray type)
Copies an array to the given raw storage address.
|
static Object |
moveObject(Address toAddress,
Object fromObj,
int numBytes,
RVMClass type)
Copy a scalar to the given raw storage address.
|
static Object |
moveObject(Address toAddress,
Object fromObj,
Object toObj,
int numBytes)
Copies an object to the given raw storage address.
|
static Object |
moveObject(Object fromObj,
Object toObj,
int numBytes,
RVMArray type)
Copies an array to the given location.
|
static Object |
moveObject(Object fromObj,
Object toObj,
int numBytes,
RVMClass type)
Copies a scalar to the given location.
|
static int |
objectStartOffset(RVMClass klass)
What is the offset of the first word of the class?
|
static Address |
objectStartRef(ObjectReference obj)
Maps 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 |
setAvailableBit(Object o,
int idx,
boolean flag)
Sets argument bit to 1 if value is true, 0 if value is false
|
static void |
setTIB(BootImageInterface bootImage,
Address refOffset,
Address tibAddr,
RVMType type)
Sets the TIB for an object during bootimage writing.
|
static void |
setTIB(Object ref,
TIB tib)
Sets the TIB for an object.
|
static boolean |
testAvailableBit(Object o,
int idx) |
static void |
writeAvailableBitsWord(Object o,
Word val)
Non-atomic write of word containing available bits.
|
static void |
writeAvailableByte(BootImageInterface bootImage,
Address ref,
byte val)
Non-atomic write of word containing available bits
|
static void |
writeAvailableByte(Object o,
byte val)
Non-atomic write of byte containing available bits
|
protected static final int SCALAR_HEADER_SIZE
protected static final int ARRAY_HEADER_SIZE
public static final int OBJECT_REF_OFFSET
protected static final Offset TIB_OFFSET
protected static final Offset STATUS_OFFSET
protected static final Offset AVAILABLE_BITS_OFFSET
protected static final int HASH_CODE_SHIFT
protected static final Word HASH_CODE_MASK
protected static Word hashCodeGenerator
public static final int NUM_THIN_LOCK_BITS
public static final int THIN_LOCK_SHIFT
public static final int THIN_LOCK_DEDICATED_U16_OFFSET
public static final int THIN_LOCK_DEDICATED_U16_SHIFT
public static final int ALIGNMENT_VALUE
public static final int LOG_MIN_ALIGNMENT
public JavaHeader()
public static Offset getTibOffset()
public static Address getObjectEndAddress(Object obj, RVMClass type)
obj
- the object in questiontype
- the object's classpublic static Address getObjectEndAddress(Object obj, RVMArray type, int numElements)
obj
- the object in questiontype
- the object's classnumElements
- the number of elements in the arraypublic static int objectStartOffset(RVMClass klass)
klass
- unusedpublic static int getHeaderEndOffset()
public static int minimumObjectSize()
public static Address getPointerInMemoryRegion(ObjectReference ref)
ref
- an object referencepublic static void setTIB(Object ref, TIB tib)
ref
- the objecttib
- the TIB to set for the objectpublic static void setTIB(BootImageInterface bootImage, Address refOffset, Address tibAddr, RVMType type)
bootImage
- the bootimagerefOffset
- the object's address in the bootimagetibAddr
- the TIB's address in the bootimagetype
- the object's typepublic static int bytesRequiredWhenCopied(Object fromObj, RVMClass type)
fromObj
- the object to copytype
- the object's typepublic static int bytesUsed(Object obj, RVMClass type)
obj
- the objecttype
- the object's typepublic static int bytesRequiredWhenCopied(Object fromObj, RVMArray type, int numElements)
fromObj
- the object to copytype
- the object's typenumElements
- the array lengthpublic static int bytesUsed(Object obj, RVMArray type, int numElements)
obj
- the object to copytype
- the object's typenumElements
- the array lengthpublic static Address objectStartRef(ObjectReference obj)
obj
- the object referencepublic static ObjectReference getObjectFromStartAddress(Address start)
start
- the lowest word in the storage of an allocated objectpublic static ObjectReference getScalarFromStartAddress(Address start)
start
- the lowest word in the storage of an allocated objectpublic static ObjectReference getArrayFromStartAddress(Address start)
start
- the lowest word in the storage of an allocated objectprotected static ObjectReference getNextObject(ObjectReference obj, int size)
obj
- the present objectsize
- the object's sizepublic static ObjectReference getNextObject(ObjectReference obj, RVMClass type)
obj
- the current object, which must be a scalartype
- the object's typepublic static ObjectReference getNextObject(ObjectReference obj, RVMArray type, int numElements)
obj
- the current object, which must be an arraytype
- the object's typenumElements
- the length of the arraypublic static Object getReferenceWhenCopiedTo(Object obj, Address to, RVMArray type)
obj
- the object to copyto
- the target address for the copytype
- the array's typepublic static Object getReferenceWhenCopiedTo(Object obj, Address to, RVMClass type)
obj
- the object to copyto
- the target address for the copytype
- the scalar's typeprotected static Object getReferenceWhenCopiedTo(Object obj, Address to)
public static Object moveObject(Address toAddress, Object fromObj, int numBytes, RVMClass type)
toAddress
- the target addressfromObj
- the object to copynumBytes
- how many bytes to copytype
- the scalar's typepublic static Object moveObject(Object fromObj, Object toObj, int numBytes, RVMClass type)
fromObj
- the scalar to copytoObj
- target address for copynumBytes
- how many bytes to copytype
- the scalar's typepublic static Object moveObject(Address toAddress, Object fromObj, int numBytes, RVMArray type)
toAddress
- the target addressfromObj
- the object to copynumBytes
- how many bytes to copytype
- the array's typepublic static Object moveObject(Object fromObj, Object toObj, int numBytes, RVMArray type)
fromObj
- the object to copytoObj
- the target objectnumBytes
- the number of bytes to copytype
- the array's typepublic static Object moveObject(Address toAddress, Object fromObj, Object toObj, int numBytes)
toObj
- the target object. If this is non-null
, the target
address must be Address.zero()
.toAddress
- the target address. If this is not Address.zero()
,
the target object must be null
.fromObj
- the object to copy fromnumBytes
- the number of bytes to copypublic static int getObjectHashCode(Object o)
protected static int installHashCode(Object o)
public static Offset getThinLockOffset(Object o)
public static Offset defaultThinLockOffset()
public static void allocateThinLock(RVMType t)
t
- the type that is supposed to receive a thin
lock wordpublic static void genericLock(Object o)
public static void genericUnlock(Object o)
public static boolean holdsLock(Object obj, RVMThread thread)
obj
- an objectthread
- a threadtrue
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 foundpublic static Word readAvailableBitsWord(Object o)
o
- the object to readpublic static byte readAvailableByte(Object o)
o
- the object to readpublic static void writeAvailableBitsWord(Object o, Word val)
o
- the object whose word will be writtenval
- the available bits wordpublic static void writeAvailableByte(BootImageInterface bootImage, Address ref, byte val)
bootImage
- the bootimageref
- an object reference whose word will be writtenval
- the available bits wordpublic static void writeAvailableByte(Object o, byte val)
o
- the object whose available byte will be writtenval
- the value to write to the available bytepublic static boolean testAvailableBit(Object o, int idx)
o
- the object whose bit will be testedidx
- the index in the bitstrue
if argument bit is 1, false
if it is 0public static void setAvailableBit(Object o, int idx, boolean flag)
o
- the object whose bit will be setidx
- the index in the bitsflag
- true
for 1, false
for 0public static void initializeAvailableByte(Object o)
o
- the object whose available bytes will be initializedpublic static Word prepareAvailableBits(Object o)
Note: this method is intended to be used in conjunction with the attempt method.
o
- the object which has the available bitsattemptAvailableBits(Object, Word, Word)
public static boolean attemptAvailableBits(Object o, Word oldVal, Word newVal)
Note: this method is intended to be used in conjunction
with the prepare method. If the method returns false
,
callers must update their information about the old value of
the available bits word before retrying again.
o
- the object which has the available bitsoldVal
- the old value that the word is expected to havenewVal
- the new value that will be written, if possiblepublic static Address minimumObjectRef(Address regionBaseAddr)
regionBaseAddr
- the smallest base address in the regionpublic static Address maximumObjectRef(Address regionHighAddr)
regionHighAddr
- the highest base address in the regionpublic static int computeScalarHeaderSize(RVMClass type)
type
- the instance's typepublic static int computeArrayHeaderSize(RVMArray type)
type
- the instance's typepublic 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 createdneedsIdentityHash
- TODO document this parameter. Is it still needed?
It's never set to true.public 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 createdneedsIdentityHash
- TODO document this parameter. Is it still needed?
It's never set to true.public static int getOffsetForAlignment(RVMArray t, ObjectReference obj)
t
- RVMArray instance being copiedobj
- the object being copiedpublic static Object initializeScalarHeader(Address ptr, TIB tib, int size)
ptr
- the raw storage to be initializedtib
- the TIB of the instance being createdsize
- the number of bytes allocated by the GC system for this object.public static Address initializeScalarHeader(BootImageInterface bootImage, Address ptr, TIB tib, int size, boolean needsIdentityHash, int identityHashValue)
bootImage
- The bootimage being writtenptr
- The object ref to the storage to be initializedtib
- The TIB of the instance being createdsize
- The number of bytes allocated by the GC system for this object.needsIdentityHash
- needs an identity hash valueidentityHashValue
- the value for the identity hashpublic static Object initializeArrayHeader(Address ptr, TIB tib, int size)
ptr
- the raw storage to be initializedtib
- the TIB of the instance being createdsize
- the number of bytes allocated by the GC system for this object.public static Address initializeArrayHeader(BootImageInterface bootImage, Address ptr, TIB tib, int size, int numElements, boolean needsIdentityHash, int identityHashValue)
bootImage
- the bootimage being writtenptr
- the object ref to the storage to be initializedtib
- the TIB of the instance being createdsize
- the number of bytes allocated by the GC system for this object.numElements
- the number of elements in the arrayneedsIdentityHash
- needs an identity hash valueidentityHashValue
- the value for the identity hashpublic static void dumpHeader(Object ref)
ref
- the object reference whose header should be dumped