package com.oracle.svm.core.genscavenge;
import com.oracle.svm.core.config.ConfigurationValues;
import com.oracle.svm.core.image.ImageHeap;
import com.oracle.svm.core.image.ImageHeapLayoutInfo;
public class LinearImageHeapLayouter extends AbstractImageHeapLayouter<LinearImageHeapPartition> {
private final ImageHeapInfo heapInfo;
private final long startOffset;
private final boolean compressedNullPadding;
public LinearImageHeapLayouter(ImageHeapInfo heapInfo, long startOffset, boolean compressedNullPadding) {
this.heapInfo = heapInfo;
this.startOffset = startOffset;
this.compressedNullPadding = compressedNullPadding;
}
@Override
protected LinearImageHeapPartition[] createPartitionsArray(int count) {
return new LinearImageHeapPartition[count];
}
@Override
protected LinearImageHeapPartition createPartition(String name, boolean containsReferences, boolean writable, boolean hugeObjects) {
return new LinearImageHeapPartition(name, writable);
}
@Override
protected ImageHeapLayoutInfo doLayout(ImageHeap imageHeap) {
long beginOffset = startOffset;
if (compressedNullPadding) {
beginOffset += ConfigurationValues.getObjectLayout().getAlignment();
}
LinearImageHeapAllocator allocator = new LinearImageHeapAllocator(beginOffset);
for (LinearImageHeapPartition partition : getPartitions()) {
partition.allocateObjects(allocator);
}
initializeHeapInfo(imageHeap.countDynamicHubs());
return createLayoutInfo(startOffset, getWritablePrimitive().getStartOffset());
}
private void initializeHeapInfo(int dynamicHubCount) {
heapInfo.initialize(getReadOnlyPrimitive().firstObject, getReadOnlyPrimitive().lastObject, getReadOnlyReference().firstObject, getReadOnlyReference().lastObject,
getReadOnlyRelocatable().firstObject, getReadOnlyRelocatable().lastObject, getWritablePrimitive().firstObject, getWritablePrimitive().lastObject,
getWritableReference().firstObject, getWritableReference().lastObject, getWritableHuge().firstObject, getWritableHuge().lastObject,
getReadOnlyHuge().firstObject, getReadOnlyHuge().lastObject, ImageHeapInfo.NO_CHUNK, ImageHeapInfo.NO_CHUNK, dynamicHubCount);
}
}