this.sizeOffset = Offset.fromIntSignExtend(-((ObjectLayout.HEADER_SLOTS + 1) * slotSize));
this.headerSize = ObjectLayout.objectAlign(this.headerSize + slotSize);
final int size = getSize();
final Address myAddr = ObjectReference.fromObject(this).toAddress();
final Word mySize = myAddr.loadWord(sizeOffset);
Address firstObject;
if (inHeap(myAddr)) {
firstObject = myAddr.add(mySize).add(headerSize);
} else {
firstObject = start.add(headerSize);
}
// Initialize an allocation bitmap
final int allocationBits = size / ObjectLayout.OBJECT_ALIGN;
final int allocationBitmapSize = ObjectLayout
.objectAlign((allocationBits + 7) / 8);
this.allocationBitmapPtr = firstObject;
final Address bitmapPtr = this.allocationBitmapPtr;
// Make the bitmap an object, so it is easy to manipulate.
bitmapPtr.store(Word.fromIntZeroExtend(allocationBitmapSize), sizeOffset);
bitmapPtr.store(Word.fromIntZeroExtend(GC_DEFAULT_COLOR), flagsOffset);
bitmapPtr.store(ObjectReference.fromObject(VmType.getObjectClass().getTIB()), tibOffset);
firstObject = firstObject.add(allocationBitmapSize + headerSize);
helper.clear(allocationBitmapPtr, allocationBitmapSize);
this.allocationBitmap = allocationBitmapPtr.toObjectReference().toObject();
// Mark this heap in the allocation bitmap
setAllocationBit(this, true);
// Mark the allocation bitmap in the allocation bitmap
setAllocationBit(allocationBitmap, true);
// Initialize the remaining space as free object.
final Word remainingSize = end.toWord().sub(firstObject.toWord());
final Address ptr = firstObject;
ptr.store(remainingSize, sizeOffset);
ptr.store(ObjectReference.fromObject(FREE), tibOffset);
this.nextFreePtr = ptr;
this.freeSize = remainingSize.toExtent();
}