diff --git a/runtime/ecma_vm.cpp b/runtime/ecma_vm.cpp index bab1724126f4abad5748d6defcaa9d790af5c827..c558177dbba55696b8611ebb265a74b0af2f6cc8 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) @@ -147,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); @@ -179,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; } @@ -191,7 +165,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 0f46dfce117672e237758155bd34a386e26f37c4..924a8c6190c3c05762d2cdd3dba1d39b7dc1a50a 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 "runtime/single_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.