From bf4f5d333257cc1d978f65a44fc4fe7aed6f8a1a Mon Sep 17 00:00:00 2001 From: ElevenDuan Date: Mon, 25 Aug 2025 19:41:47 +0800 Subject: [PATCH] Fix multi-threaded memory allocation Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICUMN1?from=project-issue Change-Id: I04a83d5ede947fc4b556949939a61662c6ee8a58 Signed-off-by: ElevenDuan --- es2panda/BUILD.gn | 4 ++++ es2panda/aot/main.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/es2panda/BUILD.gn b/es2panda/BUILD.gn index be827ef5e5..cf68f32450 100644 --- a/es2panda/BUILD.gn +++ b/es2panda/BUILD.gn @@ -560,6 +560,10 @@ ohos_executable("es2panda") { ] } + if (is_build_sdk && is_ohos) { + defines = [ "OHOS_PLATFORM" ] + } + if (ark_standalone_build) { external_deps += [ "protobuf:protobuf_lite_static", diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index ae547863dc..c84b9af5ef 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -23,6 +23,9 @@ #include #include #include +#ifdef OHOS_PLATFORM +#include +#endif namespace panda::es2panda::aot { using mem::MemConfig; @@ -353,6 +356,13 @@ int Run(int argc, const char **argv) int main(int argc, const char **argv) { +// Enable tcache for malloc, resolve the global lock competition caused by multi-threaded scenarios. +#ifdef OHOS_PLATFORM + mallopt(M_OHOS_CONFIG, M_TCACHE_PERFORMANCE_MODE); + mallopt(M_OHOS_CONFIG, M_ENABLE_OPT_TCACHE); + mallopt(M_SET_THREAD_CACHE, M_THREAD_CACHE_ENABLE); + mallopt(M_DELAYED_FREE, M_DELAYED_FREE_ENABLE); +#endif panda::es2panda::aot::MemManager mm; return panda::es2panda::aot::Run(argc, argv); } -- Gitee