From 328ff4cd67439f33b0e6287d131740e29830a4d3 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 bab172412..ca3c206c9 100644 --- a/runtime/ecma_vm.cpp +++ b/runtime/ecma_vm.cpp @@ -84,34 +84,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) @@ -191,7 +163,8 @@ EcmaVM::EcmaVM(JSRuntimeOptions options) options_ = std::move(options); icEnable_ = options_.IsIcEnable(); optionalLogEnabled_ = options_.IsEnableOptionalLog(); - rendezvous_ = chunk_.New(this); + thread_manager_ = chunk_.New(); + rendezvous_ = chunk_.New(this); snapshotSerializeEnable_ = options_.IsSnapshotSerializeEnabled(); if (!snapshotSerializeEnable_) { snapshotDeserializeEnable_ = options_.IsSnapshotDeserializeEnabled(); diff --git a/runtime/ecma_vm.h b/runtime/ecma_vm.h index 0f46dfce1..9fcfb96b9 100644 --- a/runtime/ecma_vm.h +++ b/runtime/ecma_vm.h @@ -35,6 +35,7 @@ #include "plugins/ecmascript/runtime/snapshot/mem/snapshot_serialize.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" @@ -81,14 +82,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}; // VM startup states. -- Gitee From afde86df077cc667126a829f570151fc4c3e9117 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 9fcfb96b9..924a8c619 100644 --- a/runtime/ecma_vm.h +++ b/runtime/ecma_vm.h @@ -35,7 +35,7 @@ #include "plugins/ecmascript/runtime/snapshot/mem/snapshot_serialize.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 b6a77b0cc972b4ff600e577e1c69f448b71915c4 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 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/ecma_vm.cpp b/runtime/ecma_vm.cpp index ca3c206c9..c558177db 100644 --- a/runtime/ecma_vm.cpp +++ b/runtime/ecma_vm.cpp @@ -119,6 +119,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 JSRuntimeOpti vm->InitializeGC(); auto jsThread = ecmascript::JSThread::Create(runtime, vm); vm->thread_ = jsThread; + vm->thread_manager_->SetMainThread(jsThread); return vm; } -- Gitee