From e2a27f691749dd49b93385daeb3d22df9172a294 Mon Sep 17 00:00:00 2001 From: Artem Udovichenko Date: Wed, 6 Jul 2022 16:58:37 +0300 Subject: [PATCH] [ecmascript] Implement gc() global function Signed-off-by: Artem Udovichenko --- ecmastdlib/ecmastdlib_inline_gen.rb | 0 runtime/builtins.cpp | 1 + runtime/builtins/builtins_global.cpp | 16 ++++++++++++++++ runtime/builtins/builtins_global.h | 1 + runtime/runtime_call_id.h | 1 + runtime/snapshot/mem/snapshot_serialize.cpp | 1 + 6 files changed, 20 insertions(+) mode change 100644 => 100755 ecmastdlib/ecmastdlib_inline_gen.rb diff --git a/ecmastdlib/ecmastdlib_inline_gen.rb b/ecmastdlib/ecmastdlib_inline_gen.rb old mode 100644 new mode 100755 diff --git a/runtime/builtins.cpp b/runtime/builtins.cpp index 123b8456d..aefdbf128 100644 --- a/runtime/builtins.cpp +++ b/runtime/builtins.cpp @@ -346,6 +346,7 @@ void Builtins::InitializeGlobalObject(const JSHandle &env, const JSHa // Global object test SetFunction(env, globalObject, "print", Global::PrintEntrypoint, 0); + SetFunction(env, globalObject, "gc", Global::GcEntrypoint, 0); #if ECMASCRIPT_ENABLE_RUNTIME_STAT SetFunction(env, globalObject, "startRuntimeStat", Global::StartRuntimeStat, 0); SetFunction(env, globalObject, "stopRuntimeStat", Global::StopRuntimeStat, 0); diff --git a/runtime/builtins/builtins_global.cpp b/runtime/builtins/builtins_global.cpp index 7fec05da9..b432b25ed 100644 --- a/runtime/builtins/builtins_global.cpp +++ b/runtime/builtins/builtins_global.cpp @@ -502,6 +502,22 @@ JSTaggedValue BuiltinsGlobal::PrintEntrypoint(EcmaRuntimeCallInfo *msg) return JSTaggedValue::Undefined(); } +JSTaggedValue BuiltinsGlobal::GcEntrypoint(EcmaRuntimeCallInfo *msg) +{ + if (msg == nullptr) { + return JSTaggedValue::Undefined(); + } + JSThread *thread = msg->GetThread(); + ASSERT(thread != nullptr); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + BUILTINS_API_TRACE(thread, Global, GcEntryPoint); + + thread->GetEcmaVM()->GetGC()->WaitForGCInManaged(GCTask(GCTaskCause::EXPLICIT_CAUSE, thread)); + thread->SafepointPoll(); + + 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 b0f713ca0..61d75fa92 100644 --- a/runtime/builtins/builtins_global.h +++ b/runtime/builtins/builtins_global.h @@ -42,6 +42,7 @@ public: static JSTaggedValue EncodeURIComponent(EcmaRuntimeCallInfo *msg); static JSTaggedValue PrintEntrypoint(EcmaRuntimeCallInfo *msg); + static JSTaggedValue GcEntrypoint(EcmaRuntimeCallInfo *msg); static JSTaggedValue CallJsBoundFunction(EcmaRuntimeCallInfo *msg); static JSTaggedValue CallJsProxy(EcmaRuntimeCallInfo *msg); #if ECMASCRIPT_ENABLE_RUNTIME_STAT diff --git a/runtime/runtime_call_id.h b/runtime/runtime_call_id.h index 766deb375..72f39f1ca 100644 --- a/runtime/runtime_call_id.h +++ b/runtime/runtime_call_id.h @@ -318,6 +318,7 @@ namespace panda::ecmascript { V(Global, IsFinite) \ V(Global, IsNaN) \ V(Global, PrintEntryPoint) \ + V(Global, GcEntryPoint) \ V(Global, NewobjDynrange) \ V(Global, CallJsBoundFunction) \ V(Global, CallJsProxy) \ diff --git a/runtime/snapshot/mem/snapshot_serialize.cpp b/runtime/snapshot/mem/snapshot_serialize.cpp index 30a071b7b..69d83bd37 100644 --- a/runtime/snapshot/mem/snapshot_serialize.cpp +++ b/runtime/snapshot/mem/snapshot_serialize.cpp @@ -433,6 +433,7 @@ static uintptr_t g_nativeTable[] = { reinterpret_cast(DataView::GetByteLength), reinterpret_cast(DataView::GetOffset), reinterpret_cast(Global::PrintEntrypoint), + reinterpret_cast(Global::GcEntrypoint), reinterpret_cast(Global::NotSupportEval), reinterpret_cast(Global::IsFinite), reinterpret_cast(Global::IsNaN), -- Gitee