Skip to content

Commit 71ed6c9

Browse files
committed
[GR-59482] Align image heap end when using mremap
PullRequest: graal/19176
2 parents 841b744 + 638a119 commit 71ed6c9

File tree

1 file changed

+8
-3
lines changed
  • substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image

1 file changed

+8
-3
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImage.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package com.oracle.svm.hosted.image;
2626

2727
import static com.oracle.svm.core.SubstrateOptions.SpawnIsolates;
28+
import static com.oracle.svm.core.SubstrateOptions.MremapImageHeap;
2829
import static com.oracle.svm.core.SubstrateUtil.mangleName;
2930
import static com.oracle.svm.core.util.VMError.shouldNotReachHere;
3031

@@ -489,9 +490,13 @@ public void build(String imageName, DebugContext debug) {
489490
// boundaries, so we take care of this ourselves in CommittedMemoryProvider, if we can.
490491
int alignment = pageSize;
491492

492-
// Manually add padding to the SVM_HEAP section, because when SpawnIsolates are disabled
493-
// we operate with mprotect on it with page size granularity.
494-
long paddedImageHeapSize = SpawnIsolates.getValue() ? imageHeapSize : NumUtil.roundUp(imageHeapSize, alignment);
493+
/*
494+
* Manually add padding to the SVM_HEAP section, because when SpawnIsolates are disabled
495+
* we operate with mprotect on it with page size granularity. Similarly, using mremap
496+
* aligns up the page boundary and may reset memory outside of the image heap.
497+
*/
498+
boolean padImageHeap = !SpawnIsolates.getValue() || MremapImageHeap.getValue();
499+
long paddedImageHeapSize = padImageHeap ? NumUtil.roundUp(imageHeapSize, alignment) : imageHeapSize;
495500
RelocatableBuffer heapSectionBuffer = new RelocatableBuffer(paddedImageHeapSize, objectFile.getByteOrder());
496501
ProgbitsSectionImpl heapSectionImpl = new BasicProgbitsSectionImpl(heapSectionBuffer.getBackingArray());
497502
// Note: On isolate startup the read only part of the heap will be set up as such.

0 commit comments

Comments
 (0)