From 7b33d3fddd7daf52b9479392575d41cff5fdbe14 Mon Sep 17 00:00:00 2001 From: Aleksandr Emelenko Date: Thu, 23 Mar 2023 15:45:35 +0300 Subject: [PATCH] Enable mutator check for Ecma. Fix tests Change-Id: I3f585916fcbb79a107ef69aee7b3e844b890e11b Signed-off-by: Aleksandr Emelenko --- runtime/builtins/builtins_global.cpp | 3 +++ tests/runtime/mem/g1gc_barrier_test.cpp | 16 ++++++++++++---- tests/runtime/mem/object_helpers_test.cpp | 3 +++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/runtime/builtins/builtins_global.cpp b/runtime/builtins/builtins_global.cpp index 5fdbf9dbe..607ab1aba 100644 --- a/runtime/builtins/builtins_global.cpp +++ b/runtime/builtins/builtins_global.cpp @@ -79,6 +79,9 @@ void BuiltinsGlobal::GCTaskTracker::GCPhaseStarted(mem::GCPhase phase) JSHandle global(thread, thread->GetGlobalObject()); JSHandle new_target(thread, JSTaggedValue::Undefined()); auto info = NewRuntimeCallInfo(thread, fn, global, JSTaggedValue::Undefined(), 1); + // JS has only one thread, therefore, we run this callback from the mutator thread during concurrent marking. + ASSERT(!thread->GetVM()->GetMutatorLock()->HasLock()); + os::memory::ReadLockHolder lock(*thread->GetVM()->GetMutatorLock()); info->SetCallArgs(thread->GetEcmaVM()->GetGlobalEnv()->GetGcMarker()); JSFunction::Call(info.Get()); } diff --git a/tests/runtime/mem/g1gc_barrier_test.cpp b/tests/runtime/mem/g1gc_barrier_test.cpp index af01683df..729db8b58 100644 --- a/tests/runtime/mem/g1gc_barrier_test.cpp +++ b/tests/runtime/mem/g1gc_barrier_test.cpp @@ -102,6 +102,7 @@ public: TEST_F(G1GCBarrierTest, TestPreBarrier) { + ScopedManagedCodeThread s(thread); [[maybe_unused]] EcmaHandleScope scope(thread); mem::GC *gc = thread->GetVM()->GetGC(); JSHandle array(thread, AllocArray(2)); @@ -113,8 +114,11 @@ TEST_F(G1GCBarrierTest, TestPreBarrier) ConcurrentMarkListener listener(this, array, obj, replacement); gc->AddListener(&listener); - GCTask task(GCTaskCause::HEAP_USAGE_THRESHOLD_CAUSE); // trigger concurrent marking - task.Run(*gc); + { + ScopedNativeCodeThread sn(thread); + GCTask task(GCTaskCause::HEAP_USAGE_THRESHOLD_CAUSE); // trigger concurrent marking + task.Run(*gc); + } ASSERT_TRUE(listener.has_concurrent_mark); } @@ -163,6 +167,7 @@ public: TEST_P(G1GCClassCollectionTest, TestCollectClasses) { + ScopedManagedCodeThread s(thread); JSHClass *hclass = nullptr; { [[maybe_unused]] EcmaHandleScope scope(thread); @@ -175,8 +180,11 @@ TEST_P(G1GCClassCollectionTest, TestCollectClasses) ASSERT_TRUE(region->HasFlag(mem::IS_NONMOVABLE)); mem::GC *gc = thread->GetVM()->GetGC(); - GCTask task(GCTaskCause::HEAP_USAGE_THRESHOLD_CAUSE); // trigger concurrent marking - task.Run(*gc); + { + ScopedNativeCodeThread sn(thread); + GCTask task(GCTaskCause::HEAP_USAGE_THRESHOLD_CAUSE); // trigger concurrent marking + task.Run(*gc); + } bool found = false; GetAllocator()->IterateRegularSizeObjects([hclass, &found](ObjectHeader *obj) { if (obj == hclass) { diff --git a/tests/runtime/mem/object_helpers_test.cpp b/tests/runtime/mem/object_helpers_test.cpp index cc5c9227a..76dec39ef 100644 --- a/tests/runtime/mem/object_helpers_test.cpp +++ b/tests/runtime/mem/object_helpers_test.cpp @@ -10,6 +10,7 @@ #include "plugins/ecmascript/runtime/object_factory.h" #include "runtime/include/runtime.h" #include "runtime/include/panda_vm.h" +#include "runtime/include/thread_scopes.h" #include "runtime/mem/object_helpers-inl.h" namespace panda::ecmascript { @@ -42,6 +43,7 @@ public: thread_ = vm_->GetAssociatedJSThread(); factory_ = vm_->GetFactory(); handle_scope_ = new EcmaHandleScope(thread_); + vm_->GetMutatorLock()->ReadLock(); initial_dyn_class_ = factory_->NewEcmaDynClassClass(nullptr, JSHClass::SIZE, JSType::HCLASS); JSHClass *dynclass = reinterpret_cast(initial_dyn_class_.GetTaggedValue().GetTaggedObject()); dynclass->SetClass(dynclass); @@ -50,6 +52,7 @@ public: ~DynamicObjectHelpersTest() { + vm_->GetMutatorLock()->Unlock(); delete handle_scope_; Runtime::Destroy(); } -- Gitee