Skip to content

Commit

Permalink
Revert "Disable sweeping due to low fragmentation."
Browse files Browse the repository at this point in the history
This reverts commit d5c351c.
  • Loading branch information
peter-hofer committed May 7, 2024
1 parent 615b4c1 commit c5bc94e
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.oracle.svm.core.config.ConfigurationValues;
import com.oracle.svm.core.genscavenge.AlignedHeapChunk;
import com.oracle.svm.core.genscavenge.HeapChunk;
import com.oracle.svm.core.genscavenge.HeapParameters;
import com.oracle.svm.core.genscavenge.ObjectHeaderImpl;
import com.oracle.svm.core.genscavenge.Space;
import com.oracle.svm.core.genscavenge.remset.BrickTable;
Expand All @@ -47,6 +48,8 @@
* or overwrite dead objects.
*/
public final class PlanningVisitor implements AlignedHeapChunk.Visitor {
private static final ResetNewLocationsForSweepingVisitor RESET_NEW_LOCATIONS_FOR_SWEEPING_VISITOR = new ResetNewLocationsForSweepingVisitor();

private AlignedHeapChunk.AlignedHeader allocChunk;
private Pointer allocPointer;

Expand All @@ -62,7 +65,9 @@ public boolean visitChunk(AlignedHeapChunk.AlignedHeader chunk) {
Pointer objSeq = AlignedHeapChunk.getObjectsStart(chunk);
UnsignedWord gapSize = WordFactory.zero();
UnsignedWord objSeqSize = WordFactory.zero();

UnsignedWord brickIndex = WordFactory.zero();
UnsignedWord totalUnusedBytes = WordFactory.zero();

/* Initialize the move info structure at the chunk's object start location. */
ObjectMoveInfo.setNewAddress(objSeq, allocPointer);
Expand Down Expand Up @@ -107,6 +112,7 @@ public boolean visitChunk(AlignedHeapChunk.AlignedHeader chunk) {
objSeq = p;
ObjectMoveInfo.setNextObjectSeqOffset(objSeq, WordFactory.zero());

totalUnusedBytes = totalUnusedBytes.add(gapSize);
gapSize = WordFactory.zero();
}

Expand Down Expand Up @@ -141,6 +147,12 @@ public boolean visitChunk(AlignedHeapChunk.AlignedHeader chunk) {
ObjectMoveInfo.setObjectSeqSize(objSeq, objSeqSize);
}

totalUnusedBytes = totalUnusedBytes.add(HeapChunk.getEndOffset(chunk).subtract(HeapChunk.getTopOffset(chunk)));
if (!sweeping && shouldSweepBasedOnFragmentation(totalUnusedBytes)) {
sweeping = true;
chunk.setShouldSweepInsteadOfCompact(true);
ObjectMoveInfo.visit(chunk, RESET_NEW_LOCATIONS_FOR_SWEEPING_VISITOR);
}
if (sweeping) {
/*
* Continue allocating for compaction after the swept memory. Note that this forfeits
Expand Down Expand Up @@ -173,8 +185,21 @@ private Pointer allocate(UnsignedWord size) {
return p;
}

private static boolean shouldSweepBasedOnFragmentation(UnsignedWord unusedBytes) {
UnsignedWord limit = HeapParameters.getAlignedHeapChunkSize().unsignedDivide(16);
return unusedBytes.aboveOrEqual(0) && unusedBytes.belowThan(limit);
}

public void init(Space space) {
allocChunk = space.getFirstAlignedHeapChunk();
allocPointer = AlignedHeapChunk.getObjectsStart(allocChunk);
}

private static class ResetNewLocationsForSweepingVisitor implements ObjectMoveInfo.Visitor {
@Override
public boolean visit(Pointer objSeq, UnsignedWord size, Pointer newAddress, Pointer nextObjSeq) {
ObjectMoveInfo.setNewAddress(objSeq, objSeq);
return true;
}
}
}

0 comments on commit c5bc94e

Please sign in to comment.