From 84738d1845447c8f7b208232da5783844e569cb2 Mon Sep 17 00:00:00 2001 From: xiongluo Date: Sat, 26 Oct 2024 20:51:57 +0800 Subject: [PATCH] Trigger concurrent mark for sensitive near limit Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IAZZHQ?from=project-issue Signed-off-by: xiongluo Change-Id: I6451a886976f8ba1428536c4b6c38e73382cb40a --- ecmascript/mem/heap.cpp | 14 ++++++++++---- ecmascript/mem/heap.h | 12 ++++++++++++ ecmascript/mem/linear_space.cpp | 10 ++++++---- ecmascript/mem/partial_gc.cpp | 3 +++ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/ecmascript/mem/heap.cpp b/ecmascript/mem/heap.cpp index 92761543d5..1e3592362c 100644 --- a/ecmascript/mem/heap.cpp +++ b/ecmascript/mem/heap.cpp @@ -2336,13 +2336,19 @@ bool Heap::NeedStopCollection() if (OnStartupEvent() && !ObjectExceedMaxHeapSize()) { return true; } - - if (GetRecordHeapObjectSizeBeforeSensitive() == 0) { - SetRecordHeapObjectSizeBeforeSensitive(GetHeapObjectSize()); + size_t objSize = GetHeapObjectSize(); + size_t recordSizeBeforeSensitive = GetRecordHeapObjectSizeBeforeSensitive(); + if (recordSizeBeforeSensitive == 0) { + SetRecordHeapObjectSizeBeforeSensitive(objSize); } - if (GetHeapObjectSize() < GetRecordHeapObjectSizeBeforeSensitive() + config_.GetIncObjSizeThresholdInSensitive() + if (objSize < recordSizeBeforeSensitive + config_.GetIncObjSizeThresholdInSensitive() && !ObjectExceedMaxHeapSize()) { + if (!IsNearGCInSensitive() && + objSize > (recordSizeBeforeSensitive + config_.GetIncObjSizeThresholdInSensitive()) + * MIN_OBJECT_SURVIVAL_RATE) { + SetNearGCInSensitive(true); + } return true; } diff --git a/ecmascript/mem/heap.h b/ecmascript/mem/heap.h index 4f18fcc2f5..bcd44f4061 100644 --- a/ecmascript/mem/heap.h +++ b/ecmascript/mem/heap.h @@ -1338,6 +1338,16 @@ public: return recordObjSizeBeforeSensitive_; } + void SetNearGCInSensitive(bool flag) + { + nearGCInSensitive_ = flag; + } + + bool IsNearGCInSensitive() + { + return nearGCInSensitive_; + } + bool CASSensitiveStatus(AppSensitiveStatus expect, AppSensitiveStatus status) { return smartGCStats_.sensitiveStatus_.compare_exchange_strong(expect, status, std::memory_order_seq_cst); @@ -1752,6 +1762,8 @@ private: size_t recordNativeSize_ {0}; // Record heap object size before enter sensitive status size_t recordObjSizeBeforeSensitive_ {0}; + bool nearGCInSensitive_ {false}; + size_t pendingAsyncNativeCallbackSize_ {0}; MemGrowingType memGrowingtype_ {MemGrowingType::HIGH_THROUGHPUT}; diff --git a/ecmascript/mem/linear_space.cpp b/ecmascript/mem/linear_space.cpp index adcc16273b..8d38b33683 100644 --- a/ecmascript/mem/linear_space.cpp +++ b/ecmascript/mem/linear_space.cpp @@ -47,10 +47,12 @@ uintptr_t LinearSpace::Allocate(size_t size, bool isPromoted) return object; } if (Expand(isPromoted)) { - if (!isPromoted && !localHeap_->NeedStopCollection()) { - localHeap_->TryTriggerIncrementalMarking(); - localHeap_->TryTriggerIdleCollection(); - localHeap_->TryTriggerConcurrentMarking(); + if (!isPromoted) { + if (!localHeap_->NeedStopCollection() || localHeap_->IsNearGCInSensitive()) { + localHeap_->TryTriggerIncrementalMarking(); + localHeap_->TryTriggerIdleCollection(); + localHeap_->TryTriggerConcurrentMarking(); + } } object = allocator_.Allocate(size); } else if (localHeap_->IsMarking() || !localHeap_->IsEmptyIdleTask()) { diff --git a/ecmascript/mem/partial_gc.cpp b/ecmascript/mem/partial_gc.cpp index 2cabf968e2..fca684698b 100644 --- a/ecmascript/mem/partial_gc.cpp +++ b/ecmascript/mem/partial_gc.cpp @@ -110,6 +110,9 @@ void PartialGC::Finish() heap_->GetSweeper()->TryFillSweptRegion(); heap_->SetFullMarkRequestedState(false); } + if (heap_->IsNearGCInSensitive()) { + heap_->SetNearGCInSensitive(false); + } } void PartialGC::Mark() -- Gitee