Skip to content

Commit

Permalink
collect on allocation crossing max
Browse files Browse the repository at this point in the history
  • Loading branch information
roberttoyonaga committed Oct 8, 2024
1 parent a8efbf7 commit a969e13
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ protected AbstractCollectionPolicy(int initialNewRatio, int initialTenuringThres
}

@Override
public boolean shouldCollectOnAllocation() {
public boolean shouldCollectOnAllocation(UnsignedWord allocationSize) {
if (sizes == null) {
return false; // updateSizeParameters() has never been called
}
UnsignedWord edenUsed = HeapImpl.getAccounting().getEdenUsedBytes();
UnsignedWord edenUsed = HeapImpl.getAccounting().getEdenUsedBytes().add(allocationSize);
return edenUsed.aboveOrEqual(edenSize);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ protected static UnsignedWord m(long bytes) {
}

@Override
public boolean shouldCollectOnAllocation() {
UnsignedWord youngUsed = HeapImpl.getAccounting().getYoungUsedBytes();
public boolean shouldCollectOnAllocation(UnsignedWord allocationSize) {
UnsignedWord youngUsed = HeapImpl.getAccounting().getYoungUsedBytes().add(allocationSize);
return youngUsed.aboveOrEqual(getMaximumYoungGenerationSize());
}

Expand Down Expand Up @@ -243,7 +243,7 @@ public String getName() {
public static final class NeverCollect extends BasicPolicy {

@Override
public boolean shouldCollectOnAllocation() {
public boolean shouldCollectOnAllocation(UnsignedWord allocationSize) {
throw VMError.shouldNotReachHere("Caller is supposed to be aware of never-collect policy");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static boolean shouldCollectYoungGenSeparately(boolean defaultValue) {
* {@code true} will initiate a safepoint during which {@link #shouldCollectCompletely} will be
* called followed by the collection.
*/
boolean shouldCollectOnAllocation();
boolean shouldCollectOnAllocation(UnsignedWord allocationSize);

/**
* Called when an application provides a hint to the GC that it might be a good time to do a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void maybeCollectOnAllocation(UnsignedWord allocationSize) {
if (hasNeverCollectPolicy()) {
UnsignedWord edenUsed = HeapImpl.getAccounting().getEdenUsedBytes();
outOfMemory = edenUsed.aboveThan(GCImpl.getPolicy().getMaximumHeapSize());
} else if (getPolicy().shouldCollectOnAllocation()) {
} else if (getPolicy().shouldCollectOnAllocation(allocationSize)) {
AllocationRequiringGCEvent.emit(getCollectionEpoch(), allocationSize);
outOfMemory = collectWithoutAllocating(GenScavengeGCCause.OnAllocation, false);
}
Expand Down

0 comments on commit a969e13

Please sign in to comment.