From e8c5e572254c2c0a2691e320d09e207e039e1c66 Mon Sep 17 00:00:00 2001 From: Pavel Andrianov Date: Mon, 25 Jul 2022 15:21:31 +0300 Subject: [PATCH 1/3] Thread manager refactoring To avoid different templates for single- and multithreading thread manager we refactored it and extracted a generic interface and two two implementations: for single thread mode and multi thread mode. Signed-off-by: Pavel Andrianov --- runtime/ecma_vm.cpp | 31 ++----------------------------- runtime/ecma_vm.h | 16 +++++----------- 2 files changed, 7 insertions(+), 40 deletions(-) diff --git a/runtime/ecma_vm.cpp b/runtime/ecma_vm.cpp index 8d20bfa02..8167b8822 100644 --- a/runtime/ecma_vm.cpp +++ b/runtime/ecma_vm.cpp @@ -83,34 +83,6 @@ static const std::string_view ENTRY_POINTER = "_GLOBAL::func_main_0"; static const std::string_view ENTRY_METHOD_POINTER = "func_main_0"; JSRuntimeOptions EcmaVM::options_; // NOLINT(fuchsia-statically-constructed-objects) -void EcmaRendezvous::SafepointBegin() -{ - ASSERT(!GetMutatorLock()->HasLock()); - LOG(DEBUG, GC) << "Rendezvous: SafepointBegin"; - Thread *current = Thread::GetCurrent(); - ManagedThread *main_thread = current->GetVM()->GetAssociatedThread(); - - if (current != main_thread) { - main_thread->SuspendImpl(true); - } - // Acquire write MutatorLock - GetMutatorLock()->WriteLock(); -} - -void EcmaRendezvous::SafepointEnd() -{ - ASSERT(GetMutatorLock()->HasLock()); - LOG(DEBUG, GC) << "Rendezvous: SafepointEnd"; - // Release write MutatorLock - GetMutatorLock()->Unlock(); - Thread *current = Thread::GetCurrent(); - ManagedThread *main_thread = current->GetVM()->GetAssociatedThread(); - if (current != main_thread) { - main_thread->ResumeImpl(true); - } - LOG(DEBUG, GC) << "Rendezvous: SafepointEnd exit"; -} - // Create MemoryManager by RuntimeOptions static mem::MemoryManager *CreateMM(const LanguageContext &ctx, mem::InternalAllocatorPtr internal_allocator, const RuntimeOptions &options) @@ -188,7 +160,8 @@ EcmaVM::EcmaVM(JSRuntimeOptions options) : stringTable_(new EcmaStringTable(this options_ = std::move(options); icEnable_ = options_.IsIcEnable(); optionalLogEnabled_ = options_.IsEnableOptionalLog(); - rendezvous_ = runtime->GetInternalAllocator()->New(this); + thread_manager_ = runtime->GetInternalAllocator()(); + rendezvous_ = runtime->GetInternalAllocator()(this); frameworkAbcFileName_ = options_.GetFrameworkAbcFile(); auto allocator = runtime->GetInternalAllocator(); diff --git a/runtime/ecma_vm.h b/runtime/ecma_vm.h index a625138cd..07ba50864 100644 --- a/runtime/ecma_vm.h +++ b/runtime/ecma_vm.h @@ -29,6 +29,7 @@ #include "plugins/ecmascript/runtime/mem/object_xray.h" #include "plugins/ecmascript/runtime/tooling/pt_js_extractor.h" #include "include/panda_vm.h" +#include "include/signle_thread_manager.h" #include "libpandabase/macros.h" #include "libpandabase/os/library_loader.h" @@ -73,14 +74,6 @@ using HostPromiseRejectionTracker = void (*)(const EcmaVM *vm, const JSHandle ecma_reference_processor_; - EcmaRendezvous *rendezvous_ {nullptr}; + SingleThreadManager *thread_manager_ {nullptr}; + Rendezvous *rendezvous_ {nullptr}; bool isTestMode_ {false}; PandaSet profiles_methods_; -- Gitee From 4fbe05d1c9ffd2b56a832ba5cbb7e4015fe62a69 Mon Sep 17 00:00:00 2001 From: Pavel Andrianov Date: Mon, 25 Jul 2022 16:13:57 +0300 Subject: [PATCH 2/3] Typo fix Signed-off-by: Pavel Andrianov --- runtime/ecma_vm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/ecma_vm.h b/runtime/ecma_vm.h index 07ba50864..77778ca11 100644 --- a/runtime/ecma_vm.h +++ b/runtime/ecma_vm.h @@ -29,7 +29,7 @@ #include "plugins/ecmascript/runtime/mem/object_xray.h" #include "plugins/ecmascript/runtime/tooling/pt_js_extractor.h" #include "include/panda_vm.h" -#include "include/signle_thread_manager.h" +#include "runtime/single_thread_manager.h" #include "libpandabase/macros.h" #include "libpandabase/os/library_loader.h" -- Gitee From cba0339c55732b6eb9a4edcc5a3b5577686161e0 Mon Sep 17 00:00:00 2001 From: Pavel Andrianov Date: Tue, 26 Jul 2022 11:11:56 +0300 Subject: [PATCH 3/3] Missed init of a main thread Signed-off-by: Pavel Andrianov --- runtime/ecma_vm.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/runtime/ecma_vm.cpp b/runtime/ecma_vm.cpp index 8167b8822..0c93e1028 100644 --- a/runtime/ecma_vm.cpp +++ b/runtime/ecma_vm.cpp @@ -118,6 +118,7 @@ EcmaVM *EcmaVM::Create(const JSRuntimeOptions &options) vm->InitializeGC(); auto jsThread = JSThread::Create(runtime, vm); vm->thread_ = jsThread; + vm->thread_manager_->SetMainThread(jsThread); if (!vm->Initialize()) { LOG_ECMA(ERROR) << "Failed to initialize jsvm"; runtime->GetInternalAllocator()->Delete(vm); @@ -151,6 +152,7 @@ Expected EcmaVM::Create(Runtime *runtime, const JSRuntime vm->InitializeGC(); auto jsThread = ecmascript::JSThread::Create(runtime, vm); vm->thread_ = jsThread; + vm->thread_manager_->SetMainThread(jsThread); return vm; } @@ -160,11 +162,11 @@ EcmaVM::EcmaVM(JSRuntimeOptions options) : stringTable_(new EcmaStringTable(this options_ = std::move(options); icEnable_ = options_.IsIcEnable(); optionalLogEnabled_ = options_.IsEnableOptionalLog(); - thread_manager_ = runtime->GetInternalAllocator()(); - rendezvous_ = runtime->GetInternalAllocator()(this); frameworkAbcFileName_ = options_.GetFrameworkAbcFile(); auto allocator = runtime->GetInternalAllocator(); + thread_manager_ = allocator->New(); + rendezvous_ = allocator->New(this); notificationManager_ = allocator->New(runtime->GetInternalAllocator()); notificationManager_->SetRendezvous(rendezvous_); @@ -412,6 +414,7 @@ EcmaVM::~EcmaVM() allocator->Delete(factory_); allocator->Delete(runtimeStat_); allocator->Delete(rendezvous_); + allocator->Delete(thread_manager_); allocator->Delete(runtime_iface_); allocator->Delete(compiler_); -- Gitee