Skip to content

Commit df07ca3

Browse files
committed
Do not forfeit memory for compaction due to sweeping.
1 parent 951d307 commit df07ca3

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
@@ -151,18 +151,9 @@ public boolean visitChunk(AlignedHeapChunk.AlignedHeader chunk) {
151151
ObjectMoveInfo.setObjectSeqSize(objSeq, objSeqSize);
152152
}
153153

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

168159
/* Set remaining brick table entries at chunk end. */
@@ -176,14 +167,17 @@ public boolean visitChunk(AlignedHeapChunk.AlignedHeader chunk) {
176167
}
177168

178169
private Pointer allocate(UnsignedWord size) {
170+
assert size.belowOrEqual(AlignedHeapChunk.getUsableSizeForObjects());
179171
Pointer p = allocPointer;
180-
allocPointer = allocPointer.add(size);
181-
if (allocPointer.aboveThan(AlignedHeapChunk.getObjectsEnd(allocChunk))) {
172+
allocPointer = p.add(size);
173+
while (allocPointer.aboveThan(AlignedHeapChunk.getObjectsEnd(allocChunk))) {
182174
allocChunk = HeapChunk.getNext(allocChunk);
183175
assert allocChunk.isNonNull();
184-
assert !allocChunk.getShouldSweepInsteadOfCompact();
185-
186-
p = AlignedHeapChunk.getObjectsStart(allocChunk);
176+
if (allocChunk.getShouldSweepInsteadOfCompact()) {
177+
p = HeapChunk.getTopPointer(allocChunk); // use any free memory at the end
178+
} else {
179+
p = AlignedHeapChunk.getObjectsStart(allocChunk);
180+
}
187181
allocPointer = p.add(size);
188182
}
189183
return p;

0 commit comments

Comments
 (0)