diff --git a/runtime/ecma_vm.cpp b/runtime/ecma_vm.cpp index 8d20bfa02fa991432251eab22932e55a5dd22470..0c93e1028d9a729a1f127c04420bce31e86f368f 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) @@ -146,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); @@ -179,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; } @@ -188,10 +162,11 @@ EcmaVM::EcmaVM(JSRuntimeOptions options) : stringTable_(new EcmaStringTable(this options_ = std::move(options); icEnable_ = options_.IsIcEnable(); optionalLogEnabled_ = options_.IsEnableOptionalLog(); - rendezvous_ = runtime->GetInternalAllocator()->New(this); frameworkAbcFileName_ = options_.GetFrameworkAbcFile(); auto allocator = runtime->GetInternalAllocator(); + thread_manager_ = allocator->New(); + rendezvous_ = allocator->New(this); notificationManager_ = allocator->New(runtime->GetInternalAllocator()); notificationManager_->SetRendezvous(rendezvous_); @@ -439,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_); diff --git a/runtime/ecma_vm.h b/runtime/ecma_vm.h index a625138cd3b7ecab51b260cefd284a61836dbcd5..77778ca11f280c6a1c022d3475f0f05277e5425b 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 "runtime/single_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_;