From c010d3e4db5237efb6686e5189c3a0a646029bee Mon Sep 17 00:00:00 2001 From: yangxiaoshuai2022 Date: Mon, 11 Aug 2025 17:19:24 +0800 Subject: [PATCH] DumpHeapSnapshotBeforeOOM do not trigger GC Signed-off-by: yangxiaoshuai2022 Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICSEO6 --- .../dfx/hprof/heap_profiler_interface.cpp | 2 +- ecmascript/mem/heap-inl.h | 8 ++++---- ecmascript/mem/heap.cpp | 20 +++++++++---------- ecmascript/mem/heap.h | 4 ++-- ecmascript/serializer/base_deserializer.h | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ecmascript/dfx/hprof/heap_profiler_interface.cpp b/ecmascript/dfx/hprof/heap_profiler_interface.cpp index bcedb14608..9ea6a21e34 100644 --- a/ecmascript/dfx/hprof/heap_profiler_interface.cpp +++ b/ecmascript/dfx/hprof/heap_profiler_interface.cpp @@ -49,7 +49,7 @@ void panda::ecmascript::HeapProfilerInterface::DumpHeapSnapshotForCMCOOM(void *t auto appfreezeCallback = Runtime::GetInstance()->GetAppFreezeFilterCallback(); if (appfreezeCallback != nullptr && !appfreezeCallback(getprocpid(), true)) { - LOG_ECMA(INFO) << "DumpHeapSnapshotBeforeOOM, no dump quota."; + LOG_ECMA(INFO) << "DumpHeapSnapshotForCMCOOM, no dump quota."; return; } diff --git a/ecmascript/mem/heap-inl.h b/ecmascript/mem/heap-inl.h index d23628c2ce..1f53da3e0b 100644 --- a/ecmascript/mem/heap-inl.h +++ b/ecmascript/mem/heap-inl.h @@ -50,7 +50,7 @@ namespace panda::ecmascript { size_t oomOvershootSize = vm->GetEcmaParamConfiguration().GetOutOfMemoryOvershootSize(); \ (space)->IncreaseOutOfMemoryOvershootSize(oomOvershootSize); \ if ((space)->IsOOMDumpSpace()) { \ - DumpHeapSnapshotBeforeOOM(false); \ + DumpHeapSnapshotBeforeOOM(); \ } \ StatisticHeapDetail(); \ ThrowOutOfMemoryError(GetJSThread(), size, message); \ @@ -61,7 +61,7 @@ namespace panda::ecmascript { if (UNLIKELY((object) == nullptr)) { \ size_t oomOvershootSize = GetEcmaParamConfiguration().GetOutOfMemoryOvershootSize(); \ (space)->IncreaseOutOfMemoryOvershootSize(oomOvershootSize); \ - DumpHeapSnapshotBeforeOOM(false, thread, SharedHeapOOMSource::NORMAL_ALLOCATION); \ + DumpHeapSnapshotBeforeOOM(thread, SharedHeapOOMSource::NORMAL_ALLOCATION); \ ThrowOutOfMemoryError(thread, size, message); \ (object) = reinterpret_cast((space)->Allocate(thread, size)); \ } @@ -537,7 +537,7 @@ TaggedObject *Heap::AllocateHugeObject(size_t size) // if allocate huge object OOM, temporarily increase space size to avoid vm crash size_t oomOvershootSize = config_.GetOutOfMemoryOvershootSize(); oldSpace_->IncreaseOutOfMemoryOvershootSize(oomOvershootSize); - DumpHeapSnapshotBeforeOOM(false); + DumpHeapSnapshotBeforeOOM(); StatisticHeapDetail(); object = reinterpret_cast(hugeObjectSpace_->Allocate(size, thread_)); ThrowOutOfMemoryError(thread_, size, "Heap::AllocateHugeObject"); @@ -1128,7 +1128,7 @@ TaggedObject *SharedHeap::AllocateHugeObject(JSThread *thread, size_t size) // if allocate huge object OOM, temporarily increase space size to avoid vm crash size_t oomOvershootSize = config_.GetOutOfMemoryOvershootSize(); sHugeObjectSpace_->IncreaseOutOfMemoryOvershootSize(oomOvershootSize); - DumpHeapSnapshotBeforeOOM(false, thread, SharedHeapOOMSource::NORMAL_ALLOCATION); + DumpHeapSnapshotBeforeOOM(thread, SharedHeapOOMSource::NORMAL_ALLOCATION); ThrowOutOfMemoryError(thread, size, "SharedHeap::AllocateHugeObject"); object = reinterpret_cast(sHugeObjectSpace_->Allocate(thread, size)); if (UNLIKELY(object == nullptr)) { diff --git a/ecmascript/mem/heap.cpp b/ecmascript/mem/heap.cpp index 9c1af4436a..9c1bc4066e 100644 --- a/ecmascript/mem/heap.cpp +++ b/ecmascript/mem/heap.cpp @@ -659,7 +659,7 @@ void SharedHeap::CollectGarbageFinish(bool inDaemon, TriggerGCType gcType) if (shouldThrowOOMError_ || shouldForceThrowOOMError_) { // LocalHeap could do FullGC later instead of Fatal at once if only set `shouldThrowOOMError_` because there // is kind of partial compress GC in LocalHeap, but SharedHeap differs. - DumpHeapSnapshotBeforeOOM(false, Runtime::GetInstance()->GetMainThread(), SharedHeapOOMSource::SHARED_GC); + DumpHeapSnapshotBeforeOOM(Runtime::GetInstance()->GetMainThread(), SharedHeapOOMSource::SHARED_GC); LOG_GC(FATAL) << "SharedHeap OOM"; UNREACHABLE(); } @@ -785,7 +785,7 @@ void SharedHeap::ReclaimForAppSpawn() sHugeObjectSpace_->EnumerateRegions(cb); } -void SharedHeap::DumpHeapSnapshotBeforeOOM([[maybe_unused]]bool isFullGC, [[maybe_unused]]JSThread *thread, +void SharedHeap::DumpHeapSnapshotBeforeOOM([[maybe_unused]]JSThread *thread, [[maybe_unused]] SharedHeapOOMSource source) { #if defined(ECMASCRIPT_SUPPORT_SNAPSHOT) && defined(ENABLE_DUMP_IN_FAULTLOG) @@ -813,7 +813,7 @@ void SharedHeap::DumpHeapSnapshotBeforeOOM([[maybe_unused]]bool isFullGC, [[mayb heapProfile = HeapProfilerInterface::GetInstance(vm); } // Filter appfreeze when dump. - LOG_ECMA(INFO) << "SharedHeap::DumpHeapSnapshotBeforeOOM, isFullGC = " << isFullGC; + LOG_ECMA(INFO) << "SharedHeap::DumpHeapSnapshotBeforeOOM, trigger oom dump"; base::BlockHookScope blockScope; vm->GetEcmaGCKeyStats()->SendSysEventBeforeDump("OOMDump", GetEcmaParamConfiguration().GetMaxHeapSize(), GetHeapObjectSize()); @@ -822,7 +822,7 @@ void SharedHeap::DumpHeapSnapshotBeforeOOM([[maybe_unused]]bool isFullGC, [[mayb dumpOption.isVmMode = true; dumpOption.isPrivate = false; dumpOption.captureNumericValue = false; - dumpOption.isFullGC = isFullGC; + dumpOption.isFullGC = false; dumpOption.isSimplify = true; dumpOption.isSync = true; dumpOption.isBeforeFill = false; @@ -1419,7 +1419,7 @@ void Heap::CollectGarbageImpl(TriggerGCType gcType, GCReason reason) oldSpace_->ResetCommittedOverSizeLimit(); if (oldSpace_->CommittedSizeExceed()) { // LCOV_EXCL_BR_LINE sweeper_->EnsureAllTaskFinished(); - DumpHeapSnapshotBeforeOOM(false); + DumpHeapSnapshotBeforeOOM(); StatisticHeapDetail(); ThrowOutOfMemoryError(thread_, oldSpace_->GetMergeSize(), " OldSpace::Merge"); } @@ -1429,7 +1429,7 @@ void Heap::CollectGarbageImpl(TriggerGCType gcType, GCReason reason) // Allocate region failed during GC, MUST throw OOM here if (shouldForceThrowOOMError_) { sweeper_->EnsureAllTaskFinished(); - DumpHeapSnapshotBeforeOOM(false); + DumpHeapSnapshotBeforeOOM(); StatisticHeapDetail(); ThrowOutOfMemoryError(thread_, DEFAULT_REGION_SIZE, " HeapRegionAllocator::AllocateAlignedRegion"); } @@ -1563,7 +1563,7 @@ void Heap::CheckNonMovableSpaceOOM() { if (nonMovableSpace_->GetHeapObjectSize() > MAX_NONMOVABLE_LIVE_OBJ_SIZE) { // LCOV_EXCL_BR_LINE sweeper_->EnsureAllTaskFinished(); - DumpHeapSnapshotBeforeOOM(false); + DumpHeapSnapshotBeforeOOM(); StatisticHeapDetail(); ThrowOutOfMemoryError(thread_, nonMovableSpace_->GetHeapObjectSize(), "Heap::CheckNonMovableSpaceOOM", true); } @@ -1700,7 +1700,7 @@ void BaseHeap::OnAllocateEvent([[maybe_unused]] EcmaVM *ecmaVm, [[maybe_unused]] #endif } -void Heap::DumpHeapSnapshotBeforeOOM([[maybe_unused]] bool isFullGC) +void Heap::DumpHeapSnapshotBeforeOOM() { #if defined(ECMASCRIPT_SUPPORT_SNAPSHOT) && defined(ENABLE_DUMP_IN_FAULTLOG) AppFreezeFilterCallback appfreezeCallback = Runtime::GetInstance()->GetAppFreezeFilterCallback(); @@ -1716,7 +1716,7 @@ void Heap::DumpHeapSnapshotBeforeOOM([[maybe_unused]] bool isFullGC) return; } // Filter appfreeze when dump. - LOG_ECMA(INFO) << " Heap::DumpHeapSnapshotBeforeOOM, isFullGC = " << isFullGC; + LOG_ECMA(INFO) << " Heap::DumpHeapSnapshotBeforeOOM, trigger oom dump"; base::BlockHookScope blockScope; HeapProfilerInterface *heapProfile = HeapProfilerInterface::GetInstance(ecmaVm_); #ifdef ENABLE_HISYSEVENT @@ -1729,7 +1729,7 @@ void Heap::DumpHeapSnapshotBeforeOOM([[maybe_unused]] bool isFullGC) dumpOption.isVmMode = true; dumpOption.isPrivate = false; dumpOption.captureNumericValue = false; - dumpOption.isFullGC = isFullGC; + dumpOption.isFullGC = false; dumpOption.isSimplify = true; dumpOption.isSync = true; dumpOption.isBeforeFill = false; diff --git a/ecmascript/mem/heap.h b/ecmascript/mem/heap.h index ff19871346..bd6db36ec5 100644 --- a/ecmascript/mem/heap.h +++ b/ecmascript/mem/heap.h @@ -892,7 +892,7 @@ public: inline void MergeToOldSpaceSync(SharedLocalSpace *localSpace); - void DumpHeapSnapshotBeforeOOM(bool isFullGC, JSThread *thread, SharedHeapOOMSource source); + void DumpHeapSnapshotBeforeOOM(JSThread *thread, SharedHeapOOMSource source); inline void ProcessSharedNativeDelete(const WeakRootVisitor& visitor); inline void PushToSharedNativePointerList(JSNativePointer* pointer); @@ -1669,7 +1669,7 @@ public: } void CheckNonMovableSpaceOOM(); - void DumpHeapSnapshotBeforeOOM(bool isFullGC = true); + void DumpHeapSnapshotBeforeOOM(); std::tuple CalCallSiteInfo(uintptr_t retAddr) const; MachineCode *GetMachineCodeObject(uintptr_t pc) const; void SetMachineCodeObject(uintptr_t start, uintptr_t end, uintptr_t address) const; diff --git a/ecmascript/serializer/base_deserializer.h b/ecmascript/serializer/base_deserializer.h index 83b1c3c462..fc53a0791a 100644 --- a/ecmascript/serializer/base_deserializer.h +++ b/ecmascript/serializer/base_deserializer.h @@ -185,7 +185,7 @@ private: { if (isShared) { if (dump) { - sheap_->DumpHeapSnapshotBeforeOOM(false, thread_, SharedHeapOOMSource::DESERIALIZE); + sheap_->DumpHeapSnapshotBeforeOOM(thread_, SharedHeapOOMSource::DESERIALIZE); } LOG_ECMA(FATAL) << "BaseDeserializer::OutOfMemory when deserialize shared obj size: " << size << ", old space heap object size: " @@ -201,7 +201,7 @@ private: } else { if (dump) { heap_->StatisticHeapDetail(); - heap_->DumpHeapSnapshotBeforeOOM(false); + heap_->DumpHeapSnapshotBeforeOOM(); } LOG_ECMA(FATAL) << "BaseDeserializer::OutOfMemory when deserialize obj size: " << size << ", old space heap object size: " -- Gitee