diff --git a/BUILD.gn b/BUILD.gn index f1a0fbe9fb7420708ffbf95dacc793a5ab5ad8fe..a3d8ce8340c4858e491696c31de141fe29d8c4c3 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 2b24d8b1ce7ee41b09b898b3f21f507bb1232024..365531c55be8b2e0545adeb68c45ed07e5934b24 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 4831f037e28d74344aeec2deeeed98bf24a3d116..b07a4386d0585c57bffd254d10b77f060def5f67 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 99e679ee930c4b16d56872d3fe8fc16d88870fd4..f44c2d3d44cf3a6e56b575ad0e2d2503c28e8dae 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 f944146181defb7fd4e2e15d133f229b6d74c437..b1d70f3fdfb2319a56ac6c9b292318ff1fd37c7b 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 b919db11eb2a0e958885819a278d76d0f211b36c..edfb42ffbad808f60b811a27cc29b3552e0e8813 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 b97e03a9f26f122d3f453ecaf2169c24288b43c8..25aae65bf21769458aa3409e622824f5ad8e8ce1 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 caa3640de73d1ffa364f3cb9b00db45ac0854fcb..e88e9935098105d01db3f01095e68e732c881283 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 7f25657f7a9a1c679649b3e6d06d51cd76a39f49..65a7c01ce216a3a8f4424971f0e16a3e9e0355c1 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 88eb609f68e4c28cb7bf122a2221e5c2d3207a44..892a9e1879f635cf9d4538f91ec005a2e857b756 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