From 9ddffceed5f24f93833f6750882d0063d926642b Mon Sep 17 00:00:00 2001 From: "yingguofeng@huawei.com" Date: Thu, 3 Jul 2025 16:22:47 +0800 Subject: [PATCH] Support constexpr enable_cmc_gc Issue: #ICJO0B Change-Id: Ic9f3729a78022876a81e1e88befa5217442e1540 Signed-off-by: yingguofeng@huawei.com --- BUILD.gn | 4 ++++ ecmascript/base/config.cpp | 3 ++- ecmascript/base/config.h | 4 ++++ ecmascript/checkpoint/thread_state_transition.h | 8 +++++++- ecmascript/ecma_vm.h | 4 ++++ ecmascript/js_thread.h | 9 ++++----- ecmascript/napi/include/jsnapi_expo.h | 6 +++--- ecmascript/napi/jsnapi_expo.cpp | 17 ++++++++++++----- ecmascript/runtime.cpp | 2 ++ js_runtime_config.gni | 4 +++- 10 files changed, 45 insertions(+), 16 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index f1a0fbe9fb..a3d8ce8340 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -416,6 +416,10 @@ config("ark_jsruntime_common_config") { if (is_ohos && current_cpu == "arm64") { defines += [ "ENABLE_COLD_STARTUP_GC_POLICY" ] } + if (enable_const_enable_cmc_gc) { + defines += [ "USE_CONST_ENABLE_CMC_GC" ] + print("########## enable const enable cmc gc ##############") + } if (ets_runtime_enable_cmc_gc) { defines += [ "DEFAULT_USE_CMC_GC" ] defines += [ "USE_CMC_GC" ] diff --git a/ecmascript/base/config.cpp b/ecmascript/base/config.cpp index 2b24d8b1ce..365531c55b 100644 --- a/ecmascript/base/config.cpp +++ b/ecmascript/base/config.cpp @@ -17,8 +17,9 @@ #include "common_interfaces/base/common.h" namespace panda::ecmascript { - +#ifndef USE_CONST_ENABLE_CMC_GC uint32_t PUBLIC_API g_isEnableCMCGC = 0; +#endif } // namespace panda::ecmascript diff --git a/ecmascript/base/config.h b/ecmascript/base/config.h index 4831f037e2..b07a4386d0 100644 --- a/ecmascript/base/config.h +++ b/ecmascript/base/config.h @@ -21,7 +21,11 @@ #include namespace panda::ecmascript { +#ifdef USE_CONST_ENABLE_CMC_GC +uint32_t constexpr PUBLIC_API g_isEnableCMCGC = 1; +#else extern uint32_t g_isEnableCMCGC; +#endif enum class PUBLIC_API RBMode : uint8_t { DEFAULT_RB = 0, // Default read barrier mode to support both gc. diff --git a/ecmascript/checkpoint/thread_state_transition.h b/ecmascript/checkpoint/thread_state_transition.h index 99e679ee93..f44c2d3d44 100644 --- a/ecmascript/checkpoint/thread_state_transition.h +++ b/ecmascript/checkpoint/thread_state_transition.h @@ -65,7 +65,9 @@ public: #endif } } else { +#ifndef USE_CONST_ENABLE_CMC_GC isEnbaleCMCGC_ = true; +#endif if constexpr (newState == ThreadState::RUNNING) { hasSwitchState_ = self_->GetThreadHolder()->TransferToRunningIfInNative(); } else { @@ -77,7 +79,11 @@ public: ~ThreadStateTransitionScope() { if (LIKELY(hasSwitchState_)) { +#ifdef USE_CONST_ENABLE_CMC_GC + if (LIKELY(!g_isEnableCMCGC)) { +#else if (LIKELY(!isEnbaleCMCGC_)) { +#endif if constexpr (std::is_same_v) { if (oldState_ == ThreadState::RUNNING) { self_->TransferDaemonThreadToRunning(); @@ -104,7 +110,7 @@ public: private: T* self_; ThreadState oldState_; - uint32_t isEnbaleCMCGC_ {0}; + [[maybe_unused]] uint32_t isEnbaleCMCGC_ {0}; uint32_t hasSwitchState_ {0}; NO_COPY_SEMANTIC(ThreadStateTransitionScope); }; diff --git a/ecmascript/ecma_vm.h b/ecmascript/ecma_vm.h index f944146181..b1d70f3fdf 100644 --- a/ecmascript/ecma_vm.h +++ b/ecmascript/ecma_vm.h @@ -371,7 +371,11 @@ public: uint32_t IsEnableCMCGC() const { +#ifdef USE_CONST_ENABLE_CMC_GC + return g_isEnableCMCGC; +#else return isEnableCMCGC_; +#endif } void PushToNativePointerList(JSNativePointer *pointer, Concurrent isConcurrent = Concurrent::NO); diff --git a/ecmascript/js_thread.h b/ecmascript/js_thread.h index b919db11eb..edfb42ffba 100644 --- a/ecmascript/js_thread.h +++ b/ecmascript/js_thread.h @@ -1081,12 +1081,11 @@ public: uint32_t PUBLIC_API IsEnableCMCGC() const { +#ifdef USE_CONST_ENABLE_CMC_GC + return g_isEnableCMCGC; +#else return glueData_.isEnableCMCGC_; - } - - void SetEnableCMCGC(bool enableCMCGC) - { - glueData_.isEnableCMCGC_ = enableCMCGC; +#endif } uintptr_t GetAllocBuffer() const diff --git a/ecmascript/napi/include/jsnapi_expo.h b/ecmascript/napi/include/jsnapi_expo.h index b97e03a9f2..25aae65bf2 100644 --- a/ecmascript/napi/include/jsnapi_expo.h +++ b/ecmascript/napi/include/jsnapi_expo.h @@ -983,7 +983,7 @@ public: Local *keys = nullptr, PropertyAttribute *attrs = nullptr, size_t nativeBindingsize = 0); - + static Local NewClassFunction(EcmaVM *vm, InternalFunctionCallback nativeFunc, NativePointerCallback deleter, @@ -1416,7 +1416,7 @@ public: private: JSThread *thread_; uint16_t oldThreadState_ {0}; - uint32_t isEnableCMCGC_ {0}; + [[maybe_unused]] uint32_t isEnableCMCGC_ {0}; uint32_t hasSwitchState_ {0}; }; @@ -1430,7 +1430,7 @@ public: private: JSThread *thread_ {nullptr}; uint16_t oldThreadState_ {0}; - uint32_t isEnableCMCGC_ {0}; + [[maybe_unused]] uint32_t isEnableCMCGC_ {0}; uint32_t hasSwitchState_ {0}; }; diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index caa3640de7..e88e993509 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -2389,7 +2389,6 @@ Local StringRef::GetProxyNapiWrapperString(const EcmaVM *vm) return JSNApiHelper::ToLocal(proxyNapiWapperString); } - Local StringRef::EncodeIntoUint8Array(const EcmaVM *vm) { CROSS_THREAD_CHECK(vm); @@ -4293,7 +4292,9 @@ JsiNativeScope::JsiNativeScope(const EcmaVM *vm) oldThreadState_ = static_cast(thread_->TransferToNonRunning(ecmascript::ThreadState::NATIVE)); hasSwitchState_ = oldThreadState_ != static_cast(ecmascript::ThreadState::NATIVE); } else { +#ifndef USE_CONST_ENABLE_CMC_GC isEnableCMCGC_ = true; +#endif hasSwitchState_ = thread_->GetThreadHolder()->TransferToNativeIfInRunning(); } } @@ -4301,7 +4302,11 @@ JsiNativeScope::JsiNativeScope(const EcmaVM *vm) JsiNativeScope::~JsiNativeScope() { if (hasSwitchState_) { +#ifdef USE_CONST_ENABLE_CMC_GC + if (LIKELY(!ecmascript::g_isEnableCMCGC)) { +#else if (LIKELY(!isEnableCMCGC_)) { +#endif thread_->TransferInNonRunning(static_cast(oldThreadState_)); } else { thread_->GetThreadHolder()->TransferToRunning(); @@ -4324,7 +4329,9 @@ JsiFastNativeScope::JsiFastNativeScope(const EcmaVM *vm) oldThreadState_ = static_cast(thread_->TransferToRunningIfNonRunning()); hasSwitchState_ = oldThreadState_ != static_cast(ecmascript::ThreadState::RUNNING); } else { +#ifndef USE_CONST_ENABLE_CMC_GC isEnableCMCGC_ = true; +#endif hasSwitchState_ = thread_->GetThreadHolder()->TransferToRunningIfInNative(); } } @@ -4332,7 +4339,11 @@ JsiFastNativeScope::JsiFastNativeScope(const EcmaVM *vm) JsiFastNativeScope::~JsiFastNativeScope() { if (hasSwitchState_) { +#ifdef USE_CONST_ENABLE_CMC_GC + if (LIKELY(!ecmascript::g_isEnableCMCGC)) { +#else if (LIKELY(!isEnableCMCGC_)) { +#endif thread_->TransferToNonRunningInRunning(static_cast(oldThreadState_)); } else { thread_->GetThreadHolder()->TransferToNative(); @@ -6255,7 +6266,6 @@ void JSNApi::SetHostResolveBufferTrackerForHybridApp(EcmaVM *vm, vm->SetResolveBufferCallbackForHybridApp(cb); } - void JSNApi::SetSearchHapPathTracker(EcmaVM *vm, std::function cb) { @@ -6562,7 +6572,6 @@ Local JSNApi::GetModuleNameSpaceFromFile(EcmaVM *vm, const std::strin return JSNApiHelper::ToLocal(moduleNamespace); } - template Local JSNApi::GetModuleNameSpaceWithModuleInfo(EcmaVM *vm, const std::string &file, const std::string &module_path) @@ -7025,6 +7034,4 @@ void HandshakeHelper::DoHandshake([[maybe_unused]] EcmaVM *vm, void *stsIface, v ecmascript::CrossVMOperator::DoHandshake(vm, stsIface, ecmaIface); } #endif // PANDA_JS_ETS_HYBRID_MODE - - } // namespace panda diff --git a/ecmascript/runtime.cpp b/ecmascript/runtime.cpp index 7f25657f7a..65a7c01ce2 100644 --- a/ecmascript/runtime.cpp +++ b/ecmascript/runtime.cpp @@ -161,7 +161,9 @@ void Runtime::PostInitialization(const EcmaVM *vm) void Runtime::InitGCConfig(const JSRuntimeOptions &options) { bool defaultValue = options.IsEnableCMCGC(); +#ifndef USE_CONST_ENABLE_CMC_GC g_isEnableCMCGC = IsEnableCMCGC(defaultValue); +#endif if (g_isEnableCMCGC) { g_maxRegularHeapObjectSize = 32_KB; } diff --git a/js_runtime_config.gni b/js_runtime_config.gni index 88eb609f68..892a9e1879 100644 --- a/js_runtime_config.gni +++ b/js_runtime_config.gni @@ -73,6 +73,8 @@ declare_args() { ets_runtime_enable_cmc_gc = false enable_handle_leak_detect = false + + enable_const_enable_cmc_gc = false } if (defined(enable_cmc_gc) && !ets_runtime_enable_cmc_gc) { @@ -164,7 +166,7 @@ enable_hitrace = enable_unwinder = !ark_standalone_build && !(defined(is_arkui_x) && is_arkui_x) && is_ohos && is_standard_system && !is_qemu_runtime -enable_rss = +enable_rss = !ark_standalone_build && !(defined(is_arkui_x) && is_arkui_x) && is_ohos && is_standard_system && !is_qemu_runtime -- Gitee