diff --git a/runtime/builtins/builtins_global.cpp b/runtime/builtins/builtins_global.cpp index d0a0e903806c75e976c29b6b288341e6b0010468..76885b34f35809f4ba2061f6a47f397f50e3750c 100644 --- a/runtime/builtins/builtins_global.cpp +++ b/runtime/builtins/builtins_global.cpp @@ -22,6 +22,7 @@ #include "plugins/ecmascript/runtime/base/string_helper.h" #include "plugins/ecmascript/runtime/ecma_macros.h" #include "plugins/ecmascript/runtime/internal_call_params.h" +#include "plugins/ecmascript/runtime/interpreter/fast_runtime_stub-inl.h" #include "plugins/ecmascript/runtime/interpreter/slow_runtime_helper.h" #include "plugins/ecmascript/runtime/js_invoker.h" #include "plugins/ecmascript/runtime/tagged_array-inl.h" @@ -654,9 +655,6 @@ JSTaggedValue BuiltinsGlobal::PrintEntrypoint(EcmaRuntimeCallInfo *msg) JSTaggedValue BuiltinsGlobal::GcEntrypoint(EcmaRuntimeCallInfo *msg) { - if (msg == nullptr) { - return JSTaggedValue::Undefined(); - } JSThread *thread = msg->GetThread(); ASSERT(thread != nullptr); [[maybe_unused]] EcmaHandleScope handleScope(thread); @@ -668,6 +666,41 @@ JSTaggedValue BuiltinsGlobal::GcEntrypoint(EcmaRuntimeCallInfo *msg) return JSTaggedValue::Undefined(); } +JSTaggedValue BuiltinsGlobal::MarkObject(EcmaRuntimeCallInfo *msg) +{ + JSThread *thread = msg->GetThread(); + BUILTINS_API_TRACE(thread, Global, MarkObject); + EcmaVM *vm = thread->GetEcmaVM(); + JSHandle arg = GetCallArg(msg, 0); + if (arg->IsHeapObject()) { + vm->MarkObject(arg->GetHeapObject()); + } + return JSTaggedValue::Undefined(); +} + +JSTaggedValue BuiltinsGlobal::GetMarkQueue(EcmaRuntimeCallInfo *msg) +{ + JSThread *thread = msg->GetThread(); + BUILTINS_API_TRACE(thread, Global, GetMarkQueue); + EcmaVM *vm = thread->GetEcmaVM(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle array = vm->GetFactory()->NewJSArray(); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + size_t index = 0; + vm->IterateOverMarkQueue([&index, &array, thread](ObjectHeader *obj) { + FastRuntimeStub::SetPropertyByIndex(thread, array.GetTaggedValue(), index++, JSTaggedValue(obj)); + }); + return array.GetTaggedValue(); +} + +JSTaggedValue BuiltinsGlobal::ClearMarkQueue(EcmaRuntimeCallInfo *msg) +{ + JSThread *thread = msg->GetThread(); + BUILTINS_API_TRACE(thread, Global, ClearMarkQueue); + thread->GetEcmaVM()->ClearMarkQueue(); + return JSTaggedValue::Undefined(); +} + JSTaggedValue BuiltinsGlobal::CallJsBoundFunction(EcmaRuntimeCallInfo *msg) { JSThread *thread = msg->GetThread(); diff --git a/runtime/builtins/builtins_global.h b/runtime/builtins/builtins_global.h index d269f644a2390d57a523911da43dcaccc976b3bc..c3f6c074703406f0366a4ac1c74d61635058d1b9 100644 --- a/runtime/builtins/builtins_global.h +++ b/runtime/builtins/builtins_global.h @@ -46,6 +46,9 @@ public: static JSTaggedValue PrintEntrypoint(EcmaRuntimeCallInfo *msg); static JSTaggedValue GcEntrypoint(EcmaRuntimeCallInfo *msg); + static JSTaggedValue MarkObject(EcmaRuntimeCallInfo *msg); + static JSTaggedValue GetMarkQueue(EcmaRuntimeCallInfo *msg); + static JSTaggedValue ClearMarkQueue(EcmaRuntimeCallInfo *msg); static JSTaggedValue CallJsBoundFunction(EcmaRuntimeCallInfo *msg); static JSTaggedValue CallJsProxy(EcmaRuntimeCallInfo *msg); #if ECMASCRIPT_ENABLE_RUNTIME_STAT diff --git a/runtime/ecma_vm.cpp b/runtime/ecma_vm.cpp index 4364466441a6a4719d9c9922e08793fbbf13d166..c2c4533667f97af13e799d5efe28f1d17817028b 100644 --- a/runtime/ecma_vm.cpp +++ b/runtime/ecma_vm.cpp @@ -987,6 +987,7 @@ void EcmaVM::HandleReturnFrame() void EcmaVM::VisitVmRoots(const GCRootVisitor &visitor) { + PandaVM::VisitVmRoots(visitor); ObjectXRay rootManager(this); auto common_visitor = [&visitor](Root type, ObjectSlot slot) { mem::RootType root; @@ -1016,6 +1017,7 @@ void EcmaVM::VisitVmRoots(const GCRootVisitor &visitor) void EcmaVM::UpdateVmRefs() { + PandaVM::UpdateVmRefs(); ObjectXRay rootManager(this); auto single_visitor = []([[maybe_unused]] Root type, ObjectSlot slot) { JSTaggedValue value(slot.GetTaggedType()); diff --git a/runtime/runtime_call_id.h b/runtime/runtime_call_id.h index 9fd144983bfdea5349d27d9245b2782e08c7cef3..0878b61d844dd0e68b923e12e53ebe4a74d934cf 100644 --- a/runtime/runtime_call_id.h +++ b/runtime/runtime_call_id.h @@ -327,6 +327,9 @@ namespace panda::ecmascript { V(Global, DecodeURI) \ V(Global, EncodeURI) \ V(Global, DecodeURIComponent) \ + V(Global, MarkObject) \ + V(Global, GetMarkQueue) \ + V(Global, ClearMarkQueue) \ V(Global, EncodeURIComponent) \ V(Iterator, Constructor) \ V(Iterator, Next) \