Force Full GC in case of failed Old GC

Description: Start Full GC after failed Old in case
old space exceed capacity to avoid OOM exception

Issue: #IAFD1D

Signed-off-by: Panferov Ivan <panferov.ivan@huawei-partners.com>
This commit is contained in:
Panferov Ivan 2024-07-24 21:09:46 +08:00
parent b5a45212f5
commit 6160920e02
4 changed files with 33 additions and 5 deletions

View File

@ -898,6 +898,11 @@ void Heap::EnableParallelGC()
TriggerGCType Heap::SelectGCType() const
{
if (shouldThrowOOMError_) {
// Force Full GC after failed Old GC to avoid OOM
return FULL_GC;
}
// If concurrent mark is enabled, the TryTriggerConcurrentMarking decide which GC to choose.
if (concurrentMarker_->IsEnabled() && !thread_->IsReadyToConcurrentMark()) {
return YOUNG_GC;
@ -1069,11 +1074,14 @@ void Heap::CollectGarbage(TriggerGCType gcType, GCReason reason)
CheckNonMovableSpaceOOM();
}
// OOMError object is not allowed to be allocated during gc process, so throw OOMError after gc
if (shouldThrowOOMError_) {
if (shouldThrowOOMError_ && gcType_ == TriggerGCType::FULL_GC) {
sweeper_->EnsureAllTaskFinished();
DumpHeapSnapshotBeforeOOM(false);
StatisticHeapDetail();
ThrowOutOfMemoryError(thread_, oldSpace_->GetMergeSize(), " OldSpace::Merge");
oldSpace_->ResetCommittedOverSizeLimit();
if (oldSpace_->CommittedSizeExceed()) {
DumpHeapSnapshotBeforeOOM(false);
StatisticHeapDetail();
ThrowOutOfMemoryError(thread_, oldSpace_->GetMergeSize(), " OldSpace::Merge");
}
oldSpace_->ResetMergeSize();
shouldThrowOOMError_ = false;
}

View File

@ -183,6 +183,12 @@ public:
outOfMemoryOvershootSize_ += size;
}
void DecreaseOutOfMemoryOvershootSize(size_t size)
{
ASSERT(outOfMemoryOvershootSize_ >= size);
outOfMemoryOvershootSize_ -= size;
}
MemSpaceType GetSpaceType() const
{
return spaceType_;

View File

@ -433,8 +433,10 @@ void OldSpace::Merge(LocalSpace *localSpace)
localHeap_->ShouldThrowOOMError(true);
}
IncreaseMergeSize(committedSize_ - oldCommittedSize);
size_t committedOverSizeLimit = committedSize_ + hugeSpaceCommitSize - GetOverShootMaximumCapacity();
IncreaseCommittedOverSizeLimit(committedOverSizeLimit);
// if throw OOM, temporarily increase space size to avoid vm crash
IncreaseOutOfMemoryOvershootSize(committedSize_ + hugeSpaceCommitSize - GetOverShootMaximumCapacity());
IncreaseOutOfMemoryOvershootSize(committedOverSizeLimit);
}
localSpace->GetRegionList().Clear();

View File

@ -223,6 +223,17 @@ public:
mergeSize_ = 0;
}
void IncreaseCommittedOverSizeLimit(size_t size)
{
committedOverSizeLimit_ += size;
}
void ResetCommittedOverSizeLimit()
{
DecreaseOutOfMemoryOvershootSize(committedOverSizeLimit_);
committedOverSizeLimit_ = 0;
}
template<class Callback>
void EnumerateCollectRegionSet(const Callback &cb) const
{
@ -249,6 +260,7 @@ private:
CVector<Region *> collectRegionSet_;
Mutex lock_;
size_t mergeSize_ {0};
size_t committedOverSizeLimit_ {0};
};
class NonMovableSpace : public SparseSpace {