From b7da85930b07828e26461883908171d8ba1bbb44 Mon Sep 17 00:00:00 2001 From: wangzhaoyong Date: Sat, 30 Oct 2021 17:18:14 +0800 Subject: [PATCH 1/2] [[GC Threshold]] Signed-off-by: wangzhaoyong Change-Id: I9a21ae4a6300dabdfb549e5a4e2eda87cc4da3dc --- ecmascript/ecma_vm.cpp | 12 ++++++++++++ ecmascript/ecma_vm.h | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/ecmascript/ecma_vm.cpp b/ecmascript/ecma_vm.cpp index 761862a892..4cd073332f 100644 --- a/ecmascript/ecma_vm.cpp +++ b/ecmascript/ecma_vm.cpp @@ -193,6 +193,18 @@ bool EcmaVM::Initialize() InitializeFinish(); notificationManager_->VmStartEvent(); notificationManager_->VmInitializationEvent(0); + Platform::GetCurrentPlatform()->PostTask(std::make_unique(heap_)); + return true; +} + +bool EcmaVM::TrimNewSpaceLimitTask::Run() +{ + sleep(THREAD_SLEEP_TIME); + if (heap_->GetMemController()->IsInAppStartup()) { + heap_->SetFromSpaceMaximumCapacity(SEMI_SPACE_SIZE_CAPACITY); + heap_->SetNewSpaceMaximumCapacity(SEMI_SPACE_SIZE_CAPACITY); + heap_->ResetAppStartup(); + } return true; } diff --git a/ecmascript/ecma_vm.h b/ecmascript/ecma_vm.h index d100ccfdba..bbf496dfe8 100644 --- a/ecmascript/ecma_vm.h +++ b/ecmascript/ecma_vm.h @@ -32,6 +32,7 @@ #include "ecmascript/mem/heap.h" #include "ecmascript/mem/heap_roots.h" #include "ecmascript/mem/space.h" +#include "ecmascript/platform/task.h" #include "ecmascript/snapshot/mem/snapshot_serialize.h" #include "ecmascript/tooling/pt_js_extractor.h" #include "include/panda_vm.h" @@ -362,6 +363,20 @@ protected: void PrintJSErrorInfo(const JSHandle &exceptionInfo); private: + static constexpr uint32_t THREAD_SLEEP_TIME = 2; + class TrimNewSpaceLimitTask : public Task { + public: + TrimNewSpaceLimitTask(Heap *heap) : heap_(heap) {}; + ~TrimNewSpaceLimitTask() override = default; + bool Run() override; + + NO_COPY_SEMANTIC(TrimNewSpaceLimitTask); + NO_MOVE_SEMANTIC(TrimNewSpaceLimitTask); + + private: + Heap *heap_; + }; + void AddPandaFile(const panda_file::File *pf, bool isModule); void SetProgram(Program *program, const panda_file::File *pf); bool IsFrameworkPandaFile(std::string_view filename) const; -- Gitee From a3d72dd271ccc99a3bcb9e4a62e3f724c7c05708 Mon Sep 17 00:00:00 2001 From: wangzhaoyong Date: Sat, 30 Oct 2021 17:26:33 +0800 Subject: [PATCH 2/2] [[Set GC]] Signed-off-by: wangzhaoyong Change-Id: I5805aa688806c004669e8a66821a3e4e84983f85 --- ecmascript/ecma_vm.cpp | 9 +++++++++ ecmascript/ecma_vm.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/ecmascript/ecma_vm.cpp b/ecmascript/ecma_vm.cpp index 4cd073332f..d9f8698996 100644 --- a/ecmascript/ecma_vm.cpp +++ b/ecmascript/ecma_vm.cpp @@ -208,6 +208,15 @@ bool EcmaVM::TrimNewSpaceLimitTask::Run() return true; } +void EcmaVM::TurnDownLimit() { + sleep(THREAD_SLEEP_TIME); + if (heap_->GetMemController()->IsInAppStartup()) { + heap_->SetFromSpaceMaximumCapacity(SEMI_SPACE_SIZE_CAPACITY); + heap_->SetNewSpaceMaximumCapacity(SEMI_SPACE_SIZE_CAPACITY); + heap_->ResetAppStartup(); + } +} + void EcmaVM::InitializeEcmaScriptRunStat() { // NOLINTNEXTLINE(modernize-avoid-c-arrays) diff --git a/ecmascript/ecma_vm.h b/ecmascript/ecma_vm.h index bbf496dfe8..c7b88d2da6 100644 --- a/ecmascript/ecma_vm.h +++ b/ecmascript/ecma_vm.h @@ -447,6 +447,8 @@ private: CVector arrayBufferDataList_; CVector> pandaFileWithProgram_; + std::vector> asyncTask_ {}; + friend class SnapShotSerialize; friend class ObjectFactory; friend class ValueSerializer; -- Gitee