diff --git a/ecmascript/dfx/hprof/heap_profiler.cpp b/ecmascript/dfx/hprof/heap_profiler.cpp index e974502955d8d621864f049c2b6e1be35a37b6ad..733ce8e42539b5729dac36ce8c2386ae50b31bf6 100644 --- a/ecmascript/dfx/hprof/heap_profiler.cpp +++ b/ecmascript/dfx/hprof/heap_profiler.cpp @@ -156,10 +156,10 @@ bool HeapProfiler::DumpHeapSnapshot(DumpFormat dumpFormat, Stream *stream, Progr ASSERT(heapClean); } LOG_ECMA(INFO) << "HeapProfiler DumpSnapshot start"; + size_t heapSize = vm_->GetHeap()->GetHeapObjectSize(); + LOG_ECMA(INFO) << "HeapProfiler DumpSnapshot heap size " << heapSize; int32_t heapCount = 0; if (isFullGC) { - size_t heapSize = vm_->GetHeap()->GetLiveObjectSize(); - LOG_ECMA(INFO) << "HeapProfiler DumpSnapshot heap size " << heapSize; heapCount = static_cast(vm_->GetHeap()->GetHeapObjectCount()); if (progress != nullptr) { progress->ReportProgress(0, heapCount); diff --git a/ecmascript/mem/heap.cpp b/ecmascript/mem/heap.cpp index fd9035deb8f8cd7f798725698459c010bbab8508..11d9bc788cedac270ad3ce74754da12394bc61f5 100644 --- a/ecmascript/mem/heap.cpp +++ b/ecmascript/mem/heap.cpp @@ -773,8 +773,7 @@ void Heap::RecomputeLimits() globalSpaceAllocLimit_ = newGlobalSpaceLimit; oldSpace_->SetInitialCapacity(newOldSpaceLimit); globalSpaceNativeLimit_ = memController_->CalculateAllocLimit(GetGlobalNativeSize(), MIN_HEAP_SIZE, - MAX_GLOBAL_NATIVE_LIMIT, newSpaceCapacity, - growingFactor); + maxGlobalSize, newSpaceCapacity, growingFactor); OPTIONAL_LOG(ecmaVm_, INFO) << "RecomputeLimits oldSpaceAllocLimit_: " << newOldSpaceLimit << " globalSpaceAllocLimit_: " << globalSpaceAllocLimit_ << " globalSpaceNativeLimit_:" << globalSpaceNativeLimit_; @@ -1373,16 +1372,6 @@ size_t Heap::GetArrayBufferSize() const return result; } -size_t Heap::GetLiveObjectSize() const -{ - size_t objectSize = 0; - sweeper_->EnsureAllTaskFinished(); - this->IterateOverObjects([&objectSize]([[maybe_unused]] TaggedObject *obj) { - objectSize += obj->GetClass()->SizeFromJSHClass(obj); - }); - return objectSize; -} - size_t Heap::GetHeapLimitSize() const { // Obtains the theoretical upper limit of space that can be allocated to JS heap. diff --git a/ecmascript/mem/heap.h b/ecmascript/mem/heap.h index f3245b1052b5c07830852d7c948147731c47091b..f48e44412ac78b92c835765666ac050b749fab19 100644 --- a/ecmascript/mem/heap.h +++ b/ecmascript/mem/heap.h @@ -389,7 +389,6 @@ public: inline size_t GetCommittedSize() const; inline size_t GetHeapObjectSize() const; - size_t GetLiveObjectSize() const; inline uint32_t GetHeapObjectCount() const; diff --git a/ecmascript/mem/mem.h b/ecmascript/mem/mem.h index 55732c0597cf8b95b661117e75301a4862f9f0cb..da6311a0d5bae8b8d4c872a5f6e43e9c2a63aa02 100644 --- a/ecmascript/mem/mem.h +++ b/ecmascript/mem/mem.h @@ -46,7 +46,6 @@ static constexpr size_t MIN_MEM_POOL_CAPACITY = 64_MB; static constexpr size_t WORKER_NUM = 8; static constexpr size_t PHY_SIZE_MULTIPLE = WORKER_NUM + 1; static constexpr size_t STANDARD_POOL_SIZE = WORKER_NUM * DEFAULT_WORKER_HEAP_SIZE + DEFAULT_HEAP_SIZE; -static constexpr size_t MAX_GLOBAL_NATIVE_LIMIT = 2048_MB; static constexpr size_t MIN_OLD_SPACE_LIMIT = 2_MB; diff --git a/ecmascript/object_factory-inl.h b/ecmascript/object_factory-inl.h index 8220335f84fd20a94418a5d0a816a40b9872ae28..0f9a898c170fb1170581ad6f5f3971bf4697f381 100644 --- a/ecmascript/object_factory-inl.h +++ b/ecmascript/object_factory-inl.h @@ -94,9 +94,6 @@ JSHandle ObjectFactory::NewJSNativePointer(void *externalPointe if (callBack != nullptr) { heap_->IncreaseNativeBindingSize(nativeBindingsize); vm_->PushToNativePointerList(static_cast(header)); - // In some cases, the size of JS/TS object is too small and the native binding size is too large. - // Check and try trigger concurrent mark here. - heap_->TryTriggerFullMarkByNativeSize(); } return obj; } diff --git a/ecmascript/tests/gc_test.cpp b/ecmascript/tests/gc_test.cpp index d70df854d3d38f9641de1ac600c2b36c4b432eba..6f5fa4b2ebe291d38138f4fdfe89a6f0c4db79e9 100644 --- a/ecmascript/tests/gc_test.cpp +++ b/ecmascript/tests/gc_test.cpp @@ -182,7 +182,7 @@ HWTEST_F_L0(GCTest, NativeBindingCheckGCTest) { auto heap = const_cast(thread->GetEcmaVM()->GetHeap()); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - heap->CollectGarbage(TriggerGCType::FULL_GC); + heap->CollectGarbage(TriggerGCType::OLD_GC); size_t oldNativeSize = heap->GetNativeBindingSize(); size_t newNativeSize = heap->GetNativeBindingSize(); { @@ -199,17 +199,16 @@ HWTEST_F_L0(GCTest, NativeBindingCheckGCTest) EXPECT_TRUE(newNativeSize - oldNativeSize > 0); EXPECT_TRUE(newNativeSize - oldNativeSize <= 2 * 1024 *1024); - for (int i = 0; i < 2048; i++) { - auto newData2 = thread->GetEcmaVM()->GetNativeAreaAllocator()->AllocateBuffer(1 * 1024 * 1024); + for (int i = 0; i < 300; i++) { + auto newData2 = thread->GetEcmaVM()->GetNativeAreaAllocator()->AllocateBuffer(1024); // malloc size is smaller to avoid test fail in the small devices. [[maybe_unused]] JSHandle obj3 = factory->NewJSNativePointer(newData2, NativeAreaAllocator::FreeBufferFunc, nullptr, true, 1 * 1024 * 1024); } - newNativeSize = heap->GetNativeBindingSize(); // Old GC should be trigger here, so the size should be reduced. - EXPECT_TRUE(newNativeSize - oldNativeSize < 2048 * 1024 *1024); + EXPECT_TRUE(newNativeSize - oldNativeSize < 256 * 1024 *1024); } - heap->CollectGarbage(TriggerGCType::FULL_GC); + heap->CollectGarbage(TriggerGCType::OLD_GC); newNativeSize = heap->GetNativeBindingSize(); EXPECT_EQ(newNativeSize - oldNativeSize, 0UL); } @@ -237,11 +236,13 @@ HWTEST_F_L0(GCTest, NativeGCTestConcurrentMarkDisabled) EXPECT_TRUE(newNativeSize - oldNativeSize > 0); EXPECT_TRUE(newNativeSize - oldNativeSize <= 2 * 1024 *1024); - for (int i = 0; i < 2048; i++) { + for (int i = 0; i < 20; i++) { auto newData2 = thread->GetEcmaVM()->GetNativeAreaAllocator()->AllocateBuffer(1 * 1024 * 1024); [[maybe_unused]] JSHandle obj3 = factory->NewJSNativePointer(newData2, NativeAreaAllocator::FreeBufferFunc, nullptr, false, 1 * 1024 * 1024); } + // Young GC should be trigger here, so the size should be reduced. + EXPECT_TRUE(newNativeSize - oldNativeSize < 22 * 1024 *1024); } const_cast(thread->GetEcmaVM()->GetHeap())->CollectGarbage(TriggerGCType::OLD_GC); newNativeSize = heap->GetNativeBindingSize(); @@ -270,15 +271,14 @@ HWTEST_F_L0(GCTest, NonNewSpaceNativeGCTestConcurrentMarkDisabled) EXPECT_TRUE(newNativeSize - oldNativeSize > 0); EXPECT_TRUE(newNativeSize - oldNativeSize <= 2 * 1024 *1024); - for (int i = 0; i < 2048; i++) { - auto newData2 = thread->GetEcmaVM()->GetNativeAreaAllocator()->AllocateBuffer(1 * 1024 * 1024); + for (int i = 0; i < 300; i++) { + auto newData2 = thread->GetEcmaVM()->GetNativeAreaAllocator()->AllocateBuffer(1024); // malloc size is smaller to avoid test fail in the small devices. [[maybe_unused]] JSHandle obj3 = factory->NewJSNativePointer(newData2, NativeAreaAllocator::FreeBufferFunc, nullptr, true, 1 * 1024 * 1024); } - newNativeSize = heap->GetNativeBindingSize(); // Old GC should be trigger here, so the size should be reduced. - EXPECT_TRUE(newNativeSize - oldNativeSize < 2048 * 1024 *1024); + EXPECT_TRUE(newNativeSize - oldNativeSize < 256 * 1024 *1024); } const_cast(thread->GetEcmaVM()->GetHeap())->CollectGarbage(TriggerGCType::OLD_GC); newNativeSize = heap->GetNativeBindingSize();