From cb4d86ef6f476a852c33f14b420c48177139f337 Mon Sep 17 00:00:00 2001 From: wanxiaoqing Date: Tue, 19 Dec 2023 16:43:27 +0800 Subject: [PATCH 1/2] Revert "revert the implement of GetHeapUsedSize" This reverts commit e57ffa73a32fca9a30a6717042d4d1fa5521c11f. Signed-off-by: wanxiaoqing --- ecmascript/napi/dfx_jsnapi.cpp | 2 +- ecmascript/napi/test/dfx_jsnapi_tests.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ecmascript/napi/dfx_jsnapi.cpp b/ecmascript/napi/dfx_jsnapi.cpp index adeca9c896..4f377e1e9e 100644 --- a/ecmascript/napi/dfx_jsnapi.cpp +++ b/ecmascript/napi/dfx_jsnapi.cpp @@ -249,7 +249,7 @@ size_t DFXJSNApi::GetHeapTotalSize(const EcmaVM *vm) size_t DFXJSNApi::GetHeapUsedSize(const EcmaVM *vm) { - return vm->GetHeap()->GetHeapObjectSize(); + return vm->GetHeap()->GetLiveObjectSize(); } size_t DFXJSNApi::GetHeapLimitSize(const EcmaVM *vm) diff --git a/ecmascript/napi/test/dfx_jsnapi_tests.cpp b/ecmascript/napi/test/dfx_jsnapi_tests.cpp index 1b4ac07949..dc2ad88cb2 100644 --- a/ecmascript/napi/test/dfx_jsnapi_tests.cpp +++ b/ecmascript/napi/test/dfx_jsnapi_tests.cpp @@ -284,7 +284,7 @@ HWTEST_F_L0(DFXJSNApiTests, GetArrayBufferSize_GetHeapTotalSize_GetHeapUsedSize) EXPECT_EQ(heapTotalSize, expectHeapTotalSize); size_t heapUsedSize = DFXJSNApi::GetHeapUsedSize(vm_); - size_t expectHeapUsedSize = heap->GetHeapObjectSize(); + size_t expectHeapUsedSize = heap->GetLiveObjectSize(); EXPECT_EQ(heapUsedSize, expectHeapUsedSize); } -- Gitee From 1c614bc8375785f470d166fb3915be7ac6e433cd Mon Sep 17 00:00:00 2001 From: wanxiaoqing Date: Tue, 19 Dec 2023 16:44:37 +0800 Subject: [PATCH 2/2] Revert "complete native size check machanism" This reverts commit fee8541c2a172be668497f0f259f1a6ef175210a. Signed-off-by: wanxiaoqing --- ecmascript/dfx/hprof/heap_profiler.cpp | 4 ++-- ecmascript/mem/heap.cpp | 13 +------------ ecmascript/mem/heap.h | 1 - ecmascript/mem/mem.h | 1 - ecmascript/napi/dfx_jsnapi.cpp | 2 +- ecmascript/napi/test/dfx_jsnapi_tests.cpp | 2 +- ecmascript/object_factory-inl.h | 3 --- ecmascript/tests/gc_test.cpp | 22 +++++++++++----------- 8 files changed, 16 insertions(+), 32 deletions(-) diff --git a/ecmascript/dfx/hprof/heap_profiler.cpp b/ecmascript/dfx/hprof/heap_profiler.cpp index e974502955..733ce8e425 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 fd9035deb8..11d9bc788c 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 f3245b1052..f48e44412a 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 55732c0597..da6311a0d5 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/napi/dfx_jsnapi.cpp b/ecmascript/napi/dfx_jsnapi.cpp index 4f377e1e9e..adeca9c896 100644 --- a/ecmascript/napi/dfx_jsnapi.cpp +++ b/ecmascript/napi/dfx_jsnapi.cpp @@ -249,7 +249,7 @@ size_t DFXJSNApi::GetHeapTotalSize(const EcmaVM *vm) size_t DFXJSNApi::GetHeapUsedSize(const EcmaVM *vm) { - return vm->GetHeap()->GetLiveObjectSize(); + return vm->GetHeap()->GetHeapObjectSize(); } size_t DFXJSNApi::GetHeapLimitSize(const EcmaVM *vm) diff --git a/ecmascript/napi/test/dfx_jsnapi_tests.cpp b/ecmascript/napi/test/dfx_jsnapi_tests.cpp index dc2ad88cb2..1b4ac07949 100644 --- a/ecmascript/napi/test/dfx_jsnapi_tests.cpp +++ b/ecmascript/napi/test/dfx_jsnapi_tests.cpp @@ -284,7 +284,7 @@ HWTEST_F_L0(DFXJSNApiTests, GetArrayBufferSize_GetHeapTotalSize_GetHeapUsedSize) EXPECT_EQ(heapTotalSize, expectHeapTotalSize); size_t heapUsedSize = DFXJSNApi::GetHeapUsedSize(vm_); - size_t expectHeapUsedSize = heap->GetLiveObjectSize(); + size_t expectHeapUsedSize = heap->GetHeapObjectSize(); EXPECT_EQ(heapUsedSize, expectHeapUsedSize); } diff --git a/ecmascript/object_factory-inl.h b/ecmascript/object_factory-inl.h index 8220335f84..0f9a898c17 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 d70df854d3..6f5fa4b2eb 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(); -- Gitee