Skip to content

Commit ecacee0

Browse files
committed
[GR-54021] Do not forfeit memory for compaction due to sweeping.
PullRequest: graal/22470
2 parents 2083fcd + df07ca3 commit ecacee0

File tree

1 file changed

+11
-17
lines changed
  • substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/compacting

1 file changed

+11
-17
lines changed

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/compacting/PlanningVisitor.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,9 @@ public boolean visitChunk(AlignedHeapChunk.AlignedHeader chunk) {
149149
ObjectMoveInfo.setObjectSeqSize(objSeq, objSeqSize);
150150
}
151151

152-
if (sweeping) {
153-
/*
154-
* Continue allocating for compaction after the swept memory. Note that this forfeits
155-
* unused memory in the chunks before, but the order of objects must stay the same
156-
* across all chunks. If chunks end up completely empty however, they will be released
157-
* after compaction.
158-
*
159-
* GR-54021: it should be possible to avoid this limitation by sweeping chunks without
160-
* ObjectMoveInfo and brick tables and potentially even do the sweeping right here.
161-
*/
162-
this.allocChunk = chunk;
163-
this.allocPointer = HeapChunk.getTopPointer(chunk);
152+
if (sweeping && chunk.equal(allocChunk)) {
153+
/* Continue allocating for compaction after the swept memory. */
154+
allocPointer = HeapChunk.getTopPointer(chunk);
164155
}
165156

166157
/* Set remaining brick table entries at chunk end. */
@@ -174,14 +165,17 @@ public boolean visitChunk(AlignedHeapChunk.AlignedHeader chunk) {
174165
}
175166

176167
private Pointer allocate(UnsignedWord size) {
168+
assert size.belowOrEqual(AlignedHeapChunk.getUsableSizeForObjects());
177169
Pointer p = allocPointer;
178-
allocPointer = allocPointer.add(size);
179-
if (allocPointer.aboveThan(AlignedHeapChunk.getObjectsEnd(allocChunk))) {
170+
allocPointer = p.add(size);
171+
while (allocPointer.aboveThan(AlignedHeapChunk.getObjectsEnd(allocChunk))) {
180172
allocChunk = HeapChunk.getNext(allocChunk);
181173
assert allocChunk.isNonNull();
182-
assert !allocChunk.getShouldSweepInsteadOfCompact();
183-
184-
p = AlignedHeapChunk.getObjectsStart(allocChunk);
174+
if (allocChunk.getShouldSweepInsteadOfCompact()) {
175+
p = HeapChunk.getTopPointer(allocChunk); // use any free memory at the end
176+
} else {
177+
p = AlignedHeapChunk.getObjectsStart(allocChunk);
178+
}
185179
allocPointer = p.add(size);
186180
}
187181
return p;

0 commit comments

Comments
 (0)