Skip to content

Commit 68b79a2

Browse files
committed
Avoid unnecessary ChunkedImageHeapPartition alignment from empty huge object partitions.
1 parent eca7e0b commit 68b79a2

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ChunkedImageHeapLayouter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.graalvm.nativeimage.ImageInfo;
3131
import org.graalvm.word.UnsignedWord;
3232

33-
import com.oracle.svm.core.SubstrateOptions;
3433
import com.oracle.svm.core.SubstrateUtil;
3534
import com.oracle.svm.core.config.ConfigurationValues;
3635
import com.oracle.svm.core.genscavenge.ChunkedImageHeapAllocator.AlignedChunk;
@@ -96,7 +95,7 @@ public ChunkedImageHeapLayouter(ImageHeapInfo heapInfo, long startOffset) {
9695
this.partitions[WRITABLE_PATCHED] = new ChunkedImageHeapPartition("writablePatched", true, false, alignment, alignment);
9796
this.partitions[WRITABLE_REGULAR] = new ChunkedImageHeapPartition("writable", true, false, alignment, alignment);
9897
this.partitions[WRITABLE_HUGE] = new ChunkedImageHeapPartition("writableHuge", true, true, alignment, alignment);
99-
this.partitions[READ_ONLY_HUGE] = new ChunkedImageHeapPartition("readOnlyHuge", false, true, alignment, SubstrateOptions.getPageSize());
98+
this.partitions[READ_ONLY_HUGE] = new ChunkedImageHeapPartition("readOnlyHuge", false, true, alignment, alignment);
10099

101100
this.heapInfo = heapInfo;
102101
this.startOffset = startOffset;
@@ -219,7 +218,9 @@ private ImageHeapLayoutInfo populateInfoObjects(int dynamicHubCount, int pageSiz
219218

220219
long writableEnd = getWritableHuge().getStartOffset() + getWritableHuge().getSize();
221220
long writableSize = writableEnd - offsetOfFirstWritableAlignedChunk;
222-
long imageHeapSize = getReadOnlyHuge().getStartOffset() + getReadOnlyHuge().getSize() - startOffset;
221+
/* Aligning the end to the page size can be required for mapping into memory. */
222+
long imageHeapEnd = NumUtil.roundUp(getReadOnlyHuge().getStartOffset() + getReadOnlyHuge().getSize(), pageSize);
223+
long imageHeapSize = imageHeapEnd - startOffset;
223224
return new ImageHeapLayoutInfo(startOffset, imageHeapSize, offsetOfFirstWritableAlignedChunk, writableSize, getReadOnlyRelocatable().getStartOffset(), getReadOnlyRelocatable().getSize(),
224225
getWritablePatched().getStartOffset(), getWritablePatched().getSize());
225226
}

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ChunkedImageHeapPartition.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ void layout(ChunkedImageHeapAllocator allocator, ImageHeapLayouterControl contro
8282
}
8383

8484
private void layoutInUnalignedChunks(ChunkedImageHeapAllocator allocator, ImageHeapLayouterControl control) {
85+
if (objects.isEmpty()) {
86+
/*
87+
* Without objects, don't force finishing the current chunk and therefore committing
88+
* space for the rest of it. Another partition might be able to continue filling it, or,
89+
* if no more objects follow, we don't need to dedicate space in the image at all.
90+
*/
91+
startOffset = allocator.getPosition();
92+
endOffset = startOffset;
93+
return;
94+
}
95+
8596
allocator.finishAlignedChunk();
8697
allocator.alignBetweenChunks(getStartAlignment());
8798
startOffset = allocator.getPosition();

0 commit comments

Comments
 (0)