From 5b305347e1f84d5ffd7c4282625eb9a8ae56151a Mon Sep 17 00:00:00 2001 From: yangliping Date: Wed, 9 Apr 2025 15:01:16 +0800 Subject: [PATCH 01/54] fix warning Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IBZQC7?from=project-issue Signed-off-by: yangliping --- compiler_service/src/aot_args_handler.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler_service/src/aot_args_handler.cpp b/compiler_service/src/aot_args_handler.cpp index a586750a55..f2fa9aa327 100644 --- a/compiler_service/src/aot_args_handler.cpp +++ b/compiler_service/src/aot_args_handler.cpp @@ -15,6 +15,7 @@ #include "aot_args_handler.h" +#include #include #include @@ -102,9 +103,10 @@ int32_t AOTArgsParserBase::FindArgsIdxToInteger(const std::unordered_map(std::stoi(argsMap.at(keyName), &sz)); - if (sz < static_cast(argsMap.at(keyName).size())) { + const char* beginPtr = argsMap.at(keyName).data(); + const char* endPtr = argsMap.at(keyName).data() + argsMap.at(keyName).size(); + auto res = std::from_chars(beginPtr, endPtr, bundleID); + if ((res.ec != std::errc()) || (res.ptr != endPtr)) { LOG_SA(ERROR) << "trigger exception as converting string to integer"; return ERR_AOT_COMPILER_PARAM_FAILED; } -- Gitee From 2270ba3dc90ca4a413c88ca723b57de9fd69da4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E6=9D=B0?= Date: Wed, 9 Apr 2025 15:28:59 +0800 Subject: [PATCH 02/54] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E4=BF=AE=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issues: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IBZQRX Signed-off-by: 唐杰 Signed-off-by: lhc Change-Id: Iee815fa03264a135b8a071a6faa669084a588b67 --- ecmascript/jspandafile/js_pandafile_executor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ecmascript/jspandafile/js_pandafile_executor.cpp b/ecmascript/jspandafile/js_pandafile_executor.cpp index 128e69084a..983a4d8f11 100644 --- a/ecmascript/jspandafile/js_pandafile_executor.cpp +++ b/ecmascript/jspandafile/js_pandafile_executor.cpp @@ -23,6 +23,7 @@ #include "ecmascript/module/module_tools.h" #include "ecmascript/checkpoint/thread_state_transition.h" #include "ecmascript/platform/pandafile.h" +#include "ecmascript/base/number_helper.h" namespace panda::ecmascript { using PathHelper = base::PathHelper; -- Gitee From 22452c2b2599114c0cb9d5a13b67c31b6bc3cd1f Mon Sep 17 00:00:00 2001 From: herongpeng Date: Mon, 7 Apr 2025 15:43:41 +0800 Subject: [PATCH 03/54] ArkTS1.2 add framework Integration AOT ArkTS1.2 add framework Integration AOT Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IBZ283 Signed-off-by: herongpeng Change-Id: I376796c4c8ae6a8314209c35ebf5c3ce37c27a34 Signed-off-by: lhc --- bundle.json | 3 +- compiler_service/BUILD.gn | 9 +++ compiler_service/compiler_service.cfg | 8 ++ compiler_service/include/aot_args_handler.h | 12 ++- compiler_service/include/aot_args_list.h | 12 ++- .../include/aot_compiler_constants.h | 7 ++ compiler_service/include/aot_compiler_impl.h | 1 + compiler_service/src/aot_args_handler.cpp | 80 ++++++++++++++++++- compiler_service/src/aot_compiler_impl.cpp | 11 ++- .../system_framework_aot_enable_list.conf | 2 + .../aotcompilerargshandler_unit.cpp | 44 ++++++++++ 11 files changed, 180 insertions(+), 9 deletions(-) create mode 100644 compiler_service/system_framework_aot_enable_list.conf diff --git a/bundle.json b/bundle.json index 323c78ea1e..81a9ff1cd6 100644 --- a/bundle.json +++ b/bundle.json @@ -68,7 +68,8 @@ "//arkcompiler/ets_runtime:ark_js_host_linux_tools_packages", "//arkcompiler/ets_runtime/etc:arkcompiler.para.dac", "//arkcompiler/ets_runtime/compiler_service:ark_aot_compiler.cfg", - "//arkcompiler/ets_runtime/compiler_service:compiler_service" + "//arkcompiler/ets_runtime/compiler_service:compiler_service", + "//arkcompiler/ets_runtime/compiler_service:system_framework_aot_enable_list.conf" ], "inner_kits": [ { diff --git a/compiler_service/BUILD.gn b/compiler_service/BUILD.gn index ade3a39216..ebd7ca1bab 100644 --- a/compiler_service/BUILD.gn +++ b/compiler_service/BUILD.gn @@ -124,6 +124,15 @@ ohos_prebuilt_etc("ark_aot_compiler.cfg") { subsystem_name = "arkcompiler" } +ohos_prebuilt_etc("system_framework_aot_enable_list.conf") { + relative_install_dir = "ark" + source = "system_framework_aot_enable_list.conf" + + # Set the subsystem name + part_name = "ets_runtime" + subsystem_name = "arkcompiler" +} + ohos_sa_profile("compiler_sa_profile") { sources = [ "sa_profile/5300.json" ] part_name = "ets_runtime" diff --git a/compiler_service/compiler_service.cfg b/compiler_service/compiler_service.cfg index 289573f7d5..3df6400dbe 100644 --- a/compiler_service/compiler_service.cfg +++ b/compiler_service/compiler_service.cfg @@ -1,4 +1,12 @@ { + "jobs" : [{ + "name" : "post-fs-data", + "cmds" : [ + "mkdir /data/service/el1/public/for-all-app/framework_ark_cache 0755 system system", + "restorecon /data/service/el1/public/for-all-app/framework_ark_cache" + ] + } + ], "services" : [{ "name" : "compiler_service", "path" : ["/system/bin/sa_main", "/system/profile/compiler_service.json"], diff --git a/compiler_service/include/aot_args_handler.h b/compiler_service/include/aot_args_handler.h index 79af0c5633..5c5ec557d9 100644 --- a/compiler_service/include/aot_args_handler.h +++ b/compiler_service/include/aot_args_handler.h @@ -83,7 +83,7 @@ public: #endif }; -class StaticAOTArgsParser final : public AOTArgsParserBase { +class StaticAOTArgsParser : public AOTArgsParserBase { public: int32_t Parse(const std::unordered_map &argsMap, HapArgs &hapArgs, int32_t thermalLevel) override; @@ -93,6 +93,16 @@ public: std::string ParseLocation(std::string &anfilePath); }; +class StaticFrameworkAOTArgsParser final : public StaticAOTArgsParser { +public: + int32_t Parse(const std::unordered_map &argsMap, HapArgs &hapArgs, + int32_t thermalLevel) override; + + std::string ParseFrameworkBootPandaFiles(const std::string &bootfiles, const std::string &paocPandaFiles); + + bool IsFileExists(const std::string &fileName); +}; + class AOTArgsParserFactory { public: static std::optional> GetParser(const std::unordered_map AotArgsList { +std::unordered_set aotArgsList { "aot-file", "ark-properties", "ark-bundleName", @@ -146,7 +146,7 @@ std::unordered_set AotArgsList { "compiler-trace-builtins", }; -std::unordered_set StaticAotArgsList { +std::unordered_set staticAOTArgsList { "boot-panda-files", "paoc-panda-files", "paoc-output", @@ -154,10 +154,16 @@ std::unordered_set StaticAotArgsList { "paoc-use-cha", }; -std::vector StaticAotDefaultArgs { +std::vector staticAOTDefaultArgs { "--load-runtimes=ets", "--compiler-enable-fast-interop=false", "--paoc-zip-panda-file=ets/modules_static.abc" }; + +std::vector staticFrameworkAOTDefaultArgs { + "--load-runtimes=ets", + "--compiler-enable-fast-interop=false", +}; + } // namespace OHOS::ArkCompiler #endif // OHOS_ARKCOMPILER_AOT_ARGS_LIST_H diff --git a/compiler_service/include/aot_compiler_constants.h b/compiler_service/include/aot_compiler_constants.h index d1f33e3b16..45461e4046 100644 --- a/compiler_service/include/aot_compiler_constants.h +++ b/compiler_service/include/aot_compiler_constants.h @@ -17,6 +17,7 @@ #define OHOS_ARKCOMPILER_AOTCOMPILER_CONSTANTS_H #include +#include #include #include "aot_compiler_error_utils.h" @@ -34,10 +35,16 @@ const std::string COMPILER_ENABLE_AOT_CODE_COMMENT = "compiler-enable-aot-code-c const std::string COMPILER_LOG_OPT = "compiler-log"; const std::string COMPILER_AN_FILE_MAX_SIZE = "compiler-an-file-max-size"; const std::string AOT_FILE = "aot-file"; +const std::string IS_SYSTEM_COMPONENT = "isSysComp"; const std::string CODE_LANGUAGE = "codeLanguage"; } // namespace ArgsIdx +// UID and GID of system users +constexpr uid_t OID_SYSTEM = 1000; + +constexpr const char* BOOLEAN_FALSE = "0"; + namespace Symbols { constexpr const char* PREFIX = "--"; constexpr const char* EQ = "="; diff --git a/compiler_service/include/aot_compiler_impl.h b/compiler_service/include/aot_compiler_impl.h index 0162888863..7b6a05d120 100644 --- a/compiler_service/include/aot_compiler_impl.h +++ b/compiler_service/include/aot_compiler_impl.h @@ -61,6 +61,7 @@ protected: void ResetState(); void PauseAotCompiler(); void AllowAotCompiler(); + bool IsSystemComponent(const std::unordered_map &argsMap); bool VerifyCompilerModeAndPkgInfo(const std::unordered_map &argsMap); AotCompilerImpl() = default; diff --git a/compiler_service/src/aot_args_handler.cpp b/compiler_service/src/aot_args_handler.cpp index f2fa9aa327..4be8b305ce 100644 --- a/compiler_service/src/aot_args_handler.cpp +++ b/compiler_service/src/aot_args_handler.cpp @@ -16,6 +16,7 @@ #include "aot_args_handler.h" #include +#include #include #include @@ -36,6 +37,7 @@ const std::string STATIC_PAOC_LOCATION = "paoc-location"; const std::string STATIC_PAOC_OUTPUT = "paoc-output"; const std::string STATIC_BOOT_PATH = "/system/framework/bootpath.json"; +const std::string AN_FILE_NAME = "anFileName"; const std::string ARKTS_1_1 = "1.1"; const std::string ARKTS_1_2 = "1.2"; const std::string ARKTS_HYBRID = "hybrid"; @@ -43,6 +45,7 @@ const std::string ARKTS_HYBRID = "hybrid"; const std::string AN_SUFFIX = ".an"; const std::string APP_SANBOX_PATH_PREFIX = "/data/storage/el1/bundle/"; const std::string ETS_PATH = "/ets"; +const std::string OWNERID_SHARED_TAG = "SHARED_LIB_ID"; AOTArgsHandler::AOTArgsHandler(const std::unordered_map &argsMap) : argsMap_(argsMap) { @@ -144,7 +147,7 @@ int32_t AOTArgsParser::Parse(const std::unordered_map AddExpandArgs(hapArgs.argVector, thermalLevel); for (auto &argPair : argsMap) { - if (AotArgsList.find(argPair.first) != AotArgsList.end()) { + if (aotArgsList.find(argPair.first) != aotArgsList.end()) { hapArgs.argVector.emplace_back(Symbols::PREFIX + argPair.first + Symbols::EQ + argPair.second); } } @@ -185,7 +188,7 @@ int32_t StaticAOTArgsParser::Parse(const std::unordered_map> AOTArgsParserFactory::GetParser( const std::unordered_map &argsMap) { + int32_t isSystemComponent = 0; + if ((AOTArgsParserBase::FindArgsIdxToInteger(argsMap, ArgsIdx::IS_SYSTEM_COMPONENT, isSystemComponent) != ERR_OK)) { + LOG_SA(INFO) << "aot sa failed to get isSystemComponent"; + } + if (isSystemComponent) { + return std::make_unique(); + } std::string codeLanguage = ARKTS_1_1; if (AOTArgsParserBase::FindArgsIdxToString(argsMap, ArgsIdx::CODE_LANGUAGE, codeLanguage) != ERR_OK) { LOG_SA(INFO) << "aot sa failed to get language version"; @@ -284,4 +294,68 @@ std::optional> AOTArgsParserFactory::GetParse LOG_SA(FATAL) << "aot sa get invalid code language version"; return std::nullopt; } + +bool StaticFrameworkAOTArgsParser::IsFileExists(const std::string &fileName) +{ + std::ifstream inFile(fileName); + return inFile.good(); +} + +int32_t StaticFrameworkAOTArgsParser::Parse(const std::unordered_map &argsMap, + HapArgs &hapArgs, [[maybe_unused]] int32_t thermalLevel) +{ + std::string abcPath; + if ((FindArgsIdxToString(argsMap, ArgsIdx::ABC_PATH, abcPath) != ERR_OK) || + (FindArgsIdxToString(argsMap, ArgsIdx::AN_FILE_NAME, hapArgs.fileName) != ERR_OK)) { + LOG_SA(ERROR) << "aot compiler args parsing error"; + return ERR_AOT_COMPILER_PARAM_FAILED; + } + + if (IsFileExists(hapArgs.fileName)) { + LOG_SA(INFO) << "framework's an is exist"; + return ERR_AOT_COMPILER_CALL_CANCELLED; + } + + hapArgs.argVector.clear(); + hapArgs.argVector.emplace_back(STATIC_AOT_EXE); + + hapArgs.signature = OWNERID_SHARED_TAG; + + hapArgs.bundleUid = OID_SYSTEM; + hapArgs.bundleGid = OID_SYSTEM; + + for (auto &defaultArg : staticFrameworkAOTDefaultArgs) { + hapArgs.argVector.emplace_back(defaultArg); + } + + std::string fullBootfiles; + if (!ParseBootPandaFiles(fullBootfiles)) { + return ERR_AOT_COMPILER_PARAM_FAILED; + } + std::string bootfiles = ParseFrameworkBootPandaFiles(fullBootfiles, abcPath); + if (bootfiles.empty()) { + LOG_SA(ERROR) << "can not find paoc panda files "; + return ERR_AOT_COMPILER_PARAM_FAILED; + } + hapArgs.argVector.emplace_back(Symbols::PREFIX + STATIC_BOOT_PANDA_FILES + Symbols::EQ + bootfiles); + + for (auto &argPair : argsMap) { + if (argPair.first == AN_FILE_NAME) { + hapArgs.argVector.emplace_back(Symbols::PREFIX + STATIC_PAOC_OUTPUT + Symbols::EQ + argPair.second); + } + } + hapArgs.argVector.emplace_back(Symbols::PREFIX + STATIC_PAOC_PANDA_FILES + Symbols::EQ + abcPath); + return ERR_OK; +} + +std::string StaticFrameworkAOTArgsParser::ParseFrameworkBootPandaFiles(const std::string &bootfiles, + const std::string &paocPandaFiles) +{ + size_t pos = bootfiles.find(paocPandaFiles); + std::string frameworkBootPandaFiles; + if (pos != std::string::npos) { + frameworkBootPandaFiles += bootfiles.substr(0, pos + paocPandaFiles.length()); + } + return frameworkBootPandaFiles; +} } // namespace OHOS::ArkCompiler diff --git a/compiler_service/src/aot_compiler_impl.cpp b/compiler_service/src/aot_compiler_impl.cpp index 66146545dd..d79b7230c6 100644 --- a/compiler_service/src/aot_compiler_impl.cpp +++ b/compiler_service/src/aot_compiler_impl.cpp @@ -133,6 +133,15 @@ void AotCompilerImpl::ExecuteInParentProcess(const pid_t childPid, int32_t &ret) } } +bool AotCompilerImpl::IsSystemComponent(const std::unordered_map &argsMap) +{ + auto isSystemComponent = argsMap.find(ArgsIdx::IS_SYSTEM_COMPONENT); + if (isSystemComponent != argsMap.end() && isSystemComponent->second != BOOLEAN_FALSE) { + return true; + } + return false; +} + bool AotCompilerImpl::VerifyCompilerModeAndPkgInfo(const std::unordered_map &argsMap) { auto targetCompilerMode = argsMap.find(ArgsIdx::TARGET_COMPILER_MODE); @@ -154,7 +163,7 @@ int32_t AotCompilerImpl::EcmascriptAotCompiler(const std::unordered_map +#include #include #include #include @@ -203,4 +204,47 @@ HWTEST_F(AotArgsHandlerTest, AotArgsHandlerTest_009, TestSize.Level0) std::string arg = aotVector[0]; EXPECT_STREQ(arg.c_str(), "--compiler-thermal-level=0"); } + +const std::unordered_map framewordArgsMapForTest { + {"outputPath", "/data/service/el1/public/for-all-app/framework_ark_cache/etsstdlib_bootabc.an"}, + {"anFileName", "/data/service/el1/public/for-all-app/framework_ark_cache/etsstdlib_bootabc.an"}, + {"isSysComp", "1"}, + {"sysCompPath", "/system/framework/etsstdlib_bootabc.abc"}, + {"ABC-Path", "/system/framework/etsstdlib_bootabc.abc"} +}; + +HWTEST_F(AotArgsHandlerTest, AotArgsHandlerTest_010, TestSize.Level0) +{ + const char *systemDir = "/system"; + const char *systemFrameworkDir = "/system/framework"; + const char *bootPathJson = "/system/framework/bootpath.json"; + mkdir(systemDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + mkdir(systemFrameworkDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + std::string bootpathJsonStr = + "{\"bootpath\":\"/system/framework/etsstdlib_bootabc.abc:/system/framework/arkoala.abc\"}"; + std::ofstream file(bootPathJson); + file << bootpathJsonStr << std::endl; + file.close(); + + std::unique_ptr argsHandler = std::make_unique(framewordArgsMapForTest); + int32_t ret = argsHandler->Handle(0); + EXPECT_EQ(ret, ERR_OK); + std::string fileName = argsHandler->GetFileName(); + EXPECT_TRUE(!fileName.empty()); + int32_t bundleUid; + int32_t bundleGid; + argsHandler->GetBundleId(bundleUid, bundleGid); + EXPECT_EQ(bundleUid, OID_SYSTEM); + EXPECT_EQ(bundleGid, OID_SYSTEM); + std::vector argv = argsHandler->GetAotArgs(); + EXPECT_STREQ(argv[0], "/system/bin/ark_aot"); + for (const auto& arg : argv) { + if (std::strcmp(arg, "boot-panda-files") == 0) { + EXPECT_STREQ(arg, "--boot-panda-files=/system/framework/etsstdlib_bootabc.abc"); + } + } + unlink(bootPathJson); + rmdir(systemFrameworkDir); + rmdir(systemDir); +} } // namespace OHOS::ArkCompiler \ No newline at end of file -- Gitee From 8eb686e67139a963c11030ab79b76778cb7adcd7 Mon Sep 17 00:00:00 2001 From: hewei Date: Wed, 21 May 2025 10:56:53 +0800 Subject: [PATCH 04/54] Add const modifier Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IC6L96 Change-Id: I52661bb90c4cf96b94d463da073896ae95278f8e Signed-off-by: hewei Signed-off-by: lhc --- ecmascript/dynamic_object_accessor.cpp | 27 ++++++++++++++----- ecmascript/dynamic_object_accessor.h | 20 +++++++------- ecmascript/dynamic_object_descriptor.h | 10 ++++--- ecmascript/dynamic_type_converter.cpp | 2 +- test/ut/ignore-ut-debug-x64-ets_runtime.txt | 3 +++ .../ut/ignore-ut-release-qemu-ets_runtime.txt | 3 +++ 6 files changed, 44 insertions(+), 21 deletions(-) diff --git a/ecmascript/dynamic_object_accessor.cpp b/ecmascript/dynamic_object_accessor.cpp index d851084886..b8fe9a8713 100644 --- a/ecmascript/dynamic_object_accessor.cpp +++ b/ecmascript/dynamic_object_accessor.cpp @@ -29,7 +29,9 @@ void DynamicObjectAccessor::Initialize() common::BaseObjectDispatcher::GetDispatcher().RegisterDynamicObjectAccessor(&dynObjectAccessor_); } -bool DynamicObjectAccessor::HasProperty(ThreadHolder *thread, BaseObject *obj, char *name) +bool DynamicObjectAccessor::HasProperty(ThreadHolder *thread, + const BaseObject *obj, + const char *name) const { JSThread *jsThread = thread->GetJSThread(); ObjectFactory *factory = jsThread->GetEcmaVM()->GetFactory(); @@ -39,7 +41,10 @@ bool DynamicObjectAccessor::HasProperty(ThreadHolder *thread, BaseObject *obj, c return JSTaggedValue::HasProperty(jsThread, holderHandle, keyHandle); } -JSTaggedValue DynamicObjectAccessor::GetProperty(ThreadHolder *thread, BaseObject *obj, char *name) + +JSTaggedValue DynamicObjectAccessor::GetProperty(ThreadHolder *thread, + const BaseObject *obj, + const char *name) const { JSThread *jsThread = thread->GetJSThread(); ObjectFactory *factory = jsThread->GetEcmaVM()->GetFactory(); @@ -49,7 +54,10 @@ JSTaggedValue DynamicObjectAccessor::GetProperty(ThreadHolder *thread, BaseObjec return JSTaggedValue::GetProperty(jsThread, holderHandle, keyHandle).GetValue().GetTaggedValue(); } -bool DynamicObjectAccessor::SetProperty(ThreadHolder *thread, BaseObject *obj, char *name, JSTaggedValue value) +bool DynamicObjectAccessor::SetProperty(ThreadHolder *thread, + BaseObject *obj, + const char *name, + JSTaggedValue value) { JSThread *jsThread = thread->GetJSThread(); ObjectFactory *factory = jsThread->GetEcmaVM()->GetFactory(); @@ -60,7 +68,9 @@ bool DynamicObjectAccessor::SetProperty(ThreadHolder *thread, BaseObject *obj, c return JSTaggedValue::SetProperty(jsThread, holderHandle, keyHandle, valueHandle); } -bool DynamicObjectAccessor::HasElementByIdx(ThreadHolder *thread, BaseObject *obj, uint32_t index) +bool DynamicObjectAccessor::HasElementByIdx(ThreadHolder *thread, + const BaseObject *obj, + const uint32_t index) const { JSThread *jsThread = thread->GetJSThread(); [[maybe_unused]] EcmaHandleScope handleScope(jsThread); @@ -68,7 +78,9 @@ bool DynamicObjectAccessor::HasElementByIdx(ThreadHolder *thread, BaseObject *ob return JSTaggedValue::HasProperty(jsThread, holderHandle, index); } -JSTaggedValue DynamicObjectAccessor::GetElementByIdx(ThreadHolder *thread, BaseObject *obj, uint32_t index) +JSTaggedValue DynamicObjectAccessor::GetElementByIdx(ThreadHolder *thread, + const BaseObject *obj, + const uint32_t index) const { JSThread *jsThread = thread->GetJSThread(); [[maybe_unused]] EcmaHandleScope handleScope(jsThread); @@ -76,7 +88,10 @@ JSTaggedValue DynamicObjectAccessor::GetElementByIdx(ThreadHolder *thread, BaseO return JSTaggedValue::GetProperty(jsThread, holderHandle, index).GetValue().GetTaggedValue(); } -bool DynamicObjectAccessor::SetElementByIdx(ThreadHolder *thread, BaseObject *obj, uint32_t index, JSTaggedValue value) +bool DynamicObjectAccessor::SetElementByIdx(ThreadHolder *thread, + BaseObject *obj, + const uint32_t index, + JSTaggedValue value) { JSThread *jsThread = thread->GetJSThread(); [[maybe_unused]] EcmaHandleScope handleScope(jsThread); diff --git a/ecmascript/dynamic_object_accessor.h b/ecmascript/dynamic_object_accessor.h index 5bf4d0f70b..3e7d138ae6 100644 --- a/ecmascript/dynamic_object_accessor.h +++ b/ecmascript/dynamic_object_accessor.h @@ -27,25 +27,25 @@ class DynamicObjectAccessor : public common::DynamicObjectAccessorInterface { public: static void Initialize(); - bool HasProperty(ThreadHolder *thread, BaseObject *obj, - char *name) override; + bool HasProperty(ThreadHolder *thread, const BaseObject *obj, + const char *name) const override; - JSTaggedValue GetProperty(ThreadHolder *thread, BaseObject *obj, - char *name) override; + JSTaggedValue GetProperty(ThreadHolder *thread, const BaseObject *obj, + const char *name) const override; bool SetProperty(ThreadHolder *thread, BaseObject *obj, - char *name, JSTaggedValue value) override; + const char *name, JSTaggedValue value) override; bool HasElementByIdx(ThreadHolder *thread, - BaseObject *obj, - uint32_t index) override; + const BaseObject *obj, + const uint32_t index) const override; JSTaggedValue GetElementByIdx(ThreadHolder *thread, - BaseObject *obj, - uint32_t index) override; + const BaseObject *obj, + const uint32_t index) const override; bool SetElementByIdx(ThreadHolder *thread, BaseObject *obj, - uint32_t index, JSTaggedValue value) override; + const uint32_t index, JSTaggedValue value) override; private: static DynamicObjectAccessor dynObjectAccessor_; diff --git a/ecmascript/dynamic_object_descriptor.h b/ecmascript/dynamic_object_descriptor.h index 3e4391e7d8..30bf7f4a7e 100644 --- a/ecmascript/dynamic_object_descriptor.h +++ b/ecmascript/dynamic_object_descriptor.h @@ -25,13 +25,15 @@ class DynamicObjectDescriptor : public common::DynamicObjectDescriptorInterface public: static void Initialize(); - std::pair GetProperty(ThreadHolder *thread, BaseObject *obj, char *name) override; + std::pair GetProperty(ThreadHolder *thread, + const BaseObject *obj, + const char *name) const override; - std::pair SetProperty(ThreadHolder *thread, BaseObject *obj, char *name, + std::pair SetProperty(ThreadHolder *thread, BaseObject *obj, const char *name, JSTaggedValue value) override; - std::pair GetElementByIdx(ThreadHolder *thread, BaseObject *obj, - uint32_t index) override; + std::pair GetElementByIdx(ThreadHolder *thread, const BaseObject *obj, + const uint32_t index) const override; std::pair SetElementByIdx(ThreadHolder *thread, BaseObject *obj, uint32_t index, JSTaggedValue value) override; diff --git a/ecmascript/dynamic_type_converter.cpp b/ecmascript/dynamic_type_converter.cpp index e78bd6185f..bbaaaff7c1 100644 --- a/ecmascript/dynamic_type_converter.cpp +++ b/ecmascript/dynamic_type_converter.cpp @@ -71,7 +71,7 @@ JSTaggedValue DynamicTypeConverter::WrapTagged(ThreadHolder *thread, BaseType va return result; } -BaseType DynamicTypeConverter::UnWrapTagged(JSTaggedValue value) +PandaType DynamicTypeConverter::UnwrapTagged(JSTaggedValue value) { if (value.IsBoolean()) { return value.ToBoolean(); diff --git a/test/ut/ignore-ut-debug-x64-ets_runtime.txt b/test/ut/ignore-ut-debug-x64-ets_runtime.txt index 291b1da9ec..4247858039 100644 --- a/test/ut/ignore-ut-debug-x64-ets_runtime.txt +++ b/test/ut/ignore-ut-debug-x64-ets_runtime.txt @@ -20,3 +20,6 @@ obj/arkcompiler/ets_runtime/test/aottest/forin_enum_cache_chain/forin_enum_cache #25962 obj/arkcompiler/ets_runtime/ecmascript/tests/JS_Hclass_Test + +#25854 +obj/arkcompiler/ets_runtime/ecmascript/tests/Sendable_JsSharedArray_Test diff --git a/test/ut/ignore-ut-release-qemu-ets_runtime.txt b/test/ut/ignore-ut-release-qemu-ets_runtime.txt index 1a4a4792b0..e8dbd61420 100644 --- a/test/ut/ignore-ut-release-qemu-ets_runtime.txt +++ b/test/ut/ignore-ut-release-qemu-ets_runtime.txt @@ -198,3 +198,6 @@ obj/arkcompiler/ets_runtime/test/moduletest/hugearray/hugearryAsmAssert #24283 #26429 obj/arkcompiler/ets_runtime/ecmascript/base/tests/JSHelper_NumberHelper_TestWithQemu + +#26017 +obj/arkcompiler/ets_runtime/test/moduletest/allocatearraybuffer/allocatearraybufferAsm \ No newline at end of file -- Gitee From 5ee348d6e73e9aca158f417db0be1cae806542df Mon Sep 17 00:00:00 2001 From: wengchangcheng Date: Sat, 24 May 2025 12:26:24 +0800 Subject: [PATCH 05/54] Fix compiler error Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICA85Z Signed-off-by: wengchangcheng Change-Id: I35b983bf54c5f5e02d14e1e97668c9b4db893d3a Signed-off-by: lhc --- ecmascript/dynamic_object_descriptor.cpp | 19 ++++++++++++------- ecmascript/dynamic_object_descriptor.h | 2 +- ecmascript/runtime.cpp | 3 ++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ecmascript/dynamic_object_descriptor.cpp b/ecmascript/dynamic_object_descriptor.cpp index 0e870e7fad..77f5974990 100644 --- a/ecmascript/dynamic_object_descriptor.cpp +++ b/ecmascript/dynamic_object_descriptor.cpp @@ -26,27 +26,32 @@ void DynamicObjectDescriptor::Initialize() common::BaseObjectDispatcher::GetDispatcher().RegisterDynamicObjectDescriptor(&dynObjectDescriptor_); } -std::pair DynamicObjectDescriptor::GetProperty(ThreadHolder *thread, BaseObject *obj, - char *name) +std::pair DynamicObjectDescriptor::GetProperty(ThreadHolder *thread, + const BaseObject *obj, + const char *name) const { return std::make_pair(JSTaggedValue(), HandlerBase()); } std::pair DynamicObjectDescriptor::SetProperty(ThreadHolder *thread, - BaseObject *obj, char *name, + BaseObject *obj, + const char *name, JSTaggedValue value) { return std::make_pair(false, HandlerBase()); } -std::pair DynamicObjectDescriptor::GetElementByIdx(ThreadHolder *thread, BaseObject *obj, - uint32_t index) +std::pair DynamicObjectDescriptor::GetElementByIdx(ThreadHolder *thread, + const BaseObject *obj, + uint32_t index) const { return std::make_pair(JSTaggedValue::Undefined(), HandlerBase()); } -std::pair DynamicObjectDescriptor::SetElementByIdx(ThreadHolder *thread, BaseObject *obj, - uint32_t index, JSTaggedValue value) +std::pair DynamicObjectDescriptor::SetElementByIdx(ThreadHolder *thread, + BaseObject *obj, + uint32_t index, + JSTaggedValue value) { return std::make_pair(false, HandlerBase()); } diff --git a/ecmascript/dynamic_object_descriptor.h b/ecmascript/dynamic_object_descriptor.h index 30bf7f4a7e..04440f5e7a 100644 --- a/ecmascript/dynamic_object_descriptor.h +++ b/ecmascript/dynamic_object_descriptor.h @@ -33,7 +33,7 @@ public: JSTaggedValue value) override; std::pair GetElementByIdx(ThreadHolder *thread, const BaseObject *obj, - const uint32_t index) const override; + uint32_t index) const override; std::pair SetElementByIdx(ThreadHolder *thread, BaseObject *obj, uint32_t index, JSTaggedValue value) override; diff --git a/ecmascript/runtime.cpp b/ecmascript/runtime.cpp index 7f25657f7a..ec57d3cf09 100644 --- a/ecmascript/runtime.cpp +++ b/ecmascript/runtime.cpp @@ -16,10 +16,11 @@ #include "ecmascript/runtime.h" #include "ecmascript/checkpoint/thread_state_transition.h" #include "common_interfaces/base_runtime.h" + +#include "common_interfaces/thread/thread_holder_manager.h" #include "ecmascript/dynamic_object_accessor.h" #include "ecmascript/dynamic_object_descriptor.h" #include "ecmascript/dynamic_type_converter.h" -#include "common_interfaces/thread/thread_holder_manager.h" #include "ecmascript/jit/jit.h" #include "ecmascript/jspandafile/program_object.h" #include "ecmascript/js_runtime_options.h" -- Gitee From ac0bd84a7a152f32ce857e9aa98aa6649c441069 Mon Sep 17 00:00:00 2001 From: lhc Date: Wed, 9 Jul 2025 00:01:30 +0800 Subject: [PATCH 06/54] merge 0702 Signed-off-by: lhc Change-Id: Ia5a84afbdde717cf791a0afe221faed1a562159c --- ecmascript/ecma_string.h | 2 - ...resstest-fastverify-x64-aot-pgo-litecg.txt | 3 + ...ignore-ut-debug-x64-ets_runtime-cmc-gc.txt | 9 + ...ore-ut-release-qemu-ets_runtime-cmc-gc.txt | 224 ++++++++++++++++++ ...nore-ut-release-x64-ets_runtime-cmc-gc.txt | 17 ++ 5 files changed, 253 insertions(+), 2 deletions(-) diff --git a/ecmascript/ecma_string.h b/ecmascript/ecma_string.h index cfb447e75e..c640d3f880 100755 --- a/ecmascript/ecma_string.h +++ b/ecmascript/ecma_string.h @@ -21,11 +21,9 @@ #include #include "common_components/base/utf_helper.h" -#include "common_interfaces/objects/base_string.h" #include "common_interfaces/objects/string/line_string.h" #include "common_interfaces/objects/string/sliced_string.h" #include "common_interfaces/objects/string/tree_string.h" -#include "common_interfaces/objects/string/base_string-inl1.h" #include "ecmascript/common.h" #include "ecmascript/ecma_macros.h" #include "ecmascript/js_hclass.h" diff --git a/test/regresstest/ignored-regresstest-fastverify-x64-aot-pgo-litecg.txt b/test/regresstest/ignored-regresstest-fastverify-x64-aot-pgo-litecg.txt index bcbee314c8..b5fd7e2d30 100644 --- a/test/regresstest/ignored-regresstest-fastverify-x64-aot-pgo-litecg.txt +++ b/test/regresstest/ignored-regresstest-fastverify-x64-aot-pgo-litecg.txt @@ -17,3 +17,6 @@ regresstest/ark-regress/mjsunit/es6/array-concat-spreadable-function.js # Issue #20325 regresstest/ark-regress/mjsunit/regress/regress-crbug-1263994.js + +#26099 +regresstest/ark-regress/mjsunit/regress/regress-3612.js diff --git a/test/ut/ignore-ut-debug-x64-ets_runtime-cmc-gc.txt b/test/ut/ignore-ut-debug-x64-ets_runtime-cmc-gc.txt index d9d9db1537..6554c101ec 100644 --- a/test/ut/ignore-ut-debug-x64-ets_runtime-cmc-gc.txt +++ b/test/ut/ignore-ut-debug-x64-ets_runtime-cmc-gc.txt @@ -8,3 +8,12 @@ obj/arkcompiler/ets_runtime/ecmascript/jspandafile/tests/JSPandaFileTest #27094 obj/arkcompiler/ets_runtime/test/aottest/forin_enum_cache_chain/forin_enum_cache_chain/pgo + +#21813 +obj/arkcompiler/ets_runtime/test/jittest/try_catch_empty/try_catch_empty + +#23099 +obj/arkcompiler/ets_runtime/ecmascript/pgo_profiler/tests/PGOProfilerTestOne + +#24219 +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_Barrier_Test \ No newline at end of file diff --git a/test/ut/ignore-ut-release-qemu-ets_runtime-cmc-gc.txt b/test/ut/ignore-ut-release-qemu-ets_runtime-cmc-gc.txt index 0ec667650e..df14543114 100644 --- a/test/ut/ignore-ut-release-qemu-ets_runtime-cmc-gc.txt +++ b/test/ut/ignore-ut-release-qemu-ets_runtime-cmc-gc.txt @@ -1 +1,225 @@ # Known failure list for ut - release - qemu - ets_runtime -cmc -gc + +#21801 +obj/arkcompiler/ets_runtime/test/aottest/builtin_inlining/math/Ceil/builtinMathCeilContext + +#20471 +obj/arkcompiler/ets_runtime/test/aottest/builtin_inlining/set/Delete/builtinSetDelete + +#23236 +obj/arkcompiler/ets_runtime/test/moduletest/hugearray/hugearryAsmAssertContext + +#22100 +obj/arkcompiler/ets_runtime/ecmascript/tests/GC_NewToOldPromotion_Test + +#24283 +obj/arkcompiler/ets_runtime/test/aottest/add/add/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/analyze_property/dictionary_mode/dictionary_mode/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/analyze_property/multi_storing/multi_storing/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/analyze_property/base/base/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/analyze_property/escape_this/escape_this/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/analyze_property/not_meet_subtyping/not_meet_subtyping/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/analyze_property/loading_before_storing/loading_before_storing/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/aot_compatibility_test/base_verification/base_verification/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/array_forof_test/array_forof_test/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/array_inline_exception/array_inline_exception/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/async_context/async_context/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/builtin_math1/builtin_math1/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/builtin_math1/builtin_math1Context/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/call_builtin_objects/call_builtin_objects/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/createarraywithbuffer3/createarraywithbuffer3/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/createarraywithbuffer2/createarraywithbuffer2/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/dateview_native_inline/dateview_native_inline/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/deopt/deopt/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/deopt/deoptContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/duplicatekey/duplicatekey/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/func_profile_type_info/func_profile_type_info/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/inline_abs/inline_abs/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/instanceof/instanceof/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/newobjrange/newobjrange/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_float32array_construct/pgo_float32array_construct/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_retype/pgo_retype/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/proxy_fast_call/proxy_fast_call/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/retype_isnan/retype_isnan/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/retype_test2/retype_test2/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/proxy2/proxy2/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/stobjbyname/stobjbyname/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/string_add/string_add/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/string_add/string_addContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/string_inline/string_inline/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/string_slice/string_slice/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/string_sub_string/string_sub_string/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/string_sub_str/string_sub_str/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/supercallforward/supercallforward/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/typedarraymap/typedarraymap/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/vtable/break_inherit_info/break_inherit_info_on_object/break_inherit_info_on_object/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/webkit_call_convention/webkit_call_convention/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/deopttest/elements_kind/elements_kind/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/deopttest/newobjrange_nodeopt/newobjrange_nodeopt/LiteCG +obj/arkcompiler/ets_runtime/ecmascript/compiler/aot_file/tests/AOTFileTest/aot_file_test.o +obj/arkcompiler/ets_runtime/ecmascript/base/tests/JSHelper_NumberHelper_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/dfx/hprof/tests/HeapTrackerThirdTest/heap_tracker_third_test.o +obj/arkcompiler/ets_runtime/ecmascript/dfx/hprof/tests/HeapDumpTest/heap_dump_test.o +obj/arkcompiler/ets_runtime/ecmascript/dfx/hprof/tests/HeapTrackerSecondTest/heap_tracker_second_test.o +obj/arkcompiler/ets_runtime/ecmascript/dfx/hprof/tests/HeapSnapShotTest/heap_snapshot_test.o +obj/arkcompiler/ets_runtime/ecmascript/dfx/hprof/tests/HeapTrackerFirstTest/heap_tracker_first_test.o +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_DateTimeFormat_Second_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/dfx/hprof/tests/JSMetadataTest/js_metadata_test.o +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Intl_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_DisPlayNames_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_ListFormat_First_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_ListFormat_Second_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Local_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_PluralRules_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_RelativeTimeFormat_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Segmenter_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_String_TestWithQemu +tests/unittest/ets_runtime/ExtractorToolTest +obj/arkcompiler/ets_runtime/ecmascript/pgo_profiler/tests/PGOProfilerTest/pgo_profiler_test.o +obj/arkcompiler/ets_runtime/ecmascript/napi/test/Jsnapi_Sendable_Test/jsnapi_sendable_tests.o +obj/arkcompiler/ets_runtime/ecmascript/pgo_profiler/tests/PGOProfilerTestOne/pgo_profiler_test_one.o +obj/arkcompiler/ets_runtime/ecmascript/jspandafile/tests/JSPandaFileTestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/platform/unix/ohos/tests/BacktraceTestWithQemu +tests/unittest/ets_runtime/Jsnapi_002_Test +tests/unittest/ets_runtime/SerializerTest +obj/arkcompiler/ets_runtime/ecmascript/tests/GC_Second_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_AsyncGengeratorObject_Test/js_async_generator_object_test.o +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_Collator_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_DateTimeFormat_First_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_Date_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_DisPlayNames_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_DateTimeFormat_Second_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_LocaleHelper_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_Object_Test/js_object_test.o +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_Locale_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_NumberFormat_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_PluralRules_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_RelativeTimeFormat_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_TaggedQueue_Test/js_tagged_queue_test.o +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_TaggedValue_Test/tagged_value_test.o +obj/arkcompiler/ets_runtime/test/aottest/array_concat/array_concat/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/array_concat/array_concatContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/builtins_decode_uri_component/builtins_decode_uri_componentContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/builtins_decode_uri_component/builtins_decode_uri_component/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/construct_deopt_frame_stack_overflow2/construct_deopt_frame_stack_overflow2/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/construct_deopt_frame_stack_overflow2/construct_deopt_frame_stack_overflow2Context/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/construct_deopt_frame_stack_overflow/construct_deopt_frame_stack_overflow/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/construct_deopt_frame_stack_overflow/construct_deopt_frame_stack_overflowContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/definefieldbyname2/definefieldbyname2/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/definefieldbyname2/definefieldbyname2Context/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/elements_kind/elements_kind/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/elements_kind/elements_kindContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/elements_kind_update/elements_kind_update/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/elements_kind_update/elements_kind_updateContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/frame_iteration/frame_iteration/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/frame_iteration/frame_iterationContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/icnotfound/icnotfoundContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/icnotfound/icnotfound/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/intern_string_strict_equal1/intern_string_strict_equal1/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/intern_string_strict_equal1/intern_string_strict_equal1Context/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/intern_string_strict_equal2/intern_string_strict_equal2/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/intern_string_strict_equal2/intern_string_strict_equal2Context/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/mono_builtin/mono_builtinContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/mono_builtin/mono_builtin/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/nested_try_emptycatch/nested_try_emptycatch/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/nested_if_try_emptycatch/nested_if_try_emptycatchContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/nested_try_emptycatch_finally/nested_try_emptycatch_finally/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/nested_try_emptycatch_finally/nested_try_emptycatch_finallyContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/nested_try_emptycatch/nested_try_emptycatchContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/object_literal/object_literal/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/object_literal/object_literalContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_aot_call_deopt_bridge/pgo_aot_call_deopt_bridge/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_aot_call_deopt_bridge/pgo_aot_call_deopt_bridgeContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_aot_newobj/pgo_aot_newobj/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_aot_newobj/pgo_aot_newobjContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_char_to_string_deopt/pgo_char_to_string_deopt/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_char_to_string_deopt/pgo_char_to_string_deoptContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_class_prototype/pgo_class_prototype/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_class_prototype/pgo_class_prototypeContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgostand_value_deopt/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_constant_value_deopt/pgo_constant_value_deoptContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_fast_call_bridge/pgo_fast_call_bridgeContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_fast_call_bridge/pgo_fast_call_bridge/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_fast_call_deopt_bridge/pgo_fast_call_deopt_bridge/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_fast_call_deopt_bridge/pgo_fast_call_deopt_bridgeContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_forof_map/pgo_forof_map/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_forof_map/pgo_forof_mapContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_function_operation/pgo_function_operationContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_function_operation/pgo_function_operation/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_inherited_function_operation/pgo_inherited_function_operationContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_inherited_function_operation/pgo_function_operation/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_Idobjbyvalue_string/pgo_Idobjbyvalue_string/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_Idobjbyvalue_string/pgo_Idobjbyvalue_stringContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_napi1/pgo_napi1/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_napi2/pgo_napi2/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_Idobjbyvalue_array/pgo_Idobjbyvalue_array/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_napi1/pgo_napi1Context/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_napi2/pgo_napi2Context/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_Idobjbyvalue_array/pgo_Idobjbyvalue_arrayContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_space_flag/pgo_space_flag/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_track_type/pgo_track_type/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_space_flag/pgo_space_flagContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_track_type/pgo_track_typeContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/regressioncase/regressioncase/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/regressioncase/regressioncaseContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/stobjbyname1/stobjbyname1/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/stobjbyname1/stobjbyname1Context/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/shr_overflow/shr_overflowContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/supercall/supercall/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/shr_overflow/shr_overflow/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/supercall/supercallContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/sync_representation/sync_representation/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/sync_representation/sync_representationContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/try_emptycatch_switch_case/try_emptycatch_switch_case/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/try_emptycatch_forloop/try_emptycatch_forloop/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/try_emptycatch_nested/try_emptycatch_nested/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/try_emptycatch_forloop/try_emptycatch_forloopContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/try_forloop_emptycatch/try_forloop_emptycatch/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/try_emptycatch_switch_case/try_emptycatch_switch_caseContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/try_forloop_emptycatch/try_forloop_emptycatchContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/try_emptycatch_nested/try_emptycatch_nestedContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/dataview_native_inline/dataview_native_inline/SlowPath/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/nested_if_try_emptycatch/nested_if_try_emptycatch/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_constant_value_deopt/pgo_constant_value_deopt/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_inherited_function_operation/pgo_inherited_function_operation/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_ldobjbyvalue_string/pgo_ldobjbyvalue_string/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_ldobjbyvalue_string/pgo_ldobjbyvalue_stringContext/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_ldobjbyvalue_array/pgo_ldobjbyvalue_array/LiteCG +obj/arkcompiler/ets_runtime/test/aottest/pgo_ldobjbyvalue_array/pgo_ldobjbyvalue_arrayContext/LiteCG +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Collator_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_NumberFormat_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_DateTimeFormat_First_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_BigInt_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/JS_ListFormat_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_ListFormat_TestWithQemu + +#25856 +obj/arkcompiler/ets_runtime/ecmascript/mem/cmc_gc/libcommon_components_set/gc_hooks.o + +#26061 +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Global_Test +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Array_Test +obj/arkcompiler/ets_runtime/ecmascript/pgo_profiler/tests/PGOProfilerTest +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_FinalizationRegistry_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/napi/test/Jsnapi_001_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/base/tests/JS_JsonStringlfier_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Json_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/base/tests/JS_Ason_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Atomics_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Lazy_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/base/tests/JSHelper_UtfHelper_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Regexp_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Sendable_BuiltinsSendableArrayBuffer_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Number_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Errors_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Object_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Data_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/containers/tests/Containers_002_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Array_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/pgo_profiler/tests/PGOProfilerTestOneWithQemu +obj/arkcompiler/ets_runtime/ecmascript/containers/tests/Containers_001_TestWithQemu +obj/arkcompiler/ets_runtime/test/moduletest/arrayRelease/arrayReleaseAsmAssert +obj/arkcompiler/ets_runtime/test/moduletest/arrayRelease/arrayReleaseAsmAssertContext +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_DataView_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Sendable_BuiltinsSharedTypedArray_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Sendable_BuiltinsSharedArray_TestWithQemu \ No newline at end of file diff --git a/test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt b/test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt index 036be17962..84643a67fe 100644 --- a/test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt +++ b/test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt @@ -1 +1,18 @@ # Known failure list for ut - release - x64 - ets_runtime -cmc -gc +#20980 +obj/arkcompiler/ets_runtime/test/aottest/builtin_inlining/map/Delete/builtinMapDelete + +#20471 +obj/arkcompiler/ets_runtime/test/aottest/builtin_inlining/set/Delete/builtinSetDelete + +#21629 +obj/arkcompiler/ets_runtime/test/aottest/builtin_inlining/set/Delete/builtinSetDeleteContext + +#20896 +obj/arkcompiler/ets_runtime/test/aottest/builtin_inlining/math/Ceil/builtinMathCeil + +#21801 +obj/arkcompiler/ets_runtime/test/aottest/builtin_inlining/math/Ceil/builtinMathCeilContext + +#20981 +obj/arkcompiler/ets_runtime/test/aottest/builtin_inlining/map/Delete/builtinMapDeleteContext \ No newline at end of file -- Gitee From 167168457caf86a1357bea01401b91834c847bdb Mon Sep 17 00:00:00 2001 From: lhc Date: Wed, 9 Jul 2025 00:49:43 +0800 Subject: [PATCH 07/54] Disabling ArkTools.GC interface Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICA6L2 Signed-off-by: lhc Change-Id: Ic398104b9405ab7c089579eedb950be0a963b043 --- ecmascript/builtins/builtins_ark_tools.cpp | 14 -- ecmascript/builtins/builtins_ark_tools.h | 14 ++ ecmascript/builtins/builtins_gc.cpp | 11 + ...ignore-ut-debug-x64-ets_runtime-cmc-gc.txt | 6 - ...ore-ut-release-qemu-ets_runtime-cmc-gc.txt | 227 +++--------------- ...nore-ut-release-x64-ets_runtime-cmc-gc.txt | 19 +- 6 files changed, 54 insertions(+), 237 deletions(-) diff --git a/ecmascript/builtins/builtins_ark_tools.cpp b/ecmascript/builtins/builtins_ark_tools.cpp index b94ff95149..34c3ffe1db 100644 --- a/ecmascript/builtins/builtins_ark_tools.cpp +++ b/ecmascript/builtins/builtins_ark_tools.cpp @@ -24,20 +24,6 @@ #include "builtins_typedarray.h" #include "ecmascript/jit/jit.h" -#if defined(PANDA_TARGET_ARM64) - /* Note: If not open ArkTools option(set by `persist.ark.mem_config_property openArkTools`), */ - /* ArkTools return Empty Implementation */ - // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) - #define RETURN_IF_DISALLOW_ARKTOOLS(thread) \ - do { \ - if (!((thread)->GetEcmaVM()->GetJSOptions().IsOpenArkTools())) { \ - return JSTaggedValue::Undefined(); \ - } \ - } while (0) -#else - #define RETURN_IF_DISALLOW_ARKTOOLS(thread) static_cast(0) // NOLINT(cppcoreguidelines-macro-usage) -#endif - namespace panda::ecmascript::builtins { using StringHelper = base::StringHelper; diff --git a/ecmascript/builtins/builtins_ark_tools.h b/ecmascript/builtins/builtins_ark_tools.h index 1b9ebd6406..84bd399bde 100644 --- a/ecmascript/builtins/builtins_ark_tools.h +++ b/ecmascript/builtins/builtins_ark_tools.h @@ -19,6 +19,20 @@ #include "ecmascript/base/builtins_base.h" #include "ecmascript/js_thread.h" +#if defined(PANDA_TARGET_ARM64) + /* Note: If not open ArkTools option(set by `persist.ark.mem_config_property openArkTools`), */ + /* ArkTools return Empty Implementation */ + // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) + #define RETURN_IF_DISALLOW_ARKTOOLS(thread) \ + do { \ + if (!((thread)->GetEcmaVM()->GetJSOptions().IsOpenArkTools())) { \ + return JSTaggedValue::Undefined(); \ + } \ + } while (0) +#else + #define RETURN_IF_DISALLOW_ARKTOOLS(thread) static_cast(0) // NOLINT(cppcoreguidelines-macro-usage) +#endif + // List of functions in ArkTools, extension of ArkTS engine. // V(name, func, length, stubIndex) // where BuiltinsArkTools::func refers to the native implementation of ArkTools[name]. diff --git a/ecmascript/builtins/builtins_gc.cpp b/ecmascript/builtins/builtins_gc.cpp index 1fe1b844d9..0e39d658d4 100644 --- a/ecmascript/builtins/builtins_gc.cpp +++ b/ecmascript/builtins/builtins_gc.cpp @@ -14,6 +14,7 @@ */ #include "ecmascript/builtins/builtins_gc.h" +#include "ecmascript/builtins/builtins_ark_tools.h" #include "ecmascript/mem/heap-inl.h" #include "ecmascript/js_tagged_value-inl.h" #include "ecmascript/interpreter/interpreter-inl.h" @@ -22,6 +23,7 @@ namespace panda::ecmascript::builtins { JSTaggedValue BuiltinsGc::GetFreeHeapSize(EcmaRuntimeCallInfo *info) { + RETURN_IF_DISALLOW_ARKTOOLS(info->GetThread()); if (g_isEnableCMCGC) { auto size = common::Heap::GetHeap().GetRemainHeapSize(); return JSTaggedValue(static_cast(size)); @@ -33,6 +35,7 @@ JSTaggedValue BuiltinsGc::GetFreeHeapSize(EcmaRuntimeCallInfo *info) JSTaggedValue BuiltinsGc::GetReservedHeapSize(EcmaRuntimeCallInfo *info) { + RETURN_IF_DISALLOW_ARKTOOLS(info->GetThread()); if (g_isEnableCMCGC) { auto size = common::Heap::GetHeap().GetMaxCapacity(); return JSTaggedValue(static_cast(size)); @@ -43,6 +46,7 @@ JSTaggedValue BuiltinsGc::GetReservedHeapSize(EcmaRuntimeCallInfo *info) JSTaggedValue BuiltinsGc::GetUsedHeapSize(EcmaRuntimeCallInfo *info) { + RETURN_IF_DISALLOW_ARKTOOLS(info->GetThread()); if (g_isEnableCMCGC) { auto size = common::Heap::GetHeap().GetAllocatedSize(); return JSTaggedValue(static_cast(size)); @@ -53,12 +57,14 @@ JSTaggedValue BuiltinsGc::GetUsedHeapSize(EcmaRuntimeCallInfo *info) JSTaggedValue BuiltinsGc::GetObjectAddress(EcmaRuntimeCallInfo *info) { + RETURN_IF_DISALLOW_ARKTOOLS(info->GetThread()); JSHandle h = GetCallArg(info, 0); return JSTaggedValue(reinterpret_cast(h->GetHeapObject())); } JSTaggedValue BuiltinsGc::GetObjectSpaceType(EcmaRuntimeCallInfo *info) { + RETURN_IF_DISALLOW_ARKTOOLS(info->GetThread()); JSHandle h = GetCallArg(info, 0); auto *region = Region::ObjectAddressToRange(h->GetHeapObject()); return JSTaggedValue(region->GetSpaceType()); @@ -81,6 +87,7 @@ JSTaggedValue BuiltinsGc::RegisterNativeAllocation(EcmaRuntimeCallInfo *info) JSTaggedValue BuiltinsGc::RegisterNativeFree(EcmaRuntimeCallInfo *info) { + RETURN_IF_DISALLOW_ARKTOOLS(info->GetThread()); JSHandle h = GetCallArg(info, 0); auto *heap = const_cast(info->GetThread()->GetEcmaVM()->GetHeap()); auto size = h->GetInt(); @@ -95,6 +102,7 @@ JSTaggedValue BuiltinsGc::RegisterNativeFree(EcmaRuntimeCallInfo *info) JSTaggedValue BuiltinsGc::ClearWeakRefForTest(EcmaRuntimeCallInfo *info) { + RETURN_IF_DISALLOW_ARKTOOLS(info->GetThread()); ASSERT(info); JSThread *thread = info->GetThread(); if (!((thread)->GetEcmaVM()->GetJSOptions().IsOpenArkTools())) { @@ -106,6 +114,7 @@ JSTaggedValue BuiltinsGc::ClearWeakRefForTest(EcmaRuntimeCallInfo *info) JSTaggedValue BuiltinsGc::WaitForFinishGC(EcmaRuntimeCallInfo *info) { + RETURN_IF_DISALLOW_ARKTOOLS(info->GetThread()); auto *heap = const_cast(info->GetThread()->GetEcmaVM()->GetHeap()); auto gcId = GetCallArg(info, 0)->GetInt(); if (gcId <= 0) { @@ -122,6 +131,7 @@ JSTaggedValue BuiltinsGc::WaitForFinishGC(EcmaRuntimeCallInfo *info) JSTaggedValue BuiltinsGc::StartGC(EcmaRuntimeCallInfo *info) { + RETURN_IF_DISALLOW_ARKTOOLS(info->GetThread()); static int counter = 0; auto *thread = info->GetThread(); auto *heap = const_cast(info->GetThread()->GetEcmaVM()->GetHeap()); @@ -190,6 +200,7 @@ void BuiltinsGc::WaitAndHandleConcurrentMarkingFinished(Heap *heap) JSTaggedValue BuiltinsGc::AllocateArrayObject(EcmaRuntimeCallInfo *info) { + RETURN_IF_DISALLOW_ARKTOOLS(info->GetThread()); auto *thread = info->GetThread(); auto *factory = thread->GetEcmaVM()->GetFactory(); ASSERT(thread != nullptr); diff --git a/test/ut/ignore-ut-debug-x64-ets_runtime-cmc-gc.txt b/test/ut/ignore-ut-debug-x64-ets_runtime-cmc-gc.txt index 6554c101ec..9269c4dfee 100644 --- a/test/ut/ignore-ut-debug-x64-ets_runtime-cmc-gc.txt +++ b/test/ut/ignore-ut-debug-x64-ets_runtime-cmc-gc.txt @@ -9,11 +9,5 @@ obj/arkcompiler/ets_runtime/ecmascript/jspandafile/tests/JSPandaFileTest #27094 obj/arkcompiler/ets_runtime/test/aottest/forin_enum_cache_chain/forin_enum_cache_chain/pgo -#21813 -obj/arkcompiler/ets_runtime/test/jittest/try_catch_empty/try_catch_empty - #23099 obj/arkcompiler/ets_runtime/ecmascript/pgo_profiler/tests/PGOProfilerTestOne - -#24219 -obj/arkcompiler/ets_runtime/ecmascript/tests/JS_Barrier_Test \ No newline at end of file diff --git a/test/ut/ignore-ut-release-qemu-ets_runtime-cmc-gc.txt b/test/ut/ignore-ut-release-qemu-ets_runtime-cmc-gc.txt index df14543114..d16f44452d 100644 --- a/test/ut/ignore-ut-release-qemu-ets_runtime-cmc-gc.txt +++ b/test/ut/ignore-ut-release-qemu-ets_runtime-cmc-gc.txt @@ -1,225 +1,52 @@ # Known failure list for ut - release - qemu - ets_runtime -cmc -gc -#21801 -obj/arkcompiler/ets_runtime/test/aottest/builtin_inlining/math/Ceil/builtinMathCeilContext - -#20471 -obj/arkcompiler/ets_runtime/test/aottest/builtin_inlining/set/Delete/builtinSetDelete - -#23236 -obj/arkcompiler/ets_runtime/test/moduletest/hugearray/hugearryAsmAssertContext - -#22100 -obj/arkcompiler/ets_runtime/ecmascript/tests/GC_NewToOldPromotion_Test - #24283 -obj/arkcompiler/ets_runtime/test/aottest/add/add/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/analyze_property/dictionary_mode/dictionary_mode/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/analyze_property/multi_storing/multi_storing/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/analyze_property/base/base/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/analyze_property/escape_this/escape_this/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/analyze_property/not_meet_subtyping/not_meet_subtyping/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/analyze_property/loading_before_storing/loading_before_storing/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/aot_compatibility_test/base_verification/base_verification/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/array_forof_test/array_forof_test/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/array_inline_exception/array_inline_exception/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/async_context/async_context/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/builtin_math1/builtin_math1/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/builtin_math1/builtin_math1Context/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/call_builtin_objects/call_builtin_objects/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/createarraywithbuffer3/createarraywithbuffer3/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/createarraywithbuffer2/createarraywithbuffer2/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/dateview_native_inline/dateview_native_inline/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/deopt/deopt/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/deopt/deoptContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/duplicatekey/duplicatekey/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/func_profile_type_info/func_profile_type_info/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/inline_abs/inline_abs/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/instanceof/instanceof/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/newobjrange/newobjrange/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_float32array_construct/pgo_float32array_construct/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_retype/pgo_retype/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/proxy_fast_call/proxy_fast_call/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/retype_isnan/retype_isnan/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/retype_test2/retype_test2/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/proxy2/proxy2/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/stobjbyname/stobjbyname/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/string_add/string_add/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/string_add/string_addContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/string_inline/string_inline/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/string_slice/string_slice/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/string_sub_string/string_sub_string/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/string_sub_str/string_sub_str/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/supercallforward/supercallforward/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/typedarraymap/typedarraymap/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/vtable/break_inherit_info/break_inherit_info_on_object/break_inherit_info_on_object/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/webkit_call_convention/webkit_call_convention/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/deopttest/elements_kind/elements_kind/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/deopttest/newobjrange_nodeopt/newobjrange_nodeopt/LiteCG -obj/arkcompiler/ets_runtime/ecmascript/compiler/aot_file/tests/AOTFileTest/aot_file_test.o -obj/arkcompiler/ets_runtime/ecmascript/base/tests/JSHelper_NumberHelper_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/dfx/hprof/tests/HeapTrackerThirdTest/heap_tracker_third_test.o -obj/arkcompiler/ets_runtime/ecmascript/dfx/hprof/tests/HeapDumpTest/heap_dump_test.o -obj/arkcompiler/ets_runtime/ecmascript/dfx/hprof/tests/HeapTrackerSecondTest/heap_tracker_second_test.o -obj/arkcompiler/ets_runtime/ecmascript/dfx/hprof/tests/HeapSnapShotTest/heap_snapshot_test.o -obj/arkcompiler/ets_runtime/ecmascript/dfx/hprof/tests/HeapTrackerFirstTest/heap_tracker_first_test.o -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_DateTimeFormat_Second_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/dfx/hprof/tests/JSMetadataTest/js_metadata_test.o -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Intl_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_DisPlayNames_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_ListFormat_First_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_ListFormat_Second_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Local_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_PluralRules_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_RelativeTimeFormat_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Segmenter_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_String_TestWithQemu tests/unittest/ets_runtime/ExtractorToolTest -obj/arkcompiler/ets_runtime/ecmascript/pgo_profiler/tests/PGOProfilerTest/pgo_profiler_test.o -obj/arkcompiler/ets_runtime/ecmascript/napi/test/Jsnapi_Sendable_Test/jsnapi_sendable_tests.o -obj/arkcompiler/ets_runtime/ecmascript/pgo_profiler/tests/PGOProfilerTestOne/pgo_profiler_test_one.o -obj/arkcompiler/ets_runtime/ecmascript/jspandafile/tests/JSPandaFileTestWithQemu obj/arkcompiler/ets_runtime/ecmascript/platform/unix/ohos/tests/BacktraceTestWithQemu tests/unittest/ets_runtime/Jsnapi_002_Test tests/unittest/ets_runtime/SerializerTest -obj/arkcompiler/ets_runtime/ecmascript/tests/GC_Second_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/tests/JS_AsyncGengeratorObject_Test/js_async_generator_object_test.o -obj/arkcompiler/ets_runtime/ecmascript/tests/JS_Collator_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/tests/JS_DateTimeFormat_First_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_String_TestWithQemu obj/arkcompiler/ets_runtime/ecmascript/tests/JS_Date_TestWithQemu obj/arkcompiler/ets_runtime/ecmascript/tests/JS_DisPlayNames_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/tests/JS_DateTimeFormat_Second_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/tests/JS_LocaleHelper_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/tests/JS_Object_Test/js_object_test.o +obj/arkcompiler/ets_runtime/ecmascript/base/tests/JSHelper_NumberHelper_TestWithQemu obj/arkcompiler/ets_runtime/ecmascript/tests/JS_Locale_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/tests/JS_NumberFormat_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/jspandafile/tests/JSPandaFileTestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_PluralRules_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_RelativeTimeFormat_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_ListFormat_First_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_DateTimeFormat_Second_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Local_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Intl_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Segmenter_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_Collator_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_DisPlayNames_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_DateTimeFormat_First_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_DateTimeFormat_Second_TestWithQemu obj/arkcompiler/ets_runtime/ecmascript/tests/JS_PluralRules_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/tests/JS_RelativeTimeFormat_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/tests/JS_TaggedQueue_Test/js_tagged_queue_test.o -obj/arkcompiler/ets_runtime/ecmascript/tests/JS_TaggedValue_Test/tagged_value_test.o -obj/arkcompiler/ets_runtime/test/aottest/array_concat/array_concat/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/array_concat/array_concatContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/builtins_decode_uri_component/builtins_decode_uri_componentContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/builtins_decode_uri_component/builtins_decode_uri_component/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/construct_deopt_frame_stack_overflow2/construct_deopt_frame_stack_overflow2/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/construct_deopt_frame_stack_overflow2/construct_deopt_frame_stack_overflow2Context/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/construct_deopt_frame_stack_overflow/construct_deopt_frame_stack_overflow/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/construct_deopt_frame_stack_overflow/construct_deopt_frame_stack_overflowContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/definefieldbyname2/definefieldbyname2/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/definefieldbyname2/definefieldbyname2Context/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/elements_kind/elements_kind/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/elements_kind/elements_kindContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/elements_kind_update/elements_kind_update/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/elements_kind_update/elements_kind_updateContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/frame_iteration/frame_iteration/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/frame_iteration/frame_iterationContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/icnotfound/icnotfoundContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/icnotfound/icnotfound/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/intern_string_strict_equal1/intern_string_strict_equal1/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/intern_string_strict_equal1/intern_string_strict_equal1Context/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/intern_string_strict_equal2/intern_string_strict_equal2/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/intern_string_strict_equal2/intern_string_strict_equal2Context/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/mono_builtin/mono_builtinContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/mono_builtin/mono_builtin/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/nested_try_emptycatch/nested_try_emptycatch/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/nested_if_try_emptycatch/nested_if_try_emptycatchContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/nested_try_emptycatch_finally/nested_try_emptycatch_finally/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/nested_try_emptycatch_finally/nested_try_emptycatch_finallyContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/nested_try_emptycatch/nested_try_emptycatchContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/object_literal/object_literal/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/object_literal/object_literalContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_aot_call_deopt_bridge/pgo_aot_call_deopt_bridge/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_aot_call_deopt_bridge/pgo_aot_call_deopt_bridgeContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_aot_newobj/pgo_aot_newobj/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_aot_newobj/pgo_aot_newobjContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_char_to_string_deopt/pgo_char_to_string_deopt/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_char_to_string_deopt/pgo_char_to_string_deoptContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_class_prototype/pgo_class_prototype/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_class_prototype/pgo_class_prototypeContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgostand_value_deopt/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_constant_value_deopt/pgo_constant_value_deoptContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_fast_call_bridge/pgo_fast_call_bridgeContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_fast_call_bridge/pgo_fast_call_bridge/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_fast_call_deopt_bridge/pgo_fast_call_deopt_bridge/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_fast_call_deopt_bridge/pgo_fast_call_deopt_bridgeContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_forof_map/pgo_forof_map/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_forof_map/pgo_forof_mapContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_function_operation/pgo_function_operationContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_function_operation/pgo_function_operation/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_inherited_function_operation/pgo_inherited_function_operationContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_inherited_function_operation/pgo_function_operation/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_Idobjbyvalue_string/pgo_Idobjbyvalue_string/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_Idobjbyvalue_string/pgo_Idobjbyvalue_stringContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_napi1/pgo_napi1/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_napi2/pgo_napi2/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_Idobjbyvalue_array/pgo_Idobjbyvalue_array/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_napi1/pgo_napi1Context/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_napi2/pgo_napi2Context/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_Idobjbyvalue_array/pgo_Idobjbyvalue_arrayContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_space_flag/pgo_space_flag/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_track_type/pgo_track_type/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_space_flag/pgo_space_flagContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_track_type/pgo_track_typeContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/regressioncase/regressioncase/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/regressioncase/regressioncaseContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/stobjbyname1/stobjbyname1/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/stobjbyname1/stobjbyname1Context/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/shr_overflow/shr_overflowContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/supercall/supercall/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/shr_overflow/shr_overflow/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/supercall/supercallContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/sync_representation/sync_representation/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/sync_representation/sync_representationContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/try_emptycatch_switch_case/try_emptycatch_switch_case/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/try_emptycatch_forloop/try_emptycatch_forloop/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/try_emptycatch_nested/try_emptycatch_nested/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/try_emptycatch_forloop/try_emptycatch_forloopContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/try_forloop_emptycatch/try_forloop_emptycatch/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/try_emptycatch_switch_case/try_emptycatch_switch_caseContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/try_forloop_emptycatch/try_forloop_emptycatchContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/try_emptycatch_nested/try_emptycatch_nestedContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/dataview_native_inline/dataview_native_inline/SlowPath/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/nested_if_try_emptycatch/nested_if_try_emptycatch/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_constant_value_deopt/pgo_constant_value_deopt/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_inherited_function_operation/pgo_inherited_function_operation/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_ldobjbyvalue_string/pgo_ldobjbyvalue_string/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_ldobjbyvalue_string/pgo_ldobjbyvalue_stringContext/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_ldobjbyvalue_array/pgo_ldobjbyvalue_array/LiteCG -obj/arkcompiler/ets_runtime/test/aottest/pgo_ldobjbyvalue_array/pgo_ldobjbyvalue_arrayContext/LiteCG -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Collator_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_NumberFormat_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_DateTimeFormat_First_TestWithQemu obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_BigInt_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/JS_ListFormat_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_RelativeTimeFormat_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_LocaleHelper_TestWithQemu obj/arkcompiler/ets_runtime/ecmascript/tests/JS_ListFormat_TestWithQemu #25856 -obj/arkcompiler/ets_runtime/ecmascript/mem/cmc_gc/libcommon_components_set/gc_hooks.o +obj/arkcompiler/ets_runtime/ecmascript/tests/JS_NumberFormat_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_ListFormat_Second_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_DateTimeFormat_First_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_NumberFormat_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Collator_TestWithQemu #26061 -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Global_Test -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Array_Test -obj/arkcompiler/ets_runtime/ecmascript/pgo_profiler/tests/PGOProfilerTest obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_FinalizationRegistry_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_DataView_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Lazy_TestWithQemu obj/arkcompiler/ets_runtime/ecmascript/napi/test/Jsnapi_001_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/base/tests/JS_JsonStringlfier_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Json_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/base/tests/JS_Ason_TestWithQemu obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Atomics_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Lazy_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/base/tests/JSHelper_UtfHelper_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Regexp_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/pgo_profiler/tests/PGOProfilerTestOneWithQemu obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Sendable_BuiltinsSendableArrayBuffer_TestWithQemu obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Number_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Errors_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Object_TestWithQemu obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Data_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Errors_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/base/tests/JSHelper_UtfHelper_TestWithQemu +obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Sendable_BuiltinsSharedTypedArray_TestWithQemu obj/arkcompiler/ets_runtime/ecmascript/containers/tests/Containers_002_TestWithQemu obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_Array_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/pgo_profiler/tests/PGOProfilerTestOneWithQemu -obj/arkcompiler/ets_runtime/ecmascript/containers/tests/Containers_001_TestWithQemu -obj/arkcompiler/ets_runtime/test/moduletest/arrayRelease/arrayReleaseAsmAssert -obj/arkcompiler/ets_runtime/test/moduletest/arrayRelease/arrayReleaseAsmAssertContext -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Builtins_DataView_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Sendable_BuiltinsSharedTypedArray_TestWithQemu -obj/arkcompiler/ets_runtime/ecmascript/builtins/tests/Sendable_BuiltinsSharedArray_TestWithQemu \ No newline at end of file diff --git a/test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt b/test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt index 84643a67fe..798d15629f 100644 --- a/test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt +++ b/test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt @@ -1,18 +1,3 @@ # Known failure list for ut - release - x64 - ets_runtime -cmc -gc -#20980 -obj/arkcompiler/ets_runtime/test/aottest/builtin_inlining/map/Delete/builtinMapDelete - -#20471 -obj/arkcompiler/ets_runtime/test/aottest/builtin_inlining/set/Delete/builtinSetDelete - -#21629 -obj/arkcompiler/ets_runtime/test/aottest/builtin_inlining/set/Delete/builtinSetDeleteContext - -#20896 -obj/arkcompiler/ets_runtime/test/aottest/builtin_inlining/math/Ceil/builtinMathCeil - -#21801 -obj/arkcompiler/ets_runtime/test/aottest/builtin_inlining/math/Ceil/builtinMathCeilContext - -#20981 -obj/arkcompiler/ets_runtime/test/aottest/builtin_inlining/map/Delete/builtinMapDeleteContext \ No newline at end of file +#26061 +obj/arkcompiler/ets_runtime/test/moduletest/hugeictest/hugeictestContextAssert \ No newline at end of file -- Gitee From ab74e0b3094cd0e3fcc01d4f6e30ad26b1d9bcd4 Mon Sep 17 00:00:00 2001 From: lhc Date: Wed, 9 Jul 2025 01:02:39 +0800 Subject: [PATCH 08/54] Update kfl 0605 Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICCKEM Signed-off-by: lhc Change-Id: I222d2d4e758cab8b4e551306a1a733a8a4752e26 --- test/regresstest/ignored-regresstest-fastverify-x64.txt | 3 +++ test/ut/ignore-ut-debug-x64-ets_runtime-cmc-gc.txt | 4 ++++ test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt | 6 +++++- test/ut/ignore-ut-release-x64-ets_runtime.txt | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/test/regresstest/ignored-regresstest-fastverify-x64.txt b/test/regresstest/ignored-regresstest-fastverify-x64.txt index ba00a7c0b1..49dca28cd2 100644 --- a/test/regresstest/ignored-regresstest-fastverify-x64.txt +++ b/test/regresstest/ignored-regresstest-fastverify-x64.txt @@ -13,3 +13,6 @@ regresstest/ark-regress/mjsunit/es8/async-arrow-default-function-await.js #20325 regresstest/ark-regress/mjsunit/harmony/weakrefs/finalizationregistry-independent-lifetime.js + +#26260 +regresstest/ark-regress/mjsunit/regress/regress-155924.js \ No newline at end of file diff --git a/test/ut/ignore-ut-debug-x64-ets_runtime-cmc-gc.txt b/test/ut/ignore-ut-debug-x64-ets_runtime-cmc-gc.txt index 9269c4dfee..e3ff20ac0f 100644 --- a/test/ut/ignore-ut-debug-x64-ets_runtime-cmc-gc.txt +++ b/test/ut/ignore-ut-debug-x64-ets_runtime-cmc-gc.txt @@ -11,3 +11,7 @@ obj/arkcompiler/ets_runtime/test/aottest/forin_enum_cache_chain/forin_enum_cache #23099 obj/arkcompiler/ets_runtime/ecmascript/pgo_profiler/tests/PGOProfilerTestOne + +#26061 +obj/arkcompiler/ets_runtime/ecmascript/napi/test/Jsnapi_004_Test +obj/arkcompiler/ets_runtime/ecmascript/serializer/tests/SerializerTest \ No newline at end of file diff --git a/test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt b/test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt index 798d15629f..aa08c87e02 100644 --- a/test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt +++ b/test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt @@ -1,3 +1,7 @@ # Known failure list for ut - release - x64 - ets_runtime -cmc -gc #26061 -obj/arkcompiler/ets_runtime/test/moduletest/hugeictest/hugeictestContextAssert \ No newline at end of file +obj/arkcompiler/ets_runtime/test/moduletest/hugeictest/hugeictestContextAssert +obj/arkcompiler/ets_runtime/test/moduletest/hugeictest/hugeictestAsmAssert + +#26090 +obj/arkcompiler/ets_runtime/ecmascript/pgo_profiler/tests/PGOProfilerTest \ No newline at end of file diff --git a/test/ut/ignore-ut-release-x64-ets_runtime.txt b/test/ut/ignore-ut-release-x64-ets_runtime.txt index 0e1633e45a..57444b8875 100644 --- a/test/ut/ignore-ut-release-x64-ets_runtime.txt +++ b/test/ut/ignore-ut-release-x64-ets_runtime.txt @@ -19,3 +19,6 @@ obj/arkcompiler/ets_runtime/test/aottest/builtin_inlining/map/Delete/builtinMapD #23236 obj/arkcompiler/ets_runtime/test/moduletest/hugearray/hugearrayAsmAssertContext + +#26263 +obj/arkcompiler/ets_runtime/ecmascript/tests/GC_Third_Test -- Gitee From 0c90f33261c9d080f46e03597664c0c0d5005459 Mon Sep 17 00:00:00 2001 From: lhc Date: Wed, 9 Jul 2025 01:09:52 +0800 Subject: [PATCH 09/54] Update kfl 0605 Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICCXB1 Signed-off-by: lhc Change-Id: Icabf8ae432faa64d44e91ba5f8260e6ca1bd199a --- test/ut/ignore-ut-debug-x64-ets_runtime.txt | 3 +++ test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/test/ut/ignore-ut-debug-x64-ets_runtime.txt b/test/ut/ignore-ut-debug-x64-ets_runtime.txt index 4247858039..de8184dada 100644 --- a/test/ut/ignore-ut-debug-x64-ets_runtime.txt +++ b/test/ut/ignore-ut-debug-x64-ets_runtime.txt @@ -23,3 +23,6 @@ obj/arkcompiler/ets_runtime/ecmascript/tests/JS_Hclass_Test #25854 obj/arkcompiler/ets_runtime/ecmascript/tests/Sendable_JsSharedArray_Test + +#26095 +obj/arkcompiler/ets_runtime/test/aottest/sharedset/sharedset/modules.ap diff --git a/test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt b/test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt index aa08c87e02..6ebf55a2d3 100644 --- a/test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt +++ b/test/ut/ignore-ut-release-x64-ets_runtime-cmc-gc.txt @@ -4,4 +4,7 @@ obj/arkcompiler/ets_runtime/test/moduletest/hugeictest/hugeictestContextAssert obj/arkcompiler/ets_runtime/test/moduletest/hugeictest/hugeictestAsmAssert #26090 -obj/arkcompiler/ets_runtime/ecmascript/pgo_profiler/tests/PGOProfilerTest \ No newline at end of file +obj/arkcompiler/ets_runtime/ecmascript/pgo_profiler/tests/PGOProfilerTest + +#23099 +obj/arkcompiler/ets_runtime/ecmascript/pgo_profiler/tests/PGOProfilerTestOne \ No newline at end of file -- Gitee From 1524f870452c02bf5d8e1d1b29b98e45df3ede06 Mon Sep 17 00:00:00 2001 From: lhc Date: Wed, 9 Jul 2025 01:34:06 +0800 Subject: [PATCH 10/54] Reason: A bug existing in lower boxed boolean, we need to disable this pass before bug is fixed. Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICFNMB Signed-off-by: lhc Change-Id: I08c97797f417fd81f836cb9951c46c34c02e18fb --- compiler_service/include/aot_args_list.h | 2 ++ ecmascript/compiler/BUILD.gn | 2 +- ecmascript/module/accessor/module_data_accessor.h | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler_service/include/aot_args_list.h b/compiler_service/include/aot_args_list.h index 36b1146e70..01671159b0 100644 --- a/compiler_service/include/aot_args_list.h +++ b/compiler_service/include/aot_args_list.h @@ -157,12 +157,14 @@ std::unordered_set staticAOTArgsList { std::vector staticAOTDefaultArgs { "--load-runtimes=ets", "--compiler-enable-fast-interop=false", + "--compiler-lower-boxed-boolean=false", "--paoc-zip-panda-file=ets/modules_static.abc" }; std::vector staticFrameworkAOTDefaultArgs { "--load-runtimes=ets", "--compiler-enable-fast-interop=false", + "--compiler-lower-boxed-boolean=false" }; } // namespace OHOS::ArkCompiler diff --git a/ecmascript/compiler/BUILD.gn b/ecmascript/compiler/BUILD.gn index a9e984c769..f8fc059caa 100644 --- a/ecmascript/compiler/BUILD.gn +++ b/ecmascript/compiler/BUILD.gn @@ -18,7 +18,7 @@ declare_args() { } if (defined(timeout)) { - _timeout_ = timeout + _timeout_ = 14400 } else { _timeout_ = 2400 } diff --git a/ecmascript/module/accessor/module_data_accessor.h b/ecmascript/module/accessor/module_data_accessor.h index f8222e89fb..8d98a8e284 100644 --- a/ecmascript/module/accessor/module_data_accessor.h +++ b/ecmascript/module/accessor/module_data_accessor.h @@ -31,8 +31,8 @@ class ModuleDataAccessor { public: ModuleDataAccessor(const JSPandaFile *pandaFile, panda_file::File::EntityId module_data_id); ~ModuleDataAccessor() = default; - DEFAULT_MOVE_CTOR(ModuleDataAccessor) - DEFAULT_COPY_CTOR(ModuleDataAccessor) + DEFAULT_MOVE_CTOR(ModuleDataAccessor); + DEFAULT_COPY_CTOR(ModuleDataAccessor); NO_MOVE_OPERATOR(ModuleDataAccessor); NO_COPY_OPERATOR(ModuleDataAccessor); -- Gitee From 273a235b0a2591c7abd892db288a5476522d7d6a Mon Sep 17 00:00:00 2001 From: zhao1d Date: Sat, 24 May 2025 19:52:38 +0800 Subject: [PATCH 11/54] =?UTF-8?q?1.0=E8=BF=90=E8=A1=8C=E6=97=B6=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=AE=9E=E7=8E=B01.2=E7=9A=84interface(0328)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICAOLR Signed-off-by: zhao1d Change-Id: Ie2ff5ca9f30734f2de93593b618acfff9cc7e865 Signed-off-by: lhc --- .../builtins_function_stub_builder.cpp | 2 + ecmascript/compiler/stub_builder-inl.h | 7 ++++ ecmascript/compiler/stub_builder.h | 2 + .../dfx/hprof/tests/js_metadata_test.cpp | 10 +++-- ecmascript/js_function.cpp | 2 + ecmascript/js_function.h | 3 +- ecmascript/js_type_metadata/js_function.json | 13 +++++-- .../jspandafile/class_info_extractor.cpp | 15 +++++--- ecmascript/jspandafile/class_info_extractor.h | 3 +- .../jspandafile/literal_data_extractor.cpp | 6 ++- ecmascript/napi/include/jsnapi_expo.h | 3 ++ ecmascript/napi/jsnapi_expo.cpp | 29 +++++++++++++++ ecmascript/serializer/base_serializer.cpp | 2 + ecmascript/stubs/runtime_stubs-inl.h | 37 +++++++++++++++---- ecmascript/stubs/runtime_stubs.h | 10 +++++ ecmascript/tests/dump_test.cpp | 2 +- 16 files changed, 120 insertions(+), 26 deletions(-) diff --git a/ecmascript/compiler/builtins/builtins_function_stub_builder.cpp b/ecmascript/compiler/builtins/builtins_function_stub_builder.cpp index b937889140..8a3f1c7f65 100644 --- a/ecmascript/compiler/builtins/builtins_function_stub_builder.cpp +++ b/ecmascript/compiler/builtins/builtins_function_stub_builder.cpp @@ -558,6 +558,7 @@ void BuiltinsFunctionStubBuilder::InitializeSFunction(GateRef glue, GateRef func auto emptyProfileTypeInfoCell = GetGlobalConstantValue(VariableType::JS_POINTER(), glue, ConstantIndex::EMPTY_PROFILE_TYPE_INFO_CELL_INDEX); SetRawProfileTypeInfoToFunction(glue, func, emptyProfileTypeInfoCell, MemoryAttribute::NoBarrier()); + SetInterfaceTypeToFunction(glue, func, Undefined(), MemoryAttribute::NoBarrier()); env->SubCfgExit(); return; } @@ -687,6 +688,7 @@ void BuiltinsFunctionStubBuilder::InitializeJSFunction(GateRef glue, GateRef fun auto emptyProfileTypeInfoCell = GetGlobalConstantValue(VariableType::JS_POINTER(), glue, ConstantIndex::EMPTY_PROFILE_TYPE_INFO_CELL_INDEX); SetRawProfileTypeInfoToFunction(glue, func, emptyProfileTypeInfoCell, MemoryAttribute::NoBarrier()); + SetInterfaceTypeToFunction(glue, func, Undefined(), MemoryAttribute::NoBarrier()); env->SubCfgExit(); return; } diff --git a/ecmascript/compiler/stub_builder-inl.h b/ecmascript/compiler/stub_builder-inl.h index 98c4e6d54d..23b3b73f95 100644 --- a/ecmascript/compiler/stub_builder-inl.h +++ b/ecmascript/compiler/stub_builder-inl.h @@ -3613,6 +3613,13 @@ inline void StubBuilder::SetMachineCodeToFunction(GateRef glue, GateRef function Store(VariableType::JS_ANY(), glue, function, offset, value, mAttr); } +inline void StubBuilder::SetInterfaceTypeToFunction(GateRef glue, GateRef function, GateRef value, + MemoryAttribute mAttr) +{ + GateRef offset = IntPtr(JSFunction::INTERFACETYPE_OFFSET); + Store(VariableType::JS_ANY(), glue, function, offset, value, mAttr); +} + inline void StubBuilder::SetBaselineJitCodeToFunction(GateRef glue, GateRef function, GateRef value, MemoryAttribute mAttr) { diff --git a/ecmascript/compiler/stub_builder.h b/ecmascript/compiler/stub_builder.h index 220b3c7d8d..dc7c8bab54 100644 --- a/ecmascript/compiler/stub_builder.h +++ b/ecmascript/compiler/stub_builder.h @@ -922,6 +922,8 @@ public: MemoryAttribute mAttr = MemoryAttribute::Default()); void SetMachineCodeToFunction(GateRef glue, GateRef function, GateRef value, MemoryAttribute mAttr = MemoryAttribute::Default()); + void SetInterfaceTypeToFunction(GateRef glue, GateRef function, GateRef value, + MemoryAttribute mAttr = MemoryAttribute::Default()); void SetBaselineJitCodeToFunction(GateRef glue, GateRef function, GateRef value, MemoryAttribute mAttr = MemoryAttribute::Default()); void SetTypedArrayName(GateRef glue, GateRef typedArray, GateRef name, diff --git a/ecmascript/dfx/hprof/tests/js_metadata_test.cpp b/ecmascript/dfx/hprof/tests/js_metadata_test.cpp index 9c1827d2f4..b69b7f46f7 100644 --- a/ecmascript/dfx/hprof/tests/js_metadata_test.cpp +++ b/ecmascript/dfx/hprof/tests/js_metadata_test.cpp @@ -254,9 +254,9 @@ public: "MaybeUnregister", "Next", "Prev", "JS_FINALIZATION_REGISTRY"}}, {JSType::JS_FLOAT32_ARRAY, {"ViewedArrayBufferOrByteArray", "TypedArrayName", "JS_FLOAT32_ARRAY"}}, {JSType::JS_FLOAT64_ARRAY, {"ViewedArrayBufferOrByteArray", "TypedArrayName", "JS_FLOAT64_ARRAY"}}, - {JSType::JS_FORIN_ITERATOR, {"Object", "CachedHClass", "Keys", "JS_FORIN_ITERATOR"}}, - {JSType::JS_FUNCTION, {"ProtoOrHClass", "LexicalEnv", "MachineCode", "BaselineCode", "RawProfileTypeInfo", - "HomeObject", "Module", "JS_FUNCTION"}}, + {JSType::JS_FORIN_ITERATOR, {"Object", "CachedHclass", "Keys", "JS_FORIN_ITERATOR"}}, + {JSType::JS_FUNCTION, {"ProtoOrHClass", "LexicalEnv", "MachineCode", "BaselineCode", "InterfaceType", + "RawProfileTypeInfo", "HomeObject", "Module", "JS_FUNCTION"}}, {JSType::JS_FUNCTION_BASE, {"Method", "JS_FUNCTION_BASE"}}, {JSType::JS_GENERATOR_CONTEXT, {"RegsArray", "Method", "This", "Acc", "GeneratorObject", "LexicalEnv", "JS_GENERATOR_CONTEXT"}}, @@ -672,6 +672,7 @@ public: JSFunction::LEXICAL_ENV_OFFSET, JSFunction::MACHINECODE_OFFSET, JSFunction::BASELINECODE_OFFSET, + JSFunction::INTERFACETYPE_OFFSET, JSFunction::RAW_PROFILE_TYPE_INFO_OFFSET, JSFunction::HOME_OBJECT_OFFSET, JSFunction::ECMA_MODULE_OFFSET, @@ -1455,7 +1456,8 @@ public: JSFunction::LEXICAL_ENV_OFFSET - JSFunction::PROTO_OR_DYNCLASS_OFFSET, JSFunction::MACHINECODE_OFFSET - JSFunction::LEXICAL_ENV_OFFSET, JSFunction::BASELINECODE_OFFSET - JSFunction::MACHINECODE_OFFSET, - JSFunction::RAW_PROFILE_TYPE_INFO_OFFSET - JSFunction::BASELINECODE_OFFSET, + JSFunction::INTERFACETYPE_OFFSET - JSFunction::BASELINECODE_OFFSET, + JSFunction::RAW_PROFILE_TYPE_INFO_OFFSET - JSFunction::INTERFACETYPE_OFFSET, JSFunction::HOME_OBJECT_OFFSET - JSFunction::RAW_PROFILE_TYPE_INFO_OFFSET, JSFunction::ECMA_MODULE_OFFSET - JSFunction::HOME_OBJECT_OFFSET, JSFunction::WORK_NODE_POINTER_OFFSET - JSFunction::ECMA_MODULE_OFFSET}}, diff --git a/ecmascript/js_function.cpp b/ecmascript/js_function.cpp index ba331bdd91..d7ff7e2cd8 100644 --- a/ecmascript/js_function.cpp +++ b/ecmascript/js_function.cpp @@ -105,11 +105,13 @@ void JSFunction::InitializeWithDefaultValueCommon(JSThread *thread, const JSHand func->SetProtoOrHClass(thread, JSTaggedValue::Hole()); func->SetHomeObject(thread, JSTaggedValue::Undefined()); func->SetWorkNodePointer(reinterpret_cast(nullptr)); + func->SetMachineCode(thread, JSTaggedValue::Undefined()); func->SetBaselineCode(thread, JSTaggedValue::Undefined()); func->SetRawProfileTypeInfo(thread, thread->GlobalConstants()->GetEmptyProfileTypeInfoCell()); func->SetMethod(thread, JSTaggedValue::Undefined()); func->SetModule(thread, JSTaggedValue::Undefined()); + func->SetInterfaceType(thread, JSTaggedValue::Undefined(), SKIP_BARRIER); func->SetCodeEntry(reinterpret_cast(nullptr)); func->ClearCompiledCodeFlags(); func->SetTaskConcurrentFuncFlag(0); // 0 : default value diff --git a/ecmascript/js_function.h b/ecmascript/js_function.h index 12fb47b1e3..1cc483b341 100644 --- a/ecmascript/js_function.h +++ b/ecmascript/js_function.h @@ -427,7 +427,8 @@ public: // For runtime native function, the LexicalEnv field is used to store GlobalEnv, such as RegExp's native function ACCESSORS(LexicalEnv, LEXICAL_ENV_OFFSET, MACHINECODE_OFFSET) ACCESSORS(MachineCode, MACHINECODE_OFFSET, BASELINECODE_OFFSET) - ACCESSORS(BaselineCode, BASELINECODE_OFFSET, RAW_PROFILE_TYPE_INFO_OFFSET) + ACCESSORS(BaselineCode, BASELINECODE_OFFSET, INTERFACETYPE_OFFSET) + ACCESSORS(InterfaceType, INTERFACETYPE_OFFSET, RAW_PROFILE_TYPE_INFO_OFFSET) ACCESSORS(RawProfileTypeInfo, RAW_PROFILE_TYPE_INFO_OFFSET, HOME_OBJECT_OFFSET) ACCESSORS(HomeObject, HOME_OBJECT_OFFSET, ECMA_MODULE_OFFSET) ACCESSORS(Module, ECMA_MODULE_OFFSET, WORK_NODE_POINTER_OFFSET) diff --git a/ecmascript/js_type_metadata/js_function.json b/ecmascript/js_type_metadata/js_function.json index 182c61241a..abdb679da3 100644 --- a/ecmascript/js_type_metadata/js_function.json +++ b/ecmascript/js_type_metadata/js_function.json @@ -22,22 +22,27 @@ "size": 8 }, { - "name": "RawProfileTypeInfo", + "name": "InterfaceType", "offset": 32, "size": 8 }, { - "name": "HomeObject", + "name": "RawProfileTypeInfo", "offset": 40, "size": 8 }, { - "name": "Module", + "name": "HomeObject", "offset": 48, "size": 8 + }, + { + "name": "Module", + "offset": 56, + "size": 8 } ], - "end_offset": 64, + "end_offset": 72, "parents": [ "JS_FUNCTION_BASE" ] diff --git a/ecmascript/jspandafile/class_info_extractor.cpp b/ecmascript/jspandafile/class_info_extractor.cpp index 36ef9a9f26..584ba724fa 100644 --- a/ecmascript/jspandafile/class_info_extractor.cpp +++ b/ecmascript/jspandafile/class_info_extractor.cpp @@ -25,8 +25,8 @@ namespace panda::ecmascript { void ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(JSThread *thread, JSHandle &extractor, const JSHandle &literal, - uint32_t length, - ClassKind kind) + uint32_t length, ClassKind kind, + uint32_t implementLength) { [[maybe_unused]] EcmaHandleScope handleScope(thread); const GlobalEnvConstants *globalConst = thread->GlobalConstants(); @@ -35,8 +35,10 @@ void ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(JSThread *thread, JS ASSERT(length <= literal->GetLength()); // non static properties number is hidden in the last index of Literal buffer uint32_t nonStaticNum = 0; + // The effective data length of taggedarray(valueLength) is equal to length - implementationLength -1 + int32_t valueLength = length - implementLength - 1; if (length != 0) { - nonStaticNum = static_cast(literal->Get(thread, length - 1).GetInt()); + nonStaticNum = static_cast(literal->Get(thread, valueLength).GetInt()); } // Reserve sufficient length to prevent frequent creation. @@ -71,7 +73,7 @@ void ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(JSThread *thread, JS extractor->SetNonStaticKeys(thread, nonStaticKeys); extractor->SetNonStaticProperties(thread, nonStaticProperties); - uint32_t staticNum = length == 0 ? 0 : (length - 1) / 2 - nonStaticNum; + uint32_t staticNum = length == 0 ? 0 : (valueLength) / 2 - nonStaticNum; // Reserve sufficient length to prevent frequent creation. JSHandle staticKeys; @@ -97,9 +99,10 @@ void ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(JSThread *thread, JS ExtractContentsDetail staticDetail {}; if (kind == ClassKind::SENDABLE) { - staticDetail = { nonStaticNum * 2, length - 1, SENDABLE_STATIC_RESERVED_LENGTH, methodLiteral }; + staticDetail = { + nonStaticNum * 2, valueLength, SENDABLE_STATIC_RESERVED_LENGTH, methodLiteral }; } else { - staticDetail = { nonStaticNum * 2, length - 1, STATIC_RESERVED_LENGTH, methodLiteral }; + staticDetail = { nonStaticNum * 2, valueLength, STATIC_RESERVED_LENGTH, methodLiteral }; } if (UNLIKELY(ExtractAndReturnWhetherWithElements(thread, literal, staticDetail, staticKeys, diff --git a/ecmascript/jspandafile/class_info_extractor.h b/ecmascript/jspandafile/class_info_extractor.h index 81a9691bb5..07389a17d4 100644 --- a/ecmascript/jspandafile/class_info_extractor.h +++ b/ecmascript/jspandafile/class_info_extractor.h @@ -63,7 +63,8 @@ public: static void BuildClassInfoExtractorFromLiteral(JSThread *thread, JSHandle &extractor, const JSHandle &literal, uint32_t length, - ClassKind kind = ClassKind::NON_SENDABLE); + ClassKind kind = ClassKind::NON_SENDABLE, + uint32_t implementLength = 0); static JSHandle CreatePrototypeHClass(JSThread *thread, JSHandle &keys, diff --git a/ecmascript/jspandafile/literal_data_extractor.cpp b/ecmascript/jspandafile/literal_data_extractor.cpp index 0bc9086683..d55471131d 100644 --- a/ecmascript/jspandafile/literal_data_extractor.cpp +++ b/ecmascript/jspandafile/literal_data_extractor.cpp @@ -173,7 +173,8 @@ JSHandle LiteralDataExtractor::EnumerateLiteralVals(JSThread *threa jt = JSTaggedValue(std::get(value)); break; } - case LiteralTag::STRING: { + case LiteralTag::STRING: + case LiteralTag::ETS_IMPLEMENTS:{ StringData sd = jsPandaFile->GetStringData(EntityId(std::get(value))); EcmaString *str = factory->GetRawStringFromStringTable(sd, MemSpaceType::SHARED_OLD_SPACE); jt = JSTaggedValue(str); @@ -575,7 +576,8 @@ JSHandle LiteralDataExtractor::GetDatasIgnoreType(JSThread *thread, jt = JSTaggedValue(std::get(value)); break; } - case LiteralTag::STRING: { + case LiteralTag::STRING: + case LiteralTag::ETS_IMPLEMENTS:{ StringData sd = jsPandaFile->GetStringData(EntityId(std::get(value))); EcmaString *str = factory->GetRawStringFromStringTable(sd, MemSpaceType::SHARED_OLD_SPACE); jt = JSTaggedValue(str); diff --git a/ecmascript/napi/include/jsnapi_expo.h b/ecmascript/napi/include/jsnapi_expo.h index f5d78d3095..c2f2f44f2e 100644 --- a/ecmascript/napi/include/jsnapi_expo.h +++ b/ecmascript/napi/include/jsnapi_expo.h @@ -1912,6 +1912,9 @@ public: static void SwitchContext(const EcmaVM *vm, const Local &context); + // 1.2runtime interface info + static Local GetImplements(const EcmaVM *vm, Local instance); + private: static bool isForked_; static bool CreateRuntime(const RuntimeOption &option); diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index 3a308fb385..419497d168 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -2815,6 +2815,35 @@ bool ObjectRef::Set(const EcmaVM *vm, const char *utf8, Local value) val.GetTaggedValue()); } +Local JSNApi::GetImplements(const EcmaVM *vm, Local instance) +{ + CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); + ecmascript::ThreadManagedScope managedScope(thread); + JSTaggedValue result; + { + LocalScope scope(vm); + if (!instance->IsObject(vm)) { + return JSValueRef::Undefined(vm); + } + JSHandle obj(JSNApiHelper::ToJSHandle(instance)); + OperationResult ret = JSTaggedValue::GetProperty( + thread, obj, thread->GlobalConstants()->GetHandledConstructorString()); + RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Undefined(vm)); + result = ret.GetValue().GetTaggedValue(); + if (!result.IsJSFunction()) { + return JSValueRef::Undefined(vm); + } + JSHandle resultValue(thread, result); + JSHandle objFunc = JSHandle::Cast(resultValue); + result = objFunc->GetInterfaceType(); + if (result.IsUndefined()) { + return JSValueRef::Undefined(vm); + } + } + JSHandle implementRet(thread, result); + return JSNApiHelper::ToLocal(implementRet); +} + bool ObjectRef::Set(const EcmaVM *vm, uint32_t key, Local value) { CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, false); diff --git a/ecmascript/serializer/base_serializer.cpp b/ecmascript/serializer/base_serializer.cpp index 94b69f09d0..ef0bb992ff 100644 --- a/ecmascript/serializer/base_serializer.cpp +++ b/ecmascript/serializer/base_serializer.cpp @@ -194,6 +194,7 @@ void BaseSerializer::SerializeSFunctionFieldIndividually(TaggedObject *root, Obj switch (fieldOffset) { case JSFunction::MACHINECODE_OFFSET: case JSFunction::BASELINECODE_OFFSET: + case JSFunction::INTERFACETYPE_OFFSET: case JSFunction::RAW_PROFILE_TYPE_INFO_OFFSET: { data_->WriteEncodeFlag(EncodeFlag::PRIMITIVE); data_->WriteJSTaggedValue(JSTaggedValue::Undefined()); @@ -324,6 +325,7 @@ void BaseSerializer::SerializeAsyncFunctionFieldIndividually(TaggedObject *root, case JSFunction::PROTO_OR_DYNCLASS_OFFSET: case JSFunction::MACHINECODE_OFFSET: case JSFunction::BASELINECODE_OFFSET: + case JSFunction::INTERFACETYPE_OFFSET: case JSFunction::RAW_PROFILE_TYPE_INFO_OFFSET: case JSFunction::HOME_OBJECT_OFFSET: case JSFunction::ECMA_MODULE_OFFSET: { diff --git a/ecmascript/stubs/runtime_stubs-inl.h b/ecmascript/stubs/runtime_stubs-inl.h index 3d14e31815..cc68674bae 100644 --- a/ecmascript/stubs/runtime_stubs-inl.h +++ b/ecmascript/stubs/runtime_stubs-inl.h @@ -927,6 +927,28 @@ bool RuntimeStubs::ShouldUseAOTHClass(const JSHandle &ihc, // Therefore, there is no need to check for the existence of both at this point. return (!ihc->IsUndefined() || !chc->IsUndefined()) && !classLiteral->GetIsAOTUsed(); } + +bool RuntimeStubs::MaybeHasInterfacesType(JSThread *thread, const JSHandle &arrayHandle) +{ + // this interface is one of the conditions for determining whether it is an interop scenario. + return arrayHandle->GetLength() != 0 && arrayHandle->Get(thread, arrayHandle->GetLength() - 1).IsString(); +} + +JSHandle RuntimeStubs::EntranceForDefineClass(JSThread *thread, + const JSHandle &base, + const JSHandle &lexenv, + JSHandle &extractor, + const JSHandle &ihc, + const JSHandle &chc, + const JSHandle &classLiteral) +{ + if (ShouldUseAOTHClass(ihc, chc, classLiteral)) { + classLiteral->SetIsAOTUsed(true); + return ClassHelper::DefineClassWithIHClass(thread, base, extractor, lexenv, ihc, chc); + } else { + return ClassHelper::DefineClassFromExtractor(thread, base, extractor, lexenv); + } +} // clone class may need re-set inheritance relationship due to extends may be a variable. JSTaggedValue RuntimeStubs::RuntimeCreateClassWithBuffer(JSThread *thread, const JSHandle &base, @@ -965,14 +987,15 @@ JSTaggedValue RuntimeStubs::RuntimeCreateClassWithBuffer(JSThread *thread, JSHandle classLiteral(thread, literalObj); JSHandle arrayHandle(thread, classLiteral->GetArray()); JSHandle extractor = factory->NewClassInfoExtractor(method); - auto literalLength = arrayHandle->GetLength(); - ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(thread, extractor, arrayHandle, literalLength); - - if (ShouldUseAOTHClass(ihc, chc, classLiteral)) { - classLiteral->SetIsAOTUsed(true); - cls = ClassHelper::DefineClassWithIHClass(thread, base, extractor, lexenv, ihc, chc); + if (MaybeHasInterfacesType(thread, arrayHandle)) { + ClassInfoExtractor::BuildClassInfoExtractorFromLiteral( + thread, extractor, arrayHandle, arrayHandle->GetLength(), ClassKind::NON_SENDABLE, 1); + cls = EntranceForDefineClass(thread, base, lexenv, extractor, ihc, chc, classLiteral); + cls->SetInterfaceType(thread, arrayHandle->Get(thread, arrayHandle->GetLength() - 1)); } else { - cls = ClassHelper::DefineClassFromExtractor(thread, base, extractor, lexenv); + ClassInfoExtractor::BuildClassInfoExtractorFromLiteral( + thread, extractor, arrayHandle, arrayHandle->GetLength()); + cls = EntranceForDefineClass(thread, base, lexenv, extractor, ihc, chc, classLiteral); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); diff --git a/ecmascript/stubs/runtime_stubs.h b/ecmascript/stubs/runtime_stubs.h index d002e41595..4fb9e1ae44 100644 --- a/ecmascript/stubs/runtime_stubs.h +++ b/ecmascript/stubs/runtime_stubs.h @@ -19,6 +19,7 @@ #include "ecmascript/frames.h" #include "ecmascript/ecma_macros.h" #include "ecmascript/js_tagged_value.h" +#include "ecmascript/jspandafile/class_info_extractor.h" #include "ecmascript/jspandafile/class_literal.h" #include "ecmascript/method.h" #include "ecmascript/mem/c_containers.h" @@ -557,7 +558,16 @@ private: static inline RememberedSet* CreateLocalToShare(Region *region); static inline RememberedSet* CreateOldToNew(Region *region); static inline uint8_t GetValueFromTwoHex(uint8_t front, uint8_t behind); + static inline bool IsTargetBundleName(uintptr_t argGlue); + static inline bool MaybeHasInterfacesType(JSThread *thread, const JSHandle &arrayHandle); + static inline JSHandle EntranceForDefineClass(JSThread *thread, + const JSHandle &base, + const JSHandle &lexenv, + JSHandle &extractor, + const JSHandle &ihc, + const JSHandle &chc, + const JSHandle &classLiteral); friend class SlowRuntimeStub; }; } // namespace panda::ecmascript diff --git a/ecmascript/tests/dump_test.cpp b/ecmascript/tests/dump_test.cpp index 41c4ab4d09..f94189458f 100644 --- a/ecmascript/tests/dump_test.cpp +++ b/ecmascript/tests/dump_test.cpp @@ -541,7 +541,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) } case JSType::JS_FUNCTION: case JSType::JS_SHARED_FUNCTION: { - CHECK_DUMP_FIELDS(JSFunctionBase::SIZE, JSFunction::SIZE, 8U); + CHECK_DUMP_FIELDS(JSFunctionBase::SIZE, JSFunction::SIZE, 9U); JSHandle jsFunc = globalEnv->GetFunctionFunction(); DUMP_FOR_HANDLE(jsFunc); break; -- Gitee From 50c50b8590755bff5ed602fff6d7a1712feae9e2 Mon Sep 17 00:00:00 2001 From: yangliping Date: Thu, 26 Jun 2025 09:49:09 +0800 Subject: [PATCH 12/54] fix warning Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICGDM7?from=project-issue Signed-off-by: yangliping Signed-off-by: lhc Change-Id: I2f0d24b86ae8781f0c8102df27b7c2cd1ffac90c --- compiler_service/BUILD.gn | 9 +++++ compiler_service/src/aot_args_handler.cpp | 9 ++++- .../aotcompilerargsprepare_fuzzer/BUILD.gn | 35 ++++++++++++++++- .../compilerinterfacestub_fuzzer/BUILD.gn | 35 ++++++++++++++++- .../aotcompilerargshandler_unit/BUILD.gn | 38 +++++++++++++++++-- .../unittest/aotcompilerclient_unit/BUILD.gn | 38 +++++++++++++++++-- .../aotcompilererrorutils_unit/BUILD.gn | 38 +++++++++++++++++-- .../unittest/aotcompilerimpl_unit/BUILD.gn | 38 +++++++++++++++++-- .../unittest/aotcompilerproxy_unit/BUILD.gn | 38 +++++++++++++++++-- .../unittest/aotcompilerservice_unit/BUILD.gn | 38 +++++++++++++++++-- .../unittest/aotcompilerstub_unit/BUILD.gn | 38 +++++++++++++++++-- .../jspandafile/class_info_extractor.cpp | 2 +- ecmascript/module/js_module_deregister.cpp | 14 +++++++ ecmascript/module/js_module_deregister.h | 2 + ecmascript/platform/file.h | 2 - ecmascript/platform/unix/file.cpp | 14 +------ ecmascript/platform/windows/file.cpp | 5 --- 17 files changed, 345 insertions(+), 48 deletions(-) diff --git a/compiler_service/BUILD.gn b/compiler_service/BUILD.gn index ebd7ca1bab..51bcf0ea19 100644 --- a/compiler_service/BUILD.gn +++ b/compiler_service/BUILD.gn @@ -71,6 +71,15 @@ ohos_shared_library("libcompiler_service") { "${js_root}/ecmascript/platform/unix/linux/os.cpp", ] } + if (is_mingw) { + sources += [ + "${js_root}/ecmascript/platform/windows/file.cpp", + ] + } else { + sources += [ + "${js_root}/ecmascript/platform/unix/file.cpp", + ] + } external_deps = [ "ability_base:want", "access_token:libaccesstoken_sdk", diff --git a/compiler_service/src/aot_args_handler.cpp b/compiler_service/src/aot_args_handler.cpp index 4be8b305ce..358902e9b3 100644 --- a/compiler_service/src/aot_args_handler.cpp +++ b/compiler_service/src/aot_args_handler.cpp @@ -23,6 +23,7 @@ #include "aot_args_list.h" #include "aot_compiler_constants.h" #include "ecmascript/log_wrapper.h" +#include "ecmascript/platform/file.h" #ifdef ENABLE_COMPILER_SERVICE_GET_PARAMETER #include "parameters.h" @@ -297,8 +298,12 @@ std::optional> AOTArgsParserFactory::GetParse bool StaticFrameworkAOTArgsParser::IsFileExists(const std::string &fileName) { - std::ifstream inFile(fileName); - return inFile.good(); + std::string realPath; + if (!panda::ecmascript::RealPath(fileName, realPath)) { + LOG_SA(ERROR) << "get real path failed:" << fileName; + return false; + } + return panda::ecmascript::FileExist(realPath.c_str()); } int32_t StaticFrameworkAOTArgsParser::Parse(const std::unordered_map &argsMap, diff --git a/compiler_service/test/fuzztest/aotcompilerargsprepare_fuzzer/BUILD.gn b/compiler_service/test/fuzztest/aotcompilerargsprepare_fuzzer/BUILD.gn index b18fb7eb5c..6270be63b0 100644 --- a/compiler_service/test/fuzztest/aotcompilerargsprepare_fuzzer/BUILD.gn +++ b/compiler_service/test/fuzztest/aotcompilerargsprepare_fuzzer/BUILD.gn @@ -13,6 +13,7 @@ import( "//arkcompiler/ets_runtime/compiler_service/test/compiler_service_test.gni") +import("//arkcompiler/ets_runtime/js_runtime_config.gni") ohos_fuzztest("AotCompilerArgsPrepareFuzzTest") { module_out_path = module_output_path @@ -24,8 +25,38 @@ ohos_fuzztest("AotCompilerArgsPrepareFuzzTest") { "-Wno-unused-variable", "-fno-omit-frame-pointer", ] - include_dirs = compiler_service_include_dirs - sources = aot_compiler_service_sources + include_dirs = [ + "${compiler_service_root}/include", + "${compiler_service_root}/interface", + ] + configs = [ + "$js_root:ark_jsruntime_public_config", + "$js_root:ark_jsruntime_common_config", + ] + version_script = "${compiler_service_root}/libaot_compiler_service.map" + sources = [ + "${js_root}/common_components/log/log.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_proxy.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_stub.cpp", + "${compiler_service_root}/src/aot_args_handler.cpp", + "${compiler_service_root}/src/aot_compiler_client.cpp", + "${compiler_service_root}/src/aot_compiler_error_utils.cpp", + "${compiler_service_root}/src/aot_compiler_impl.cpp", + "${compiler_service_root}/src/aot_compiler_load_callback.cpp", + "${compiler_service_root}/src/aot_compiler_service.cpp", + "${compiler_service_root}/src/power_disconnected_listener.cpp", + "${compiler_service_root}/src/screen_status_listener.cpp", + "${compiler_service_root}/src/thermal_mgr_listener.cpp", + ] + if (is_mingw) { + sources += [ + "${js_root}/ecmascript/platform/windows/file.cpp", + ] + } else { + sources += [ + "${js_root}/ecmascript/platform/unix/file.cpp", + ] + } external_deps = [ "ability_base:want", "access_token:libaccesstoken_sdk", diff --git a/compiler_service/test/fuzztest/compilerinterfacestub_fuzzer/BUILD.gn b/compiler_service/test/fuzztest/compilerinterfacestub_fuzzer/BUILD.gn index 32da482a4a..9fe719bfbe 100644 --- a/compiler_service/test/fuzztest/compilerinterfacestub_fuzzer/BUILD.gn +++ b/compiler_service/test/fuzztest/compilerinterfacestub_fuzzer/BUILD.gn @@ -13,6 +13,7 @@ import( "//arkcompiler/ets_runtime/compiler_service/test/compiler_service_test.gni") +import("//arkcompiler/ets_runtime/js_runtime_config.gni") ohos_fuzztest("CompilerInterfaceStubFuzzTest") { module_out_path = module_output_path @@ -24,8 +25,38 @@ ohos_fuzztest("CompilerInterfaceStubFuzzTest") { "-Wno-unused-variable", "-fno-omit-frame-pointer", ] - include_dirs = compiler_service_include_dirs - sources = aot_compiler_service_sources + include_dirs = [ + "${compiler_service_root}/include", + "${compiler_service_root}/interface", + ] + configs = [ + "$js_root:ark_jsruntime_public_config", + "$js_root:ark_jsruntime_common_config", + ] + version_script = "${compiler_service_root}/libaot_compiler_service.map" + sources = [ + "${js_root}/common_components/log/log.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_proxy.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_stub.cpp", + "${compiler_service_root}/src/aot_args_handler.cpp", + "${compiler_service_root}/src/aot_compiler_client.cpp", + "${compiler_service_root}/src/aot_compiler_error_utils.cpp", + "${compiler_service_root}/src/aot_compiler_impl.cpp", + "${compiler_service_root}/src/aot_compiler_load_callback.cpp", + "${compiler_service_root}/src/aot_compiler_service.cpp", + "${compiler_service_root}/src/power_disconnected_listener.cpp", + "${compiler_service_root}/src/screen_status_listener.cpp", + "${compiler_service_root}/src/thermal_mgr_listener.cpp", + ] + if (is_mingw) { + sources += [ + "${js_root}/ecmascript/platform/windows/file.cpp", + ] + } else { + sources += [ + "${js_root}/ecmascript/platform/unix/file.cpp", + ] + } external_deps = [ "ability_base:want", "access_token:libaccesstoken_sdk", diff --git a/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn index 94cfaa11a2..af75d4a9b7 100644 --- a/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn @@ -12,17 +12,49 @@ # limitations under the License. import("../../../test/compiler_service_test.gni") +import("//arkcompiler/ets_runtime/js_runtime_config.gni") config("module_private_config") { visibility = [ ":*" ] - include_dirs = compiler_service_include_dirs + include_dirs = [ + "compiler_service_include_dirs", + "${compiler_service_root}/include", + "${compiler_service_root}/interface", + ] cflags = [ "-Wno-error=keyword-macro" ] } ohos_unittest("AotCompilerArgsHandlerUnitTest") { module_out_path = module_output_path - sources = aot_compiler_service_sources - configs = [ ":module_private_config" ] + configs = [ + ":module_private_config", + "$js_root:ark_jsruntime_public_config", + "$js_root:ark_jsruntime_common_config", + ] + version_script = "${compiler_service_root}/libaot_compiler_service.map" + sources = [ + "${js_root}/common_components/log/log.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_proxy.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_stub.cpp", + "${compiler_service_root}/src/aot_args_handler.cpp", + "${compiler_service_root}/src/aot_compiler_client.cpp", + "${compiler_service_root}/src/aot_compiler_error_utils.cpp", + "${compiler_service_root}/src/aot_compiler_impl.cpp", + "${compiler_service_root}/src/aot_compiler_load_callback.cpp", + "${compiler_service_root}/src/aot_compiler_service.cpp", + "${compiler_service_root}/src/power_disconnected_listener.cpp", + "${compiler_service_root}/src/screen_status_listener.cpp", + "${compiler_service_root}/src/thermal_mgr_listener.cpp", + ] + if (is_mingw) { + sources += [ + "${js_root}/ecmascript/platform/windows/file.cpp", + ] + } else { + sources += [ + "${js_root}/ecmascript/platform/unix/file.cpp", + ] + } deps = [ "${compiler_service_root}:libcompiler_service", ] diff --git a/compiler_service/test/unittest/aotcompilerclient_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerclient_unit/BUILD.gn index 56486c917b..8984540153 100644 --- a/compiler_service/test/unittest/aotcompilerclient_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerclient_unit/BUILD.gn @@ -13,17 +13,49 @@ import( "//arkcompiler/ets_runtime/compiler_service/test/compiler_service_test.gni") +import("//arkcompiler/ets_runtime/js_runtime_config.gni") config("module_private_config") { visibility = [ ":*" ] - include_dirs = compiler_service_include_dirs + include_dirs = [ + "compiler_service_include_dirs", + "${compiler_service_root}/include", + "${compiler_service_root}/interface", + ] cflags = [ "-Wno-error=keyword-macro" ] } ohos_unittest("AotCompilerClientUnitTest") { module_out_path = module_output_path - sources = aot_compiler_service_sources - configs = [ ":module_private_config" ] + configs = [ + ":module_private_config", + "$js_root:ark_jsruntime_public_config", + "$js_root:ark_jsruntime_common_config", + ] + version_script = "${compiler_service_root}/libaot_compiler_service.map" + sources = [ + "${js_root}/common_components/log/log.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_proxy.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_stub.cpp", + "${compiler_service_root}/src/aot_args_handler.cpp", + "${compiler_service_root}/src/aot_compiler_client.cpp", + "${compiler_service_root}/src/aot_compiler_error_utils.cpp", + "${compiler_service_root}/src/aot_compiler_impl.cpp", + "${compiler_service_root}/src/aot_compiler_load_callback.cpp", + "${compiler_service_root}/src/aot_compiler_service.cpp", + "${compiler_service_root}/src/power_disconnected_listener.cpp", + "${compiler_service_root}/src/screen_status_listener.cpp", + "${compiler_service_root}/src/thermal_mgr_listener.cpp", + ] + if (is_mingw) { + sources += [ + "${js_root}/ecmascript/platform/windows/file.cpp", + ] + } else { + sources += [ + "${js_root}/ecmascript/platform/unix/file.cpp", + ] + } deps = [ "${compiler_service_root}:libcompiler_service", ] diff --git a/compiler_service/test/unittest/aotcompilererrorutils_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilererrorutils_unit/BUILD.gn index 217637c99f..a23e784c6d 100644 --- a/compiler_service/test/unittest/aotcompilererrorutils_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilererrorutils_unit/BUILD.gn @@ -12,17 +12,49 @@ # limitations under the License. import("../../compiler_service_test.gni") +import("//arkcompiler/ets_runtime/js_runtime_config.gni") config("module_private_config") { visibility = [ ":*" ] - include_dirs = compiler_service_include_dirs + include_dirs = [ + "compiler_service_include_dirs", + "${compiler_service_root}/include", + "${compiler_service_root}/interface", + ] cflags = [ "-Wno-error=keyword-macro" ] } ohos_unittest("AotCompilerErrorUtilsUnitTest") { module_out_path = module_output_path - sources = aot_compiler_service_sources - configs = [ ":module_private_config" ] + configs = [ + ":module_private_config", + "$js_root:ark_jsruntime_public_config", + "$js_root:ark_jsruntime_common_config", + ] + version_script = "${compiler_service_root}/libaot_compiler_service.map" + sources = [ + "${js_root}/common_components/log/log.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_proxy.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_stub.cpp", + "${compiler_service_root}/src/aot_args_handler.cpp", + "${compiler_service_root}/src/aot_compiler_client.cpp", + "${compiler_service_root}/src/aot_compiler_error_utils.cpp", + "${compiler_service_root}/src/aot_compiler_impl.cpp", + "${compiler_service_root}/src/aot_compiler_load_callback.cpp", + "${compiler_service_root}/src/aot_compiler_service.cpp", + "${compiler_service_root}/src/power_disconnected_listener.cpp", + "${compiler_service_root}/src/screen_status_listener.cpp", + "${compiler_service_root}/src/thermal_mgr_listener.cpp", + ] + if (is_mingw) { + sources += [ + "${js_root}/ecmascript/platform/windows/file.cpp", + ] + } else { + sources += [ + "${js_root}/ecmascript/platform/unix/file.cpp", + ] + } deps = [ "${compiler_service_root}:libcompiler_service", ] diff --git a/compiler_service/test/unittest/aotcompilerimpl_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerimpl_unit/BUILD.gn index 4a8101c770..d00c787c0e 100644 --- a/compiler_service/test/unittest/aotcompilerimpl_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerimpl_unit/BUILD.gn @@ -13,17 +13,49 @@ import( "//arkcompiler/ets_runtime/compiler_service/test/compiler_service_test.gni") +import("//arkcompiler/ets_runtime/js_runtime_config.gni") config("module_private_config") { visibility = [ ":*" ] - include_dirs = compiler_service_include_dirs + include_dirs = [ + "compiler_service_include_dirs", + "${compiler_service_root}/include", + "${compiler_service_root}/interface", + ] cflags = [ "-Wno-error=keyword-macro" ] } ohos_unittest("AotCompilerImplUnitTest") { module_out_path = module_output_path - sources = aot_compiler_service_sources - configs = [ ":module_private_config" ] + configs = [ + ":module_private_config", + "$js_root:ark_jsruntime_public_config", + "$js_root:ark_jsruntime_common_config", + ] + version_script = "${compiler_service_root}/libaot_compiler_service.map" + sources = [ + "${js_root}/common_components/log/log.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_proxy.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_stub.cpp", + "${compiler_service_root}/src/aot_args_handler.cpp", + "${compiler_service_root}/src/aot_compiler_client.cpp", + "${compiler_service_root}/src/aot_compiler_error_utils.cpp", + "${compiler_service_root}/src/aot_compiler_impl.cpp", + "${compiler_service_root}/src/aot_compiler_load_callback.cpp", + "${compiler_service_root}/src/aot_compiler_service.cpp", + "${compiler_service_root}/src/power_disconnected_listener.cpp", + "${compiler_service_root}/src/screen_status_listener.cpp", + "${compiler_service_root}/src/thermal_mgr_listener.cpp", + ] + if (is_mingw) { + sources += [ + "${js_root}/ecmascript/platform/windows/file.cpp", + ] + } else { + sources += [ + "${js_root}/ecmascript/platform/unix/file.cpp", + ] + } deps = [ "${compiler_service_root}:libcompiler_service", ] diff --git a/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn index d357201e08..9465063857 100644 --- a/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn @@ -12,17 +12,49 @@ # limitations under the License. import("../../compiler_service_test.gni") +import("//arkcompiler/ets_runtime/js_runtime_config.gni") config("module_private_config") { visibility = [ ":*" ] - include_dirs = compiler_service_include_dirs + include_dirs = [ + "compiler_service_include_dirs", + "${compiler_service_root}/include", + "${compiler_service_root}/interface", + ] cflags = [ "-Wno-error=keyword-macro" ] } ohos_unittest("AotCompilerProxyUnitTest") { module_out_path = module_output_path - sources = aot_compiler_service_sources - configs = [ ":module_private_config" ] + configs = [ + ":module_private_config", + "$js_root:ark_jsruntime_public_config", + "$js_root:ark_jsruntime_common_config", + ] + version_script = "${compiler_service_root}/libaot_compiler_service.map" + sources = [ + "${js_root}/common_components/log/log.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_proxy.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_stub.cpp", + "${compiler_service_root}/src/aot_args_handler.cpp", + "${compiler_service_root}/src/aot_compiler_client.cpp", + "${compiler_service_root}/src/aot_compiler_error_utils.cpp", + "${compiler_service_root}/src/aot_compiler_impl.cpp", + "${compiler_service_root}/src/aot_compiler_load_callback.cpp", + "${compiler_service_root}/src/aot_compiler_service.cpp", + "${compiler_service_root}/src/power_disconnected_listener.cpp", + "${compiler_service_root}/src/screen_status_listener.cpp", + "${compiler_service_root}/src/thermal_mgr_listener.cpp", + ] + if (is_mingw) { + sources += [ + "${js_root}/ecmascript/platform/windows/file.cpp", + ] + } else { + sources += [ + "${js_root}/ecmascript/platform/unix/file.cpp", + ] + } deps = [ "${compiler_service_root}:libcompiler_service", ] diff --git a/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn index 2af81ac72a..3a9b2bb84a 100644 --- a/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn @@ -13,17 +13,49 @@ import( "//arkcompiler/ets_runtime/compiler_service/test/compiler_service_test.gni") +import("//arkcompiler/ets_runtime/js_runtime_config.gni") config("module_private_config") { visibility = [ ":*" ] - include_dirs = compiler_service_include_dirs + include_dirs = [ + "compiler_service_include_dirs", + "${compiler_service_root}/include", + "${compiler_service_root}/interface", + ] cflags = [ "-Wno-error=keyword-macro" ] } ohos_unittest("AotCompilerServiceUnitTest") { module_out_path = module_output_path - sources = aot_compiler_service_sources - configs = [ ":module_private_config" ] + configs = [ + ":module_private_config", + "$js_root:ark_jsruntime_public_config", + "$js_root:ark_jsruntime_common_config", + ] + version_script = "${compiler_service_root}/libaot_compiler_service.map" + sources = [ + "${js_root}/common_components/log/log.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_proxy.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_stub.cpp", + "${compiler_service_root}/src/aot_args_handler.cpp", + "${compiler_service_root}/src/aot_compiler_client.cpp", + "${compiler_service_root}/src/aot_compiler_error_utils.cpp", + "${compiler_service_root}/src/aot_compiler_impl.cpp", + "${compiler_service_root}/src/aot_compiler_load_callback.cpp", + "${compiler_service_root}/src/aot_compiler_service.cpp", + "${compiler_service_root}/src/power_disconnected_listener.cpp", + "${compiler_service_root}/src/screen_status_listener.cpp", + "${compiler_service_root}/src/thermal_mgr_listener.cpp", + ] + if (is_mingw) { + sources += [ + "${js_root}/ecmascript/platform/windows/file.cpp", + ] + } else { + sources += [ + "${js_root}/ecmascript/platform/unix/file.cpp", + ] + } deps = [ "${compiler_service_root}:libcompiler_service", ] diff --git a/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn index a65dedc566..b537e743d6 100644 --- a/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn @@ -12,17 +12,49 @@ # limitations under the License. import("../../compiler_service_test.gni") +import("//arkcompiler/ets_runtime/js_runtime_config.gni") config("module_private_config") { visibility = [ ":*" ] - include_dirs = compiler_service_include_dirs + include_dirs = [ + "compiler_service_include_dirs", + "${compiler_service_root}/include", + "${compiler_service_root}/interface", + ] cflags = [ "-Wno-error=keyword-macro" ] } ohos_unittest("AotCompilerStubUnitTest") { module_out_path = module_output_path - sources = aot_compiler_service_sources - configs = [ ":module_private_config" ] + configs = [ + ":module_private_config", + "$js_root:ark_jsruntime_public_config", + "$js_root:ark_jsruntime_common_config", + ] + version_script = "${compiler_service_root}/libaot_compiler_service.map" + sources = [ + "${js_root}/common_components/log/log.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_proxy.cpp", + "${compiler_service_root}/interface/aot_compiler_interface_stub.cpp", + "${compiler_service_root}/src/aot_args_handler.cpp", + "${compiler_service_root}/src/aot_compiler_client.cpp", + "${compiler_service_root}/src/aot_compiler_error_utils.cpp", + "${compiler_service_root}/src/aot_compiler_impl.cpp", + "${compiler_service_root}/src/aot_compiler_load_callback.cpp", + "${compiler_service_root}/src/aot_compiler_service.cpp", + "${compiler_service_root}/src/power_disconnected_listener.cpp", + "${compiler_service_root}/src/screen_status_listener.cpp", + "${compiler_service_root}/src/thermal_mgr_listener.cpp", + ] + if (is_mingw) { + sources += [ + "${js_root}/ecmascript/platform/windows/file.cpp", + ] + } else { + sources += [ + "${js_root}/ecmascript/platform/unix/file.cpp", + ] + } deps = [ "${compiler_service_root}:libcompiler_service", ] diff --git a/ecmascript/jspandafile/class_info_extractor.cpp b/ecmascript/jspandafile/class_info_extractor.cpp index 584ba724fa..9c7e41c360 100644 --- a/ecmascript/jspandafile/class_info_extractor.cpp +++ b/ecmascript/jspandafile/class_info_extractor.cpp @@ -36,7 +36,7 @@ void ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(JSThread *thread, JS // non static properties number is hidden in the last index of Literal buffer uint32_t nonStaticNum = 0; // The effective data length of taggedarray(valueLength) is equal to length - implementationLength -1 - int32_t valueLength = length - implementLength - 1; + uint32_t valueLength = length - implementLength - 1; if (length != 0) { nonStaticNum = static_cast(literal->Get(thread, valueLength).GetInt()); } diff --git a/ecmascript/module/js_module_deregister.cpp b/ecmascript/module/js_module_deregister.cpp index 2f16ab6e09..7616159b5e 100644 --- a/ecmascript/module/js_module_deregister.cpp +++ b/ecmascript/module/js_module_deregister.cpp @@ -14,8 +14,10 @@ */ #include "ecmascript/module/js_module_deregister.h" +#include "ecmascript/base/path_helper.h" #include "ecmascript/checkpoint/thread_state_transition.h" #include "ecmascript/jspandafile/js_pandafile_executor.h" +#include "ecmascript/module/js_module_source_text.h" #include "ecmascript/module/module_path_helper.h" #include "ecmascript/module/module_resolver.h" @@ -174,4 +176,16 @@ void ModuleDeregister::DecreaseRegisterCounts(JSThread *thread, JSHandleSetRegisterCounts(registerNum); } + +bool ModuleDeregister::TryToRemoveSO(JSThread *thread, JSHandle module) +{ + UnloadNativeModuleCallback unloadNativeModuleCallback = thread->GetEcmaVM()->GetUnloadNativeModuleCallback(); + if (unloadNativeModuleCallback == nullptr) { + LOG_ECMA(ERROR) << "unloadNativeModuleCallback is nullptr"; + return false; + } + + CString soName = base::PathHelper::GetStrippedModuleName(module->GetEcmaModuleRecordNameString()); + return unloadNativeModuleCallback(soName.c_str()); +} } // namespace panda::ecmascript diff --git a/ecmascript/module/js_module_deregister.h b/ecmascript/module/js_module_deregister.h index d2bdca1077..941854a399 100644 --- a/ecmascript/module/js_module_deregister.h +++ b/ecmascript/module/js_module_deregister.h @@ -53,6 +53,8 @@ public: static void DecreaseRegisterCounts(JSThread *thread, JSHandle module, std::set &decreaseModule); + + static bool TryToRemoveSO(JSThread *thread, JSHandle module); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_MODULE_JS_MODULE_DEREGISTER_H diff --git a/ecmascript/platform/file.h b/ecmascript/platform/file.h index 9c237f36be..fc9a1883c2 100644 --- a/ecmascript/platform/file.h +++ b/ecmascript/platform/file.h @@ -31,7 +31,6 @@ #include "ecmascript/js_tagged_value.h" namespace panda::ecmascript { -class SourceTextModule; #ifdef PANDA_TARGET_WINDOWS using fd_t = HANDLE; #define INVALID_FD INVALID_HANDLE_VALUE @@ -86,7 +85,6 @@ int PUBLIC_API FileSync(MemMap addr, int flag); CString ResolveFilenameFromNative(JSThread *thread, const CString &dirname, CString request); bool PUBLIC_API FileExist(const char *filename); int PUBLIC_API Unlink(const char *filename); -bool TryToRemoveSO(JSThread *thread, JSHandle module); void *LoadLib(const std::string &libname); void *FindSymbol(void *handle, const char *symbol); int CloseLib(void *handle); diff --git a/ecmascript/platform/unix/file.cpp b/ecmascript/platform/unix/file.cpp index f525c99279..6817a668e5 100644 --- a/ecmascript/platform/unix/file.cpp +++ b/ecmascript/platform/unix/file.cpp @@ -15,8 +15,8 @@ #include "ecmascript/platform/file.h" + #include -#include "ecmascript/base/path_helper.h" #include "common_components/log/log.h" #include "ecmascript/module/js_module_source_text.h" @@ -213,18 +213,6 @@ int Unlink(const char *filename) return unlink(filename); } -bool TryToRemoveSO(JSThread *thread, JSHandle module) -{ - UnloadNativeModuleCallback unloadNativeModuleCallback = thread->GetEcmaVM()->GetUnloadNativeModuleCallback(); - if (unloadNativeModuleCallback == nullptr) { - LOG_ECMA(ERROR) << "unloadNativeModuleCallback is nullptr"; - return false; - } - - CString soName = base::PathHelper::GetStrippedModuleName(module->GetEcmaModuleRecordNameString()); - return unloadNativeModuleCallback(soName.c_str()); -} - void *LoadLib(const std::string &libname) { return dlopen(libname.c_str(), RTLD_NOW); diff --git a/ecmascript/platform/windows/file.cpp b/ecmascript/platform/windows/file.cpp index 155d201eee..072db6648f 100644 --- a/ecmascript/platform/windows/file.cpp +++ b/ecmascript/platform/windows/file.cpp @@ -194,11 +194,6 @@ int Unlink(const char *filename) return _unlink(filename); } -bool TryToRemoveSO([[maybe_unused]] JSThread *thread, [[maybe_unused]] JSHandle module) -{ - return false; -} - void *LoadLib([[maybe_unused]] const std::string &liname) { LOG_ECMA(INFO) << "Unsupport LoadLib"; -- Gitee From 138d5335350218d60c4f7d805cb17e6cc9735bd7 Mon Sep 17 00:00:00 2001 From: jiangmengyang Date: Sat, 24 May 2025 15:44:36 +0800 Subject: [PATCH 13/54] 1.1 dynamic import 1.2 module Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICAMO0 Signed-off-by: jiangmengyang Change-Id: I8076ebeab0d710fe9257356e31e31fa79ecd0145 Signed-off-by: lhc --- BUILD.gn | 2 + ecmascript/builtins/builtins_promise_job.cpp | 48 +-- ecmascript/builtins/builtins_promise_job.h | 4 +- ecmascript/builtins/tests/BUILD.gn | 25 ++ .../tests/builtins_promise_job_test.cpp | 154 ++++++++++ ecmascript/global_env_constants.h | 8 +- ecmascript/module/js_dynamic_import.cpp | 15 +- ecmascript/module/js_module_source_text.h | 5 +- .../module/static/static_module_loader.cpp | 152 ++++++++++ .../module/static/static_module_loader.h | 41 +++ .../static/static_module_proxy_handler.cpp | 277 ++++++++++++++++++ .../static/static_module_proxy_handler.h | 68 +++++ ecmascript/module/tests/BUILD.gn | 3 +- .../tests/static_module_loader_test.cpp | 180 ++++++++++++ ecmascript/runtime_call_id.h | 4 +- 15 files changed, 955 insertions(+), 31 deletions(-) create mode 100644 ecmascript/builtins/tests/builtins_promise_job_test.cpp create mode 100644 ecmascript/module/static/static_module_loader.cpp create mode 100644 ecmascript/module/static/static_module_loader.h create mode 100644 ecmascript/module/static/static_module_proxy_handler.cpp create mode 100644 ecmascript/module/static/static_module_proxy_handler.h create mode 100644 ecmascript/module/tests/static_module_loader_test.cpp diff --git a/BUILD.gn b/BUILD.gn index 090dae612c..393119667a 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1054,6 +1054,8 @@ ecma_source = [ "ecmascript/module/accessor/module_data_accessor.cpp", "ecmascript/module/js_module_manager.cpp", "ecmascript/module/js_dynamic_import.cpp", + "ecmascript/module/static/static_module_proxy_handler.cpp", + "ecmascript/module/static/static_module_loader.cpp", "ecmascript/module/js_module_namespace.cpp", "ecmascript/module/js_module_source_text.cpp", "ecmascript/module/js_module_deregister.cpp", diff --git a/ecmascript/builtins/builtins_promise_job.cpp b/ecmascript/builtins/builtins_promise_job.cpp index d8de2bf3b6..ab15169de8 100644 --- a/ecmascript/builtins/builtins_promise_job.cpp +++ b/ecmascript/builtins/builtins_promise_job.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,11 +24,13 @@ #include "ecmascript/module/js_module_manager.h" #include "ecmascript/module/module_path_helper.h" #include "ecmascript/module/module_tools.h" +#include "ecmascript/module/static/static_module_loader.h" namespace panda::ecmascript::builtins { using JSRecordInfo = ecmascript::JSPandaFile::JSRecordInfo; using ModulePathHelper = ecmascript::ModulePathHelper; using PathHelper = ecmascript::base::PathHelper; +using StaticModuleLoader = ecmascript::StaticModuleLoader; JSTaggedValue BuiltinsPromiseJob::PromiseReactionJob(EcmaRuntimeCallInfo *argv) { @@ -145,7 +147,7 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) // Let specifierString be Completion(ToString(specifier)) JSHandle specifierString = JSTaggedValue::ToString(thread, specifier); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchToStringException(thread, reject)); // Resolve request module's ohmurl CString entryPoint = JSPandaFile::ENTRY_MAIN_FUNCTION; @@ -159,7 +161,8 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) recordNameStr = ModulePathHelper::Utf8ConvertToString(recordName.GetTaggedValue()); curJsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( thread, fileName, recordNameStr.c_str(), false, false, ExecuteTypes::STATIC); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, + StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); if (curJsPandaFile == nullptr) { LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << recordNameStr; } @@ -168,7 +171,8 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) ModulePathHelper::TranslateExpressionToNormalized(thread, curJsPandaFile.get(), fileName, recordNameStr, requestPath); LOG_ECMA(DEBUG) << "Exit Translate Normalized OhmUrl for DynamicImport, resultPath: " << requestPath; - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, + StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); } else if (ModulePathHelper::NeedTranstale(requestPath)) { ModulePathHelper::TranstaleExpressionInput(curJsPandaFile.get(), requestPath); LOG_ECMA(DEBUG) << "Exit Translate OhmUrl for DynamicImport, resultPath: " << requestPath; @@ -184,18 +188,22 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) CString moduleName; if (recordName->IsUndefined()) { fileName = ResolveFilenameFromNative(thread, fileName, requestPath); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, + StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); moduleName = fileName; } else { entryPoint = ModulePathHelper::ConcatFileNameWithMerge(thread, curJsPandaFile.get(), fileName, recordNameStr, requestPath); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, + StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); moduleName = entryPoint; } - std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, fileName, entryPoint, false, false, ExecuteTypes::STATIC); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); + std::shared_ptr jsPandaFile = + JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, + fileName, entryPoint, false, false, ExecuteTypes::STATIC); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, + StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); if (jsPandaFile == nullptr) { LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << fileName; } @@ -204,7 +212,8 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) if (recordInfo == nullptr) { CString normalizeStr = ModulePathHelper::ReformatPath(entryPoint); CString msg = "Cannot find dynamic-import module '" + normalizeStr; - THROW_REFERENCE_ERROR_AND_RETURN(thread, msg.c_str(), CatchException(thread, reject)); + THROW_REFERENCE_ERROR_AND_RETURN(thread, msg.c_str(), + StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); } if (jsPandaFile->IsJson(recordInfo)) { @@ -218,13 +227,15 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) if (!JSPandaFileExecutor::ExecuteFromAbcFile( thread, fileName.c_str(), entryPoint.c_str(), false, ExecuteTypes::DYNAMIC)) { CString msg = "Cannot execute request dynamic-imported module : " + entryPoint; - THROW_REFERENCE_ERROR_AND_RETURN(thread, msg.c_str(), CatchException(thread, reject)); + THROW_REFERENCE_ERROR_AND_RETURN(thread, msg.c_str(), + StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); } } else { ModuleDeregister::ReviseLoadedModuleCount(thread, moduleName); } - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, + StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); JSMutableHandle moduleNamespace(thread, JSTaggedValue::Undefined()); // only support importing es module, or return a default object. if (!jsPandaFile->IsModule(recordInfo)) { @@ -234,9 +245,11 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) JSHandle moduleRecord = moduleManager->GetImportedModule(moduleName); moduleRecord->CheckAndThrowModuleError(thread); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, + StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); JSHandle nameSp = SourceTextModule::GetModuleNamespace(thread, moduleRecord); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, + StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); // d. Let namespace be ? GetModuleNamespace(moduleRecord). moduleNamespace.Update(nameSp); } @@ -245,15 +258,16 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle(resolve), undefined, undefined, 1); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, + StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); info->SetCallArg(moduleNamespace.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSFunction::Call(info); } -JSTaggedValue BuiltinsPromiseJob::CatchException(JSThread *thread, JSHandle reject) +JSTaggedValue BuiltinsPromiseJob::CatchToStringException(JSThread *thread, JSHandle reject) { - BUILTINS_API_TRACE(thread, PromiseJob, CatchException); + BUILTINS_API_TRACE(thread, PromiseJob, CatchToStringException); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); ASSERT(thread->HasPendingException()); JSHandle thenResult = JSPromise::IfThrowGetThrowValue(thread); diff --git a/ecmascript/builtins/builtins_promise_job.h b/ecmascript/builtins/builtins_promise_job.h index 3b58ff359e..a2df9b07b4 100644 --- a/ecmascript/builtins/builtins_promise_job.h +++ b/ecmascript/builtins/builtins_promise_job.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,7 +24,7 @@ public: static JSTaggedValue PromiseReactionJob(EcmaRuntimeCallInfo *argv); static JSTaggedValue PromiseResolveThenableJob(EcmaRuntimeCallInfo *argv); static JSTaggedValue DynamicImportJob(EcmaRuntimeCallInfo *argv); - static JSTaggedValue CatchException(JSThread *thread, JSHandle reject); + static JSTaggedValue CatchToStringException(JSThread *thread, JSHandle reject); }; } // namespace panda::ecmascript::builtins #endif // ECMASCRIPT_JS_PROMISE_JOB_H \ No newline at end of file diff --git a/ecmascript/builtins/tests/BUILD.gn b/ecmascript/builtins/tests/BUILD.gn index e5beb08787..a4e11b1504 100755 --- a/ecmascript/builtins/tests/BUILD.gn +++ b/ecmascript/builtins/tests/BUILD.gn @@ -765,6 +765,28 @@ host_unittest_action("Builtins_Promise_Test") { deps += hiviewdfx_deps } +host_unittest_action("Builtins_Promise_Job_Test") { + module_out_path = module_output_path + + sources = [ + # test file + "builtins_promise_job_test.cpp", + ] + + configs = [ "../../../:ecma_test_config" ] + + deps = [ "../../../:libark_jsruntime_test" ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + external_deps += [ + "icu:shared_icui18n", + "icu:shared_icuuc", + "runtime_core:libarkassembler_static", + ] + deps += hiviewdfx_deps +} + host_unittest_action("Builtins_Proxy_Test") { module_out_path = module_output_path @@ -1199,6 +1221,7 @@ group("unittest") { ":Builtins_Object_Test", ":Builtins_PluralRules_Test", ":Builtins_Promise_Test", + ":Builtins_Promise_Job_Test", ":Builtins_Proxy_Test", ":Builtins_Reflect_Test", ":Builtins_Regexp_Test", @@ -1257,6 +1280,7 @@ group("host_unittest") { ":Builtins_Object_TestAction", ":Builtins_PluralRules_TestAction", ":Builtins_Promise_TestAction", + ":Builtins_Promise_Job_Test", ":Builtins_Proxy_TestAction", ":Builtins_Reflect_TestAction", ":Builtins_Regexp_TestAction", @@ -1310,6 +1334,7 @@ group("host_unittest") { ":Builtins_Object_TestAction", ":Builtins_PluralRules_TestAction", ":Builtins_Promise_TestAction", + ":Builtins_Promise_Job_Test", ":Builtins_Proxy_TestAction", ":Builtins_Reflect_TestAction", ":Builtins_Regexp_TestAction", diff --git a/ecmascript/builtins/tests/builtins_promise_job_test.cpp b/ecmascript/builtins/tests/builtins_promise_job_test.cpp new file mode 100644 index 0000000000..2f5bd8736d --- /dev/null +++ b/ecmascript/builtins/tests/builtins_promise_job_test.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/builtins/builtins_promise_job.h" +#include "ecmascript/global_env.h" +#include "ecmascript/tests/test_helper.h" +#include "ecmascript/module/napi_module_loader.h" +#include "ecmascript/ecma_vm.h" +#include "ecmascript/js_promise.h" +#include "ecmascript/js_array.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::builtins; + +using FunctionCallbackInfo = Local (*)(JsiRuntimeCallInfo *); +namespace panda::test { +class BuiltinsPromiseJobTest : public BaseTestWithScope { + public: + static Local MockGetModule(JsiRuntimeCallInfo *runtimeCallInfo); + static Local MockGetModuleJSError(JsiRuntimeCallInfo *runtimeCallInfo); +}; + +Local BuiltinsPromiseJobTest::MockGetModule(JsiRuntimeCallInfo *runtimeCallInfo) +{ + auto *thread = runtimeCallInfo->GetThread(); + auto vm = thread->GetEcmaVM(); + Local requestPath = StringRef::NewFromUtf8(vm, "requestPath"); + Local exportObejct = ObjectRef::New(vm); + exportObejct->Set(vm, requestPath, runtimeCallInfo->GetCallArgRef(0)); + return exportObejct; +} + +Local BuiltinsPromiseJobTest::MockGetModuleJSError(JsiRuntimeCallInfo *runtimeCallInfo) +{ + auto *thread = runtimeCallInfo->GetThread(); + auto vm = thread->GetEcmaVM(); + JsiFastNativeScope fastNativeScope(vm); + Local error(JSValueRef::Undefined(vm)); + error = Exception::Error(vm, runtimeCallInfo->GetCallArgRef(0)); + Local codeKey = StringRef::NewFromUtf8(vm, "code"); + Local codeValue = runtimeCallInfo->GetCallArgRef(0); + Local errorObj(error); + errorObj->Set(vm, codeKey, codeValue); + JSNApi::ThrowException(vm, error); + return runtimeCallInfo->GetCallArgRef(0); +} + +// dynamic import static module after load 1.0 module failed +HWTEST_F_L0(BuiltinsPromiseJobTest, DynamicImportJobCatchException) +{ + auto vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + JSHandle env = vm->GetGlobalEnv(); + + auto globalConstants = thread->GlobalConstants(); + JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); + EXPECT_TRUE(arr != nullptr); + JSHandle pandaObject(thread, arr); + JSTaggedValue::SetProperty(thread, pandaObject, + globalConstants->GetHandledGetModuleString(), + JSNApiHelper::ToJSHandle(FunctionRef::New(const_cast(vm), MockGetModule))); + Local globalObject = JSNApi::GetGlobalObject(vm); + globalObject->Set(vm, + JSNApiHelper::ToLocal(globalConstants->GetHandledPandaString()), + JSNApiHelper::ToLocal(pandaObject)); + + JSHandle promiseFunc = env->GetPromiseFunction(); + JSHandle jsPromise = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(promiseFunc), promiseFunc)); + JSHandle resolvingFunctions = + JSPromise::CreateResolvingFunctions(thread, jsPromise); + JSHandle resolve(thread, resolvingFunctions->GetResolveFunction()); + JSHandle reject(thread, resolvingFunctions->GetRejectFunction()); + JSHandle dirPath(factory->NewFromASCII("./main.abc")); + JSHandle specifier(factory->NewFromASCII("exportFile")); + JSHandle recordName(factory->NewFromASCII("main")); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 14); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, resolve.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, reject.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(2, dirPath.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(3, specifier.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(4, recordName.GetTaggedValue()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsPromiseJob::DynamicImportJob(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); + JSHandle result(thread, jsPromise->GetPromiseResult()); + EXPECT_EQ(result->IsJSProxy(), true); + JSHandle requestPath(factory->NewFromASCII("requestPath")); + EXPECT_EQ(JSTaggedValue::SameValue(JSTaggedValue::GetProperty(thread, result, requestPath).GetValue(), + specifier), true); +} + +// throw 1.2 load failed +HWTEST_F_L0(BuiltinsPromiseJobTest, DynamicImportJobCatchException2) +{ + auto vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + JSHandle env = vm->GetGlobalEnv(); + + auto globalConstants = thread->GlobalConstants(); + JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); + EXPECT_TRUE(arr != nullptr); + JSHandle pandaObject(thread, arr); + JSTaggedValue::SetProperty(thread, pandaObject, + globalConstants->GetHandledGetModuleString(), + JSNApiHelper::ToJSHandle(FunctionRef::New(const_cast(vm), MockGetModuleJSError))); + Local globalObject = JSNApi::GetGlobalObject(vm); + globalObject->Set(vm, + JSNApiHelper::ToLocal(globalConstants->GetHandledPandaString()), + JSNApiHelper::ToLocal(pandaObject)); + + JSHandle promiseFunc = env->GetPromiseFunction(); + JSHandle jsPromise = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(promiseFunc), promiseFunc)); + JSHandle resolvingFunctions = + JSPromise::CreateResolvingFunctions(thread, jsPromise); + JSHandle resolve(thread, resolvingFunctions->GetResolveFunction()); + JSHandle reject(thread, resolvingFunctions->GetRejectFunction()); + JSHandle dirPath(factory->NewFromASCII("./main.abc")); + JSHandle specifier(factory->NewFromASCII("exportFile")); + JSHandle recordName(factory->NewFromASCII("main")); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 14); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, resolve.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, reject.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(2, dirPath.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(3, specifier.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(4, recordName.GetTaggedValue()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsPromiseJob::DynamicImportJob(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); + JSHandle error(thread, jsPromise->GetPromiseResult()); + JSHandle code(factory->NewFromASCII("code")); + JSHandle message = JSTaggedValue::GetProperty(thread, error, code).GetValue(); + EXPECT_EQ(JSTaggedValue::SameValue(message, specifier), true); + thread->ClearException(); +} +} diff --git a/ecmascript/global_env_constants.h b/ecmascript/global_env_constants.h index 22b0cc38e4..da4320cd0e 100644 --- a/ecmascript/global_env_constants.h +++ b/ecmascript/global_env_constants.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -465,6 +465,8 @@ class ObjectFactory; /* for require native module */ \ V(RequireNativeModuleString, REQUIRE_NATIVE_MOUDULE_FUNC_INDEX, "requireNativeModule") \ V(RequireNapiString, REQUIRE_NAPI_FUNC_INDEX, "requireNapi") \ + V(RequireNapiPreviewString, REQUIRE_NAPI_PREVIEW_FUNC_INDEX, "requireNapiPreview") \ + V(PandaString, PANDA_STRING_INDEX, "Panda") \ V(DollarStringOne, DOLLAR_STRING_ONE_INDEX, "$1") \ V(DollarStringTwo, DOLLAR_STRING_TWO_INDEX, "$2") \ V(DollarStringThree, DOLLAR_STRING_THREE_INDEX, "$3") \ @@ -496,7 +498,9 @@ class ObjectFactory; V(SharedFullGcCause, SHARED_FULL_GC_CAUSE, "shared_full") \ V(AppSpawnSharedFullGcCause, APP_SPAWN_SHARED_FULL_GC_CAUSE, "app_spawn_shared_full") \ V(UnifiedGcCause, UNIFIED_GC_CAUSE, "unified") \ - V(SymbolLeftParentheses, SYMBOL_LEFT_PARENTHESES, "Symbol(") + V(SymbolLeftParentheses, SYMBOL_LEFT_PARENTHESES, "Symbol(") \ + V(InteropJsNapiString, INTEROP_JS_NAPI, "ets_interop_js_napi") \ + V(GetModuleString, GET_MODULE, "getModule") // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define SHARED_GLOBAL_ENV_CONSTANT_ACCESSOR(V) \ diff --git a/ecmascript/module/js_dynamic_import.cpp b/ecmascript/module/js_dynamic_import.cpp index 2de284402c..a7f09aa074 100644 --- a/ecmascript/module/js_dynamic_import.cpp +++ b/ecmascript/module/js_dynamic_import.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,6 +20,7 @@ #include "ecmascript/module/js_module_manager.h" #include "ecmascript/module/module_data_extractor.h" #include "ecmascript/module/module_resolver.h" +#include "ecmascript/module/static/static_module_loader.h" namespace panda::ecmascript { using PathHelper = base::PathHelper; @@ -40,7 +41,8 @@ JSTaggedValue DynamicImport::ExecuteNativeOrJsonModule(JSThread *thread, const C JSHandle moduleRecord = moduleManager->HostGetImportedModule(specifierString); moduleRecord->CheckAndThrowModuleError(thread); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, BuiltinsPromiseJob::CatchException(thread, reject)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, + StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); requiredModule.Update(moduleRecord); } else { JSHandle moduleRecord(thread, thread->GlobalConstants()->GetUndefined()); @@ -57,7 +59,8 @@ JSTaggedValue DynamicImport::ExecuteNativeOrJsonModule(JSThread *thread, const C moduleRecord = JSHandle::Cast(ModuleDataExtractor::ParseJsonModule( thread, jsPandaFile, jsPandaFile->GetJSPandaFileDesc(), specifierString)); SourceTextModule::RecordEvaluatedOrError(thread, moduleRecord); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, BuiltinsPromiseJob::CatchException(thread, reject)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, + StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); } moduleManager->AddResolveImportedModule(specifierString, moduleRecord.GetTaggedValue()); moduleRecord->SetLoadingTypes(LoadingTypes::DYNAMITC_MODULE); @@ -68,13 +71,15 @@ JSTaggedValue DynamicImport::ExecuteNativeOrJsonModule(JSThread *thread, const C JSHandle moduleNamespace = SourceTextModule::GetModuleNamespace(thread, JSHandle::Cast(requiredModule)); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, BuiltinsPromiseJob::CatchException(thread, reject)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, + StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle(resolve), undefined, undefined, 1); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, BuiltinsPromiseJob::CatchException(thread, reject)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, + StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); info->SetCallArg(moduleNamespace.GetTaggedValue()); return JSFunction::Call(info); } diff --git a/ecmascript/module/js_module_source_text.h b/ecmascript/module/js_module_source_text.h index 44bb9e698e..199bbaa1b5 100644 --- a/ecmascript/module/js_module_source_text.h +++ b/ecmascript/module/js_module_source_text.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -46,7 +46,8 @@ enum class ModuleTypes : uint8_t { OHOS_MODULE, APP_MODULE, INTERNAL_MODULE, - UNKNOWN + UNKNOWN, + STATIC_MODULE }; enum class LoadingTypes : uint8_t { diff --git a/ecmascript/module/static/static_module_loader.cpp b/ecmascript/module/static/static_module_loader.cpp new file mode 100644 index 0000000000..31a4010839 --- /dev/null +++ b/ecmascript/module/static/static_module_loader.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/module/static/static_module_loader.h" +#include "ecmascript/global_env.h" +#include "ecmascript/object_factory-inl.h" +#include "ecmascript/module/module_manager_helper.h" +#include "ecmascript/module/module_path_helper.h" +#include "ecmascript/module/js_module_deregister.h" +#include "ecmascript/module/js_shared_module_manager.h" +#include "ecmascript/shared_objects/js_shared_array.h" +#include "ecmascript/module/js_module_source_text.h" +#include "ecmascript/module/module_data_extractor.h" +#include "ecmascript/builtins/builtins_promise_job.h" +#include "ecmascript/interpreter/interpreter.h" +#include "ecmascript/js_promise.h" +#include "ecmascript/module/module_path_helper.h" +#include "ecmascript/module/static/static_module_proxy_handler.h" + +namespace panda::ecmascript { +bool StaticModuleLoader::CanTryLoadStaticModulePath(const CString &requestPath) +{ + // Filters the 1.0 ohmurl that can be determined + if (ModulePathHelper::IsOhmUrl(requestPath) || ModulePathHelper::IsImportFile(requestPath) + || StringHelper::StringStartWith(requestPath, ModulePathHelper::PREFIX_MODULE) + || StringHelper::StringStartWith(requestPath, ModulePathHelper::RAW_ARKUIX_PREFIX) + || StringHelper::StringStartWith(requestPath, ModulePathHelper::PREFIX_NORMALIZED)) { + return false; + } + return true; +} + +Local StaticModuleLoader::GetStaticModuleLoadFunc(EcmaVM *vm) +{ + auto thread = vm->GetJSThread(); + auto globalConstants = thread->GlobalConstants(); + Local globalObject = JSNApi::GetGlobalObject(vm); + Local pandaObject = globalObject->Get(vm, + JSNApiHelper::ToLocal(globalConstants->GetHandledPandaString())); + if (pandaObject->IsUndefined()) { + LOG_ECMA(DEBUG) << "the current env is not 1.2 vm"; + return JSValueRef::Undefined(vm); + } + JSHandle getModule = JSTaggedValue::GetProperty(thread, JSNApiHelper::ToJSHandle(pandaObject), + globalConstants->GetHandledGetModuleString()).GetValue(); + Local getModuleRef = JSNApiHelper::ToLocal(getModule); + if (!getModuleRef->IsFunction(vm)) { + return JSValueRef::Undefined(vm); + } + return getModuleRef; +} + +JSHandle StaticModuleLoader::LoadStaticModule(JSThread *thread, + Local getEsModuleFunc, const CString &key) +{ + auto moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager(); + if (moduleManager->IsModuleLoaded(key)) { + LOG_ECMA(INFO) << "load ets module from cache."; + JSHandle moduleRecord = moduleManager->HostGetImportedModule(key); + return JSHandle(thread, moduleRecord->GetModuleValue(thread, 0, false)); + } + + auto vm = thread->GetEcmaVM(); + auto globalConstants = thread->GlobalConstants(); + + JSHandle moduleRecord = ModuleDataExtractor::ParseNativeModule(thread, key, + "", ModuleTypes::STATIC_MODULE); + JSHandle nativeModule = JSHandle::Cast(moduleRecord); + std::vector> moduleArgs; + moduleArgs.emplace_back(StringRef::NewFromUtf8(vm, key.c_str())); + Local moduleExport = getEsModuleFunc->Call(vm, JSValueRef::Undefined(vm), + moduleArgs.data(), moduleArgs.size()); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Undefined())); + JSHandle proxyExport = StaticModuleProxyHandler::CreateStaticModuleProxyHandler(thread, + JSNApiHelper::ToJSHandle(moduleExport)); + JSHandle value(proxyExport); + SourceTextModule::RecordEvaluatedOrError(thread, nativeModule); + nativeModule->SetLoadingTypes(LoadingTypes::STABLE_MODULE); + SourceTextModule::StoreModuleValue(thread, nativeModule, 0, value); + moduleManager->AddResolveImportedModule(key, moduleRecord.GetTaggedValue()); + return value; +} + +JSTaggedValue StaticModuleLoader::TryLoadStaticModule(JSThread *thread, JSHandle resolve, + JSHandle reject, JSHandle specifierString) +{ + CString requestPath = ModulePathHelper::Utf8ConvertToString(specifierString.GetTaggedValue()); + return TryLoadStaticModule(thread, resolve, reject, requestPath); +} + +JSTaggedValue StaticModuleLoader::TryLoadStaticModule(JSThread *thread, JSHandle resolve, + JSHandle reject, const CString &requestPath) +{ + JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); + ASSERT(thread->HasPendingException()); + LOG_ECMA(DEBUG) << "start try load static module: " << requestPath; + // If the ohmurl is detected to be in compliance with the 1.0 prefix rule, then throw an exception directly + if (StaticModuleLoader::CanTryLoadStaticModulePath(requestPath)) { + JSHandle errorReuslt = JSPromise::IfThrowGetThrowValue(thread); + LOG_ECMA(DEBUG) << "start load static module: " << requestPath; + thread->ClearException(); + EcmaVM *vm = thread->GetEcmaVM(); + Local getEsModule = GetStaticModuleLoadFunc(vm); + if (!getEsModule->IsFunction(vm)) { + LOG_ECMA(DEBUG) << "napi static module function not found " << requestPath; + thread->SetException(errorReuslt.GetTaggedValue()); + return CatchException(thread, reject); + } + // try load 1.2 module; + Local getEsModuleFunc = getEsModule; + ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager(); + JSHandle exportObject = LoadStaticModule(thread, getEsModuleFunc, requestPath); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); + LOG_ECMA(DEBUG) << "load static module successfull, requestPath: " << requestPath; + JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); + EcmaRuntimeCallInfo *info = + EcmaInterpreter::NewRuntimeCallInfo(thread, + JSHandle(resolve), + undefined, undefined, 1); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); + info->SetCallArg(exportObject.GetTaggedValue()); + return JSFunction::Call(info); + } + return CatchException(thread, reject); +} + +JSTaggedValue StaticModuleLoader::CatchException(JSThread *thread, JSHandle reject) +{ + JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); + ASSERT(thread->HasPendingException()); + JSHandle errorReuslt = JSPromise::IfThrowGetThrowValue(thread); + thread->ClearException(); + JSHandle rejectfun(reject); + EcmaRuntimeCallInfo *runtimeInfo = + EcmaInterpreter::NewRuntimeCallInfo(thread, rejectfun, undefined, undefined, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + runtimeInfo->SetCallArg(errorReuslt.GetTaggedValue()); + return JSFunction::Call(runtimeInfo); +} +} // namespace panda::ecmascript diff --git a/ecmascript/module/static/static_module_loader.h b/ecmascript/module/static/static_module_loader.h new file mode 100644 index 0000000000..2ca171b6ba --- /dev/null +++ b/ecmascript/module/static/static_module_loader.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef ECMASCRIPT_SATTIC_MODULE_LOADER_H +#define ECMASCRIPT_SATTIC_MODULE_LOADER_H +#include "ecmascript/js_object.h" +#include "ecmascript/js_tagged_value.h" +#include "ecmascript/js_proxy.h" +#include "ecmascript/js_function.h" + +namespace panda::ecmascript { +class StaticModuleLoader { +public: + static bool CanTryLoadStaticModulePath(const CString &requestPath); + + static Local GetStaticModuleLoadFunc(EcmaVM *vm); + + static JSHandle LoadStaticModule(JSThread *thread, + Local getEsModuleFunc, const CString &key); + + static JSTaggedValue TryLoadStaticModule(JSThread *thread, JSHandle resolve, + JSHandle reject, JSHandle specifierString); + + static JSTaggedValue TryLoadStaticModule(JSThread *thread, JSHandle resolve, + JSHandle reject, const CString &requestPath); + + static JSTaggedValue CatchException(JSThread *thread, JSHandle reject); +}; +} // namespace panda::ecmascript +#endif // ECMASCRIPT_SATTIC_MODULE_NAMESPACE_H diff --git a/ecmascript/module/static/static_module_proxy_handler.cpp b/ecmascript/module/static/static_module_proxy_handler.cpp new file mode 100644 index 0000000000..e2169594ea --- /dev/null +++ b/ecmascript/module/static/static_module_proxy_handler.cpp @@ -0,0 +1,277 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/module/static/static_module_proxy_handler.h" +#include "ecmascript/global_env.h" +#include "ecmascript/object_factory-inl.h" +#include "ecmascript/module/module_manager_helper.h" +#include "ecmascript/module/module_path_helper.h" +#include "ecmascript/module/js_module_deregister.h" +#include "ecmascript/module/js_shared_module_manager.h" +#include "ecmascript/shared_objects/js_shared_array.h" +#include "ecmascript/module/js_module_source_text.h" +#include "ecmascript/module/module_data_extractor.h" +#include "ecmascript/builtins/builtins_promise_job.h" +#include "ecmascript/interpreter/interpreter.h" +#include "ecmascript/js_promise.h" +#include "ecmascript/module/module_path_helper.h" + +namespace panda::ecmascript { +JSHandle StaticModuleProxyHandler::CreateStaticModuleProxyHandler(JSThread *thread, + const JSHandle exportObject) +{ + EcmaVM *vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + JSHandle targetHandler(factory->NewJSFunction(vm->GetGlobalEnv())); + + JSHandle setPrototype(factory->NewJSFunction(vm->GetGlobalEnv(), + reinterpret_cast(StaticModuleProxyHandler::SetPrototype))); + JSTaggedValue::SetProperty(thread, targetHandler, + thread->GlobalConstants()->GetHandledSetPrototypeOfString(), setPrototype); + + JSHandle preventExtensions(factory->NewJSFunction(vm->GetGlobalEnv(), + reinterpret_cast(StaticModuleProxyHandler::PreventExtensions))); + JSTaggedValue::SetProperty(thread, targetHandler, + thread->GlobalConstants()->GetHandledPreventExtensionsString(), preventExtensions); + + JSHandle getOwnProperty(factory->NewJSFunction(vm->GetGlobalEnv(), + reinterpret_cast(StaticModuleProxyHandler::GetOwnProperty))); + JSTaggedValue::SetProperty(thread, targetHandler, + thread->GlobalConstants()->GetHandledGetOwnPropertyDescriptorString(), getOwnProperty); + + JSHandle defineOwnProperty(factory->NewJSFunction(vm->GetGlobalEnv(), + reinterpret_cast(StaticModuleProxyHandler::DefineOwnProperty))); + JSTaggedValue::SetProperty(thread, targetHandler, + thread->GlobalConstants()->GetHandledDefinePropertyString(), defineOwnProperty); + + JSHandle hasProperty(factory->NewJSFunction(vm->GetGlobalEnv(), + reinterpret_cast(StaticModuleProxyHandler::HasProperty))); + JSTaggedValue::SetProperty(thread, targetHandler, + thread->GlobalConstants()->GetHandledHasString(), hasProperty); + + JSHandle getProperty(factory->NewJSFunction(vm->GetGlobalEnv(), + reinterpret_cast(StaticModuleProxyHandler::GetProperty))); + JSTaggedValue::SetProperty(thread, targetHandler, + thread->GlobalConstants()->GetHandledGetString(), getProperty); + + JSHandle setProperty(factory->NewJSFunction(vm->GetGlobalEnv(), + reinterpret_cast(StaticModuleProxyHandler::SetProperty))); + JSTaggedValue::SetProperty(thread, targetHandler, + thread->GlobalConstants()->GetHandledSetString(), setProperty); + + JSHandle deleteProperty(factory->NewJSFunction(vm->GetGlobalEnv(), + reinterpret_cast(StaticModuleProxyHandler::DeleteProperty))); + JSTaggedValue::SetProperty(thread, targetHandler, + thread->GlobalConstants()->GetHandledDeletePropertyString(), deleteProperty); + + JSHandle ownPropertyKeys(factory->NewJSFunction(vm->GetGlobalEnv(), + reinterpret_cast(StaticModuleProxyHandler::OwnPropertyKeys))); + JSTaggedValue::SetProperty(thread, targetHandler, + thread->GlobalConstants()->GetHandledOwnKeysString(), ownPropertyKeys); + + return JSProxy::ProxyCreate(thread, exportObject, targetHandler); +} + +JSTaggedValue StaticModuleProxyHandler::GetProperty(EcmaRuntimeCallInfo *argv) +{ + JSThread *thread = argv->GetThread(); + JSHandle obj(argv->GetCallArg(FIRST)); + JSHandle key(argv->GetCallArg(SECOND)); + // 1. Assert: IsPropertyKey(P) is true. + // 2. If Type(P) is Symbol, then + // a. Return ? OrdinaryGet(O, P, Receiver). + return GetPropertyInternal(thread, obj, key); +} + +JSTaggedValue StaticModuleProxyHandler::GetPropertyInternal(JSThread *thread, const JSHandle &obj, + const JSHandle &key) +{ + // 1. Assert: IsPropertyKey(P) is true. + ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); + // 2. If Type(P) is Symbol, then + // a. Return ? OrdinaryGet(O, P, Receiver). + return JSObject::GetProperty(thread, obj, key).GetValue().GetTaggedValue(); +} + + +JSTaggedValue StaticModuleProxyHandler::OwnPropertyKeys(EcmaRuntimeCallInfo *argv) +{ + JSHandle obj(argv->GetCallArg(FIRST)); + JSThread *thread = argv->GetThread(); + JSHandle symbolKeys = JSObject::GetOwnPropertyKeys(thread, JSHandle(obj)); //todo copy array + JSHandle propertyKeys = JSArray::CreateArrayFromList(thread, symbolKeys); + return propertyKeys.GetTaggedValue(); +} + +bool StaticModuleProxyHandler::GetOwnPropertyInternal(JSThread *thread, const JSHandle &obj, + const JSHandle &key, PropertyDescriptor &desc) +{ + ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); + // 1. If Type(P) is Symbol, return OrdinaryGetOwnProperty(O, P). + if (key->IsSymbol()) { + return JSObject::GetOwnProperty(thread, JSHandle(obj), key, desc); + } + // 2. Let value be ? O.[[Get]](P, O). + JSHandle value(thread, StaticModuleProxyHandler::GetPropertyInternal(thread, obj, key)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); + if (value->IsUndefined()) { + return false; + } + // 3. Return PropertyDescriptor { + // [[Value]]: value, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: false }. + desc.SetValue(value); + desc.SetEnumerable(true); + desc.SetWritable(true); + desc.SetConfigurable(false); + return true; +} + +JSTaggedValue StaticModuleProxyHandler::OwnEnumPropertyKeys(EcmaRuntimeCallInfo *argv) +{ + JSHandle obj(argv->GetCallArg(FIRST)); + JSThread *thread = argv->GetThread(); + JSHandle symbolKeys = JSObject::GetOwnPropertyKeys(thread, JSHandle(obj)); //todo copy array + JSHandle propertyKeys = JSArray::CreateArrayFromList(thread, symbolKeys); + return propertyKeys.GetTaggedValue(); +} + +JSTaggedValue StaticModuleProxyHandler::PreventExtensions(EcmaRuntimeCallInfo *argv) +{ + return JSTaggedValue::True(); +} + +JSTaggedValue StaticModuleProxyHandler::DefineOwnProperty(EcmaRuntimeCallInfo *argv) +{ + JSThread *thread = argv->GetThread(); + JSHandle obj(argv->GetCallArg(FIRST)); + JSHandle key(argv->GetCallArg(SECOND)); + JSHandle descObj(argv->GetCallArg(THIRD)); + PropertyDescriptor desc(thread); + if (!descObj->IsUndefined()) { + JSObject::ToPropertyDescriptor(thread, descObj, desc); + } + // 1. If Type(P) is Symbol, return ! OrdinaryDefineOwnProperty(O, P, Desc). + if (key->IsSymbol()) { + bool res = JSObject::OrdinaryDefineOwnProperty(thread, JSHandle(obj), key, desc); + return JSTaggedValue(res); + } + + // 2. Let current be ? O.[[GetOwnProperty]](P). + PropertyDescriptor current(thread); + // 3. If current is undefined, return false. + if (!GetOwnPropertyInternal(thread, obj, key, current)) { + return JSTaggedValue::False(); + } + // 4. If Desc has a [[Configurable]] field and Desc.[[Configurable]] is true, return false. + // 5. If Desc has an [[Enumerable]] field and Desc.[[Enumerable]] is false, return false. + // 6. If IsAccessorDescriptor(Desc) is true, return false. + // 7. If Desc has a [[Writable]] field and Desc.[[Writable]] is false, return false. + if (desc.IsAccessorDescriptor()) { + return JSTaggedValue::False(); + } + if (desc.HasConfigurable() && desc.IsConfigurable()) { + return JSTaggedValue::False(); + } + if (desc.HasEnumerable() && !desc.IsEnumerable()) { + return JSTaggedValue::False(); + } + if (desc.HasWritable() && !desc.IsWritable()) { + return JSTaggedValue::False(); + } + + // 8. If Desc has a [[Value]] field, return SameValue(Desc.[[Value]], current.[[Value]]). + if (desc.HasValue()) { + JSHandle descValue = desc.GetValue(); + JSHandle currentValue = current.GetValue(); + return JSTaggedValue(JSTaggedValue::SameValue(descValue, currentValue)); + } + + // 9. Return true. + return JSTaggedValue::True(); +} + +JSTaggedValue StaticModuleProxyHandler::HasProperty(EcmaRuntimeCallInfo *argv) +{ + JSThread *thread = argv->GetThread(); + JSHandle obj(argv->GetCallArg(FIRST)); + JSHandle key(argv->GetCallArg(SECOND)); + return JSTaggedValue(JSObject::HasProperty(thread, JSHandle(obj), key)); +} + +JSTaggedValue StaticModuleProxyHandler::SetPrototype(EcmaRuntimeCallInfo *argv) +{ + // 1. Assert: Either Type(V) is Object or Type(V) is Null. + JSHandle proto(argv->GetCallArg(SECOND)); + ASSERT(proto->IsECMAObject() || proto->IsNull()); + return JSTaggedValue(proto->IsNull()); +} + +JSTaggedValue StaticModuleProxyHandler::GetPrototype(EcmaRuntimeCallInfo *argv) +{ + // 1. Assert: Either Type(V) is Object or Type(V) is Null. + return JSTaggedValue::Null(); +} + + +JSTaggedValue StaticModuleProxyHandler::GetOwnProperty(EcmaRuntimeCallInfo *argv) +{ + JSThread *thread = argv->GetThread(); + JSHandle obj(argv->GetCallArg(FIRST)); + JSHandle key(argv->GetCallArg(SECOND)); + JSHandle descObj(argv->GetCallArg(THIRD)); + PropertyDescriptor desc(thread); + if (!descObj->IsUndefined()) { + JSObject::ToPropertyDescriptor(thread, descObj, desc); + } + return JSTaggedValue(GetOwnPropertyInternal(thread, obj, key, desc)); +} + +JSTaggedValue StaticModuleProxyHandler::SetProperty(EcmaRuntimeCallInfo *argv) +{ + JSThread *thread = argv->GetThread(); + JSHandle mayThrow(argv->GetCallArg(FIRST)); + if (mayThrow->ToBoolean()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot assign to read only property of Object Module", + JSTaggedValue::False()); + } + return JSTaggedValue::False(); +} + +JSTaggedValue StaticModuleProxyHandler::DeleteProperty(EcmaRuntimeCallInfo *argv) +{ + JSThread *thread = argv->GetThread(); + JSHandle obj(argv->GetCallArg(FIRST)); + JSHandle key(argv->GetCallArg(SECOND)); + // 1. Assert: IsPropertyKey(P) is true. + ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); + // 2. If Type(P) is Symbol, then + // Return ? OrdinaryDelete(O, P). + if (key->IsSymbol()) { + return JSTaggedValue(JSObject::DeleteProperty(thread, JSHandle(obj), key)); + } + // 3. Let exports be O.[[Exports]]. + JSHandle value(thread, GetPropertyInternal(thread, obj, key)); + // 4. If P is an element of exports, return false. + if (value->IsUndefined()) { + return JSTaggedValue::True(); + } + return JSTaggedValue::False(); +} + +JSTaggedValue StaticModuleProxyHandler::IsExtensible(EcmaRuntimeCallInfo *argv) +{ + return JSTaggedValue::False(); +} +} // namespace panda::ecmascript diff --git a/ecmascript/module/static/static_module_proxy_handler.h b/ecmascript/module/static/static_module_proxy_handler.h new file mode 100644 index 0000000000..c5cf2ae193 --- /dev/null +++ b/ecmascript/module/static/static_module_proxy_handler.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_SATTIC_MODULE_PROXY_HANDLER_H +#define ECMASCRIPT_SATTIC_MODULE_PROXY_HANDLER_H + +#include "ecmascript/js_object.h" +#include "ecmascript/js_tagged_value.h" +#include "ecmascript/js_proxy.h" +#include "ecmascript/js_function.h" + +namespace panda::ecmascript { +class StaticModuleProxyHandler { +public: + static JSHandle CreateStaticModuleProxyHandler(JSThread *thread, + const JSHandle exportObject); + // [[SetPrototypeOf]] + static JSTaggedValue SetPrototype(EcmaRuntimeCallInfo *argv); + + // [[GetPrototypeOf]] + static JSTaggedValue GetPrototype(EcmaRuntimeCallInfo *argv); + + // [[PreventExtensions]] + static JSTaggedValue PreventExtensions(EcmaRuntimeCallInfo *argv); + // [[GetOwnProperty]] + static JSTaggedValue GetOwnProperty(EcmaRuntimeCallInfo *argv); + + static bool GetOwnPropertyInternal(JSThread *thread, const JSHandle &obj, + const JSHandle &key, PropertyDescriptor &desc); + // [[DefineOwnProperty]] ( P, Desc ) + static JSTaggedValue DefineOwnProperty(EcmaRuntimeCallInfo *argv); + // [[HasProperty]] + static JSTaggedValue HasProperty(EcmaRuntimeCallInfo *argv); + // [[Get]] ( P, Receiver ) + static JSTaggedValue GetProperty(EcmaRuntimeCallInfo *argv); + + static JSTaggedValue GetPropertyInternal(JSThread *thread, const JSHandle &obj, + const JSHandle &key); + // [[Set]] ( P, V, Receiver ) + static JSTaggedValue SetProperty(EcmaRuntimeCallInfo *argv); + // [[Delete]] ( P ) + static JSTaggedValue DeleteProperty(EcmaRuntimeCallInfo *argv); + // [[OwnPropertyKeys]] + static JSTaggedValue OwnPropertyKeys(EcmaRuntimeCallInfo *argv); + + static JSTaggedValue OwnEnumPropertyKeys(EcmaRuntimeCallInfo *argv); + + static JSTaggedValue IsExtensible(EcmaRuntimeCallInfo *argv); + +private: + static int const FIRST = 0; + static int const SECOND = 1; + static int const THIRD = 2; +}; +} // namespace panda::ecmascript +#endif // ECMASCRIPT_SATTIC_MODULE_PROXY_HANDLER_H diff --git a/ecmascript/module/tests/BUILD.gn b/ecmascript/module/tests/BUILD.gn index 1cd6f3e48e..f4817b9ffc 100644 --- a/ecmascript/module/tests/BUILD.gn +++ b/ecmascript/module/tests/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -60,6 +60,7 @@ host_unittest_action("ModuleTest") { sources = [ # test file "ecma_module_test.cpp", + "static_module_loader_test.cpp" ] configs = [ diff --git a/ecmascript/module/tests/static_module_loader_test.cpp b/ecmascript/module/tests/static_module_loader_test.cpp new file mode 100644 index 0000000000..bb4e8db0c4 --- /dev/null +++ b/ecmascript/module/tests/static_module_loader_test.cpp @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/js_object-inl.h" +#include "ecmascript/tests/test_helper.h" +#include "ecmascript/ecma_vm.h" +#include "ecmascript/module/static/static_module_loader.h" +#include "ecmascript/js_promise.h" +#include "ecmascript/module/napi_module_loader.h" +#include "ecmascript/js_array.h" +#include "ecmascript/global_env.h" +#include "ecmascript/module/module_path_helper.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::builtins; +using FunctionCallbackInfo = Local (*)(JsiRuntimeCallInfo *); +using namespace panda::ecmascript; +using ModulePathHelper = ecmascript::ModulePathHelper; + +namespace panda::test { +class StaticModuleLoaderTest : public testing::Test { +public: + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "TearDownCase"; + } + + void SetUp() override + { + TestHelper::CreateEcmaVMWithScope(instance, thread, scope); + } + + void TearDown() override + { + TestHelper::DestroyEcmaVMWithScope(instance, scope); + } + static Local MockGetModule(JsiRuntimeCallInfo *runtimeCallInfo); + static Local MockGetModuleJSError(JsiRuntimeCallInfo *runtimeCallInfo); + EcmaVM *instance {nullptr}; + ecmascript::EcmaHandleScope *scope {nullptr}; + JSThread *thread {nullptr}; +}; + +Local StaticModuleLoaderTest::MockGetModule(JsiRuntimeCallInfo *runtimeCallInfo) +{ + auto *thread = runtimeCallInfo->GetThread(); + auto vm = thread->GetEcmaVM(); + Local requestPath = StringRef::NewFromUtf8(vm, "requestPath"); + Local exportObejct = ObjectRef::New(vm); + exportObejct->Set(vm, requestPath, runtimeCallInfo->GetCallArgRef(0)); + return exportObejct; +} + + +Local StaticModuleLoaderTest::MockGetModuleJSError(JsiRuntimeCallInfo *runtimeCallInfo) +{ + auto *thread = runtimeCallInfo->GetThread(); + auto vm = thread->GetEcmaVM(); + JsiFastNativeScope fastNativeScope(vm); + Local error(JSValueRef::Undefined(vm)); + error = Exception::Error(vm, runtimeCallInfo->GetCallArgRef(0)); + Local codeKey = StringRef::NewFromUtf8(vm, "code"); + Local codeValue = runtimeCallInfo->GetCallArgRef(0); + Local errorObj(error); + errorObj->Set(vm, codeKey, codeValue); + JSNApi::ThrowException(vm, error); + return runtimeCallInfo->GetCallArgRef(0); +} + +HWTEST_F_L0(StaticModuleLoaderTest, CanTryLoadStaticModulePath) +{ + CString inputFileName = "./test"; + bool res1 = StaticModuleLoader::CanTryLoadStaticModulePath(inputFileName); + EXPECT_FALSE(res1); + + inputFileName = "test"; + bool res2 = StaticModuleLoader::CanTryLoadStaticModulePath(inputFileName); + EXPECT_TRUE(res2); + + inputFileName = "test.js"; + bool res3 = StaticModuleLoader::CanTryLoadStaticModulePath(inputFileName); + EXPECT_FALSE(res3); + + inputFileName = "test.ts"; + bool res4 = StaticModuleLoader::CanTryLoadStaticModulePath(inputFileName); + EXPECT_FALSE(res4); + + inputFileName = "test.ets"; + bool res5 = StaticModuleLoader::CanTryLoadStaticModulePath(inputFileName); + EXPECT_FALSE(res5); + + inputFileName = "@bundle:"; + bool res6 = StaticModuleLoader::CanTryLoadStaticModulePath(inputFileName); + EXPECT_FALSE(res6); + + inputFileName = "@normalized:"; + bool res7 = StaticModuleLoader::CanTryLoadStaticModulePath(inputFileName); + EXPECT_FALSE(res7); + + inputFileName = "@package:"; + bool res8 = StaticModuleLoader::CanTryLoadStaticModulePath(inputFileName); + EXPECT_FALSE(res8); +} + +HWTEST_F_L0(StaticModuleLoaderTest, GetStaticModuleLoadFunc) +{ + auto vm = thread->GetEcmaVM(); + Local undefinedFunc = StaticModuleLoader::GetStaticModuleLoadFunc(vm); + EXPECT_TRUE(undefinedFunc->IsUndefined()); + + auto globalConstants = thread->GlobalConstants(); + JSArray *arr = JSArray::Cast(JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); + EXPECT_TRUE(arr != nullptr); + JSHandle pandaObject(thread, arr); + JSTaggedValue::SetProperty(thread, pandaObject, + globalConstants->GetHandledGetModuleString(), + JSNApiHelper::ToJSHandle(FunctionRef::New(const_cast(vm), MockGetModule))); + Local globalObject = JSNApi::GetGlobalObject(vm); + globalObject->Set(vm, + JSNApiHelper::ToLocal(globalConstants->GetHandledPandaString()), + JSNApiHelper::ToLocal(pandaObject)); + Local func = StaticModuleLoader::GetStaticModuleLoadFunc(vm); + EXPECT_FALSE(func->IsUndefined()); +} + +HWTEST_F_L0(StaticModuleLoaderTest, LoadStaticModule) +{ + auto vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + + Local func = FunctionRef::New(const_cast(vm), MockGetModule); + JSHandle specifier(factory->NewFromASCII("exportFile")); + JSHandle specifierString = JSTaggedValue::ToString(thread, specifier); + CString path = ModulePathHelper::Utf8ConvertToString(specifierString.GetTaggedValue()); + JSHandle result = StaticModuleLoader::LoadStaticModule(thread, func, path); + + EXPECT_EQ(result->IsJSProxy(), true); + JSHandle requestPath(factory->NewFromASCII("requestPath")); + EXPECT_EQ(JSTaggedValue::SameValue(JSTaggedValue::GetProperty(thread, result, requestPath).GetValue(), + specifier), true); +} + + +HWTEST_F_L0(StaticModuleLoaderTest, LoadStaticModuleError) +{ + auto vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + + Local func = FunctionRef::New(const_cast(vm), MockGetModuleJSError); + JSHandle specifier(factory->NewFromASCII("exportFile")); + JSHandle specifierString = JSTaggedValue::ToString(thread, specifier); + CString path = ModulePathHelper::Utf8ConvertToString(specifierString.GetTaggedValue()); + StaticModuleLoader::LoadStaticModule(thread, func, path); + EXPECT_EQ(thread->HasPendingException(), true); + JSHandle error(thread, thread->GetException()); + JSHandle code(factory->NewFromASCII("code")); + JSHandle message = JSTaggedValue::GetProperty(thread, error, code).GetValue(); + EXPECT_EQ(JSTaggedValue::SameValue(message, specifier), true); + thread->ClearException(); +} + +} // namespace panda::test diff --git a/ecmascript/runtime_call_id.h b/ecmascript/runtime_call_id.h index 9a9d13cb9d..ce5d347585 100644 --- a/ecmascript/runtime_call_id.h +++ b/ecmascript/runtime_call_id.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -689,7 +689,7 @@ namespace panda::ecmascript { V(PromiseJob, Reaction) \ V(PromiseJob, ResolveThenableJob) \ V(PromiseJob, DynamicImportJob) \ - V(PromiseJob, CatchException) \ + V(PromiseJob, CatchToStringException) \ V(Promise, Constructor) \ V(Promise, All) \ V(Promise, Race) \ -- Gitee From 55dcbd23fd43fcaf83f6f4de2a09e30123d8b984 Mon Sep 17 00:00:00 2001 From: z00932658 Date: Tue, 17 Jun 2025 21:15:04 +0800 Subject: [PATCH 14/54] Revert "add hybrid for load_module_with_info" Issue: https://gitee.com/openharmony/ability_ability_runtime/issues/ICD2ZO Signed-off-by: zhushihao Change-Id: I69e9dc74300ca9a064a9cdce67c39ada7a0427a7 Signed-off-by: lhc --- ecmascript/builtins/builtins_global.cpp | 2 +- ecmascript/builtins/builtins_promise_job.cpp | 4 +-- ecmascript/ecma_vm.h | 2 +- .../jspandafile/js_pandafile_executor.cpp | 8 +++--- .../jspandafile/js_pandafile_manager.cpp | 9 +++---- ecmascript/jspandafile/js_pandafile_manager.h | 4 +-- .../tests/js_pandafile_manager_test.cpp | 2 +- ecmascript/module/js_module_source_text.cpp | 4 +-- ecmascript/module/module_resolver.cpp | 13 ++++----- ecmascript/module/napi_module_loader.cpp | 27 +++++++++---------- ecmascript/module/napi_module_loader.h | 19 +++++++------ ecmascript/napi/include/jsnapi_expo.h | 4 +-- ecmascript/napi/jsnapi_expo.cpp | 8 +++--- ecmascript/napi/test/ffi_workload.cpp | 5 ++-- ecmascript/napi/test/jsnapi_third_tests.cpp | 2 +- ecmascript/patch/quick_fix_manager.cpp | 4 +-- ecmascript/require/js_cjs_module.cpp | 2 +- ...isethostpromiserejectiontracker_fuzzer.cpp | 2 +- 18 files changed, 60 insertions(+), 61 deletions(-) diff --git a/ecmascript/builtins/builtins_global.cpp b/ecmascript/builtins/builtins_global.cpp index b7ddbce6bd..3a47f6f84c 100644 --- a/ecmascript/builtins/builtins_global.cpp +++ b/ecmascript/builtins/builtins_global.cpp @@ -731,7 +731,7 @@ JSTaggedValue BuiltinsGlobal::LoadNativeModule(EcmaRuntimeCallInfo *msg) CString abcFilePath = fileName.c_str(); if (moduleName.size() != 0) { curJsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, abcFilePath, requestPath, false, false, ExecuteTypes::STATIC); + thread, abcFilePath, requestPath, false, ExecuteTypes::STATIC); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (curJsPandaFile == nullptr) { errorMsg = "Load native module failed, filename '" + abcFilePath + diff --git a/ecmascript/builtins/builtins_promise_job.cpp b/ecmascript/builtins/builtins_promise_job.cpp index ab15169de8..5b72ff6237 100644 --- a/ecmascript/builtins/builtins_promise_job.cpp +++ b/ecmascript/builtins/builtins_promise_job.cpp @@ -160,7 +160,7 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) if (!recordName->IsUndefined()) { recordNameStr = ModulePathHelper::Utf8ConvertToString(recordName.GetTaggedValue()); curJsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, fileName, recordNameStr.c_str(), false, false, ExecuteTypes::STATIC); + thread, fileName, recordNameStr.c_str(), false, ExecuteTypes::STATIC); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); if (curJsPandaFile == nullptr) { @@ -201,7 +201,7 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) } std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, - fileName, entryPoint, false, false, ExecuteTypes::STATIC); + fileName, entryPoint, false, ExecuteTypes::STATIC); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); if (jsPandaFile == nullptr) { diff --git a/ecmascript/ecma_vm.h b/ecmascript/ecma_vm.h index 68c438a26d..f427221a0d 100644 --- a/ecmascript/ecma_vm.h +++ b/ecmascript/ecma_vm.h @@ -128,7 +128,7 @@ using SourceMapCallback = std::function; using ResolveBufferCallback = - std::function; + std::function; using TimerCallbackFunc = void (*)(void *data); using TimerTaskCallback = void* (*)(EcmaVM *vm, void *data, TimerCallbackFunc func, uint64_t timeout, bool repeat); using CancelTimerCallback = void (*)(void *timerCallbackInfo); diff --git a/ecmascript/jspandafile/js_pandafile_executor.cpp b/ecmascript/jspandafile/js_pandafile_executor.cpp index 983a4d8f11..bf75547287 100644 --- a/ecmascript/jspandafile/js_pandafile_executor.cpp +++ b/ecmascript/jspandafile/js_pandafile_executor.cpp @@ -34,7 +34,7 @@ Expected JSPandaFileExecutor::ExecuteFromFile(JSThread *thr EcmaVM *vm = thread->GetEcmaVM(); std::shared_ptr jsPandaFile = - JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, name, entry, needUpdate, false, executeType); + JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, name, entry, needUpdate, executeType); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, Unexpected(false)); if (jsPandaFile == nullptr) { #ifdef FUZZ_TEST @@ -430,7 +430,7 @@ Expected JSPandaFileExecutor::LazyExecuteModule( std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, filename, recordName, false, false, ExecuteTypes::STATIC); + thread, filename, recordName, false, ExecuteTypes::STATIC); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, Unexpected(false)); if (jsPandaFile == nullptr) { #ifdef FUZZ_TEST @@ -477,7 +477,7 @@ int JSPandaFileExecutor::ExecuteAbcFileWithSingletonPatternFlag(JSThread *thread { CString abcFilePath = ModulePathHelper::ConcatPandaFilePath(moduleName); std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, abcFilePath, entry, false, false, ExecuteTypes::STATIC); + thread, abcFilePath, entry, false, ExecuteTypes::STATIC); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ROUTE_URI_ERROR); if (jsPandaFile == nullptr) { LOG_ECMA(ERROR) << "When the route jump, loading panda file failed. Current file is " << abcFilePath; @@ -520,7 +520,7 @@ bool JSPandaFileExecutor::IsExecuteModuleInAbcFile(JSThread *thread, [[maybe_unu return false; } std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, abcFilePath, entry, false, false, ExecuteTypes::STATIC); + thread, abcFilePath, entry, false, ExecuteTypes::STATIC); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (jsPandaFile == nullptr) { LOG_ECMA(ERROR) << "When checking if module is in abc file, loading panda file failed. Current file is " << diff --git a/ecmascript/jspandafile/js_pandafile_manager.cpp b/ecmascript/jspandafile/js_pandafile_manager.cpp index 30feebd395..1c039b6840 100644 --- a/ecmascript/jspandafile/js_pandafile_manager.cpp +++ b/ecmascript/jspandafile/js_pandafile_manager.cpp @@ -50,7 +50,7 @@ JSPandaFileManager::~JSPandaFileManager() * Specifically, return jscrash if napi load hsp failed. */ std::shared_ptr JSPandaFileManager::LoadJSPandaFile(JSThread *thread, const CString &filename, - std::string_view entryPoint, bool needUpdate, bool isHybrid, const ExecuteTypes &executeType) + std::string_view entryPoint, bool needUpdate, const ExecuteTypes &executeType) { { LockHolder lock(jsPandaFileLock_); @@ -97,7 +97,7 @@ std::shared_ptr JSPandaFileManager::LoadJSPandaFile(JSThread *threa uint8_t *data = nullptr; size_t dataSize = 0; std::string errorMsg; - bool getBuffer = resolveBufferCallback(hspPath, isHybrid, &data, &dataSize, errorMsg); + bool getBuffer = resolveBufferCallback(hspPath, &data, &dataSize, errorMsg); if (!getBuffer) { LoadJSPandaFileFailLog("[ArkRuntime Log] Importing shared package in the Previewer."); CString msg = "resolveBufferCallback get hsp buffer failed, hsp path:" + filename + @@ -552,7 +552,7 @@ std::shared_ptr JSPandaFileManager::GenerateJSPandaFile(JSThread *t /* * Check whether the file path can be loaded into pandafile, excluding bundle packaging and decompression paths */ -bool JSPandaFileManager::CheckFilePath(JSThread *thread, const CString &fileName, bool isHybrid) +bool JSPandaFileManager::CheckFilePath(JSThread *thread, const CString &fileName) { std::shared_ptr jsPandaFile = FindJSPandaFileUnlocked(fileName); if (jsPandaFile != nullptr) { @@ -569,8 +569,7 @@ bool JSPandaFileManager::CheckFilePath(JSThread *thread, const CString &fileName uint8_t *data = nullptr; size_t dataSize = 0; std::string errorMsg; - bool getBuffer = - resolveBufferCallback(ModulePathHelper::ParseHapPath(fileName), isHybrid, &data, &dataSize, errorMsg); + bool getBuffer = resolveBufferCallback(ModulePathHelper::ParseHapPath(fileName), &data, &dataSize, errorMsg); if (!getBuffer) { LOG_FULL(ERROR) << "When checking file path, resolveBufferCallback get buffer failed, errorMsg = " << errorMsg; diff --git a/ecmascript/jspandafile/js_pandafile_manager.h b/ecmascript/jspandafile/js_pandafile_manager.h index 734a0f34d0..460ac1c5a4 100644 --- a/ecmascript/jspandafile/js_pandafile_manager.h +++ b/ecmascript/jspandafile/js_pandafile_manager.h @@ -34,7 +34,7 @@ public: JSHandle GenerateProgram(EcmaVM *vm, const JSPandaFile *jsPandaFile, std::string_view entryPoint); std::shared_ptr LoadJSPandaFile(JSThread *thread, const CString &filename, std::string_view entryPoint, - bool needUpdate = false, bool isHybrid = false, + bool needUpdate = false, const ExecuteTypes &executeType = ExecuteTypes::STATIC); std::shared_ptr LoadJSPandaFile(JSThread *thread, const CString &filename, std::string_view entryPoint, @@ -59,7 +59,7 @@ public: DebugInfoExtractor *CpuProfilerGetJSPtExtractor(const JSPandaFile *jsPandaFile); - bool CheckFilePath(JSThread *thread, const CString &fileName, bool isHybrid = false); + bool CheckFilePath(JSThread *thread, const CString &fileName); // for debugger template diff --git a/ecmascript/jspandafile/tests/js_pandafile_manager_test.cpp b/ecmascript/jspandafile/tests/js_pandafile_manager_test.cpp index 1f369a8356..f1eecb2bc6 100644 --- a/ecmascript/jspandafile/tests/js_pandafile_manager_test.cpp +++ b/ecmascript/jspandafile/tests/js_pandafile_manager_test.cpp @@ -166,7 +166,7 @@ HWTEST_F_L0(JSPandaFileManagerTest, MultiEcmaVM_Add_Find_Remove_JSPandaFile) JSThread *thread1; TestHelper::CreateEcmaVMWithScope(instance1, thread1, scope1); std::shared_ptr loadedPf1 = pfManager->LoadJSPandaFile( - thread1, filename1, JSPandaFile::ENTRY_MAIN_FUNCTION, false, false, ExecuteTypes::STATIC); + thread1, filename1, JSPandaFile::ENTRY_MAIN_FUNCTION, false, ExecuteTypes::STATIC); EXPECT_TRUE(pf1 == loadedPf1); EXPECT_TRUE(instance1->GetJSThread()->GetEcmaVM()->HasCachedConstpool(pf1.get())); TestHelper::DestroyEcmaVMWithScope(instance1, scope1); // Remove 'instance1' when ecmaVM destruct. diff --git a/ecmascript/module/js_module_source_text.cpp b/ecmascript/module/js_module_source_text.cpp index 5e71844da8..c739f52308 100644 --- a/ecmascript/module/js_module_source_text.cpp +++ b/ecmascript/module/js_module_source_text.cpp @@ -1186,7 +1186,7 @@ Expected SourceTextModule::ModuleExecution(JSThread *thread JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, moduleFilenameStr, entryPoint, buffer, size); } else { jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, moduleFilenameStr, entryPoint, false, false, executeType); + thread, moduleFilenameStr, entryPoint, false, executeType); } RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, Unexpected(false)); if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE @@ -1728,7 +1728,7 @@ void SourceTextModule::ExecuteAsyncModule(JSThread *thread, const JSHandleLoadJSPandaFile(thread, moduleFilenameStr, entryPoint, buffer, size); } else { jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, moduleFilenameStr, entryPoint, false, false, executeType); + thread, moduleFilenameStr, entryPoint, false, executeType); } RETURN_IF_ABRUPT_COMPLETION(thread); if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE diff --git a/ecmascript/module/module_resolver.cpp b/ecmascript/module/module_resolver.cpp index 355886d392..69ded0c7d7 100644 --- a/ecmascript/module/module_resolver.cpp +++ b/ecmascript/module/module_resolver.cpp @@ -43,7 +43,7 @@ JSHandle ModuleResolver::HostResolveImportedModule(JSThread* thre { if (jsPandaFile == nullptr) { std::shared_ptr file = - JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, fileName, recordName, false, false, executeType); + JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, fileName, recordName, false, executeType); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (file == nullptr) { CString msg = "Load file with filename '" + fileName + "' failed, recordName '" + recordName + "'"; @@ -103,7 +103,7 @@ JSHandle ModuleResolver::HostResolveImportedModuleWithMerge(JSThr } CString recordName = module->GetEcmaModuleRecordNameString(); std::shared_ptr pandaFile = - JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, baseFilename, recordName, false, false, executeType); + JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, baseFilename, recordName, false, executeType); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (pandaFile == nullptr) { // LCOV_EXCL_BR_LINE LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << baseFilename; @@ -182,7 +182,8 @@ JSHandle ModuleResolver::HostResolveImportedModuleForHotReload(JS const ExecuteTypes &executeType) { std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, moduleFileName, recordName, false, false, executeType); + thread, moduleFileName, recordName, false, executeType); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << moduleFileName; } @@ -209,7 +210,7 @@ JSHandle ModuleResolver::HostResolveImportedModuleWithMerge(JSThr { if (jsPandaFile == nullptr) { std::shared_ptr file = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, moduleFileName, recordName, false, false, executeType); + thread, moduleFileName, recordName, false, executeType); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (file == nullptr) { CString msg = "Load file with filename '" + moduleFileName + "' failed, recordName '" + recordName + "'"; @@ -257,7 +258,7 @@ JSHandle ModuleResolver::HostResolveImportedModuleBundlePack(JSTh // Can not use jsPandaFile from js_pandafile_executor, need to construct with JSPandaFile::ENTRY_MAIN_FUNCTION std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, referencingModule, JSPandaFile::ENTRY_MAIN_FUNCTION, false, false, executeType); + thread, referencingModule, JSPandaFile::ENTRY_MAIN_FUNCTION, false, executeType); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (jsPandaFile == nullptr) { // LCOV_EXCL_BR_LINE LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << referencingModule; @@ -278,7 +279,7 @@ JSHandle ModuleResolver::HostResolveImportedModuleBundlePack(JSTh return module; } std::shared_ptr pandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, moduleFileName, JSPandaFile::ENTRY_MAIN_FUNCTION, false, false, executeType); + thread, moduleFileName, JSPandaFile::ENTRY_MAIN_FUNCTION, false, executeType); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (pandaFile == nullptr) { // LCOV_EXCL_BR_LINE LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << referencingModule; diff --git a/ecmascript/module/napi_module_loader.cpp b/ecmascript/module/napi_module_loader.cpp index 9ffb7ec702..f996390a7d 100644 --- a/ecmascript/module/napi_module_loader.cpp +++ b/ecmascript/module/napi_module_loader.cpp @@ -22,8 +22,7 @@ namespace panda::ecmascript { JSHandle NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo(EcmaVM *vm, CString &requestPath, - CString &modulePath, CString &abcFilePath, - bool isHybrid) + CString &modulePath, CString &abcFilePath) { LOG_ECMA(INFO) << "NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo requestPath:" << requestPath << "," << "modulePath:" << modulePath; @@ -31,7 +30,7 @@ JSHandle NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo(Ecma std::shared_ptr curJsPandaFile; if (!modulePath.empty()) { curJsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, abcFilePath, requestPath, false, - isHybrid, ExecuteTypes::NAPI); + ExecuteTypes::NAPI); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (curJsPandaFile == nullptr) { LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << abcFilePath; @@ -49,8 +48,7 @@ JSHandle NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo(Ecma } JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CString requestPath, - const CString &moduleName, CString &abcFilePath, - bool isHybrid) + const CString &moduleName, CString &abcFilePath) { JSThread *thread = vm->GetJSThread(); CString path = base::ConcatToCString(vm->GetBundleName(), PathHelper::SLASH_TAG); @@ -67,13 +65,12 @@ JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CStrin path += abcModuleName; // RequestPath starts with moduleName/src/main/xxx if (StringHelper::StringStartWith(requestPath, srcPrefix)) { - return LoadFilePathWithinModule(thread, abcFilePath, srcPrefix, requestPath, path, isHybrid); + return LoadFilePathWithinModule(thread, abcFilePath, srcPrefix, requestPath, path); } - return LoadModuleNameSpaceWithModuleInfo(vm, requestPath, path, abcFilePath, isHybrid); + return LoadModuleNameSpaceWithModuleInfo(vm, requestPath, path, abcFilePath); } -JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CString requestPath, CString modulePath, - bool isHybrid) +JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CString requestPath, CString modulePath) { JSThread *thread = vm->GetJSThread(); CString moduleName = ModulePathHelper::GetModuleNameWithPath(modulePath); @@ -81,20 +78,20 @@ JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CStrin CString srcPrefix = base::ConcatToCString(moduleName, ModulePathHelper::PHYCICAL_FILE_PATH.data()); // RequestPath starts with moduleName/src/main/xxx if (StringHelper::StringStartWith(requestPath, srcPrefix)) { - return LoadFilePathWithinModule(thread, abcFilePath, srcPrefix, requestPath, modulePath, isHybrid); + return LoadFilePathWithinModule(thread, abcFilePath, srcPrefix, requestPath, modulePath); } - return LoadModuleNameSpaceWithModuleInfo(vm, requestPath, modulePath, abcFilePath, isHybrid); + return LoadModuleNameSpaceWithModuleInfo(vm, requestPath, modulePath, abcFilePath); } JSHandle NapiModuleLoader::LoadFilePathWithinModule(JSThread *thread, const CString& abcFilePath, - const CString& srcPrefix, const CString& requestPath, const CString& modulePath, bool isHybrid) + const CString& srcPrefix, const CString& requestPath, const CString& modulePath) { if (requestPath.size() > srcPrefix.size()) { // Sub after moduleName/src/main/ CString fileName = requestPath.substr(srcPrefix.size() + 1); CString recordNameStr = ModulePathHelper::TranslateNapiFileRequestPath(thread, modulePath, fileName); LOG_ECMA(DEBUG) << "NapiModuleLoader::LoadFilePathWithinModule: Concated recordName " << recordNameStr; - return LoadModuleNameSpaceFromFile(thread, recordNameStr, abcFilePath, isHybrid); + return LoadModuleNameSpaceFromFile(thread, recordNameStr, abcFilePath); } else { CString msg = "cannot find record '" + requestPath + "' in basefileName " + abcFilePath + "," + "from napi load module"; @@ -117,10 +114,10 @@ JSHandle NapiModuleLoader::LoadModuleNameSpaceWithPath(JSThread * } JSHandle NapiModuleLoader::LoadModuleNameSpaceFromFile( - JSThread *thread, const CString &entryPoint, const CString &abcFilePath, bool isHybrid) + JSThread *thread, const CString &entryPoint, const CString &abcFilePath) { std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, abcFilePath, entryPoint, false, isHybrid, ExecuteTypes::NAPI); + thread, abcFilePath, entryPoint, false, ExecuteTypes::NAPI); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (jsPandaFile == nullptr) { LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << abcFilePath; diff --git a/ecmascript/module/napi_module_loader.h b/ecmascript/module/napi_module_loader.h index 05f523e4eb..37077d1b6b 100644 --- a/ecmascript/module/napi_module_loader.h +++ b/ecmascript/module/napi_module_loader.h @@ -20,19 +20,23 @@ namespace panda::ecmascript { class NapiModuleLoader { public: - static JSHandle LoadModuleNameSpace(EcmaVM *vm, CString requestPath, const CString &moduleName, - CString &abcFilePath, bool isHybrid = false); - static JSHandle LoadModuleNameSpace(EcmaVM *vm, CString requestPath, - CString modulePath, bool isHybrid = false); +static JSHandle LoadModuleNameSpace(EcmaVM *vm, CString requestPath, const CString &moduleName, + CString &abcFilePath); + +static JSHandle LoadModuleNameSpace(EcmaVM *vm, CString requestPath, + CString modulePath); + +static JSHandle GetModuleNameSpace(JSThread *thread, const CString &entryPoint, + const CString &abcFilePath); static JSHandle GetModuleNameSpace(JSThread *thread, const CString &entryPoint, const CString &abcFilePath); static JSHandle LoadModuleNameSpaceFromFile(JSThread *thread, const CString &entryPoint, - const CString &abcFilePath, bool isHybrid = false); + const CString &abcFilePath); private: static JSHandle LoadModuleNameSpaceWithModuleInfo( EcmaVM *vm, CString &requestPath, CString &modulePath, - CString &abcFilePath, bool isHybrid = false); + CString &abcFilePath); static JSHandle LoadModuleNameSpaceWithPath( JSThread *thread, CString &abcFilePath, const CString &requestPath, @@ -40,8 +44,7 @@ private: static JSHandle LoadFilePathWithinModule( JSThread *thread, const CString &abcFilePath, const CString &srcPrefix, - const CString &requestPath, const CString &modulePath, - bool isHybrid = false); + const CString &requestPath, const CString &modulePath); }; } diff --git a/ecmascript/napi/include/jsnapi_expo.h b/ecmascript/napi/include/jsnapi_expo.h index c2f2f44f2e..48f061be1c 100644 --- a/ecmascript/napi/include/jsnapi_expo.h +++ b/ecmascript/napi/include/jsnapi_expo.h @@ -1710,7 +1710,7 @@ public: static Local ExecuteNativeModule(EcmaVM *vm, const std::string &key); static Local GetModuleNameSpaceFromFile(EcmaVM *vm, const std::string &file); static Local GetModuleNameSpaceWithModuleInfo(EcmaVM *vm, const std::string &file, - const std::string &module_path, bool isHybrid = false); + const std::string &module_path); static Local GetModuleNameSpaceWithPath(const EcmaVM *vm, const char *path); static std::pair ResolveOhmUrl(std::string ohmUrl); @@ -1800,7 +1800,7 @@ public: static void SetCancelTimerCallback(EcmaVM *vm, CancelTimerCallback callback); static void NotifyEnvInitialized(EcmaVM *vm); static void SetReleaseSecureMemCallback(EcmaVM *vm, ReleaseSecureMemCallback releaseSecureMemFunc); - static void SetHostResolveBufferTracker(EcmaVM *vm, std::function cb); static void PandaFileSerialize(const EcmaVM *vm); static void ModuleSerialize(const EcmaVM *vm); diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index 419497d168..095df7724c 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -6218,7 +6218,7 @@ void JSNApi::ModuleDeserialize(EcmaVM *vm, const uint32_t appVersion) } void JSNApi::SetHostResolveBufferTracker(EcmaVM *vm, - std::function cb) + std::function cb) { vm->SetResolveBufferCallback(cb); } @@ -6440,7 +6440,7 @@ Local JSNApi::GetExportObject(EcmaVM *vm, const std::string &file, co ModulePathHelper::ParseAbcPathAndOhmUrl(vm, entry, name, entry); std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, name, entry.c_str(), false, false, ecmascript::ExecuteTypes::STATIC); + thread, name, entry.c_str(), false, ecmascript::ExecuteTypes::STATIC); if (jsPandaFile == nullptr) { JSHandle exportObj(thread, JSTaggedValue::Null()); return JSNApiHelper::ToLocal(exportObj); @@ -6530,14 +6530,14 @@ Local JSNApi::GetModuleNameSpaceFromFile(EcmaVM *vm, const std::strin } Local JSNApi::GetModuleNameSpaceWithModuleInfo(EcmaVM *vm, const std::string &file, - const std::string &module_path, bool isHybrid) + const std::string &module_path) { CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); ecmascript::ThreadManagedScope managedScope(thread); ecmascript::CString requestPath = file.c_str(); ecmascript::CString modulePath = module_path.c_str(); JSHandle nameSp = - ecmascript::NapiModuleLoader::LoadModuleNameSpace(vm, requestPath, modulePath, isHybrid); + ecmascript::NapiModuleLoader::LoadModuleNameSpace(vm, requestPath, modulePath); return JSNApiHelper::ToLocal(nameSp); } diff --git a/ecmascript/napi/test/ffi_workload.cpp b/ecmascript/napi/test/ffi_workload.cpp index cb40ea24c2..e4d5ad2112 100644 --- a/ecmascript/napi/test/ffi_workload.cpp +++ b/ecmascript/napi/test/ffi_workload.cpp @@ -3536,9 +3536,8 @@ HWTEST_F_L0(JSNApiSplTest, JSNApi_SetHostResolveBufferTracker) { LocalScope scope(vm_); CalculateForTime(); - std::function - cb = [](const std::string &inputPath, bool isHybrid, - uint8_t **buff, size_t *buffSize, std::string &errorMsg) -> bool { + std::function cb = + [](const std::string &inputPath, uint8_t **buff, size_t *buffSize, std::string &errorMsg) -> bool { if (inputPath.empty() || buff == nullptr || buffSize == nullptr) { return false; } diff --git a/ecmascript/napi/test/jsnapi_third_tests.cpp b/ecmascript/napi/test/jsnapi_third_tests.cpp index 23fc335d44..160c3cc6ae 100644 --- a/ecmascript/napi/test/jsnapi_third_tests.cpp +++ b/ecmascript/napi/test/jsnapi_third_tests.cpp @@ -697,7 +697,7 @@ HWTEST_F_L0(JSNApiTests, SetHostResolveBufferTracker) { LocalScope scope(vm_); JSNApi::SetHostResolveBufferTracker(vm_, - [&](std::string, bool, uint8_t **, size_t *, std::string &) -> bool { return true; }); + [&](std::string, uint8_t **, size_t *, std::string &) -> bool { return true; }); } /* diff --git a/ecmascript/patch/quick_fix_manager.cpp b/ecmascript/patch/quick_fix_manager.cpp index aac16b7587..0c03de0f2f 100644 --- a/ecmascript/patch/quick_fix_manager.cpp +++ b/ecmascript/patch/quick_fix_manager.cpp @@ -87,7 +87,7 @@ PatchErrorCode QuickFixManager::LoadPatch(JSThread *thread, const std::string &p } std::shared_ptr baseFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, baseFileName.c_str(), "", false, false, ExecuteTypes::STATIC); + thread, baseFileName.c_str(), "", false, ExecuteTypes::STATIC); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, PatchErrorCode::FILE_NOT_FOUND); if (baseFile == nullptr) { LOG_ECMA(ERROR) << "find base jsPandafile failed"; @@ -96,7 +96,7 @@ PatchErrorCode QuickFixManager::LoadPatch(JSThread *thread, const std::string &p // The entry point is not work for merge abc. std::shared_ptr patchFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, patchFileName.c_str(), "", false, false, ExecuteTypes::STATIC); + thread, patchFileName.c_str(), "", false, ExecuteTypes::STATIC); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, PatchErrorCode::FILE_NOT_FOUND); if (patchFile == nullptr) { LOG_ECMA(ERROR) << "load patch jsPandafile failed"; diff --git a/ecmascript/require/js_cjs_module.cpp b/ecmascript/require/js_cjs_module.cpp index cbd78169ae..f535398f65 100644 --- a/ecmascript/require/js_cjs_module.cpp +++ b/ecmascript/require/js_cjs_module.cpp @@ -160,7 +160,7 @@ void CjsModule::RequireExecution(JSThread *thread, const CString &mergedFilename { std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, mergedFilename, requestEntryPoint, false, false, ExecuteTypes::STATIC); + thread, mergedFilename, requestEntryPoint, false, ExecuteTypes::STATIC); RETURN_IF_ABRUPT_COMPLETION(thread); if (jsPandaFile == nullptr) { LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << mergedFilename; diff --git a/test/fuzztest/jsnapisethostpromiserejectiontracker_fuzzer/jsnapisethostpromiserejectiontracker_fuzzer.cpp b/test/fuzztest/jsnapisethostpromiserejectiontracker_fuzzer/jsnapisethostpromiserejectiontracker_fuzzer.cpp index 79f69541de..206f697429 100644 --- a/test/fuzztest/jsnapisethostpromiserejectiontracker_fuzzer/jsnapisethostpromiserejectiontracker_fuzzer.cpp +++ b/test/fuzztest/jsnapisethostpromiserejectiontracker_fuzzer/jsnapisethostpromiserejectiontracker_fuzzer.cpp @@ -56,7 +56,7 @@ namespace OHOS { uint8_t* ptr = nullptr; ptr = const_cast(data); JSNApi::SetHostResolveBufferTracker(vm, - [&](std::string, bool, uint8_t **, size_t *, std::string &) -> bool { return true; }); + [&](std::string, uint8_t **, size_t *, std::string &) -> bool { return true; }); JSNApi::DestroyJSVM(vm); } -- Gitee From 3ed476c14af6465a22abefbda380a431108e1b4c Mon Sep 17 00:00:00 2001 From: z00932658 Date: Sat, 21 Jun 2025 14:35:20 +0800 Subject: [PATCH 15/54] Fix isHybrid for ets_runtime Issue: https://gitee.com/openharmony/ability_ability_runtime/issues/ICD2ZO Signed-off-by: zhushihao Change-Id: Iaf85672f1cfa73c37504edc9c7349938c84078ba Signed-off-by: lhc --- ecmascript/ecma_vm.h | 11 ++++ .../jspandafile/js_pandafile_manager.cpp | 15 ++++++ ecmascript/jspandafile/js_pandafile_manager.h | 4 +- ecmascript/module/napi_module_loader.cpp | 54 +++++++++++++++---- ecmascript/module/napi_module_loader.h | 44 ++++++++------- ecmascript/napi/include/jsnapi_expo.h | 12 +++++ ecmascript/napi/jsnapi_expo.cpp | 26 ++++++++- 7 files changed, 135 insertions(+), 31 deletions(-) diff --git a/ecmascript/ecma_vm.h b/ecmascript/ecma_vm.h index f427221a0d..f944146181 100644 --- a/ecmascript/ecma_vm.h +++ b/ecmascript/ecma_vm.h @@ -556,6 +556,16 @@ public: return resolveBufferCallback_; } + void SetResolveBufferCallbackForHybridApp(ResolveBufferCallback cb) + { + resolveBufferCallbackForHybridApp_ = cb; + } + + ResolveBufferCallback GetResolveBufferCallbackForHybridApp() const + { + return resolveBufferCallbackForHybridApp_; + } + void SetTimerTaskCallback(TimerTaskCallback callback) { timerTaskCallback_ = callback; @@ -1439,6 +1449,7 @@ private: // resolve path to get abc's buffer ResolveBufferCallback resolveBufferCallback_ {nullptr}; + ResolveBufferCallback resolveBufferCallbackForHybridApp_ {nullptr}; // set timer task to execute callback on time TimerTaskCallback timerTaskCallback_ {nullptr}; diff --git a/ecmascript/jspandafile/js_pandafile_manager.cpp b/ecmascript/jspandafile/js_pandafile_manager.cpp index 1c039b6840..7bc3bb51cf 100644 --- a/ecmascript/jspandafile/js_pandafile_manager.cpp +++ b/ecmascript/jspandafile/js_pandafile_manager.cpp @@ -49,6 +49,7 @@ JSPandaFileManager::~JSPandaFileManager() * Typically return nullptr for JSPandafile load fail. Throw cppcrash if load hsp failed. * Specifically, return jscrash if napi load hsp failed. */ +template std::shared_ptr JSPandaFileManager::LoadJSPandaFile(JSThread *thread, const CString &filename, std::string_view entryPoint, bool needUpdate, const ExecuteTypes &executeType) { @@ -79,6 +80,9 @@ std::shared_ptr JSPandaFileManager::LoadJSPandaFile(JSThread *threa if (!vm->IsBundlePack() && moduleManager->GetExecuteMode() == ModuleExecuteMode::ExecuteBufferMode && !vm->IsRestrictedWorkerThread()) { ResolveBufferCallback resolveBufferCallback = vm->GetResolveBufferCallback(); + if constexpr (isHybrid == ForHybridApp::Hybrid) { + resolveBufferCallback = vm->GetResolveBufferCallbackForHybridApp(); + } if (resolveBufferCallback == nullptr) { LoadJSPandaFileFailLog("[ArkRuntime Log] Importing shared package is not supported in the Previewer."); LOG_FULL(FATAL) << "resolveBufferCallback is nullptr"; @@ -130,6 +134,10 @@ std::shared_ptr JSPandaFileManager::LoadJSPandaFile(JSThread *threa #endif return jsPandaFile; } +template std::shared_ptr JSPandaFileManager::LoadJSPandaFile(JSThread *thread, + const CString &filename, std::string_view entryPoint, bool needUpdate, const ExecuteTypes &executeType); +template std::shared_ptr JSPandaFileManager::LoadJSPandaFile(JSThread *thread, + const CString &filename, std::string_view entryPoint, bool needUpdate, const ExecuteTypes &executeType); // The security interface needs to be modified accordingly. std::shared_ptr JSPandaFileManager::LoadJSPandaFile(JSThread *thread, const CString &filename, @@ -552,6 +560,7 @@ std::shared_ptr JSPandaFileManager::GenerateJSPandaFile(JSThread *t /* * Check whether the file path can be loaded into pandafile, excluding bundle packaging and decompression paths */ +template bool JSPandaFileManager::CheckFilePath(JSThread *thread, const CString &fileName) { std::shared_ptr jsPandaFile = FindJSPandaFileUnlocked(fileName); @@ -562,6 +571,9 @@ bool JSPandaFileManager::CheckFilePath(JSThread *thread, const CString &fileName ModuleManager *moduleManager = thread->GetModuleManager(); if (!vm->IsBundlePack() && moduleManager->GetExecuteMode() == ModuleExecuteMode::ExecuteBufferMode) { ResolveBufferCallback resolveBufferCallback = vm->GetResolveBufferCallback(); + if constexpr (isHybrid == ForHybridApp::Hybrid) { + resolveBufferCallback = vm->GetResolveBufferCallbackForHybridApp(); + } if (resolveBufferCallback == nullptr) { LOG_FULL(ERROR) << "When checking file path, resolveBufferCallback is nullptr"; return false; @@ -579,6 +591,9 @@ bool JSPandaFileManager::CheckFilePath(JSThread *thread, const CString &fileName return true; } +template bool JSPandaFileManager::CheckFilePath(JSThread *thread, const CString &fileName); +template bool JSPandaFileManager::CheckFilePath(JSThread *thread, const CString &fileName); + std::shared_ptr JSPandaFileManager::GenerateJSPandafileFromBufferCache( JSThread *thread, const CString &filename, std::string_view entryPoint) { diff --git a/ecmascript/jspandafile/js_pandafile_manager.h b/ecmascript/jspandafile/js_pandafile_manager.h index 460ac1c5a4..bbdb83cd38 100644 --- a/ecmascript/jspandafile/js_pandafile_manager.h +++ b/ecmascript/jspandafile/js_pandafile_manager.h @@ -33,6 +33,7 @@ public: JSHandle GenerateProgram(EcmaVM *vm, const JSPandaFile *jsPandaFile, std::string_view entryPoint); + template std::shared_ptr LoadJSPandaFile(JSThread *thread, const CString &filename, std::string_view entryPoint, bool needUpdate = false, const ExecuteTypes &executeType = ExecuteTypes::STATIC); @@ -58,7 +59,8 @@ public: DebugInfoExtractor *GetJSPtExtractorAndExtract(const JSPandaFile *jsPandaFile); DebugInfoExtractor *CpuProfilerGetJSPtExtractor(const JSPandaFile *jsPandaFile); - + + template bool CheckFilePath(JSThread *thread, const CString &fileName); // for debugger diff --git a/ecmascript/module/napi_module_loader.cpp b/ecmascript/module/napi_module_loader.cpp index f996390a7d..a65098597b 100644 --- a/ecmascript/module/napi_module_loader.cpp +++ b/ecmascript/module/napi_module_loader.cpp @@ -21,6 +21,7 @@ #include "ecmascript/jspandafile/js_pandafile_executor.h" namespace panda::ecmascript { +template JSHandle NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo(EcmaVM *vm, CString &requestPath, CString &modulePath, CString &abcFilePath) { @@ -29,8 +30,8 @@ JSHandle NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo(Ecma JSThread *thread = vm->GetJSThread(); std::shared_ptr curJsPandaFile; if (!modulePath.empty()) { - curJsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, abcFilePath, requestPath, false, - ExecuteTypes::NAPI); + curJsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, + abcFilePath, requestPath, false, ExecuteTypes::NAPI); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (curJsPandaFile == nullptr) { LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << abcFilePath; @@ -46,7 +47,12 @@ JSHandle NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo(Ecma curJsPandaFile.get()); return nameSp; } +template JSHandle NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo(EcmaVM *vm, + CString &requestPath, CString &modulePath, CString &abcFilePath); +template JSHandle NapiModuleLoader::LoadModuleNameSpaceWithModuleInfo(EcmaVM *vm, + CString &requestPath, CString &modulePath, CString &abcFilePath); +template JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CString requestPath, const CString &moduleName, CString &abcFilePath) { @@ -58,19 +64,27 @@ JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CStrin path += moduleName; CString recordNameStr = ModulePathHelper::TranslateNapiFileRequestPath(thread, path, requestPath); LOG_ECMA(DEBUG) << "NapiModuleLoader::LoadFilePathWithinModule: Concated recordName " << recordNameStr; - return LoadModuleNameSpaceFromFile(thread, recordNameStr, abcFilePath); + return LoadModuleNameSpaceFromFile(thread, recordNameStr, abcFilePath); } CString abcModuleName = ModulePathHelper::GetModuleNameWithBaseFile(abcFilePath); CString srcPrefix = base::ConcatToCString(abcModuleName, ModulePathHelper::PHYCICAL_FILE_PATH.data()); path += abcModuleName; // RequestPath starts with moduleName/src/main/xxx if (StringHelper::StringStartWith(requestPath, srcPrefix)) { - return LoadFilePathWithinModule(thread, abcFilePath, srcPrefix, requestPath, path); + return LoadFilePathWithinModule(thread, abcFilePath, srcPrefix, requestPath, path); } - return LoadModuleNameSpaceWithModuleInfo(vm, requestPath, path, abcFilePath); + return LoadModuleNameSpaceWithModuleInfo(vm, requestPath, path, abcFilePath); } -JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CString requestPath, CString modulePath) +template JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, + CString requestPath, const CString& moduleName, CString& abcFilePath); +template JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, + CString requestPath, const CString& moduleName, CString& abcFilePath); + +template +JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, + CString requestPath, + CString modulePath) { JSThread *thread = vm->GetJSThread(); CString moduleName = ModulePathHelper::GetModuleNameWithPath(modulePath); @@ -78,11 +92,16 @@ JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, CStrin CString srcPrefix = base::ConcatToCString(moduleName, ModulePathHelper::PHYCICAL_FILE_PATH.data()); // RequestPath starts with moduleName/src/main/xxx if (StringHelper::StringStartWith(requestPath, srcPrefix)) { - return LoadFilePathWithinModule(thread, abcFilePath, srcPrefix, requestPath, modulePath); + return LoadFilePathWithinModule(thread, abcFilePath, srcPrefix, requestPath, modulePath); } - return LoadModuleNameSpaceWithModuleInfo(vm, requestPath, modulePath, abcFilePath); + return LoadModuleNameSpaceWithModuleInfo(vm, requestPath, modulePath, abcFilePath); } +template JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, + CString requestPath, CString modulePath); +template JSHandle NapiModuleLoader::LoadModuleNameSpace(EcmaVM *vm, + CString requestPath, CString modulePath); +template JSHandle NapiModuleLoader::LoadFilePathWithinModule(JSThread *thread, const CString& abcFilePath, const CString& srcPrefix, const CString& requestPath, const CString& modulePath) { @@ -91,13 +110,17 @@ JSHandle NapiModuleLoader::LoadFilePathWithinModule(JSThread *thr CString fileName = requestPath.substr(srcPrefix.size() + 1); CString recordNameStr = ModulePathHelper::TranslateNapiFileRequestPath(thread, modulePath, fileName); LOG_ECMA(DEBUG) << "NapiModuleLoader::LoadFilePathWithinModule: Concated recordName " << recordNameStr; - return LoadModuleNameSpaceFromFile(thread, recordNameStr, abcFilePath); + return LoadModuleNameSpaceFromFile(thread, recordNameStr, abcFilePath); } else { CString msg = "cannot find record '" + requestPath + "' in basefileName " + abcFilePath + "," + "from napi load module"; THROW_NEW_ERROR_AND_RETURN_HANDLE(thread, ErrorType::REFERENCE_ERROR, JSTaggedValue, msg.c_str()); } } +template JSHandle NapiModuleLoader::LoadFilePathWithinModule(JSThread *thread, + const CString& abcFilePath, const CString& srcPrefix, const CString& requestPath, const CString& modulePath); +template JSHandle NapiModuleLoader::LoadFilePathWithinModule(JSThread *thread, + const CString& abcFilePath, const CString& srcPrefix, const CString& requestPath, const CString& modulePath); JSHandle NapiModuleLoader::LoadModuleNameSpaceWithPath(JSThread *thread, CString &abcFilePath, const CString &requestPath, const CString &modulePath, const JSPandaFile *pandaFile) @@ -113,11 +136,16 @@ JSHandle NapiModuleLoader::LoadModuleNameSpaceWithPath(JSThread * return LoadModuleNameSpaceFromFile(thread, entryPoint, abcFilePath); } +template JSHandle NapiModuleLoader::LoadModuleNameSpaceFromFile( JSThread *thread, const CString &entryPoint, const CString &abcFilePath) { - std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - thread, abcFilePath, entryPoint, false, ExecuteTypes::NAPI); + std::shared_ptr jsPandaFile = + JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, + abcFilePath, + entryPoint, + false, + ExecuteTypes::NAPI); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); if (jsPandaFile == nullptr) { LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << abcFilePath; @@ -139,6 +167,10 @@ JSHandle NapiModuleLoader::LoadModuleNameSpaceFromFile( return ecmascript::NapiModuleLoader::GetModuleNameSpace( thread, entryPoint, abcFilePath); } +template JSHandle NapiModuleLoader::LoadModuleNameSpaceFromFile( + JSThread *thread, const CString &entryPoint, const CString &abcFilePath); +template JSHandle NapiModuleLoader::LoadModuleNameSpaceFromFile( + JSThread *thread, const CString &entryPoint, const CString &abcFilePath); JSHandle NapiModuleLoader::GetModuleNameSpace(JSThread *thread, const CString &entryPoint, const CString &abcFilePath) diff --git a/ecmascript/module/napi_module_loader.h b/ecmascript/module/napi_module_loader.h index 37077d1b6b..f112f91760 100644 --- a/ecmascript/module/napi_module_loader.h +++ b/ecmascript/module/napi_module_loader.h @@ -20,31 +20,39 @@ namespace panda::ecmascript { class NapiModuleLoader { public: -static JSHandle LoadModuleNameSpace(EcmaVM *vm, CString requestPath, const CString &moduleName, - CString &abcFilePath); - -static JSHandle LoadModuleNameSpace(EcmaVM *vm, CString requestPath, - CString modulePath); - -static JSHandle GetModuleNameSpace(JSThread *thread, const CString &entryPoint, - const CString &abcFilePath); + template + static JSHandle LoadModuleNameSpace(EcmaVM *vm, CString requestPath, + const CString& moduleName, + CString &abcFilePath); + + template + static JSHandle LoadModuleNameSpace(EcmaVM *vm, + CString requestPath, + CString modulePath); static JSHandle GetModuleNameSpace(JSThread *thread, const CString &entryPoint, const CString &abcFilePath); + + template static JSHandle LoadModuleNameSpaceFromFile(JSThread *thread, const CString &entryPoint, const CString &abcFilePath); private: - static JSHandle LoadModuleNameSpaceWithModuleInfo( - EcmaVM *vm, CString &requestPath, CString &modulePath, - CString &abcFilePath); + template + static JSHandle LoadModuleNameSpaceWithModuleInfo(EcmaVM *vm, + CString &requestPath, + CString &modulePath, + CString &abcFilePath); - static JSHandle LoadModuleNameSpaceWithPath( - JSThread *thread, CString &abcFilePath, const CString &requestPath, - const CString &modulePath, const JSPandaFile *pandaFile); - - static JSHandle LoadFilePathWithinModule( - JSThread *thread, const CString &abcFilePath, const CString &srcPrefix, - const CString &requestPath, const CString &modulePath); + static JSHandle LoadModuleNameSpaceWithPath(JSThread *thread, CString &abcFilePath, + const CString &requestPath, + const CString &modulePath, + const JSPandaFile *pandaFile); + + template + static JSHandle LoadFilePathWithinModule(JSThread *thread, const CString& abcFilePath, + const CString& srcPrefix, + const CString& requestPath, + const CString& modulePath); }; } diff --git a/ecmascript/napi/include/jsnapi_expo.h b/ecmascript/napi/include/jsnapi_expo.h index 48f061be1c..04c6a5a02f 100644 --- a/ecmascript/napi/include/jsnapi_expo.h +++ b/ecmascript/napi/include/jsnapi_expo.h @@ -90,6 +90,11 @@ enum class QueueType : uint8_t { } } // namespace ecmascript +enum class ForHybridApp { + Normal, + Hybrid +}; + struct HmsMap { std::string originalPath; std::string targetPath; @@ -1709,8 +1714,13 @@ public: static Local GetExportObjectFromOhmUrl(EcmaVM *vm, const std::string &ohmUrl, const std::string &key); static Local ExecuteNativeModule(EcmaVM *vm, const std::string &key); static Local GetModuleNameSpaceFromFile(EcmaVM *vm, const std::string &file); + template static Local GetModuleNameSpaceWithModuleInfo(EcmaVM *vm, const std::string &file, const std::string &module_path); + static Local GetModuleNameSpaceWithModuleInfoForNormalApp(EcmaVM *vm, const std::string &file, + const std::string &module_path); + static Local GetModuleNameSpaceWithModuleInfoForHybridApp(EcmaVM *vm, const std::string &file, + const std::string &module_path); static Local GetModuleNameSpaceWithPath(const EcmaVM *vm, const char *path); static std::pair ResolveOhmUrl(std::string ohmUrl); @@ -1805,6 +1815,8 @@ public: static void PandaFileSerialize(const EcmaVM *vm); static void ModuleSerialize(const EcmaVM *vm); static void ModuleDeserialize(EcmaVM *vm, const uint32_t appVersion); + static void SetHostResolveBufferTrackerForHybridApp(EcmaVM *vm, std::function cb); static void SetUnloadNativeModuleCallback(EcmaVM *vm, const std::function &cb); static void SetNativePtrGetter(EcmaVM *vm, void* cb); static void SetSourceMapCallback(EcmaVM *vm, SourceMapCallback cb); diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index 095df7724c..b0683168c8 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -4720,6 +4720,7 @@ void JSNApi::SynchronizVMInfo(EcmaVM *vm, const EcmaVM *hostVM) hostVM->GetAssociatedJSThread()->GetModuleManager(); vmModuleManager->SetExecuteMode(hostVMModuleManager->GetExecuteMode()); vm->SetResolveBufferCallback(hostVM->GetResolveBufferCallback()); + vm->SetResolveBufferCallbackForHybridApp(hostVM->GetResolveBufferCallbackForHybridApp()); } bool JSNApi::IsProfiling(EcmaVM *vm) @@ -6223,6 +6224,13 @@ void JSNApi::SetHostResolveBufferTracker(EcmaVM *vm, vm->SetResolveBufferCallback(cb); } +void JSNApi::SetHostResolveBufferTrackerForHybridApp(EcmaVM *vm, + std::function cb) +{ + vm->SetResolveBufferCallbackForHybridApp(cb); +} + + void JSNApi::SetSearchHapPathTracker(EcmaVM *vm, std::function cb) { @@ -6529,6 +6537,7 @@ 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) { @@ -6537,9 +6546,24 @@ Local JSNApi::GetModuleNameSpaceWithModuleInfo(EcmaVM *vm, const std: ecmascript::CString requestPath = file.c_str(); ecmascript::CString modulePath = module_path.c_str(); JSHandle nameSp = - ecmascript::NapiModuleLoader::LoadModuleNameSpace(vm, requestPath, modulePath); + ecmascript::NapiModuleLoader::LoadModuleNameSpace(vm, requestPath, modulePath); return JSNApiHelper::ToLocal(nameSp); } +template Local JSNApi::GetModuleNameSpaceWithModuleInfo(EcmaVM *vm, + const std::string &file, const std::string &module_path); +template Local JSNApi::GetModuleNameSpaceWithModuleInfo(EcmaVM *vm, + const std::string &file, const std::string &module_path); + +Local JSNApi::GetModuleNameSpaceWithModuleInfoForNormalApp(EcmaVM *vm, const std::string &file, + const std::string &module_path) +{ + return JSNApi::GetModuleNameSpaceWithModuleInfo(vm, file, module_path); +} +Local JSNApi::GetModuleNameSpaceWithModuleInfoForHybridApp(EcmaVM *vm, const std::string &file, + const std::string &module_path) +{ + return JSNApi::GetModuleNameSpaceWithModuleInfo(vm, file, module_path); +} Local JSNApi::GetModuleNameSpaceWithPath(const EcmaVM *vm, const char *path) { -- Gitee From a8c165a1ec941ac9164f1ea9bf9bd81ea03845af Mon Sep 17 00:00:00 2001 From: yangliping Date: Thu, 3 Jul 2025 10:11:37 +0800 Subject: [PATCH 16/54] fix warning Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICJMDB?from=project-issue Signed-off-by: yangliping Change-Id: I4e8565a9ed33710599f36b055d71222425a32adb --- .../test/unittest/aotcompilerargshandler_unit/BUILD.gn | 1 - compiler_service/test/unittest/aotcompilerclient_unit/BUILD.gn | 1 - .../test/unittest/aotcompilererrorutils_unit/BUILD.gn | 1 - compiler_service/test/unittest/aotcompilerimpl_unit/BUILD.gn | 1 - .../unittest/aotcompilerimpl_unit/aotcompilerimpl_unit.cpp | 2 -- compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn | 1 - .../test/unittest/aotcompilerservice_unit/BUILD.gn | 1 - .../aotcompilerservice_unit/aotcompilerservice_unit.cpp | 1 - compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn | 1 - test/ut/ignore-ut-release-x64-ets_runtime.txt | 3 +++ 10 files changed, 3 insertions(+), 10 deletions(-) diff --git a/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn index af75d4a9b7..328a9661ac 100644 --- a/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn @@ -17,7 +17,6 @@ import("//arkcompiler/ets_runtime/js_runtime_config.gni") config("module_private_config") { visibility = [ ":*" ] include_dirs = [ - "compiler_service_include_dirs", "${compiler_service_root}/include", "${compiler_service_root}/interface", ] diff --git a/compiler_service/test/unittest/aotcompilerclient_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerclient_unit/BUILD.gn index 8984540153..3c928442ca 100644 --- a/compiler_service/test/unittest/aotcompilerclient_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerclient_unit/BUILD.gn @@ -18,7 +18,6 @@ import("//arkcompiler/ets_runtime/js_runtime_config.gni") config("module_private_config") { visibility = [ ":*" ] include_dirs = [ - "compiler_service_include_dirs", "${compiler_service_root}/include", "${compiler_service_root}/interface", ] diff --git a/compiler_service/test/unittest/aotcompilererrorutils_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilererrorutils_unit/BUILD.gn index a23e784c6d..0dc8b62f61 100644 --- a/compiler_service/test/unittest/aotcompilererrorutils_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilererrorutils_unit/BUILD.gn @@ -17,7 +17,6 @@ import("//arkcompiler/ets_runtime/js_runtime_config.gni") config("module_private_config") { visibility = [ ":*" ] include_dirs = [ - "compiler_service_include_dirs", "${compiler_service_root}/include", "${compiler_service_root}/interface", ] diff --git a/compiler_service/test/unittest/aotcompilerimpl_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerimpl_unit/BUILD.gn index d00c787c0e..544ca59542 100644 --- a/compiler_service/test/unittest/aotcompilerimpl_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerimpl_unit/BUILD.gn @@ -18,7 +18,6 @@ import("//arkcompiler/ets_runtime/js_runtime_config.gni") config("module_private_config") { visibility = [ ":*" ] include_dirs = [ - "compiler_service_include_dirs", "${compiler_service_root}/include", "${compiler_service_root}/interface", ] diff --git a/compiler_service/test/unittest/aotcompilerimpl_unit/aotcompilerimpl_unit.cpp b/compiler_service/test/unittest/aotcompilerimpl_unit/aotcompilerimpl_unit.cpp index f637c4d451..7411c4dbc6 100644 --- a/compiler_service/test/unittest/aotcompilerimpl_unit/aotcompilerimpl_unit.cpp +++ b/compiler_service/test/unittest/aotcompilerimpl_unit/aotcompilerimpl_unit.cpp @@ -246,7 +246,6 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_005, TestSize.Level0) AotCompilerImpl &aotImpl = AotCompilerImplMock::GetInstance(); std::string sigData = "sig_data_for_test"; int32_t ret = aotImpl.GetAOTVersion(sigData); - EXPECT_EQ(sigData.size(), 0); EXPECT_EQ(ret, ERR_OK); } @@ -261,7 +260,6 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_006, TestSize.Level0) std::string args = "args_for_test"; bool sigData = true; int32_t ret = aotImpl.NeedReCompile(args, sigData); - EXPECT_FALSE(sigData); EXPECT_EQ(ret, ERR_OK); } diff --git a/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn index 9465063857..7d92ac28ac 100644 --- a/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn @@ -17,7 +17,6 @@ import("//arkcompiler/ets_runtime/js_runtime_config.gni") config("module_private_config") { visibility = [ ":*" ] include_dirs = [ - "compiler_service_include_dirs", "${compiler_service_root}/include", "${compiler_service_root}/interface", ] diff --git a/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn index 3a9b2bb84a..c8517a6fe2 100644 --- a/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn @@ -18,7 +18,6 @@ import("//arkcompiler/ets_runtime/js_runtime_config.gni") config("module_private_config") { visibility = [ ":*" ] include_dirs = [ - "compiler_service_include_dirs", "${compiler_service_root}/include", "${compiler_service_root}/interface", ] diff --git a/compiler_service/test/unittest/aotcompilerservice_unit/aotcompilerservice_unit.cpp b/compiler_service/test/unittest/aotcompilerservice_unit/aotcompilerservice_unit.cpp index 73f677adbf..280f83ad6e 100644 --- a/compiler_service/test/unittest/aotcompilerservice_unit/aotcompilerservice_unit.cpp +++ b/compiler_service/test/unittest/aotcompilerservice_unit/aotcompilerservice_unit.cpp @@ -199,7 +199,6 @@ HWTEST_F(AotCompilerServiceTest, AotCompilerServiceTest_009, TestSize.Level0) int32_t ret = aotService.NeedReCompile(oldVersion, sigData); EXPECT_EQ(ret, ERR_OK); EXPECT_STREQ(oldVersion.c_str(), "4.0.0.0"); - EXPECT_FALSE(sigData); } /** diff --git a/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn index b537e743d6..c451bf646a 100644 --- a/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn @@ -17,7 +17,6 @@ import("//arkcompiler/ets_runtime/js_runtime_config.gni") config("module_private_config") { visibility = [ ":*" ] include_dirs = [ - "compiler_service_include_dirs", "${compiler_service_root}/include", "${compiler_service_root}/interface", ] diff --git a/test/ut/ignore-ut-release-x64-ets_runtime.txt b/test/ut/ignore-ut-release-x64-ets_runtime.txt index 57444b8875..97af5e4316 100644 --- a/test/ut/ignore-ut-release-x64-ets_runtime.txt +++ b/test/ut/ignore-ut-release-x64-ets_runtime.txt @@ -22,3 +22,6 @@ obj/arkcompiler/ets_runtime/test/moduletest/hugearray/hugearrayAsmAssertContext #26263 obj/arkcompiler/ets_runtime/ecmascript/tests/GC_Third_Test + +#23099 +obj/arkcompiler/ets_runtime/ecmascript/pgo_profiler/tests/PGOProfilerTestOne -- Gitee From bfed3177d8578cbae79e44b1a1be93c8caff8722 Mon Sep 17 00:00:00 2001 From: Yong Zhou Date: Wed, 4 Jun 2025 10:26:53 +0800 Subject: [PATCH 17/54] Fix TraceRefField, FieldValue Maybe Change Issue: https://gitee.com/openharmony/arkcompiler_toolchain/issues/ICCE9Y Change-Id: If97b6c7e083f464f2c51567037af9714b13bf320 Signed-off-by: Yong Zhou Signed-off-by: lhc --- common_components/heap/w_collector/w_collector.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/common_components/heap/w_collector/w_collector.cpp b/common_components/heap/w_collector/w_collector.cpp index 35855c0042..c61d12ef2e 100755 --- a/common_components/heap/w_collector/w_collector.cpp +++ b/common_components/heap/w_collector/w_collector.cpp @@ -202,6 +202,7 @@ void WCollector::TraceRefField(BaseObject* obj, RefField<>& field, WorkStack& wo if (!Heap::IsTaggedObject(oldField.GetFieldValue())) { return; } + auto region = RegionDesc::GetRegionDescAt(reinterpret_cast((void*)targetObj)); // field is tagged object, should be in heap DCHECK_CC(Heap::IsHeapAddress(targetObj)); -- Gitee From 4898245cdf02248608699b1912efdd9e38204428 Mon Sep 17 00:00:00 2001 From: lhc Date: Wed, 9 Jul 2025 12:16:32 +0800 Subject: [PATCH 18/54] Add functions to work with static roots Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/IC7J8V Signed-off-by: lhc Change-Id: If9ead45439097097ab067b86d46ee314430729ec --- common_components/heap/heap_visitor.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/common_components/heap/heap_visitor.cpp b/common_components/heap/heap_visitor.cpp index dd453c5543..3e15590de0 100755 --- a/common_components/heap/heap_visitor.cpp +++ b/common_components/heap/heap_visitor.cpp @@ -19,17 +19,25 @@ #include "common_components/mutator/mutator.h" namespace common { + void VisitRoots(const RefFieldVisitor &visitor) { VisitDynamicGlobalRoots(visitor); VisitDynamicLocalRoots(visitor); VisitBaseRoots(visitor); + // if (isMark) { + // VisitStaticRoots(visitor); + // } else { + // UpdateStaticRoots(visitor); + // } } void VisitWeakRoots(const WeakRefFieldVisitor &visitor) { VisitDynamicWeakGlobalRoots(visitor); VisitDynamicWeakLocalRoots(visitor); + // UpdateStaticRoots(visitor); + // SweepStaticRoots(visitor); } void VisitGlobalRoots(const RefFieldVisitor &visitor) -- Gitee From 09d4426c9cb2ec87942d938a65401279766973df Mon Sep 17 00:00:00 2001 From: xucheng46 Date: Thu, 29 May 2025 17:53:48 +0800 Subject: [PATCH 19/54] enable C++ interpreter for CMC-GC Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICAOK8 Test: case tests Signed-off-by: xucheng46 Change-Id: If95260a49ab98ca7d8898140a8463e4e3b5be568 Signed-off-by: lhc --- BUILD.gn | 10 ----- common_components/heap/heap_visitor.cpp | 52 +++++++++++++++++++--- ecmascript/compiler/BUILD.gn | 11 ----- ecmascript/mem/cmc_gc/hooks.cpp | 26 ++++++++++- ecmascript/pgo_profiler/prof_dump/BUILD.gn | 4 +- ecmascript/runtime.cpp | 7 ++- ecmascript/runtime.h | 3 +- 7 files changed, 80 insertions(+), 33 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 393119667a..4b33fb0fb4 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1562,11 +1562,6 @@ ohos_source_set("libark_jsruntime_test_set") { } deps += [ ":libcommon_components_set" ] - if (ets_runtime_enable_cmc_gc) { - if (ark_hybrid) { - deps += [ "$ark_root/static_core/runtime:libarkruntime_set_static" ] - } - } public_configs = [ "$js_root:ark_jsruntime_public_config" ] public_configs += [ ":include_llvm" ] @@ -1614,11 +1609,6 @@ ohos_source_set("libark_jsruntime_static") { } deps += [ ":libcommon_components_set" ] - if (ets_runtime_enable_cmc_gc) { - if (ark_hybrid) { - deps += [ "$ark_root/static_core/runtime:libarkruntime_set_static" ] - } - } external_deps = [] if (!is_arkui_x) { diff --git a/common_components/heap/heap_visitor.cpp b/common_components/heap/heap_visitor.cpp index 3e15590de0..67a03d818d 100755 --- a/common_components/heap/heap_visitor.cpp +++ b/common_components/heap/heap_visitor.cpp @@ -17,18 +17,41 @@ #include "common_components/base_runtime/hooks.h" #include "common_components/mutator/mutator.h" - namespace common { +VisitStaticRootsHookFunc g_visitStaticRootsHook = nullptr; +UpdateStaticRootsHookFunc g_updateStaticRootsHook = nullptr; +SweepStaticRootsHookFunc g_sweepStaticRootsHook = nullptr; + +void RegisterVisitStaticRootsHook(VisitStaticRootsHookFunc func) +{ + g_visitStaticRootsHook = func; +} + +void RegisterUpdateStaticRootsHook(UpdateStaticRootsHookFunc func) +{ + g_updateStaticRootsHook = func; +} + +void RegisterweepStaticRootsHook(SweepStaticRootsHookFunc func) +{ + g_sweepStaticRootsHook = func; +} + + void VisitRoots(const RefFieldVisitor &visitor) { VisitDynamicGlobalRoots(visitor); VisitDynamicLocalRoots(visitor); VisitBaseRoots(visitor); // if (isMark) { - // VisitStaticRoots(visitor); + // if (g_visitStaticRootsHook != nullptr) { + // g_visitStaticRootsHook(visitor); + // } // } else { - // UpdateStaticRoots(visitor); + // if (g_updateStaticRootsHook != nullptr) { + // g_updateStaticRootsHook(visitor); + // } // } } @@ -36,19 +59,38 @@ void VisitWeakRoots(const WeakRefFieldVisitor &visitor) { VisitDynamicWeakGlobalRoots(visitor); VisitDynamicWeakLocalRoots(visitor); - // UpdateStaticRoots(visitor); - // SweepStaticRoots(visitor); + // if (g_updateStaticRootsHook != nullptr) { + // g_updateStaticRootsHook(visitor); + // } + // if (g_sweepStaticRootsHook != nullptr) { + // g_sweepStaticRootsHook(visitor); + // } } void VisitGlobalRoots(const RefFieldVisitor &visitor) { VisitDynamicGlobalRoots(visitor); VisitBaseRoots(visitor); + // if (isMark) { + // if (g_visitStaticRootsHook != nullptr) { + // g_visitStaticRootsHook(visitor); + // } + // } else { + // if (g_updateStaticRootsHook != nullptr) { + // g_updateStaticRootsHook(visitor); + // } + // } } void VisitWeakGlobalRoots(const WeakRefFieldVisitor &visitor) { VisitDynamicWeakGlobalRoots(visitor); + // if (g_updateStaticRootsHook != nullptr) { + // g_updateStaticRootsHook(visitor); + // } + // if (g_sweepStaticRootsHook != nullptr) { + // g_sweepStaticRootsHook(visitor); + // } } // Visit specific mutator's root. diff --git a/ecmascript/compiler/BUILD.gn b/ecmascript/compiler/BUILD.gn index f8fc059caa..7e5cf72ade 100644 --- a/ecmascript/compiler/BUILD.gn +++ b/ecmascript/compiler/BUILD.gn @@ -426,11 +426,6 @@ ohos_executable("ark_stub_compiler") { ] deps += [ "$js_root:libcommon_components_set" ] - if (ets_runtime_enable_cmc_gc) { - if (ark_hybrid) { - deps += [ "$ark_root/static_core/runtime:libarkruntime_set_static" ] - } - } external_deps = [ "zlib:libz" ] external_deps += hiviewdfx_ext_deps @@ -504,12 +499,6 @@ ohos_executable("ark_aot_compiler") { ] } - if (ets_runtime_enable_cmc_gc) { - if (ark_hybrid) { - deps += [ "$ark_root/static_core/runtime:libarkruntime_set_static" ] - } - } - external_deps = [ "zlib:libz" ] if (!is_arkui_x) { external_deps += [ diff --git a/ecmascript/mem/cmc_gc/hooks.cpp b/ecmascript/mem/cmc_gc/hooks.cpp index fe902ae31d..a02b25dfe1 100644 --- a/ecmascript/mem/cmc_gc/hooks.cpp +++ b/ecmascript/mem/cmc_gc/hooks.cpp @@ -100,6 +100,11 @@ private: void VisitBaseRoots(const RefFieldVisitor &visitorFunc) { + // todo 梁婷婷 + if (!ecmascript::Runtime::HasInstance()) { + return; + } + BaseClassRoots &baseClassRoots = BaseRuntime::GetInstance()->GetBaseClassRoots(); // When visit roots, the language of the object is not used, so using the visitorFunc will work for // both dynamic and static. @@ -108,6 +113,10 @@ void VisitBaseRoots(const RefFieldVisitor &visitorFunc) void VisitDynamicGlobalRoots(const RefFieldVisitor &visitorFunc) { + if (!ecmascript::Runtime::HasInstance()) { + return; + } + OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::VisitDynamicGlobalRoot", ""); CMCRootVisitor visitor(visitorFunc); // MarkSharedModule @@ -123,6 +132,9 @@ void VisitDynamicGlobalRoots(const RefFieldVisitor &visitorFunc) void VisitDynamicLocalRoots(const RefFieldVisitor &visitorFunc) { + if (!ecmascript::Runtime::HasInstance()) { + return; + } OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::VisitDynamicLocalRoots", ""); CMCRootVisitor visitor(visitorFunc); panda::ecmascript::Runtime *runtime = panda::ecmascript::Runtime::GetInstance(); @@ -132,14 +144,15 @@ void VisitDynamicLocalRoots(const RefFieldVisitor &visitorFunc) auto profiler = vm->GetPGOProfiler(); if (profiler != nullptr) { - profiler->IteratePGOPreFuncList(visitor); } - }); } void VisitDynamicWeakGlobalRoots(const common::WeakRefFieldVisitor &visitorFunc) { OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::VisitDynamicWeakGlobalRoots", ""); + if (!ecmascript::Runtime::HasInstance()) { + return; + } CMCWeakVisitor visitor(visitorFunc); panda::ecmascript::SharedHeap::GetInstance()->IteratorNativePointerList(visitor); @@ -156,6 +169,9 @@ void VisitDynamicWeakGlobalRoots(const common::WeakRefFieldVisitor &visitorFunc) void VisitDynamicWeakLocalRoots(const common::WeakRefFieldVisitor &visitorFunc) { + if (!ecmascript::Runtime::HasInstance()) { + return; + } OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::VisitDynamicWeakLocalRoots", ""); CMCWeakVisitor visitor(visitorFunc); panda::ecmascript::Runtime *runtime = panda::ecmascript::Runtime::GetInstance(); @@ -171,6 +187,9 @@ void VisitDynamicWeakLocalRoots(const common::WeakRefFieldVisitor &visitorFunc) void VisitDynamicThreadRoot(const RefFieldVisitor &visitorFunc, void *vm) { + if (!ecmascript::Runtime::HasInstance()) { + return; + } OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::VisitDynamicThreadRoot", ""); auto ecmaVm = reinterpret_cast(vm); if (!ecmaVm->GetAssociatedJSThread()->ReadyForGCIterating()) { @@ -187,6 +206,9 @@ void VisitDynamicThreadRoot(const RefFieldVisitor &visitorFunc, void *vm) void VisitDynamicWeakThreadRoot(const WeakRefFieldVisitor &visitorFunc, void *vm) { + if (!ecmascript::Runtime::HasInstance()) { + return; + } OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::VisitDynamicWeakThreadRoot", ""); auto ecmaVm = reinterpret_cast(vm); auto thread = ecmaVm->GetAssociatedJSThread(); diff --git a/ecmascript/pgo_profiler/prof_dump/BUILD.gn b/ecmascript/pgo_profiler/prof_dump/BUILD.gn index a6008aaa3a..da3a5dd969 100644 --- a/ecmascript/pgo_profiler/prof_dump/BUILD.gn +++ b/ecmascript/pgo_profiler/prof_dump/BUILD.gn @@ -55,9 +55,7 @@ ohos_executable("profdump") { } if (ets_runtime_enable_cmc_gc) { - if (ark_hybrid) { - deps += [ "$ark_root/static_core/runtime:libarkruntime_set_static" ] - } + deps += [ "$js_root:libcommon_components_set" ] } # hiviewdfx libraries diff --git a/ecmascript/runtime.cpp b/ecmascript/runtime.cpp index ec57d3cf09..134ed3e9c4 100644 --- a/ecmascript/runtime.cpp +++ b/ecmascript/runtime.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -52,6 +52,11 @@ Runtime *Runtime::GetInstance() return instance_; } +bool Runtime::HasInstance() +{ + return instance_ != nullptr; +} + Runtime::~Runtime() { LockHolder lock(constpoolLock_); diff --git a/ecmascript/runtime.h b/ecmascript/runtime.h index 9ec241f0fc..deb96c2b00 100644 --- a/ecmascript/runtime.h +++ b/ecmascript/runtime.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -41,6 +41,7 @@ using ReleaseSecureMemCallback = std::function; class Runtime { public: PUBLIC_API static Runtime *GetInstance(); + PUBLIC_API static bool HasInstance(); static void CreateIfFirstVm(const JSRuntimeOptions &options); static void DestroyIfLastVm(); -- Gitee From 58c1db35f8e129cf6070721a8bc1033e82d5ab43 Mon Sep 17 00:00:00 2001 From: xucheng46 Date: Thu, 5 Jun 2025 01:01:57 +0800 Subject: [PATCH 20/54] fix build problem with PUBLIC_API Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICCNTI Test: splay Signed-off-by: xucheng46 Change-Id: I4b340b5e4c0179da62d17bc6a38394e96ba9ee18 Signed-off-by: lhc --- common_components/heap/heap_visitor.cpp | 2 +- libark_jsruntime.map | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/common_components/heap/heap_visitor.cpp b/common_components/heap/heap_visitor.cpp index 67a03d818d..a91491d85c 100755 --- a/common_components/heap/heap_visitor.cpp +++ b/common_components/heap/heap_visitor.cpp @@ -33,7 +33,7 @@ void RegisterUpdateStaticRootsHook(UpdateStaticRootsHookFunc func) g_updateStaticRootsHook = func; } -void RegisterweepStaticRootsHook(SweepStaticRootsHookFunc func) +void RegisterSweepStaticRootsHook(SweepStaticRootsHookFunc func) { g_sweepStaticRootsHook = func; } diff --git a/libark_jsruntime.map b/libark_jsruntime.map index 92517e2693..67f34fb305 100644 --- a/libark_jsruntime.map +++ b/libark_jsruntime.map @@ -97,6 +97,7 @@ panda::JsiFastNativeScope::*; panda::JSExecutionScope::*; common::BaseRuntime::*; + common::HeapAllocator::*; common::VisitDynamicGlobalRoots*; common::VisitDynamicWeakGlobalRoots*; common::VisitDynamicLocalRoots*; @@ -109,6 +110,9 @@ common::FillFreeObject*; common::SetBaseAddress*; common::JSGCCallback*; + common::RegisterVisitStaticRootsHook*; + common::RegisterUpdateStaticRootsHook*; + common::RegisterSweepStaticRootsHook*; common::MutatorBase::*; common::Log::*; common::AndroidLog*; -- Gitee From 0d1e33581b36305e35381f0215489a71e518688e Mon Sep 17 00:00:00 2001 From: ChunyangWang Date: Thu, 3 Jul 2025 19:50:17 +0800 Subject: [PATCH 21/54] Partial mode AOT for Arkts 1.2 Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICJTUZ Signed-off-by: K0u1hw Change-Id: I0fe2c8f7fb9b21ab2daebc02b4dc27b4c9333587 --- compiler_service/include/aot_args_handler.h | 4 ++ .../include/aot_compiler_constants.h | 1 + compiler_service/src/aot_args_handler.cpp | 52 +++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/compiler_service/include/aot_args_handler.h b/compiler_service/include/aot_args_handler.h index 5c5ec557d9..c33bbdb9ec 100644 --- a/compiler_service/include/aot_args_handler.h +++ b/compiler_service/include/aot_args_handler.h @@ -91,6 +91,10 @@ public: bool ParseBootPandaFiles(std::string &bootfiles); std::string ParseLocation(std::string &anfilePath); + + bool ParseProfilePath(std::string &pkgInfo, std::string &profilePath); + + bool ParseProfileUse(HapArgs &hapArgs, std::string &pkgInfo); }; class StaticFrameworkAOTArgsParser final : public StaticAOTArgsParser { diff --git a/compiler_service/include/aot_compiler_constants.h b/compiler_service/include/aot_compiler_constants.h index 45461e4046..aedecd69cd 100644 --- a/compiler_service/include/aot_compiler_constants.h +++ b/compiler_service/include/aot_compiler_constants.h @@ -48,6 +48,7 @@ constexpr const char* BOOLEAN_FALSE = "0"; namespace Symbols { constexpr const char* PREFIX = "--"; constexpr const char* EQ = "="; +constexpr const char* COLON = ":"; } // namespace Symbols /** diff --git a/compiler_service/src/aot_args_handler.cpp b/compiler_service/src/aot_args_handler.cpp index 358902e9b3..c4ebb323bd 100644 --- a/compiler_service/src/aot_args_handler.cpp +++ b/compiler_service/src/aot_args_handler.cpp @@ -31,11 +31,16 @@ namespace OHOS::ArkCompiler { const std::string AOT_FILE = "aot-file"; +const std::string COMPILER_MODE = "target-compiler-mode"; +const std::string PARTIAL = "partial"; +const std::string COMPILER_PKG_INFO = "compiler-pkg-info"; +const std::string PATH = "path"; const std::string STATIC_BOOT_PANDA_FILES = "boot-panda-files"; const std::string STATIC_PAOC_PANDA_FILES = "paoc-panda-files"; const std::string STATIC_PAOC_LOCATION = "paoc-location"; const std::string STATIC_PAOC_OUTPUT = "paoc-output"; +const std::string STATIC_PAOC_USE_PROFILE = "paoc-use-profile"; const std::string STATIC_BOOT_PATH = "/system/framework/bootpath.json"; const std::string AN_FILE_NAME = "anFileName"; @@ -200,6 +205,8 @@ int32_t StaticAOTArgsParser::Parse(const std::unordered_map() + "/profile.ap"; + return true; +} + +bool StaticAOTArgsParser::ParseProfileUse(HapArgs &hapArgs, std::string &pkgInfo) +{ + std::string profilePath; + bool parseRet = ParseProfilePath(pkgInfo, profilePath); + if (!parseRet) { + LOG_SA(ERROR) << "parse profile path failed in partial mode"; + return false; + } + std::string pathArg = PATH + Symbols::EQ + profilePath; + hapArgs.argVector.emplace_back(Symbols::PREFIX + STATIC_PAOC_USE_PROFILE + Symbols::COLON + pathArg); + return true; +} + std::optional> AOTArgsParserFactory::GetParser( const std::unordered_map &argsMap) { -- Gitee From c70f13a81edc0e9beaa0cb2bb7fb2fbdb07cead0 Mon Sep 17 00:00:00 2001 From: jiangmengyang Date: Tue, 1 Jul 2025 10:21:09 +0800 Subject: [PATCH 22/54] Decoupling 1.1 calls 1.2 method Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICJ0O8 Signed-off-by: jiangmengyang Change-Id: Ida36f6df00e1f7ee632def1750bd2088b195de10 Signed-off-by: lhc --- ecmascript/builtins/builtins_promise_job.cpp | 72 +++++++++++++++---- ecmascript/builtins/builtins_promise_job.h | 9 ++- ecmascript/module/js_dynamic_import.cpp | 10 +-- .../module/static/static_module_loader.cpp | 58 +-------------- .../module/static/static_module_loader.h | 8 --- ecmascript/runtime_call_id.h | 2 +- 6 files changed, 73 insertions(+), 86 deletions(-) diff --git a/ecmascript/builtins/builtins_promise_job.cpp b/ecmascript/builtins/builtins_promise_job.cpp index 5b72ff6237..435f8aa5e6 100644 --- a/ecmascript/builtins/builtins_promise_job.cpp +++ b/ecmascript/builtins/builtins_promise_job.cpp @@ -147,7 +147,7 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) // Let specifierString be Completion(ToString(specifier)) JSHandle specifierString = JSTaggedValue::ToString(thread, specifier); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchToStringException(thread, reject)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); // Resolve request module's ohmurl CString entryPoint = JSPandaFile::ENTRY_MAIN_FUNCTION; @@ -162,7 +162,7 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) curJsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( thread, fileName, recordNameStr.c_str(), false, ExecuteTypes::STATIC); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, - StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); + HandelModuleException(thread, resolve, reject, specifierString)); if (curJsPandaFile == nullptr) { LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << recordNameStr; } @@ -172,7 +172,7 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) requestPath); LOG_ECMA(DEBUG) << "Exit Translate Normalized OhmUrl for DynamicImport, resultPath: " << requestPath; RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, - StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); + HandelModuleException(thread, resolve, reject, specifierString)); } else if (ModulePathHelper::NeedTranstale(requestPath)) { ModulePathHelper::TranstaleExpressionInput(curJsPandaFile.get(), requestPath); LOG_ECMA(DEBUG) << "Exit Translate OhmUrl for DynamicImport, resultPath: " << requestPath; @@ -189,21 +189,21 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) if (recordName->IsUndefined()) { fileName = ResolveFilenameFromNative(thread, fileName, requestPath); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, - StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); + HandelModuleException(thread, resolve, reject, specifierString)); moduleName = fileName; } else { entryPoint = ModulePathHelper::ConcatFileNameWithMerge(thread, curJsPandaFile.get(), fileName, recordNameStr, requestPath); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, - StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); + HandelModuleException(thread, resolve, reject, specifierString)); moduleName = entryPoint; } std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, fileName, entryPoint, false, ExecuteTypes::STATIC); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, - StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); + HandelModuleException(thread, resolve, reject, specifierString)); if (jsPandaFile == nullptr) { LOG_FULL(FATAL) << "Load current file's panda file failed. Current file is " << fileName; } @@ -213,7 +213,7 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) CString normalizeStr = ModulePathHelper::ReformatPath(entryPoint); CString msg = "Cannot find dynamic-import module '" + normalizeStr; THROW_REFERENCE_ERROR_AND_RETURN(thread, msg.c_str(), - StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); + HandelModuleException(thread, resolve, reject, specifierString)); } if (jsPandaFile->IsJson(recordInfo)) { @@ -228,14 +228,14 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) thread, fileName.c_str(), entryPoint.c_str(), false, ExecuteTypes::DYNAMIC)) { CString msg = "Cannot execute request dynamic-imported module : " + entryPoint; THROW_REFERENCE_ERROR_AND_RETURN(thread, msg.c_str(), - StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); + HandelModuleException(thread, resolve, reject, specifierString)); } } else { ModuleDeregister::ReviseLoadedModuleCount(thread, moduleName); } RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, - StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); + HandelModuleException(thread, resolve, reject, specifierString)); JSMutableHandle moduleNamespace(thread, JSTaggedValue::Undefined()); // only support importing es module, or return a default object. if (!jsPandaFile->IsModule(recordInfo)) { @@ -246,10 +246,10 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) moduleManager->GetImportedModule(moduleName); moduleRecord->CheckAndThrowModuleError(thread); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, - StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); + HandelModuleException(thread, resolve, reject, specifierString)); JSHandle nameSp = SourceTextModule::GetModuleNamespace(thread, moduleRecord); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, - StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); + HandelModuleException(thread, resolve, reject, specifierString)); // d. Let namespace be ? GetModuleNamespace(moduleRecord). moduleNamespace.Update(nameSp); } @@ -259,15 +259,15 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) JSHandle(resolve), undefined, undefined, 1); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, - StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); + HandelModuleException(thread, resolve, reject, specifierString)); info->SetCallArg(moduleNamespace.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSFunction::Call(info); } -JSTaggedValue BuiltinsPromiseJob::CatchToStringException(JSThread *thread, JSHandle reject) +JSTaggedValue BuiltinsPromiseJob::CatchException(JSThread *thread, JSHandle reject) { - BUILTINS_API_TRACE(thread, PromiseJob, CatchToStringException); + BUILTINS_API_TRACE(thread, PromiseJob, CatchException); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); ASSERT(thread->HasPendingException()); JSHandle thenResult = JSPromise::IfThrowGetThrowValue(thread); @@ -279,4 +279,48 @@ JSTaggedValue BuiltinsPromiseJob::CatchToStringException(JSThread *thread, JSHan runtimeInfo->SetCallArg(thenResult.GetTaggedValue()); return JSFunction::Call(runtimeInfo); } + +JSTaggedValue BuiltinsPromiseJob::HandelModuleException(JSThread *thread, JSHandle resolve, + JSHandle reject, JSHandle specifierString) +{ + CString requestPath = ModulePathHelper::Utf8ConvertToString(specifierString.GetTaggedValue()); + return HandelModuleException(thread, resolve, reject, requestPath); +} + +JSTaggedValue BuiltinsPromiseJob::HandelModuleException(JSThread *thread, JSHandle resolve, + JSHandle reject, const CString &requestPath) +{ + ASSERT(thread->HasPendingException()); + LOG_ECMA(DEBUG) << "start handle module exception " << requestPath; + // If the ohmurl is detected to be in compliance with the 1.0 prefix rule, then throw an exception directly + if (!StaticModuleLoader::CanTryLoadStaticModulePath(requestPath)) { + LOG_ECMA(DEBUG) << "handle dynamic module exception " << requestPath; + return CatchException(thread, reject); + } + LOG_ECMA(DEBUG) << "try to start load static module: " << requestPath; + JSHandle errorReuslt = JSPromise::IfThrowGetThrowValue(thread); + thread->ClearException(); + EcmaVM *vm = thread->GetEcmaVM(); + Local getEsModule = StaticModuleLoader::GetStaticModuleLoadFunc(vm); + if (!getEsModule->IsFunction(vm)) { + LOG_ECMA(DEBUG) << "napi static module function not found " << requestPath; + thread->SetException(errorReuslt.GetTaggedValue()); + return CatchException(thread, reject); + } + // try load 1.2 module; + Local getEsModuleFunc = getEsModule; + ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager(); + JSHandle exportObject = StaticModuleLoader::LoadStaticModule(thread, getEsModuleFunc, requestPath); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); + LOG_ECMA(DEBUG) << "load static module successfull, requestPath: " << requestPath; + JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); + EcmaRuntimeCallInfo *info = + EcmaInterpreter::NewRuntimeCallInfo(thread, + JSHandle(resolve), + undefined, undefined, 1); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); + info->SetCallArg(exportObject.GetTaggedValue()); + return JSFunction::Call(info); +} + } // namespace panda::ecmascript::builtins diff --git a/ecmascript/builtins/builtins_promise_job.h b/ecmascript/builtins/builtins_promise_job.h index a2df9b07b4..1e1e49874a 100644 --- a/ecmascript/builtins/builtins_promise_job.h +++ b/ecmascript/builtins/builtins_promise_job.h @@ -24,7 +24,14 @@ public: static JSTaggedValue PromiseReactionJob(EcmaRuntimeCallInfo *argv); static JSTaggedValue PromiseResolveThenableJob(EcmaRuntimeCallInfo *argv); static JSTaggedValue DynamicImportJob(EcmaRuntimeCallInfo *argv); - static JSTaggedValue CatchToStringException(JSThread *thread, JSHandle reject); + static JSTaggedValue CatchException(JSThread *thread, JSHandle reject); + + static JSTaggedValue HandelModuleException(JSThread *thread, JSHandle resolve, + JSHandle reject, + JSHandle specifierString); + static JSTaggedValue HandelModuleException(JSThread *thread, JSHandle resolve, + JSHandle reject, + const CString &requestPath); }; } // namespace panda::ecmascript::builtins #endif // ECMASCRIPT_JS_PROMISE_JOB_H \ No newline at end of file diff --git a/ecmascript/module/js_dynamic_import.cpp b/ecmascript/module/js_dynamic_import.cpp index a7f09aa074..6d5a6239c6 100644 --- a/ecmascript/module/js_dynamic_import.cpp +++ b/ecmascript/module/js_dynamic_import.cpp @@ -20,7 +20,7 @@ #include "ecmascript/module/js_module_manager.h" #include "ecmascript/module/module_data_extractor.h" #include "ecmascript/module/module_resolver.h" -#include "ecmascript/module/static/static_module_loader.h" +#include "ecmascript/builtins/builtins_promise_job.h" namespace panda::ecmascript { using PathHelper = base::PathHelper; @@ -42,7 +42,7 @@ JSTaggedValue DynamicImport::ExecuteNativeOrJsonModule(JSThread *thread, const C moduleManager->HostGetImportedModule(specifierString); moduleRecord->CheckAndThrowModuleError(thread); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, - StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); + BuiltinsPromiseJob::HandelModuleException(thread, resolve, reject, specifierString)); requiredModule.Update(moduleRecord); } else { JSHandle moduleRecord(thread, thread->GlobalConstants()->GetUndefined()); @@ -60,7 +60,7 @@ JSTaggedValue DynamicImport::ExecuteNativeOrJsonModule(JSThread *thread, const C thread, jsPandaFile, jsPandaFile->GetJSPandaFileDesc(), specifierString)); SourceTextModule::RecordEvaluatedOrError(thread, moduleRecord); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, - StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); + BuiltinsPromiseJob::HandelModuleException(thread, resolve, reject, specifierString)); } moduleManager->AddResolveImportedModule(specifierString, moduleRecord.GetTaggedValue()); moduleRecord->SetLoadingTypes(LoadingTypes::DYNAMITC_MODULE); @@ -72,14 +72,14 @@ JSTaggedValue DynamicImport::ExecuteNativeOrJsonModule(JSThread *thread, const C JSHandle moduleNamespace = SourceTextModule::GetModuleNamespace(thread, JSHandle::Cast(requiredModule)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, - StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); + BuiltinsPromiseJob::HandelModuleException(thread, resolve, reject, specifierString)); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle(resolve), undefined, undefined, 1); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, - StaticModuleLoader::TryLoadStaticModule(thread, resolve, reject, specifierString)); + BuiltinsPromiseJob::HandelModuleException(thread, resolve, reject, specifierString)); info->SetCallArg(moduleNamespace.GetTaggedValue()); return JSFunction::Call(info); } diff --git a/ecmascript/module/static/static_module_loader.cpp b/ecmascript/module/static/static_module_loader.cpp index 31a4010839..b4bd0e8619 100644 --- a/ecmascript/module/static/static_module_loader.cpp +++ b/ecmascript/module/static/static_module_loader.cpp @@ -67,7 +67,7 @@ JSHandle StaticModuleLoader::LoadStaticModule(JSThread *thread, { auto moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager(); if (moduleManager->IsModuleLoaded(key)) { - LOG_ECMA(INFO) << "load ets module from cache."; + LOG_ECMA(INFO) << "load static module from cache."; JSHandle moduleRecord = moduleManager->HostGetImportedModule(key); return JSHandle(thread, moduleRecord->GetModuleValue(thread, 0, false)); } @@ -93,60 +93,4 @@ JSHandle StaticModuleLoader::LoadStaticModule(JSThread *thread, return value; } -JSTaggedValue StaticModuleLoader::TryLoadStaticModule(JSThread *thread, JSHandle resolve, - JSHandle reject, JSHandle specifierString) -{ - CString requestPath = ModulePathHelper::Utf8ConvertToString(specifierString.GetTaggedValue()); - return TryLoadStaticModule(thread, resolve, reject, requestPath); -} - -JSTaggedValue StaticModuleLoader::TryLoadStaticModule(JSThread *thread, JSHandle resolve, - JSHandle reject, const CString &requestPath) -{ - JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - ASSERT(thread->HasPendingException()); - LOG_ECMA(DEBUG) << "start try load static module: " << requestPath; - // If the ohmurl is detected to be in compliance with the 1.0 prefix rule, then throw an exception directly - if (StaticModuleLoader::CanTryLoadStaticModulePath(requestPath)) { - JSHandle errorReuslt = JSPromise::IfThrowGetThrowValue(thread); - LOG_ECMA(DEBUG) << "start load static module: " << requestPath; - thread->ClearException(); - EcmaVM *vm = thread->GetEcmaVM(); - Local getEsModule = GetStaticModuleLoadFunc(vm); - if (!getEsModule->IsFunction(vm)) { - LOG_ECMA(DEBUG) << "napi static module function not found " << requestPath; - thread->SetException(errorReuslt.GetTaggedValue()); - return CatchException(thread, reject); - } - // try load 1.2 module; - Local getEsModuleFunc = getEsModule; - ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager(); - JSHandle exportObject = LoadStaticModule(thread, getEsModuleFunc, requestPath); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); - LOG_ECMA(DEBUG) << "load static module successfull, requestPath: " << requestPath; - JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo *info = - EcmaInterpreter::NewRuntimeCallInfo(thread, - JSHandle(resolve), - undefined, undefined, 1); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); - info->SetCallArg(exportObject.GetTaggedValue()); - return JSFunction::Call(info); - } - return CatchException(thread, reject); -} - -JSTaggedValue StaticModuleLoader::CatchException(JSThread *thread, JSHandle reject) -{ - JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - ASSERT(thread->HasPendingException()); - JSHandle errorReuslt = JSPromise::IfThrowGetThrowValue(thread); - thread->ClearException(); - JSHandle rejectfun(reject); - EcmaRuntimeCallInfo *runtimeInfo = - EcmaInterpreter::NewRuntimeCallInfo(thread, rejectfun, undefined, undefined, 1); - RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - runtimeInfo->SetCallArg(errorReuslt.GetTaggedValue()); - return JSFunction::Call(runtimeInfo); -} } // namespace panda::ecmascript diff --git a/ecmascript/module/static/static_module_loader.h b/ecmascript/module/static/static_module_loader.h index 2ca171b6ba..3184699ab9 100644 --- a/ecmascript/module/static/static_module_loader.h +++ b/ecmascript/module/static/static_module_loader.h @@ -28,14 +28,6 @@ public: static JSHandle LoadStaticModule(JSThread *thread, Local getEsModuleFunc, const CString &key); - - static JSTaggedValue TryLoadStaticModule(JSThread *thread, JSHandle resolve, - JSHandle reject, JSHandle specifierString); - - static JSTaggedValue TryLoadStaticModule(JSThread *thread, JSHandle resolve, - JSHandle reject, const CString &requestPath); - - static JSTaggedValue CatchException(JSThread *thread, JSHandle reject); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_SATTIC_MODULE_NAMESPACE_H diff --git a/ecmascript/runtime_call_id.h b/ecmascript/runtime_call_id.h index ce5d347585..3e8824c6eb 100644 --- a/ecmascript/runtime_call_id.h +++ b/ecmascript/runtime_call_id.h @@ -689,7 +689,7 @@ namespace panda::ecmascript { V(PromiseJob, Reaction) \ V(PromiseJob, ResolveThenableJob) \ V(PromiseJob, DynamicImportJob) \ - V(PromiseJob, CatchToStringException) \ + V(PromiseJob, CatchException) \ V(Promise, Constructor) \ V(Promise, All) \ V(Promise, Race) \ -- Gitee From 1537487742433085e0c74602eb02ad3e4aa860eb Mon Sep 17 00:00:00 2001 From: chentianyu Date: Mon, 2 Jun 2025 20:50:41 +0800 Subject: [PATCH 23/54] BaseRuntime Init&Fini Issue:https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICBJ7N Signed-off-by: chentianyu Change-Id: Idc105fad5ae02a386e8743176f4f0f7f46e414aa --- .../base_runtime/base_runtime.cpp | 16 ++++++++++ common_components/base_runtime/hooks.h | 4 +++ ecmascript/js_runtime_options.h | 1 + ecmascript/mem/cmc_gc/hooks.cpp | 29 +++++++++++++++++++ ecmascript/mem/heap.cpp | 1 + ecmascript/runtime.cpp | 4 +-- 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/common_components/base_runtime/base_runtime.cpp b/common_components/base_runtime/base_runtime.cpp index 038bd30174..e442237e28 100755 --- a/common_components/base_runtime/base_runtime.cpp +++ b/common_components/base_runtime/base_runtime.cpp @@ -86,12 +86,23 @@ inline void CheckAndFini(T*& module) module = nullptr; } +bool BaseRuntime::HasBeenInitialized() +{ + std::unique_lock lock(vmCreationLock_); + return initialized_; +} + void BaseRuntime::Init() { Init(BaseRuntimeParam::DefaultRuntimeParam()); } void BaseRuntime::Init(const RuntimeParam ¶m) +{ + CheckAndInitBaseRuntime(param); +} + +void BaseRuntime::InitFromDynamic(const RuntimeParam ¶m) { std::unique_lock lock(vmCreationLock_); if (initialized_) { @@ -123,6 +134,11 @@ void BaseRuntime::Init(const RuntimeParam ¶m) } void BaseRuntime::Fini() +{ + CheckAndFiniBaseRuntime(); +} + +void BaseRuntime::FiniFromDynamic() { std::unique_lock lock(vmCreationLock_); if (!initialized_) { diff --git a/common_components/base_runtime/hooks.h b/common_components/base_runtime/hooks.h index 0a005b2b91..7a31fff366 100644 --- a/common_components/base_runtime/hooks.h +++ b/common_components/base_runtime/hooks.h @@ -18,6 +18,7 @@ #include +#include "common_interfaces/base/runtime_param.h" #include "common_interfaces/heap/heap_visitor.h" #include "common_interfaces/thread/mutator_base.h" @@ -49,5 +50,8 @@ PUBLIC_API void SweepThreadLocalJitFort(); PUBLIC_API bool IsMachineCodeObject(uintptr_t obj); PUBLIC_API void JitFortUnProt(size_t size, void* base); +// Used for init/fini BaseRuntime from static +PUBLIC_API void CheckAndInitBaseRuntime(const RuntimeParam ¶m); +PUBLIC_API void CheckAndFiniBaseRuntime(); } // namespace common #endif // COMMON_COMPONENTS_BASE_RUNTIME_HOOKS_H diff --git a/ecmascript/js_runtime_options.h b/ecmascript/js_runtime_options.h index 20bdb8b7c9..2aeeb7be5b 100644 --- a/ecmascript/js_runtime_options.h +++ b/ecmascript/js_runtime_options.h @@ -253,6 +253,7 @@ enum CommandValues { class PUBLIC_API JSRuntimeOptions { public: JSRuntimeOptions(); + JSRuntimeOptions(const RuntimeParam ¶m) : param_(param) {} ~JSRuntimeOptions() = default; DEFAULT_COPY_SEMANTIC(JSRuntimeOptions); DEFAULT_MOVE_SEMANTIC(JSRuntimeOptions); diff --git a/ecmascript/mem/cmc_gc/hooks.cpp b/ecmascript/mem/cmc_gc/hooks.cpp index a02b25dfe1..1f4d37de2a 100644 --- a/ecmascript/mem/cmc_gc/hooks.cpp +++ b/ecmascript/mem/cmc_gc/hooks.cpp @@ -16,9 +16,11 @@ #include "common_components/base_runtime/hooks.h" #include +#include #include "common_components/heap/heap.h" #include "ecmascript/base/config.h" +#include "ecmascript/ecma_vm.h" #include "ecmascript/free_object.h" #include "ecmascript/mem/object_xray.h" #include "ecmascript/mem/tagged_object.h" @@ -35,6 +37,10 @@ using panda::ecmascript::ObjectSlot; using panda::ecmascript::JSThread; using panda::ecmascript::TaggedType; +// A fake EcmaVM which will never used, only for unify the BaseRuntime::Init&Fini +static ecmascript::EcmaVM *g_fakeEcmaVM = nullptr; +static std::mutex g_rtMutexForStatic; + class CMCRootVisitor final : public panda::ecmascript::RootVisitor { public: inline explicit CMCRootVisitor(const RefFieldVisitor &visitor): visitor_(visitor) {}; @@ -280,6 +286,29 @@ void JSGCCallback(void *ecmaVM) } } +void CheckAndInitBaseRuntime(const RuntimeParam ¶m) +{ + std::lock_guard guard(g_rtMutexForStatic); + if (BaseRuntime::GetInstance()->HasBeenInitialized()) { + // BaseRuntime is inited from Dynamic + return; + } + ecmascript::JSRuntimeOptions options(param); + g_fakeEcmaVM = ecmascript::EcmaVM::Create(options); +} + +void CheckAndFiniBaseRuntime() +{ + std::lock_guard guard(g_rtMutexForStatic); + if (g_fakeEcmaVM == nullptr) { + // BaseRuntime is inited from Dynamic + return; + } + g_fakeEcmaVM->GetJSThread()->ManagedCodeBegin(); + ecmascript::EcmaVM::Destroy(g_fakeEcmaVM); + g_fakeEcmaVM = nullptr; +} + void SetBaseAddress(uintptr_t base) { // Please be careful about reentrant diff --git a/ecmascript/mem/heap.cpp b/ecmascript/mem/heap.cpp index 61f9dccb09..cd603ad5b1 100644 --- a/ecmascript/mem/heap.cpp +++ b/ecmascript/mem/heap.cpp @@ -1534,6 +1534,7 @@ void Heap::CollectGarbage(TriggerGCType gcType, GCReason reason) reason == GCReason::ALLOCATION_FAILED) { type = common::GcType::FULL; } + ThreadNativeScope scope(thread_); common::BaseRuntime::RequestGC(type); return; } diff --git a/ecmascript/runtime.cpp b/ecmascript/runtime.cpp index 134ed3e9c4..acf13b3fc7 100644 --- a/ecmascript/runtime.cpp +++ b/ecmascript/runtime.cpp @@ -89,7 +89,7 @@ void Runtime::CreateIfFirstVm(const JSRuntimeOptions &options) if (g_isEnableCMCGC) { // Init common::BaseRuntime before daemon thread because creating mutator may access gcphase in heap LOG_ECMA(INFO) << "start run with cmc gc"; - common::BaseRuntime::GetInstance()->Init(options.GetRuntimeParam()); + common::BaseRuntime::GetInstance()->InitFromDynamic(options.GetRuntimeParam()); } DaemonThread::CreateNewInstance(); firstVmCreated_ = true; @@ -183,7 +183,7 @@ void Runtime::DestroyIfLastVm() DaemonThread::DestroyInstance(); if (g_isEnableCMCGC) { // Finish common::BaseRuntime after daemon thread because it will unregister mutator - common::BaseRuntime::GetInstance()->Fini(); + common::BaseRuntime::GetInstance()->FiniFromDynamic(); } SharedHeap::DestroyInstance(); AnFileDataManager::GetInstance()->SafeDestroyAllData(); -- Gitee From 0f12082b3ea67a7df3223dfdc7e844e63da2edeb Mon Sep 17 00:00:00 2001 From: chentianyu Date: Tue, 3 Jun 2025 22:20:56 +0800 Subject: [PATCH 24/54] fix pgo access invalid pointer Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICCBO8 Signed-off-by: chentianyu Change-Id: I0a72bc717af927f63a65bfe00ac8fd9085142d21 --- libark_jsruntime.map | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libark_jsruntime.map b/libark_jsruntime.map index 67f34fb305..13af66cfaf 100644 --- a/libark_jsruntime.map +++ b/libark_jsruntime.map @@ -18,6 +18,9 @@ panda::ecmascript::HELP_OPTION_MSG*; panda::ecmascript::COMPILER_HELP_HEAD_MSG*; panda::ecmascript::g_isEnableCMCGC*; + + panda::MutatorBase::*; + panda::ArkCrashHolder*; panda::ArrayBufferRef::*; -- Gitee From 7aa8777d640e302f88f2865a4dc9cf641acdf917 Mon Sep 17 00:00:00 2001 From: chentianyu Date: Tue, 10 Jun 2025 16:37:31 +0800 Subject: [PATCH 25/54] xref adapt to cmc-gc Issue:https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICE102 Signed-off-by: chentianyu Change-Id: I3b88f694be0bfbd703b694cdd5ae678477dc50fa --- BUILD.gn | 1 + .../base_runtime/base_runtime.cpp | 4 + common_components/base_runtime/hooks.h | 3 + .../heap/collector/gc_request.cpp | 3 +- common_components/heap/collector/gc_request.h | 1 + .../heap/collector/trace_collector.cpp | 52 ++++++++++-- .../heap/collector/trace_collector.h | 12 ++- common_components/heap/heap_visitor.cpp | 46 +++++++++++ .../heap/w_collector/w_collector.cpp | 79 +++++++++++++++++++ .../heap/w_collector/w_collector.h | 6 ++ common_components/thread/thread_holder.cpp | 38 ++++++++- .../checkpoint/thread_state_transition.h | 13 ++- ecmascript/cross_vm/cross_vm_operator.cpp | 20 +++++ ecmascript/cross_vm/cross_vm_operator.h | 3 +- ecmascript/mem/cmc_gc/hooks.cpp | 17 ++++ ecmascript/mem/dynamic_object_operator.cpp | 20 +++++ ecmascript/mem/dynamic_object_operator.h | 8 ++ ecmascript/napi/include/jsnapi.h | 9 +++ ecmascript/napi/include/jsnapi_expo.h | 7 +- ecmascript/napi/jsnapi_expo.cpp | 19 +++++ ecmascript/runtime.h | 18 +++++ 21 files changed, 366 insertions(+), 13 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 4b33fb0fb4..1e5966039a 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -421,6 +421,7 @@ config("ark_jsruntime_common_config") { } if (ets_runtime_enable_cmc_gc) { defines += [ "DEFAULT_USE_CMC_GC" ] + defines += [ "ARK_HYBRID" ] defines += [ "USE_CMC_GC" ] if (ets_runtime_enable_cmc_rb_dfx) { defines += [ "ENABLE_CMC_RB_DFX" ] diff --git a/common_components/base_runtime/base_runtime.cpp b/common_components/base_runtime/base_runtime.cpp index e442237e28..20bc232b83 100755 --- a/common_components/base_runtime/base_runtime.cpp +++ b/common_components/base_runtime/base_runtime.cpp @@ -220,6 +220,10 @@ void BaseRuntime::RequestGC(GcType type) HeapManager::RequestGC(GC_REASON_APPSPAWN, false); break; } + case GcType::FULL_WITH_XREF: { + HeapManager::RequestGC(GC_REASON_XREF, false); + break; + } } } diff --git a/common_components/base_runtime/hooks.h b/common_components/base_runtime/hooks.h index 7a31fff366..1bce87bd73 100644 --- a/common_components/base_runtime/hooks.h +++ b/common_components/base_runtime/hooks.h @@ -37,6 +37,9 @@ PUBLIC_API void VisitDynamicWeakLocalRoots(const WeakRefFieldVisitor &visitorFun PUBLIC_API void VisitDynamicThreadRoot(const RefFieldVisitor &visitorFunc, void *vm); PUBLIC_API void VisitDynamicWeakThreadRoot(const WeakRefFieldVisitor &visitorFunc, void *vm); +PUBLIC_API void AddXRefToDynamicRoots(); +PUBLIC_API void RemoveXRefFromDynamicRoots(); + PUBLIC_API void VisitJSThread(void *jsThread, CommonRootVisitor visitor); PUBLIC_API void SynchronizeGCPhaseToJSThread(void *jsThread, GCPhase gcPhase); diff --git a/common_components/heap/collector/gc_request.cpp b/common_components/heap/collector/gc_request.cpp index 1ac9be0a47..a5e9565178 100755 --- a/common_components/heap/collector/gc_request.cpp +++ b/common_components/heap/collector/gc_request.cpp @@ -68,6 +68,7 @@ GCRequest g_gcRequests[] = { { GC_REASON_HEU_SYNC, "heuristic_sync", true, true, 0, 0 }, { GC_REASON_NATIVE_SYNC, "native_alloc_sync", true, true, 0, 0 }, { GC_REASON_FORCE, "force", true, false, 0, 0 }, - { GC_REASON_APPSPAWN, "appspawn", true, false, 0, 0 } + { GC_REASON_APPSPAWN, "appspawn", true, false, 0, 0 }, + { GC_REASON_XREF, "force_xref", true, false, 0, 0 }, }; } // namespace common diff --git a/common_components/heap/collector/gc_request.h b/common_components/heap/collector/gc_request.h index a4657f46ed..8599cf732f 100755 --- a/common_components/heap/collector/gc_request.h +++ b/common_components/heap/collector/gc_request.h @@ -41,6 +41,7 @@ enum GCReason : uint32_t { GC_REASON_NATIVE_SYNC, // Just wait one gc request to reduce native heap consumption. GC_REASON_FORCE, // force gc is triggered when runtime triggers gc actively. GC_REASON_APPSPAWN, // appspawn gc is triggered when prefork. + GC_REASON_XREF, // force gc the whole heap include XRef. GC_REASON_MAX, GC_REASON_INVALID = std::numeric_limits::max(), }; diff --git a/common_components/heap/collector/trace_collector.cpp b/common_components/heap/collector/trace_collector.cpp index b4196affd4..e2117d7842 100755 --- a/common_components/heap/collector/trace_collector.cpp +++ b/common_components/heap/collector/trace_collector.cpp @@ -100,6 +100,7 @@ private: std::vector workStacks_; }; +template class ConcurrentMarkingTask : public common::Task { public: ConcurrentMarkingTask(uint32_t id, TraceCollector &tc, Taskpool *pool, TaskPackMonitor &monitor, @@ -126,7 +127,7 @@ public: if (workStack.empty()) { break; } - collector_.ProcessMarkStack(threadIndex, threadPool_, workStack, globalQueue_); + collector_.ProcessMarkStack(threadIndex, threadPool_, workStack, globalQueue_); } monitor_.NotifyFinishOne(); return true; @@ -161,6 +162,7 @@ void TraceCollector::TryForkTask(Taskpool *threadPool, WorkStack &workStack, Glo } } +template void TraceCollector::ProcessMarkStack([[maybe_unused]] uint32_t threadIndex, Taskpool *threadPool, WorkStack &workStack, GlobalWorkStackQueue &globalQueue) { @@ -194,6 +196,11 @@ void TraceCollector::ProcessMarkStack([[maybe_unused]] uint32_t threadIndex, Tas region->AddLiveByteCount(obj->GetSize()); [[maybe_unused]] auto beforeSize = workStack.count(); TraceObjectRefFields(obj, workStack, weakStack); +#ifdef PANDA_JS_ETS_HYBRID_MODE + if constexpr (ProcessXRef) { + TraceObjectXRef(obj, workStack); + } +#endif DLOG(TRACE, "[tracing] visit finished, workstack size: before=%d, after=%d, newly added=%d", beforeSize, workStack.count(), workStack.count() - beforeSize); // try to fork new task if needed. @@ -288,17 +295,44 @@ void TraceCollector::TracingImpl(WorkStack& workStack, bool parallel) TaskPackMonitor monitor(parallelCount, parallelCount); GlobalWorkStackQueue globalQueue; for (uint32_t i = 0; i < parallelCount; ++i) { - threadPool->PostTask(std::make_unique(0, *this, threadPool, monitor, globalQueue)); +#ifdef PANDA_JS_ETS_HYBRID_MODE + if (gcReason_ == GCReason::GC_REASON_XREF) { + threadPool->PostTask(std::make_unique>(0, *this, threadPool, monitor, + globalQueue)); + } else { + threadPool->PostTask(std::make_unique>(0, *this, threadPool, monitor, + globalQueue)); + } +#else + threadPool->PostTask(std::make_unique>(0, *this, threadPool, monitor, + globalQueue)); +#endif } if (!AddConcurrentTracingWork(workStack, globalQueue, static_cast(threadCount))) { - ProcessMarkStack(0, threadPool, workStack, globalQueue); +#ifdef PANDA_JS_ETS_HYBRID_MODE + if (gcReason_ == GCReason::GC_REASON_XREF) { + ProcessMarkStack(0, threadPool, workStack, globalQueue); + } else { + ProcessMarkStack(0, threadPool, workStack, globalQueue); + } +#else + ProcessMarkStack(0, threadPool, workStack, globalQueue); +#endif } while (true) { WorkStack stack = globalQueue.DrainAllWorkStack(); if (stack.empty()) { break; } - ProcessMarkStack(0, threadPool, stack, globalQueue); +#ifdef PANDA_JS_ETS_HYBRID_MODE + if (gcReason_ == GCReason::GC_REASON_XREF) { + ProcessMarkStack(0, threadPool, stack, globalQueue); + } else { + ProcessMarkStack(0, threadPool, stack, globalQueue); + } +#else + ProcessMarkStack(0, threadPool, stack, globalQueue); +#endif } globalQueue.NotifyFinish(); monitor.WaitAllFinished(); @@ -306,7 +340,15 @@ void TraceCollector::TracingImpl(WorkStack& workStack, bool parallel) // serial marking with a single mark task. GlobalWorkStackQueue globalQueue; WorkStack stack(std::move(workStack)); - ProcessMarkStack(0, nullptr, stack, globalQueue); +#ifdef PANDA_JS_ETS_HYBRID_MODE + if (gcReason_ == GCReason::GC_REASON_XREF) { + ProcessMarkStack(0, nullptr, stack, globalQueue); + } else { + ProcessMarkStack(0, nullptr, stack, globalQueue); + } +#else + ProcessMarkStack(0, nullptr, stack, globalQueue); +#endif } } diff --git a/common_components/heap/collector/trace_collector.h b/common_components/heap/collector/trace_collector.h index f5a6b8dcd9..25a21c671a 100755 --- a/common_components/heap/collector/trace_collector.h +++ b/common_components/heap/collector/trace_collector.h @@ -98,11 +98,13 @@ private: }; class MarkingWork; +template class ConcurrentMarkingWork; class TraceCollector : public Collector { friend MarkingWork; - friend ConcurrentMarkingWork; + template + friend class ConcurrentMarkingWork; public: explicit TraceCollector(Allocator& allocator, CollectorResources& resources) @@ -154,6 +156,7 @@ public: bool ShouldIgnoreRequest(GCRequest& request) override { return request.ShouldBeIgnored(); } + template void ProcessMarkStack(uint32_t threadIndex, Taskpool *threadPool, WorkStack &workStack, GlobalWorkStackQueue &globalQueue); @@ -196,6 +199,13 @@ public: LOG_COMMON(FATAL) << "Unresolved fatal"; UNREACHABLE_CC(); } +#ifdef PANDA_JS_ETS_HYBRID_MODE + virtual void TraceObjectXRef(BaseObject* obj, WorkStack& workStack) + { + LOG_COMMON(FATAL) << "Unresolved fatal"; + UNREACHABLE_CC(); + } +#endif inline bool IsResurrectedObject(const BaseObject* obj) const { return RegionSpace::IsResurrectedObject(obj); } diff --git a/common_components/heap/heap_visitor.cpp b/common_components/heap/heap_visitor.cpp index a91491d85c..f65696ac35 100755 --- a/common_components/heap/heap_visitor.cpp +++ b/common_components/heap/heap_visitor.cpp @@ -18,6 +18,10 @@ #include "common_components/base_runtime/hooks.h" #include "common_components/mutator/mutator.h" namespace common { +UnmarkAllXRefsHookFunc g_unmarkAllXRefsHook = nullptr; +SweepUnmarkedXRefsHookFunc g_sweepUnmarkedXRefsHook = nullptr; +AddXRefToStaticRootsHookFunc g_addXRefToStaticRootsHook = nullptr; +RemoveXRefFromStaticRootsHookFunc g_removeXRefFromStaticRootsHook = nullptr; VisitStaticRootsHookFunc g_visitStaticRootsHook = nullptr; UpdateStaticRootsHookFunc g_updateStaticRootsHook = nullptr; @@ -107,4 +111,46 @@ void VisitWeakMutatorRoot(const WeakRefFieldVisitor &visitor, Mutator &mutator) VisitDynamicWeakThreadRoot(visitor, mutator.GetEcmaVMPtr()); } } + +void RegisterUnmarkAllXRefsHook(UnmarkAllXRefsHookFunc func) +{ + g_unmarkAllXRefsHook = func; +} + +void RegisterSweepUnmarkedXRefsHook(SweepUnmarkedXRefsHookFunc func) +{ + g_sweepUnmarkedXRefsHook = func; +} + +void RegisterAddXRefToStaticRootsHook(AddXRefToStaticRootsHookFunc func) +{ + g_addXRefToStaticRootsHook = func; +} + +void RegisterRemoveXRefFromStaticRootsHook(RemoveXRefFromStaticRootsHookFunc func) +{ + g_removeXRefFromStaticRootsHook = func; +} + +void UnmarkAllXRefs() +{ + g_unmarkAllXRefsHook(); +} + +void SweepUnmarkedXRefs() +{ + g_sweepUnmarkedXRefsHook(); +} + +void AddXRefToRoots() +{ + AddXRefToDynamicRoots(); + g_addXRefToStaticRootsHook(); +} + +void RemoveXRefFromRoots() +{ + RemoveXRefFromDynamicRoots(); + g_removeXRefFromStaticRootsHook(); +} } // namespace common diff --git a/common_components/heap/w_collector/w_collector.cpp b/common_components/heap/w_collector/w_collector.cpp index c61d12ef2e..55255d4968 100755 --- a/common_components/heap/w_collector/w_collector.cpp +++ b/common_components/heap/w_collector/w_collector.cpp @@ -242,9 +242,43 @@ void WCollector::TraceObjectRefFields(BaseObject* obj, WorkStack& workStack, Wea TraceRefField(obj, field, workStack, weakStack); }; +#ifdef PANDA_JS_ETS_HYBRID_MODE + obj->ForEachRefFieldSkipReferent(refFunc); +#else obj->ForEachRefField(refFunc); +#endif +} + +#ifdef PANDA_JS_ETS_HYBRID_MODE +// note each ref-field will not be traced twice, so each old pointer the tracer meets must come from previous gc. +void WCollector::TraceXRef(RefField<>& field, WorkStack& workStack) const +{ + BaseObject* targetObj = field.GetTargetObject(); + auto region = RegionDesc::GetRegionDescAt(reinterpret_cast(targetObj)); + // field is tagged object, should be in heap + DCHECK_CC(Heap::IsHeapAddress(targetObj)); + + DLOG(TRACE, "trace obj %p <%p>(%zu)", targetObj, targetObj->GetTypeInfo(), targetObj->GetSize()); + if (region->IsNewObjectSinceTrace(targetObj)) { + DLOG(TRACE, "trace: skip new obj %p<%p>(%zu)", targetObj, targetObj->GetTypeInfo(), targetObj->GetSize()); + return; + } + ASSERT(!field.IsWeak()); + if (!region->MarkObject(targetObj)) { + workStack.push_back(targetObj); + } } +void WCollector::TraceObjectXRef(BaseObject* obj, WorkStack& workStack) +{ + auto refFunc = [this, &workStack] (RefField<>& field) { + TraceXRef(field, workStack); + }; + + obj->IterateXRef(refFunc); +} +#endif + void WCollector::FixRefField(BaseObject* obj, RefField<>& field) const { RefField<> oldField(field); @@ -517,9 +551,53 @@ void WCollector::FixHeap() WVerify::VerifyAfterFix(*this); } +void WCollector::CollectGarbageWithXRef() +{ +#ifdef ENABLE_CMC_RB_DFX + WVerify::DisableReadBarrierDFX(*this); +#endif + + ScopedStopTheWorld stw("stw-gc"); + RemoveXRefFromRoots(); + + WorkStack workStack = NewWorkStack(); + EnumRoots(workStack); + TraceHeap(workStack); + SweepUnmarkedXRefs(); + PostTrace(); + + AddXRefToRoots(); + Preforward(); + // reclaim large objects should after preforward(may process weak ref) and + // before fix heap(may clear live bit) + CollectLargeGarbage(); + SweepThreadLocalJitFort(); + + CopyFromSpace(); + WVerify::VerifyAfterForward(*this); + + PrepareFix(); + FixHeap(); + CollectPinnedGarbage(); + + TransitionToGCPhase(GCPhase::GC_PHASE_IDLE, true); + + ClearAllGCInfo(); + CollectSmallSpace(); + UnmarkAllXRefs(); + +#if defined(ENABLE_CMC_RB_DFX) + WVerify::EnableReadBarrierDFX(*this); +#endif +} + void WCollector::DoGarbageCollection() { OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::DoGarbageCollection", ""); + if (gcReason_ == GCReason::GC_REASON_XREF) { + CollectGarbageWithXRef(); + return; + } if (gcMode_ == GCMode::STW) { // 2: stw-gc #ifdef ENABLE_CMC_RB_DFX WVerify::DisableReadBarrierDFX(*this); @@ -529,6 +607,7 @@ void WCollector::DoGarbageCollection() WorkStack workStack = NewWorkStack(); EnumRoots(workStack); TraceHeap(workStack); + TransitionToGCPhase(GCPhase::GC_PHASE_FINAL_MARK, true); Remark(workStack); PostTrace(); diff --git a/common_components/heap/w_collector/w_collector.h b/common_components/heap/w_collector/w_collector.h index 4933f68ec2..883e993076 100755 --- a/common_components/heap/w_collector/w_collector.h +++ b/common_components/heap/w_collector/w_collector.h @@ -87,6 +87,10 @@ public: void EnumRefFieldRoot(RefField<>& ref, RootSet& rootSet) const override; void TraceRefField(BaseObject* obj, RefField<>& ref, WorkStack& workStack, WeakStack& weakStack) const; void TraceObjectRefFields(BaseObject* obj, WorkStack& workStack, WeakStack& weakStack) override; +#ifdef PANDA_JS_ETS_HYBRID_MODE + void TraceXRef(RefField<>& ref, WorkStack& workStack) const; + void TraceObjectXRef(BaseObject* obj, WorkStack& workStack) override; +#endif void FixObjectRefFields(BaseObject* obj) const override; void FixRefField(BaseObject* obj, RefField<>& field) const; @@ -197,6 +201,8 @@ private: void PreforwardFlip(WorkStack& workStack); void EnumRootsFlip(WorkStack& workStack); + void CollectGarbageWithXRef(); + CopyTable fwdTable_; GCMode gcMode_ = GCMode::CMC; diff --git a/common_components/thread/thread_holder.cpp b/common_components/thread/thread_holder.cpp index 17c59542da..877f1c0298 100755 --- a/common_components/thread/thread_holder.cpp +++ b/common_components/thread/thread_holder.cpp @@ -21,6 +21,39 @@ #include "common_interfaces/base_runtime.h" #include "common_interfaces/thread/base_thread.h" #include "common_interfaces/thread/thread_holder_manager.h" +#include "common_interfaces/thread/thread_state_transition.h" + +#ifdef PANDA_JS_ETS_HYBRID_MODE +namespace common { +InterOpCoroutineToNativeHookFunc interOpCoroutineToNativeHook = nullptr; +InterOpCoroutineToRunningHookFunc interOpCoroutineToRunningHook = nullptr; + +bool InterOpCoroutineToNative(ThreadHolder *current) +{ + if (interOpCoroutineToNativeHook == nullptr) { + return false; + } + return interOpCoroutineToNativeHook(current); +} + +bool InterOpCoroutineToRunning(ThreadHolder *current) +{ + if (interOpCoroutineToRunningHook == nullptr) { + return false; + } + return interOpCoroutineToRunningHook(current); +} + +void RegisterInterOpCoroutineToNativeHook(InterOpCoroutineToNativeHookFunc func) +{ + interOpCoroutineToNativeHook = func; +} +void RegisterInterOpCoroutineToRunningHook(InterOpCoroutineToRunningHookFunc func) +{ + interOpCoroutineToRunningHook = func; +} +} +#endif namespace common { thread_local ThreadHolder *currentThreadHolder = nullptr; @@ -81,11 +114,10 @@ void ThreadHolder::UnregisterJSThread(JSThread *jsThread) void ThreadHolder::RegisterCoroutine(Coroutine *coroutine) { - DCHECK_CC(!IsInRunningState()); - TransferToRunning(); + // Expect in Native when calling this func + ThreadManagedScope scope(this); DCHECK_CC(coroutines_.find(coroutine) == coroutines_.end()); coroutines_.insert(coroutine); - TransferToNative(); } void ThreadHolder::UnregisterCoroutine(Coroutine *coroutine) diff --git a/ecmascript/checkpoint/thread_state_transition.h b/ecmascript/checkpoint/thread_state_transition.h index 99e679ee93..bb157c10a5 100644 --- a/ecmascript/checkpoint/thread_state_transition.h +++ b/ecmascript/checkpoint/thread_state_transition.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -66,6 +66,11 @@ public: } } else { isEnbaleCMCGC_ = true; +#ifdef PANDA_JS_ETS_HYBRID_MODE + // This is a temporary impl to adapt interop to cmc, because some interop call napi + // without transfering to NATIVE + extraCoroutineSwitchedForInterop_ = InterOpCoroutineToNative(self_->GetThreadHolder()); +#endif if constexpr (newState == ThreadState::RUNNING) { hasSwitchState_ = self_->GetThreadHolder()->TransferToRunningIfInNative(); } else { @@ -99,6 +104,11 @@ public: } } } +#if defined(PANDA_JS_ETS_HYBRID_MODE) + if (isEnbaleCMCGC_ && extraCoroutineSwitchedForInterop_) { + InterOpCoroutineToRunning(self_->GetThreadHolder()); + } +#endif } private: @@ -106,6 +116,7 @@ private: ThreadState oldState_; uint32_t isEnbaleCMCGC_ {0}; uint32_t hasSwitchState_ {0}; + [[maybe_unused]] bool extraCoroutineSwitchedForInterop_ {false}; NO_COPY_SEMANTIC(ThreadStateTransitionScope); }; diff --git a/ecmascript/cross_vm/cross_vm_operator.cpp b/ecmascript/cross_vm/cross_vm_operator.cpp index 80cf3ca947..1d71b59f50 100644 --- a/ecmascript/cross_vm/cross_vm_operator.cpp +++ b/ecmascript/cross_vm/cross_vm_operator.cpp @@ -30,6 +30,13 @@ CrossVMOperator::CrossVMOperator(EcmaVM *vm) : vm_(vm) /*static*/ void CrossVMOperator::DoHandshake(EcmaVM *vm, void *stsIface, void **ecmaIface) { + if (g_isEnableCMCGC) { + auto vmOperator = vm->GetCrossVMOperator(); + *ecmaIface = vmOperator->ecmaVMInterface_.get(); + vmOperator->stsVMInterface_ = static_cast(stsIface); + Runtime::GetInstance()->SetSTSVMInterface(vmOperator->stsVMInterface_); + return; + } auto vmOperator = vm->GetCrossVMOperator(); *ecmaIface = vmOperator->ecmaVMInterface_.get(); vmOperator->stsVMInterface_ = static_cast(stsIface); @@ -39,6 +46,16 @@ void CrossVMOperator::DoHandshake(EcmaVM *vm, void *stsIface, void **ecmaIface) } } +void CrossVMOperator::MarkFromObject(JSTaggedType value, std::function &visitor) +{ + JSTaggedValue taggedValue(value); + if (!taggedValue.IsHeapObject()) { + return; + } + TaggedObject *object = taggedValue.GetHeapObject(); + visitor(reinterpret_cast(object)); // This is only mark, so could pass a stack reference +} + void CrossVMOperator::MarkFromObject(JSTaggedType value) { JSTaggedValue taggedValue(value); @@ -67,6 +84,9 @@ bool CrossVMOperator::IsValidHeapObject(JSTaggedType value) return false; } TaggedObject *object = taggedValue.GetHeapObject(); + if (g_isEnableCMCGC) { + return static_cast(object)->IsValidObject(); + } return vm_->GetHeap()->ContainObject(object); } diff --git a/ecmascript/cross_vm/cross_vm_operator.h b/ecmascript/cross_vm/cross_vm_operator.h index 8688bf7750..a10e82b3ed 100644 --- a/ecmascript/cross_vm/cross_vm_operator.h +++ b/ecmascript/cross_vm/cross_vm_operator.h @@ -47,6 +47,7 @@ public: return ecmaVMInterface_.get(); } + void MarkFromObject(JSTaggedType value, std::function &visitor); void MarkFromObject(JSTaggedType value); bool IsObjectAlive(JSTaggedType value); bool IsValidHeapObject(JSTaggedType value); @@ -61,7 +62,7 @@ private: bool StartXRefMarking() override; void NotifyXGCInterruption() override; private: - EcmaVM *vm_ {nullptr}; + [[maybe_unused]] EcmaVM *vm_ {nullptr}; }; EcmaVM *vm_ {nullptr}; diff --git a/ecmascript/mem/cmc_gc/hooks.cpp b/ecmascript/mem/cmc_gc/hooks.cpp index 1f4d37de2a..e0a750bcf2 100644 --- a/ecmascript/mem/cmc_gc/hooks.cpp +++ b/ecmascript/mem/cmc_gc/hooks.cpp @@ -21,6 +21,7 @@ #include "common_components/heap/heap.h" #include "ecmascript/base/config.h" #include "ecmascript/ecma_vm.h" +#include "ecmascript/ecma_global_storage.h" #include "ecmascript/free_object.h" #include "ecmascript/mem/object_xray.h" #include "ecmascript/mem/tagged_object.h" @@ -327,4 +328,20 @@ bool IsMachineCodeObject(uintptr_t objPtr) return value.IsMachineCodeObject(); } +void AddXRefToDynamicRoots() +{ + ecmascript::Runtime *runtime = ecmascript::Runtime::GetInstance(); + runtime->GCIterateThreadList([&](JSThread *thread) { + thread->SetNodeKind(ecmascript::NodeKind::NORMAL_NODE); + }); +} + +void RemoveXRefFromDynamicRoots() +{ + ecmascript::Runtime *runtime = ecmascript::Runtime::GetInstance(); + runtime->GCIterateThreadList([&](JSThread *thread) { + thread->SetNodeKind(ecmascript::NodeKind::UNIFIED_NODE); + }); +} + } // namespace panda diff --git a/ecmascript/mem/dynamic_object_operator.cpp b/ecmascript/mem/dynamic_object_operator.cpp index e1f0f1add2..618bb47107 100644 --- a/ecmascript/mem/dynamic_object_operator.cpp +++ b/ecmascript/mem/dynamic_object_operator.cpp @@ -14,7 +14,9 @@ */ #include "ecmascript/mem/dynamic_object_operator.h" + #include "ecmascript/mem/object_xray.h" +#include "ecmascript/runtime.h" namespace panda::ecmascript { @@ -27,6 +29,24 @@ void DynamicObjectOperator::Initialize() } } +void DynamicObjectOperator::IterateXRef([[maybe_unused]] const BaseObject *object, + [[maybe_unused]] const common::RefFieldVisitor &visitor) const +{ +#if defined(PANDA_JS_ETS_HYBRID_MODE) + if (g_isEnableCMCGC) { + JSTaggedValue value(reinterpret_cast(const_cast(object))); + if (value.IsJSXRefObject()) { + Runtime::GetInstance()->GetSTSVMInterface()->MarkFromObject( + JSObject::Cast(TaggedObject::Cast(object))->GetNativePointerField(0), visitor); + } + } else { + std:abort(); + } +#else + std::abort(); +#endif +} + void RefFieldObjectVisitor::VisitObjectRangeImpl(BaseObject *root, uintptr_t startAddr, uintptr_t endAddr, VisitObjectArea area) { diff --git a/ecmascript/mem/dynamic_object_operator.h b/ecmascript/mem/dynamic_object_operator.h index 6fa95fd97a..9be4a921d6 100644 --- a/ecmascript/mem/dynamic_object_operator.h +++ b/ecmascript/mem/dynamic_object_operator.h @@ -80,6 +80,12 @@ public: return hclass->GetClass()->IsHClass(); } + void ForEachRefFieldSkipReferent(const BaseObject *object, const common::RefFieldVisitor &visitor) const override + { + // Referent is only used in static + ForEachRefField(object, visitor); + } + void ForEachRefField(const BaseObject *object, const common::RefFieldVisitor &visitor) const override { auto freeObject = FreeObject::Cast(reinterpret_cast(object)); @@ -89,6 +95,8 @@ public: } } + void IterateXRef(const BaseObject *object, const common::RefFieldVisitor &visitor) const override; + size_t GetSize(const BaseObject *object) const override { ASSERT(!g_isEnableCMCGC || !object->IsForwarded()); diff --git a/ecmascript/napi/include/jsnapi.h b/ecmascript/napi/include/jsnapi.h index 738cfc55f4..0734368ad2 100644 --- a/ecmascript/napi/include/jsnapi.h +++ b/ecmascript/napi/include/jsnapi.h @@ -495,6 +495,15 @@ void Global::FreeXRefGlobalHandleAddr() } #ifdef PANDA_JS_ETS_HYBRID_MODE + template + void Global::MarkFromObject(std::function &visitor) + { + if (address_ == 0) { + return; + } + JSNApi::MarkFromObject(vm_, address_, visitor); + } + template void Global::MarkFromObject() { diff --git a/ecmascript/napi/include/jsnapi_expo.h b/ecmascript/napi/include/jsnapi_expo.h index 04c6a5a02f..77cb7d895e 100644 --- a/ecmascript/napi/include/jsnapi_expo.h +++ b/ecmascript/napi/include/jsnapi_expo.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -479,6 +479,7 @@ public: // This method must be called before Global is released. void FreeGlobalHandleAddr(); void FreeXRefGlobalHandleAddr(); + void MarkFromObject(std::function &visitor); void MarkFromObject(); bool IsObjectAlive() const; bool IsValidHeapObject() const; @@ -1431,6 +1432,9 @@ private: uint16_t oldThreadState_ {0}; uint32_t isEnableCMCGC_ {0}; uint32_t hasSwitchState_ {0}; + // This is a temporary impl to adapt interop to cmc, because some interop call napi + // without transfering to NATIVE + [[maybe_unused]] bool extraCoroutineSwitchedForInterop_ {false}; }; /** @@ -1945,6 +1949,7 @@ private: static void DisposeGlobalHandleAddr(const EcmaVM *vm, uintptr_t addr); static void DisposeXRefGlobalHandleAddr(const EcmaVM *vm, uintptr_t addr); #ifdef PANDA_JS_ETS_HYBRID_MODE + static void MarkFromObject(const EcmaVM *vm, uintptr_t addr, std::function &visitor); static void MarkFromObject(const EcmaVM *vm, uintptr_t addr); #endif // PANDA_JS_ETS_HYBRID_MODE diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index b0683168c8..5a007bdd73 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -4300,6 +4300,11 @@ JsiFastNativeScope::JsiFastNativeScope(const EcmaVM *vm) hasSwitchState_ = oldThreadState_ != static_cast(ecmascript::ThreadState::RUNNING); } else { isEnableCMCGC_ = true; +#ifdef PANDA_JS_ETS_HYBRID_MODE + // This is a temporary impl to adapt interop to cmc, because some interop call napi + // without transfering to NATIVE + extraCoroutineSwitchedForInterop_ = InterOpCoroutineToNative(thread_->GetThreadHolder()); +#endif hasSwitchState_ = thread_->GetThreadHolder()->TransferToRunningIfInNative(); } } @@ -4313,6 +4318,11 @@ JsiFastNativeScope::~JsiFastNativeScope() thread_->GetThreadHolder()->TransferToNative(); } } +#if defined(PANDA_JS_ETS_HYBRID_MODE) + if (isEnableCMCGC_ && extraCoroutineSwitchedForInterop_) { + InterOpCoroutineToRunning(thread_->GetThreadHolder()); + } +#endif } // ------------------------------------ JsiRuntimeCallInfo ----------------------------------------------- @@ -6018,6 +6028,15 @@ void JSNApi::DisposeXRefGlobalHandleAddr(const EcmaVM *vm, uintptr_t addr) } #ifdef PANDA_JS_ETS_HYBRID_MODE +void JSNApi::MarkFromObject(const EcmaVM *vm, uintptr_t addr, std::function &visitor) +{ + if (addr == 0 || !reinterpret_cast(addr)->IsUsing()) { + return; + } + JSTaggedType value = *(reinterpret_cast(addr)); + vm->GetCrossVMOperator()->MarkFromObject(value, visitor); +} + void JSNApi::MarkFromObject(const EcmaVM *vm, uintptr_t addr) { if (addr == 0 || !reinterpret_cast(addr)->IsUsing()) { diff --git a/ecmascript/runtime.h b/ecmascript/runtime.h index deb96c2b00..f14e56f05a 100644 --- a/ecmascript/runtime.h +++ b/ecmascript/runtime.h @@ -17,6 +17,9 @@ #define ECMASCRIPT_RUNTIME_H #include "common_interfaces/base_runtime.h" +#ifdef PANDA_JS_ETS_HYBRID_MODE +#include "ecmascript/cross_vm/cross_vm_operator.h" +#endif #include "ecmascript/ecma_string_table.h" #include "ecmascript/global_env_constants.h" #include "ecmascript/js_runtime_options.h" @@ -283,6 +286,18 @@ public: return releaseSecureMemCallback_; } +#ifdef PANDA_JS_ETS_HYBRID_MODE + void SetSTSVMInterface(arkplatform::STSVMInterface *stsIface) + { + stsVMInterface_ = stsIface; + } + + arkplatform::STSVMInterface *GetSTSVMInterface() const + { + return stsVMInterface_; + } +#endif + private: static constexpr int32_t WORKER_DESTRUCTION_COUNT = 3; static constexpr int32_t MIN_GC_TRIGGER_VM_COUNT = 4; @@ -356,6 +371,9 @@ private: static Mutex *vmCreationLock_; static Runtime *instance_; static common::BaseRuntime *baseInstance_; +#ifdef PANDA_JS_ETS_HYBRID_MODE + arkplatform::STSVMInterface *stsVMInterface_ {nullptr}; +#endif // for string cache JSTaggedValue *externalRegisteredStringTable_ {nullptr}; -- Gitee From 8046f152d6c49b2b3d0cb02ed097de00bd90c7e6 Mon Sep 17 00:00:00 2001 From: chentianyu Date: Tue, 24 Jun 2025 15:44:48 +0800 Subject: [PATCH 26/54] Support XRef serializer Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICDFSB Signed-off-by: chentianyu Change-Id: I1fd9601a7fa77af98a5d54cbeb3f590725a21433 --- BUILD.gn | 6 +- ecmascript/js_object.cpp | 18 ++++ ecmascript/js_object.h | 1 + ecmascript/napi/include/jsnapi_expo.h | 10 +++ ecmascript/napi/jsnapi_expo.cpp | 66 ++++++++++++++ ecmascript/serializer/base_deserializer.cpp | 16 +++- ecmascript/serializer/base_deserializer.h | 7 +- .../inter_op_value_deserializer.cpp | 72 +++++++++++++++ .../serializer/inter_op_value_deserializer.h | 68 +++++++++++++++ .../serializer/inter_op_value_serializer.cpp | 87 +++++++++++++++++++ .../serializer/inter_op_value_serializer.h | 38 ++++++++ ecmascript/serializer/serialize_data.h | 2 + ecmascript/serializer/value_serializer.h | 6 +- 13 files changed, 388 insertions(+), 9 deletions(-) create mode 100644 ecmascript/serializer/inter_op_value_deserializer.cpp create mode 100644 ecmascript/serializer/inter_op_value_deserializer.h create mode 100644 ecmascript/serializer/inter_op_value_serializer.cpp create mode 100644 ecmascript/serializer/inter_op_value_serializer.h diff --git a/BUILD.gn b/BUILD.gn index 1e5966039a..1196ac8079 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1156,7 +1156,11 @@ ecma_source += [ ] if (ark_js_hybrid) { - ecma_source += [ "ecmascript/cross_vm/cross_vm_operator.cpp" ] + ecma_source += [ + "ecmascript/cross_vm/cross_vm_operator.cpp", + "ecmascript/serializer/inter_op_value_deserializer.cpp", + "ecmascript/serializer/inter_op_value_serializer.cpp", + ] } if (!is_arkui_x) { diff --git a/ecmascript/js_object.cpp b/ecmascript/js_object.cpp index 770a443cc5..de94c41916 100644 --- a/ecmascript/js_object.cpp +++ b/ecmascript/js_object.cpp @@ -3087,6 +3087,24 @@ bool ECMAObject::HasHash() const return true; } +JSTaggedValue ECMAObject::GetNativePointerByIndex(int32_t index) const +{ + JSTaggedType hashField = Barriers::GetTaggedValue(this, HASH_OFFSET); + JSTaggedValue value(hashField); + if (value.IsTaggedArray()) { + auto array = TaggedArray::Cast(value); + if (static_cast(array->GetExtraLength()) > index) { + auto jsValue = array->Get(index); + if (UNLIKELY(!jsValue.IsJSNativePointer())) { + LOG_FULL(ERROR) << "jsValue is not js native pointer"; + return JSTaggedValue::Undefined(); + } + return jsValue; + } + } + return JSTaggedValue::Undefined(); +} + void *ECMAObject::GetNativePointerField(int32_t index) const { JSTaggedType hashField = Barriers::GetTaggedValue(this, HASH_OFFSET); diff --git a/ecmascript/js_object.h b/ecmascript/js_object.h index 07e4d07f5b..9c9e87177d 100644 --- a/ecmascript/js_object.h +++ b/ecmascript/js_object.h @@ -388,6 +388,7 @@ public: Barriers::SetPrimitive(this, ECMAObject::HASH_OFFSET, JSTaggedValue(0).GetRawData()); } + JSTaggedValue GetNativePointerByIndex(int32_t index) const; void* GetNativePointerField(int32_t index) const; static void SetNativePointerField(const JSThread *thread, const JSHandle &obj, int32_t index, void *nativePointer, const NativePointerCallback &callBack, void *data, diff --git a/ecmascript/napi/include/jsnapi_expo.h b/ecmascript/napi/include/jsnapi_expo.h index 77cb7d895e..5a896e9ffa 100644 --- a/ecmascript/napi/include/jsnapi_expo.h +++ b/ecmascript/napi/include/jsnapi_expo.h @@ -1656,6 +1656,12 @@ public: void *detachedHint = nullptr; }; + struct XRefBindingInfo { + static XRefBindingInfo* CreateNewInstance() { return new(std::nothrow) XRefBindingInfo(); } + void *attachXRefFunc = nullptr; + void *attachXRefData = nullptr; + }; + // JSVM // fixme: Rename SEMI_GC to YOUNG_GC enum class PUBLIC_API TRIGGER_GC_TYPE : uint8_t { @@ -1808,6 +1814,10 @@ public: Local cloneList, std::string &error, bool defaultTransfer = false, bool defaultCloneShared = true); static Local DeserializeValue(const EcmaVM *vm, void *recoder, void *hint); + // InterOp Serialize & Deserialize. + static void* InterOpSerializeValue(const EcmaVM *vm, Local data, Local transfer, + Local cloneList, bool defaultTransfer = false, bool defaultCloneShared = true); + static Local InterOpDeserializeValue(const EcmaVM *vm, void *recoder, void *hint); static void DeleteSerializationData(void *data); static void SetHostPromiseRejectionTracker(EcmaVM *vm, void *cb, void* data); static void SetTimerTaskCallback(EcmaVM *vm, TimerTaskCallback callback); diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index 5a007bdd73..d41f4387f8 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -55,6 +55,10 @@ #if defined(ENABLE_LOCAL_HANDLE_LEAK_DETECT) #include "ecmascript/dfx/hprof/heap_profiler.h" #endif +#ifdef PANDA_JS_ETS_HYBRID_MODE +#include "ecmascript/serializer/inter_op_value_deserializer.h" +#include "ecmascript/serializer/inter_op_value_serializer.h" +#endif namespace panda { using ecmascript::AccessorData; @@ -6065,6 +6069,68 @@ bool JSNApi::IsValidHeapObject(const EcmaVM *vm, uintptr_t addr) } #endif // PANDA_JS_ETS_HYBRID_MODE +void *JSNApi::InterOpSerializeValue([[maybe_unused]] const EcmaVM *vm, [[maybe_unused]] Local value, + [[maybe_unused]] Local transfer, [[maybe_unused]] Local cloneList, + [[maybe_unused]] bool defaultTransfer, [[maybe_unused]] bool defaultCloneShared) +{ + CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, nullptr); +#ifdef PANDA_JS_ETS_HYBRID_MODE + ecmascript::ThreadManagedScope scope(thread); + JSHandle arkValue = JSNApiHelper::ToJSHandle(value); + JSHandle arkTransfer = JSNApiHelper::ToJSHandle(transfer); + JSHandle arkCloneList = JSNApiHelper::ToJSHandle(cloneList); + bool serializationTimeoutCheckEnabled = IsSerializationTimeoutCheckEnabled(vm); + std::chrono::system_clock::time_point startTime; + std::chrono::system_clock::time_point endTime; + if (serializationTimeoutCheckEnabled) { + startTime = std::chrono::system_clock::now(); + } + ecmascript::InterOpValueSerializer serializer(thread, defaultTransfer, defaultCloneShared); + std::unique_ptr data; + if (serializer.WriteValue(thread, arkValue, arkTransfer, arkCloneList)) { + data = serializer.Release(); + } + if (serializationTimeoutCheckEnabled) { + endTime = std::chrono::system_clock::now(); + GenerateTimeoutTraceIfNeeded(vm, startTime, endTime, true); + } + if (data == nullptr) { + return nullptr; + } else { + return reinterpret_cast(data.release()); + } +#else + LOG_FULL(FATAL) << "Only support in inter-op"; + UNREACHABLE(); +#endif +} + +Local JSNApi::InterOpDeserializeValue([[maybe_unused]] const EcmaVM *vm, [[maybe_unused]] void *recoder, + [[maybe_unused]] void *hint) +{ + CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); +#ifdef PANDA_JS_ETS_HYBRID_MODE + ecmascript::ThreadManagedScope scope(thread); + std::unique_ptr data(reinterpret_cast(recoder)); + ecmascript::InterOpValueDeserializer deserializer(thread, data.release(), hint); + bool serializationTimeoutCheckEnabled = IsSerializationTimeoutCheckEnabled(vm); + std::chrono::system_clock::time_point startTime; + std::chrono::system_clock::time_point endTime; + if (serializationTimeoutCheckEnabled) { + startTime = std::chrono::system_clock::now(); + } + JSHandle result = deserializer.ReadValue(); + if (serializationTimeoutCheckEnabled) { + endTime = std::chrono::system_clock::now(); + GenerateTimeoutTraceIfNeeded(vm, startTime, endTime, false); + } + return JSNApiHelper::ToLocal(result); +#else + LOG_FULL(FATAL) << "Only support in inter-op"; + UNREACHABLE(); +#endif +} + void *JSNApi::SerializeValue(const EcmaVM *vm, Local value, Local transfer, Local cloneList, bool defaultTransfer, bool defaultCloneShared) { diff --git a/ecmascript/serializer/base_deserializer.cpp b/ecmascript/serializer/base_deserializer.cpp index fef5b6105a..c07e255566 100644 --- a/ecmascript/serializer/base_deserializer.cpp +++ b/ecmascript/serializer/base_deserializer.cpp @@ -28,7 +28,7 @@ namespace panda::ecmascript { BaseDeserializer::BaseDeserializer(JSThread *thread, SerializeData *data, void *hint) - : data_(data), thread_(thread), heap_(const_cast(thread->GetEcmaVM()->GetHeap())), engine_(hint) + : thread_(thread), data_(data), engine_(hint), heap_(const_cast(thread->GetEcmaVM()->GetHeap())) { sheap_ = SharedHeap::GetInstance(); uint32_t index = data_->GetDataIndex(); @@ -87,6 +87,9 @@ JSHandle BaseDeserializer::DeserializeJSTaggedValue() } jsErrorInfos_.clear(); + // May be some other special object need to process at last + DeserializeSpecialRecordedObjects(); + // recovery gc after serialize heap_->SetOnSerializeEvent(false); @@ -423,13 +426,18 @@ size_t BaseDeserializer::ReadSingleEncodeData(uint8_t encodeFlag, uintptr_t objA break; } default: - LOG_ECMA(FATAL) << "this branch is unreachable flag: " << (int)encodeFlag; - UNREACHABLE(); - break; + // This flag may be supported by subclass. + return DerivedExtraReadSingleEncodeData(encodeFlag, objAddr, fieldOffset); } return handledFieldSize; } +size_t BaseDeserializer::DerivedExtraReadSingleEncodeData(uint8_t encodeFlag, uintptr_t objAddr, size_t fieldOffset) +{ + LOG_ECMA(FATAL) << "this branch is unreachable " << static_cast(encodeFlag); + UNREACHABLE(); +} + uintptr_t BaseDeserializer::RelocateObjectAddr(SerializedObjectSpace space, size_t objSize) { uintptr_t res = 0U; diff --git a/ecmascript/serializer/base_deserializer.h b/ecmascript/serializer/base_deserializer.h index ab02cf5daa..f8cc78d8ef 100644 --- a/ecmascript/serializer/base_deserializer.h +++ b/ecmascript/serializer/base_deserializer.h @@ -100,6 +100,7 @@ private: JSTaggedType RelocateObjectProtoAddr(uint8_t objectType); void DeserializeObjectField(uintptr_t start, uintptr_t end); size_t ReadSingleEncodeData(uint8_t encodeFlag, uintptr_t objAddr, size_t fieldOffset); + virtual size_t DerivedExtraReadSingleEncodeData(uint8_t encodeFlag, uintptr_t objAddr, size_t fieldOffset); void HandleNewObjectEncodeFlag(SerializedObjectSpace space, uintptr_t objAddr, size_t fieldOffset); void TransferArrayBufferAttach(uintptr_t objAddr); @@ -230,15 +231,17 @@ private: } protected: + JSThread *thread_; SerializeData *data_; + void *engine_; size_t position_ {0}; CVector objectVector_ {}; + virtual void DeserializeSpecialRecordedObjects() {} + private: - JSThread *thread_; Heap *heap_; SharedHeap *sheap_; - void *engine_; uintptr_t currentRegularObjectAddr_ {0}; uintptr_t currentRegularRegionBeginAddr_ {0}; uintptr_t currentPinObjectAddr_ {0}; diff --git a/ecmascript/serializer/inter_op_value_deserializer.cpp b/ecmascript/serializer/inter_op_value_deserializer.cpp new file mode 100644 index 0000000000..24d0403a43 --- /dev/null +++ b/ecmascript/serializer/inter_op_value_deserializer.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/serializer/inter_op_value_deserializer.h" + +#include "ecmascript/checkpoint/thread_state_transition.h" + +namespace panda::ecmascript { +size_t InterOpValueDeserializer::DerivedExtraReadSingleEncodeData(uint8_t encodeFlag, uintptr_t objAddr, + size_t fieldOffset) +{ + size_t handledFieldSize = sizeof(JSTaggedType); + ObjectSlot slot(objAddr + fieldOffset); + switch (encodeFlag) { + case (uint8_t)EncodeFlag::XREF_BINDING_OBJECT: { + slot.Update(JSTaggedValue::Undefined().GetRawData()); + AttachXRefFunc af = reinterpret_cast(data_->ReadJSTaggedType(position_)); + void *attachXRefData = reinterpret_cast(data_->ReadJSTaggedType(position_)); + JSHandle obj(thread_, JSTaggedValue(objAddr)); + // defer new xref binding object until deserialize finish + xRefBindingAttachInfos_.emplace_back(af, attachXRefData, obj, fieldOffset); + break; + } + default: + LOG_ECMA(FATAL) << "this branch is unreachable " << static_cast(encodeFlag); + UNREACHABLE(); + } + return handledFieldSize; +} + +void InterOpValueDeserializer::DeserializeSpecialRecordedObjects() +{ + for (auto &info : xRefBindingAttachInfos_) { + DeserializeXRefBindingObject(&info); + } +} + +void InterOpValueDeserializer::DeserializeXRefBindingObject(XRefBindingAttachInfo *info) +{ + [[maybe_unused]] EcmaHandleScope scope(thread_); + AttachXRefFunc af = info->af_; + void *attachXRefData = info->attachXRefData_; + Local attachVal; + { + ThreadNativeScope nativeScope(thread_); + attachVal = af(engine_, attachXRefData); + } + if (attachVal.IsEmpty()) { + LOG_ECMA(ERROR) << "NativeBindingObject is empty"; + attachVal = JSValueRef::Undefined(thread_->GetEcmaVM()); + } + JSTaggedType res = JSNApiHelper::ToJSHandle(attachVal).GetTaggedType(); + ObjectSlot slot = info->GetSlot(); + slot.Update(res); + if (!JSTaggedValue(res).IsInvalidValue()) { + WriteBarrier(thread_, reinterpret_cast(info->GetObjAddr()), info->GetFieldOffset(), res); + } +} +} // namespace panda::ecmascript + diff --git a/ecmascript/serializer/inter_op_value_deserializer.h b/ecmascript/serializer/inter_op_value_deserializer.h new file mode 100644 index 0000000000..0d7f38eef2 --- /dev/null +++ b/ecmascript/serializer/inter_op_value_deserializer.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_SERIALIZER_INTER_OP_VALUE_DESERIALIZER_H +#define ECMASCRIPT_SERIALIZER_INTER_OP_VALUE_DESERIALIZER_H + +#include "ecmascript/serializer/base_deserializer.h" +#include "ecmascript/serializer/serialize_data.h" + +namespace panda::ecmascript { +class Heap; +class JSThread; +struct XRefBindingAttachInfo { + AttachXRefFunc af_ {nullptr}; + void *attachXRefData_ = {nullptr}; + JSHandle obj_; + size_t offset_ {0U}; + + XRefBindingAttachInfo(AttachXRefFunc af, void *attachXRefData, JSHandle obj, size_t offset) + : af_(af), attachXRefData_(attachXRefData), obj_(obj), offset_(offset) {} + + uintptr_t GetObjAddr() const + { + return static_cast(obj_->GetRawData()); + } + + size_t GetFieldOffset() const + { + return offset_; + } + + ObjectSlot GetSlot() const + { + return ObjectSlot(GetObjAddr() + offset_); + } +}; + +class InterOpValueDeserializer : public BaseDeserializer { +public: + explicit InterOpValueDeserializer(JSThread *thread, SerializeData *data, void *hint = nullptr) + : BaseDeserializer(thread, data, hint) {} + + ~InterOpValueDeserializer() = default; + + NO_COPY_SEMANTIC(InterOpValueDeserializer); + NO_MOVE_SEMANTIC(InterOpValueDeserializer); + +private: + size_t DerivedExtraReadSingleEncodeData(uint8_t encodeFlag, uintptr_t objAddr, size_t fieldOffset) override; + void DeserializeSpecialRecordedObjects() override; + void DeserializeXRefBindingObject(XRefBindingAttachInfo *info); + std::vector xRefBindingAttachInfos_; +}; +} + +#endif // ECMASCRIPT_SERIALIZER_INTER_OP_VALUE_DESERIALIZER_H \ No newline at end of file diff --git a/ecmascript/serializer/inter_op_value_serializer.cpp b/ecmascript/serializer/inter_op_value_serializer.cpp new file mode 100644 index 0000000000..e7e8e905e3 --- /dev/null +++ b/ecmascript/serializer/inter_op_value_serializer.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/serializer/inter_op_value_serializer.h" + +namespace panda::ecmascript { +void InterOpValueSerializer::SerializeObjectImpl(TaggedObject *object, bool isWeak) +{ + if (TrySerializeInterOpObject(object, isWeak)) { + return; + } + ValueSerializer::SerializeObjectImpl(object, isWeak); +} + +bool InterOpValueSerializer::TrySerializeInterOpObject(TaggedObject *object, bool isWeak) +{ + [[maybe_unused]] EcmaHandleScope handleScope(thread_); + JSType type = object->GetClass()->GetObjectType(); + JSHandle target(thread_, object); + switch (type) { + case JSType::JS_OBJECT: + case JSType::JS_FUNCTION: + break; + case JSType::JS_PROXY: + target = JSProxy::Cast(object)->GetSourceTarget(thread_); + break; + default: + return false; + } + JSHandle objHandle(target); + JSHandle keyHandle = thread_->GlobalConstants()->GetHandledProxyNapiWrapperString(); + // Otherwise, before lookup key in JSObject will intern string, which may trigger GC + ASSERT(EcmaStringAccessor(keyHandle->GetTaggedObject()).IsInternString()); + JSTaggedValue xRef = JSObject::GetProperty(thread_, objHandle, keyHandle).GetValue().GetTaggedValue(); + if (xRef.IsUndefined()) { + return false; + } + + SerializeInterOpObjectImpl(object, JSObject::Cast(xRef.GetTaggedObject()), isWeak); + return true; +} + +void InterOpValueSerializer::SerializeInterOpObjectImpl(TaggedObject *proxyObject, JSObject *xRefObject, bool isWeak) +{ + if (isWeak) { + data_->WriteEncodeFlag(EncodeFlag::WEAK); + } + if (SerializeReference(proxyObject)) { + return; + } + + JSTaggedValue nativePointer = xRefObject->GetNativePointerByIndex(0); + if (UNLIKELY(nativePointer.IsUndefined())) { + LOG_ECMA(ERROR) << "InterOpValueSerializer: SerializeInterOpObject XRefObject field is not JSNativePointer"; + notSupport_ = true; + return; + } + + ASSERT(nativePointer.IsNativePointer()); + panda::JSNApi::XRefBindingInfo *info = reinterpret_cast( + JSNativePointer::Cast(nativePointer.GetTaggedObject())->GetData()); + if (info == nullptr) { + LOG_ECMA(ERROR) << "InterOpValueSerializer: SerializeInterOpObject XRefBindingInfo is nullptr"; + notSupport_ = true; + return; + } + + AttachXRefFunc attachXRefFunc = reinterpret_cast(info->attachXRefFunc); + void *attachXRefData = info->attachXRefData; + data_->WriteEncodeFlag(EncodeFlag::XREF_BINDING_OBJECT); + data_->WriteJSTaggedType(reinterpret_cast(attachXRefFunc)); + data_->WriteJSTaggedType(reinterpret_cast(attachXRefData)); +} +} // namespace panda::ecmascript + diff --git a/ecmascript/serializer/inter_op_value_serializer.h b/ecmascript/serializer/inter_op_value_serializer.h new file mode 100644 index 0000000000..4a09052405 --- /dev/null +++ b/ecmascript/serializer/inter_op_value_serializer.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_SERIALIZER_INTER_OP_VALUE_SERIALIZER_H +#define ECMASCRIPT_SERIALIZER_INTER_OP_VALUE_SERIALIZER_H + +#include "ecmascript/serializer/value_serializer.h" + +namespace panda::ecmascript { + +class InterOpValueSerializer : public ValueSerializer { +public: + explicit InterOpValueSerializer(JSThread *thread, bool defaultTransfer = false, bool defaultCloneShared = false) + : ValueSerializer(thread, defaultTransfer, defaultCloneShared) {} + ~InterOpValueSerializer() = default; + NO_COPY_SEMANTIC(InterOpValueSerializer); + NO_MOVE_SEMANTIC(InterOpValueSerializer); + +private: + void SerializeObjectImpl(TaggedObject *object, bool isWeak = false) override; + bool TrySerializeInterOpObject(TaggedObject *object, bool isWeak); + void SerializeInterOpObjectImpl(TaggedObject *object, JSObject *xRefObject, bool isWeak); +}; +} + +#endif // ECMASCRIPT_SERIALIZER_INTER_OP_VALUE_SERIALIZER_H \ No newline at end of file diff --git a/ecmascript/serializer/serialize_data.h b/ecmascript/serializer/serialize_data.h index 4d34e8d7e1..826a92bbfe 100644 --- a/ecmascript/serializer/serialize_data.h +++ b/ecmascript/serializer/serialize_data.h @@ -33,6 +33,7 @@ static constexpr int SERIALIZE_SPACE_NUM = 12; typedef void* (*DetachFunc)(void *enginePointer, void *objPointer, void *hint, void *detachData); typedef Local (*AttachFunc)(void *enginePointer, void *buffer, void *hint, void *attachData); +typedef Local (*AttachXRefFunc)(void *enginePointer, void *attachXRefData); typedef void (*DetachFinalizer)(void *detachedObject, void *finalizerHint); struct NativeBindingDetachInfo { @@ -67,6 +68,7 @@ enum class EncodeFlag : uint8_t { SHARED_ARRAY_BUFFER, SENDABLE_ARRAY_BUFFER, NATIVE_BINDING_OBJECT, + XREF_BINDING_OBJECT, // Only support in inter-op. JS_ERROR, JS_REG_EXP, SHARED_OBJECT, diff --git a/ecmascript/serializer/value_serializer.h b/ecmascript/serializer/value_serializer.h index 6378ac7ad9..6fa72155c8 100644 --- a/ecmascript/serializer/value_serializer.h +++ b/ecmascript/serializer/value_serializer.h @@ -41,7 +41,6 @@ protected: virtual bool CheckObjectCanSerialize(TaggedObject *object, bool &findSharedObject); private: - void SerializeObjectImpl(TaggedObject *object, bool isWeak = false) override; virtual bool SerializeSharedObj([[maybe_unused]] TaggedObject *object); void SerializeJSError(TaggedObject *object); void SerializeNativeBindingObject(TaggedObject *object); @@ -69,10 +68,13 @@ private: // process SourceTextModule fields bool SerializeModuleCNativeObjects(TaggedObject *object); +protected: + void SerializeObjectImpl(TaggedObject *object) override; + bool notSupport_ {false}; + private: bool defaultTransfer_ {false}; bool defaultCloneShared_ {false}; - bool notSupport_ {false}; bool supportJSNativePointer_ {false}; std::vector> detachCallbackInfo_; CUnorderedSet transferDataSet_; -- Gitee From 63dfa6577dceecb76a7b7ab1fb6cb29df4d3efc8 Mon Sep 17 00:00:00 2001 From: chentianyu Date: Sat, 28 Jun 2025 20:19:01 +0800 Subject: [PATCH 27/54] fix compile Issue:https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICII8E Signed-off-by: chentianyu Change-Id: I90aa9657f0a05d24270aa61f4e884a78ce58bd81 --- libark_jsruntime.map | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libark_jsruntime.map b/libark_jsruntime.map index 13af66cfaf..2abb6f8faf 100644 --- a/libark_jsruntime.map +++ b/libark_jsruntime.map @@ -116,6 +116,14 @@ common::RegisterVisitStaticRootsHook*; common::RegisterUpdateStaticRootsHook*; common::RegisterSweepStaticRootsHook*; + common::InterOpCoroutineToNative*; + common::InterOpCoroutineToRunning*; + common::RegisterInterOpCoroutineToNativeHook*; + common::RegisterInterOpCoroutineToRunningHook*; + common::RegisterUnmarkAllXRefsHook*; + common::RegisterSweepUnmarkedXRefsHook*; + common::RegisterAddXRefToStaticRootsHook*; + common::RegisterRemoveXRefFromStaticRootsHook*; common::MutatorBase::*; common::Log::*; common::AndroidLog*; -- Gitee From ce9d38ddc7d4654bc5521ceb8419297835ef659c Mon Sep 17 00:00:00 2001 From: ZhouGuangyuan Date: Wed, 11 Jun 2025 22:21:23 +0800 Subject: [PATCH 28/54] sync basestring from 0328 Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICB7FR Signed-off-by: ZhouGuangyuan Change-Id: Iea0d4f68bd04725ceed7fc62f26d637bd7d72ede --- common_components/objects/base_string.cpp | 551 ++++-------------- .../objects/base_string_table.cpp | 52 +- .../objects/composite_base_class.cpp | 10 +- .../objects/string_table/hashtriemap-inl.h | 27 +- .../objects/string_table/hashtriemap.h | 12 +- .../objects/string_table/integer_cache.h | 15 +- .../objects/string_table_internal.h | 8 +- ecmascript/base/json_helper.cpp | 13 +- ecmascript/base/json_helper.h | 7 +- ecmascript/base/number_helper.cpp | 6 +- ecmascript/base/string_helper.h | 7 +- ecmascript/base/tests/json_helper_test.cpp | 28 +- ecmascript/base/tests/number_helper_test.cpp | 8 +- ecmascript/builtins/builtins_number.cpp | 2 +- .../builtins/builtins_string_stub_builder.cpp | 5 +- ecmascript/compiler/circuit_builder.cpp | 4 +- ecmascript/compiler/mcr_circuit_builder.h | 6 +- .../compiler/new_object_stub_builder.cpp | 6 +- .../dfx/hprof/tests/js_metadata_test.cpp | 10 +- ecmascript/ecma_string-inl.h | 93 +-- ecmascript/ecma_string.cpp | 164 +++--- ecmascript/ecma_string.h | 60 +- ecmascript/ecma_string_table.h | 2 +- ecmascript/global_env_constants.cpp | 6 +- ecmascript/js_api/js_api_buffer.cpp | 2 +- ecmascript/js_hclass.h | 12 +- ecmascript/js_tagged_value-inl.h | 2 +- ecmascript/js_tagged_value.cpp | 8 +- ecmascript/mem/c_string.cpp | 6 +- ecmascript/mem/tagged_state_word.h | 5 +- ecmascript/object_factory.h | 2 +- ecmascript/shared_object_factory.cpp | 2 +- ecmascript/stubs/runtime_stubs.cpp | 1 - ecmascript/tests/base_string_test.cpp | 109 ++-- .../tests/dynamic_type_converter_test.cpp | 2 +- ecmascript/tests/js_hclass_test.cpp | 8 + 36 files changed, 485 insertions(+), 776 deletions(-) diff --git a/common_components/objects/base_string.cpp b/common_components/objects/base_string.cpp index 3979df3612..575dbb326e 100644 --- a/common_components/objects/base_string.cpp +++ b/common_components/objects/base_string.cpp @@ -12,454 +12,121 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "common_interfaces/objects/string/base_string.h" -#include -#include - +#include "common_interfaces/objects/string/base_string-inl.h" #include "common_components/base/utf_helper.h" -#include "common_interfaces/objects/base_string.h" - #include "common_components/platform/string_hash.h" #include "common_components/platform/string_hash_helper.h" -namespace common { - constexpr size_t LOW_3BITS = 0x7; - constexpr size_t LOW_4BITS = 0xF; - constexpr size_t LOW_5BITS = 0x1F; - constexpr size_t LOW_6BITS = 0x3F; - constexpr size_t L_SURROGATE_START = 0xDC00; - constexpr size_t H_SURROGATE_START = 0xD800; - constexpr size_t SURROGATE_RAIR_START = 0x10000; - constexpr size_t OFFSET_18POS = 18; - constexpr size_t OFFSET_12POS = 12; - constexpr size_t OFFSET_10POS = 10; - constexpr size_t OFFSET_6POS = 6; - - size_t UtfUtils::DebuggerConvertRegionUtf16ToUtf8(const uint16_t* utf16In, uint8_t* utf8Out, size_t utf16Len, - size_t utf8Len, size_t start, bool modify, bool isWriteBuffer) - { - return common::utf_helper::DebuggerConvertRegionUtf16ToUtf8(utf16In, utf8Out, utf16Len, utf8Len, - start, modify, isWriteBuffer); - } - - size_t UtfUtils::Utf8ToUtf16Size(const uint8_t* utf8, size_t utf8Len) - { - return common::utf_helper::Utf8ToUtf16Size(utf8, utf8Len); - } - - size_t UtfUtils::Utf16ToUtf8Size(const uint16_t* utf16, uint32_t length, bool modify, bool isGetBufferSize, - bool cesu8) - { - return common::utf_helper::Utf16ToUtf8Size(utf16, length, modify, isGetBufferSize, cesu8); - } - - size_t UtfUtils::ConvertRegionUtf8ToUtf16(const uint8_t* utf8In, uint16_t* utf16Out, size_t utf8Len, - size_t utf16Len) - { - return common::utf_helper::ConvertRegionUtf8ToUtf16(utf8In, utf16Out, utf8Len, utf16Len); - } - - size_t UtfUtils::ConvertRegionUtf16ToLatin1(const uint16_t* utf16In, uint8_t* latin1Out, size_t utf16Len, - size_t latin1Len) - { - return common::utf_helper::ConvertRegionUtf16ToLatin1(utf16In, latin1Out, utf16Len, latin1Len); - } - - size_t UtfUtils::ConvertRegionUtf16ToUtf8(const uint16_t* utf16In, uint8_t* utf8Out, size_t utf16Len, - size_t utf8Len, size_t start, bool modify, bool isWriteBuffer, bool cesu) - { - return common::utf_helper::ConvertRegionUtf16ToUtf8( - utf16In, utf8Out, utf16Len, utf8Len, start, modify, isWriteBuffer, cesu); - } - - - // To change the hash algorithm of BaseString, please modify BaseString::CalculateConcatHashCode - // and BaseStringHashHelper::ComputeHashForDataPlatform simultaneously!! - template - uint32_t BaseString::ComputeHashForData(const T* data, size_t size, - uint32_t hashSeed) - { - if (size <= static_cast(StringHash::MIN_SIZE_FOR_UNROLLING)) { - uint32_t hash = hashSeed; - for (uint32_t i = 0; i < size; i++) { - hash = (hash << static_cast(StringHash::HASH_SHIFT)) - hash + data[i]; - } - return hash; - } - return StringHashHelper::ComputeHashForDataPlatform(data, size, hashSeed); - } - - template - uint32_t BaseString::ComputeHashForData(const uint8_t*, size_t, uint32_t); - template - uint32_t BaseString::ComputeHashForData(const uint16_t*, size_t, uint32_t); - - - /* static */ - uint32_t BaseString::ComputeHashcodeUtf8(const uint8_t* utf8Data, size_t utf8Len, bool canBeCompress) - { - if (canBeCompress) { - return ComputeHashForData(utf8Data, utf8Len, 0); - } - auto utf16Len = UtfUtils::Utf8ToUtf16Size(utf8Data, utf8Len); - std::vector tmpBuffer(utf16Len); - [[maybe_unused]] auto len = UtfUtils::ConvertRegionUtf8ToUtf16(utf8Data, tmpBuffer.data(), utf8Len, - utf16Len); - DCHECK_CC(len == utf16Len); - return ComputeHashForData(tmpBuffer.data(), utf16Len, 0); - } - - /* static */ - uint32_t BaseString::ComputeHashcodeUtf16(const uint16_t* utf16Data, uint32_t length) - { - return ComputeHashForData(utf16Data, length, 0); - } - - - // drop the tail bytes if the remain length can't fill the length it represents. - static size_t FixUtf8Len(const uint8_t* utf8, size_t utf8Len) - { - constexpr size_t TWO_BYTES_LENGTH = 2; - constexpr size_t THREE_BYTES_LENGTH = 3; - size_t trimSize = 0; - if (utf8Len >= 1 && utf8[utf8Len - 1] >= 0xC0) { - // The last one char claim there are more than 1 byte next to it, it's invalid, so drop the last one. - trimSize = 1; - } - if (utf8Len >= TWO_BYTES_LENGTH && utf8[utf8Len - TWO_BYTES_LENGTH] >= 0xE0) { - // The second to last char claim there are more than 2 bytes next to it, it's invalid, so drop the last two. - trimSize = TWO_BYTES_LENGTH; - } - if (utf8Len >= THREE_BYTES_LENGTH && utf8[utf8Len - THREE_BYTES_LENGTH] >= 0xF0) { - // The third to last char claim there are more than 3 bytes next to it, it's invalid, so drop the last - // three. - trimSize = THREE_BYTES_LENGTH; - } - return utf8Len - trimSize; - } - - /* static */ - bool BaseString::IsUtf8EqualsUtf16(const uint8_t* utf8Data, size_t utf8Len, - const uint16_t* utf16Data, uint32_t utf16Len) - { - size_t safeUtf8Len = FixUtf8Len(utf8Data, utf8Len); - const uint8_t* utf8End = utf8Data + utf8Len; - const uint8_t* utf8SafeEnd = utf8Data + safeUtf8Len; - const uint16_t* utf16End = utf16Data + utf16Len; - while (utf8Data < utf8SafeEnd && utf16Data < utf16End) { - uint8_t src = *utf8Data; - switch (src & 0xF0) { - case 0xF0: - { - const uint8_t c2 = *(++utf8Data); - const uint8_t c3 = *(++utf8Data); - const uint8_t c4 = *(++utf8Data); - uint32_t codePoint = ((src & LOW_3BITS) << OFFSET_18POS) | ((c2 & LOW_6BITS) << OFFSET_12POS) | - ((c3 & LOW_6BITS) << OFFSET_6POS) | (c4 & LOW_6BITS); - if (codePoint >= SURROGATE_RAIR_START) { - if (utf16Data >= utf16End - 1) { - return false; - } - codePoint -= SURROGATE_RAIR_START; - if (*utf16Data++ != static_cast((codePoint >> OFFSET_10POS) | - H_SURROGATE_START)) { - return false; - } else if (*utf16Data++ != static_cast((codePoint & 0x3FF) | L_SURROGATE_START)) { - return false; - } - } else { - if (*utf16Data++ != static_cast(codePoint)) { - return false; - } - } - utf8Data++; - break; - } - case 0xE0: - { - const uint8_t c2 = *(++utf8Data); - const uint8_t c3 = *(++utf8Data); - if (*utf16Data++ != static_cast(((src & LOW_4BITS) << OFFSET_12POS) | - ((c2 & LOW_6BITS) << OFFSET_6POS) | (c3 & LOW_6BITS))) { - return false; - } - utf8Data++; - break; - } - case 0xD0: - case 0xC0: - { - const uint8_t c2 = *(++utf8Data); - if (*utf16Data++ != static_cast(((src & LOW_5BITS) << OFFSET_6POS) | (c2 & - LOW_6BITS))) { - return false; - } - utf8Data++; - break; - } - default: - do { - if (*utf16Data++ != static_cast(*utf8Data++)) { - return false; - } - } - while (utf8Data < utf8SafeEnd && utf16Data < utf16End && *utf8Data < 0x80); - break; - } - } - // The remain chars should be treated as single byte char. - while (utf8Data < utf8End && utf16Data < utf16End) { - if (*utf16Data++ != static_cast(*utf8Data++)) { - return false; - } - } - return utf8Data == utf8End && utf16Data == utf16End; - } - - // static - template - uint32_t BaseString::CalculateDataConcatHashCode(const T1* dataFirst, size_t sizeFirst, - const T2* dataSecond, size_t sizeSecond) - { - uint32_t totalHash = ComputeHashForData(dataFirst, sizeFirst, 0); - totalHash = ComputeHashForData(dataSecond, sizeSecond, totalHash); - return totalHash; - } - - template - uint32_t BaseString::CalculateDataConcatHashCode(const uint8_t* dataFirst, size_t sizeFirst, - const uint8_t* dataSecond, size_t sizeSecond); - template - uint32_t BaseString::CalculateDataConcatHashCode(const uint16_t* dataFirst, size_t sizeFirst, - const uint16_t* dataSecond, size_t sizeSecond); - template - uint32_t BaseString::CalculateDataConcatHashCode(const uint8_t* dataFirst, size_t sizeFirst, - const uint16_t* dataSecond, size_t sizeSecond); - template - uint32_t BaseString::CalculateDataConcatHashCode(const uint16_t* dataFirst, size_t sizeFirst, - const uint8_t* dataSecond, size_t sizeSecond); - - - bool BaseString::CanBeCompressed(const BaseString* string) - { - DCHECK_CC(string->IsLineString()); - if (string->IsUtf8()) { - return CanBeCompressed(string->GetDataUtf8(), string->GetLength()); - } - return CanBeCompressed(string->GetDataUtf16(), string->GetLength()); - } - - // static - bool BaseString::CanBeCompressed(const uint8_t* utf8Data, uint32_t utf8Len) - { - uint32_t index = 0; - for (; index + 4 <= utf8Len; index += 4) { - // 4: process the data in chunks of 4 elements to improve speed - // Check if all four characters in the current block are ASCII characters - if (!IsASCIICharacter(utf8Data[index]) || - !IsASCIICharacter(utf8Data[index + 1]) || // 1: the second element of the block - !IsASCIICharacter(utf8Data[index + 2]) || // 2: the third element of the block - !IsASCIICharacter(utf8Data[index + 3])) { - // 3: the fourth element of the block - return false; - } - } - // Check remaining characters if they are ASCII - for (; index < utf8Len; ++index) { - if (!IsASCIICharacter(utf8Data[index])) { - return false; - } - } - return true; - } - - /* static */ - bool BaseString::CanBeCompressed(const uint16_t* utf16Data, uint32_t utf16Len) - { - uint32_t index = 0; - for (; index + 4 <= utf16Len; index += 4) { - // 4: process the data in chunks of 4 elements to improve speed - // Check if all four characters in the current block are ASCII characters - if (!IsASCIICharacter(utf16Data[index]) || - !IsASCIICharacter(utf16Data[index + 1]) || // 1: the second element of the block - !IsASCIICharacter(utf16Data[index + 2]) || // 2: the third element of the block - !IsASCIICharacter(utf16Data[index + 3])) { - // 3: the fourth element of the block - return false; - } - } - // Check remaining characters if they are ASCII - for (; index < utf16Len; ++index) { - if (!IsASCIICharacter(utf16Data[index])) { - return false; - } - } - return true; - } - +#include +#include - bool BaseString::IsASCIICharacter(uint16_t data) - { - if (data == 0) { +namespace common { +size_t UtfUtils::DebuggerConvertRegionUtf16ToUtf8(const uint16_t* utf16In, uint8_t* utf8Out, size_t utf16Len, + size_t utf8Len, size_t start, bool modify, bool isWriteBuffer) +{ + return utf_helper::DebuggerConvertRegionUtf16ToUtf8(utf16In, utf8Out, utf16Len, utf8Len, start, modify, + isWriteBuffer); +} + +size_t UtfUtils::ConvertRegionUtf16ToLatin1(const uint16_t* utf16In, uint8_t* latin1Out, size_t utf16Len, + size_t latin1Len) +{ + return utf_helper::ConvertRegionUtf16ToLatin1(utf16In, latin1Out, utf16Len, latin1Len); +} + +// To change the hash algorithm of BaseString, please modify BaseString::CalculateConcatHashCode +// and BaseStringHashHelper::ComputeHashForDataPlatform simultaneously!! +template +uint32_t BaseString::ComputeHashForData(const T* data, size_t size, + uint32_t hashSeed) +{ + if (size <= static_cast(StringHash::MIN_SIZE_FOR_UNROLLING)) { + uint32_t hash = hashSeed; + for (uint32_t i = 0; i < size; i++) { + hash = (hash << static_cast(StringHash::HASH_SHIFT)) - hash + data[i]; + } + return hash; + } + return StringHashHelper::ComputeHashForDataPlatform(data, size, hashSeed); +} + +template +uint32_t BaseString::ComputeHashForData(const uint8_t*, size_t, uint32_t); +template +uint32_t BaseString::ComputeHashForData(const uint16_t*, size_t, uint32_t); + + +// static +template +uint32_t BaseString::CalculateDataConcatHashCode(const T1* dataFirst, size_t sizeFirst, + const T2* dataSecond, size_t sizeSecond) +{ + uint32_t totalHash = ComputeHashForData(dataFirst, sizeFirst, 0); + totalHash = ComputeHashForData(dataSecond, sizeSecond, totalHash); + return totalHash; +} + +template +uint32_t BaseString::CalculateDataConcatHashCode(const uint8_t* dataFirst, size_t sizeFirst, + const uint8_t* dataSecond, size_t sizeSecond); +template +uint32_t BaseString::CalculateDataConcatHashCode(const uint16_t* dataFirst, size_t sizeFirst, + const uint16_t* dataSecond, size_t sizeSecond); +template +uint32_t BaseString::CalculateDataConcatHashCode(const uint8_t* dataFirst, size_t sizeFirst, + const uint16_t* dataSecond, size_t sizeSecond); +template +uint32_t BaseString::CalculateDataConcatHashCode(const uint16_t* dataFirst, size_t sizeFirst, + const uint8_t* dataSecond, size_t sizeSecond); + + +template +bool IsSubStringAtSpan(common::Span& lhsSp, common::Span& rhsSp, uint32_t offset) +{ + size_t rhsSize = rhsSp.size(); + DCHECK_CC(rhsSize + offset <= lhsSp.size()); + for (size_t i = 0; i < rhsSize; ++i) { + auto left = static_cast(lhsSp[offset + static_cast(i)]); + auto right = static_cast(rhsSp[i]); + if (left != right) { return false; } - // \0 is not considered ASCII in Ecma-Modified-UTF8 [only modify '\u0000'] - return data <= UtfUtils::UTF8_1B_MAX; - } - - - /* static */ - template - int32_t BaseString::IndexOf(Span& lhsSp, Span& rhsSp, int32_t pos, int32_t max) - { - DCHECK_CC(rhsSp.size() > 0); - auto first = static_cast(rhsSp[0]); - for (int32_t i = pos; i <= max; i++) { - if (static_cast(lhsSp[i]) != first) { - i++; - while (i <= max && static_cast(lhsSp[i]) != first) { - i++; - } - } - /* Found first character, now look at the rest of rhsSp */ - if (i <= max) { - int j = i + 1; - int end = j + static_cast(rhsSp.size()) - 1; - - for (int k = 1; j < end && static_cast(lhsSp[j]) == static_cast(rhsSp[k]); j++, k++) { - } - if (j == end) { - /* Found whole string. */ - return i; - } - } - } - return -1; - } - - template - int32_t BaseString::IndexOf(Span& lhsSp, Span& rhsSp, int32_t pos, - int32_t max); - template - int32_t BaseString::IndexOf(Span& lhsSp, Span& rhsSp, - int32_t pos, int32_t max); - - template - int32_t BaseString::IndexOf(Span& lhsSp, Span& rhsSp, int32_t pos, - int32_t max); - - template - int32_t BaseString::IndexOf(Span& lhsSp, Span& rhsSp, int32_t pos, - int32_t max); - - - template - int32_t BaseString::LastIndexOf(Span& lhsSp, Span& rhsSp, int32_t pos) - { - int rhsSize = static_cast(rhsSp.size()); - DCHECK_CC(rhsSize > 0); - auto first = rhsSp[0]; - for (int32_t i = pos; i >= 0; i--) { - if (lhsSp[i] != first) { - continue; - } - /* Found first character, now look at the rest of rhsSp */ - int j = 1; - while (j < rhsSize) { - if (rhsSp[j] != lhsSp[i + j]) { - break; - } - j++; - } - if (j == rhsSize) { - return i; - } - } - return -1; - } - - template - int32_t BaseString::LastIndexOf(Span& lhsSp, Span& rhsSp, - int32_t pos); - template - int32_t BaseString::LastIndexOf(Span& lhsSp, Span& rhsSp, - int32_t pos); - template - int32_t BaseString::LastIndexOf(Span& lhsSp, Span& rhsSp, - int32_t pos); - template - int32_t BaseString::LastIndexOf(Span& lhsSp, Span& rhsSp, - int32_t pos); - - - template - int32_t CompareStringSpan(Span& lhsSp, Span& rhsSp, int32_t count) - { - for (int32_t i = 0; i < count; ++i) { - auto left = static_cast(lhsSp[i]); - auto right = static_cast(rhsSp[i]); - if (left != right) { - return left - right; - } - } - return 0; - } - - template - int32_t CompareStringSpan(Span& lhsSp, Span& rhsSp, - int32_t count); - template - int32_t CompareStringSpan(Span& lhsSp, Span& rhsSp, - int32_t count); - template - int32_t CompareStringSpan(Span& lhsSp, Span& rhsSp, - int32_t count); - template - int32_t CompareStringSpan(Span& lhsSp, Span& rhsSp, - int32_t count); - - - template - bool IsSubStringAtSpan(Span& lhsSp, Span& rhsSp, uint32_t offset) - { - int rhsSize = static_cast(rhsSp.size()); - DCHECK_CC(rhsSize + offset <= lhsSp.size()); - for (int i = 0; i < rhsSize; ++i) { - auto left = static_cast(lhsSp[offset + static_cast(i)]); - auto right = static_cast(rhsSp[i]); - if (left != right) { - return false; - } - } - return true; - } - - template - bool IsSubStringAtSpan(Span& lhsSp, Span& rhsSp, - uint32_t offset); - template - bool IsSubStringAtSpan(Span& lhsSp, Span& rhsSp, - uint32_t offset); - template - bool IsSubStringAtSpan(Span& lhsSp, Span& rhsSp, - uint32_t offset); - template - bool IsSubStringAtSpan(Span& lhsSp, Span& rhsSp, - uint32_t offset); - - - std::u16string Utf16ToU16String(const uint16_t* utf16Data, uint32_t dataLen) - { - auto* char16tData = reinterpret_cast(utf16Data); - std::u16string u16str(char16tData, dataLen); - return u16str; - } - - std::u16string Utf8ToU16String(const uint8_t* utf8Data, uint32_t dataLen) - { - auto* charData = reinterpret_cast(utf8Data); - std::string str(charData, dataLen); - std::u16string u16str = std::wstring_convert, char16_t>{}.from_bytes(str); - return u16str; } -} // namespace common + return true; +} + +template +bool IsSubStringAtSpan(common::Span& lhsSp, + common::Span& rhsSp, + uint32_t offset); +template +bool IsSubStringAtSpan(common::Span& lhsSp, + common::Span& rhsSp, + uint32_t offset); +template +bool IsSubStringAtSpan(common::Span& lhsSp, + common::Span& rhsSp, + uint32_t offset); +template +bool IsSubStringAtSpan(common::Span& lhsSp, + common::Span& rhsSp, + uint32_t offset); + + +std::u16string Utf16ToU16String(const uint16_t* utf16Data, uint32_t dataLen) +{ + auto* char16tData = reinterpret_cast(utf16Data); + std::u16string u16str(char16tData, dataLen); + return u16str; +} + +std::u16string Utf8ToU16String(const uint8_t* utf8Data, uint32_t dataLen) +{ + auto* charData = reinterpret_cast(utf8Data); + std::string str(charData, dataLen); + std::u16string u16str = std::wstring_convert, char16_t>{}.from_bytes(str); + return u16str; +} +} // namespace common diff --git a/common_components/objects/base_string_table.cpp b/common_components/objects/base_string_table.cpp index d00397679a..72c9f33d7a 100644 --- a/common_components/objects/base_string_table.cpp +++ b/common_components/objects/base_string_table.cpp @@ -22,7 +22,7 @@ #include "common_components/objects/string_table_internal.h" #include "common_components/taskpool/taskpool.h" #include "common_components/mutator/thread_local.h" -#include "common_interfaces/objects/base_string.h" +#include "common_interfaces/objects/string/base_string.h" #include "common_interfaces/thread/thread_holder.h" #include "common_interfaces/thread/thread_state_transition.h" #include "heap/heap_allocator.h" @@ -38,7 +38,7 @@ BaseString* BaseStringTableInternal::AllocateLineStringObject(s } else { str = reinterpret_cast(HeapAllocator::AllocateInOld(size, LanguageType::DYNAMIC)); } - BaseClass* cls = BaseRuntime::GetInstance()->GetBaseClassRoots().GetBaseClass(CommonType::LINE_STRING); + BaseClass* cls = BaseRuntime::GetInstance()->GetBaseClassRoots().GetBaseClass(ObjectType::LINE_STRING); str->SetFullBaseClassWithoutBarrier(cls); return str; } @@ -48,7 +48,7 @@ BaseString* BaseStringTableInternal::GetOrInternFlattenString( ThreadHolder* holder, const HandleCreator& handleCreator, BaseString* string) { - ASSERT(string->NotTreeString()); + DCHECK_CC(!string->IsTreeString()); if (string->IsInternString()) { return string; } @@ -66,7 +66,7 @@ BaseString* BaseStringTableInternal::GetOrInternFlattenString( ReadOnlyHandle stringHandle = handleCreator(holder, string); BaseString* result = stringTable_.template StoreOrLoad( holder, readBarrier, hashcode, loadResult, stringHandle); - ASSERT(result != nullptr); + DCHECK_CC(result != nullptr); return result; } @@ -76,7 +76,7 @@ BaseString* BaseStringTableInternal::GetOrInternStringFromCompr const ReadOnlyHandle& string, uint32_t offset, uint32_t utf8Len) { - const uint8_t* utf8Data = string->GetDataUtf8() + offset; + const uint8_t* utf8Data = ReadOnlyHandle::Cast(string)->GetDataUtf8() + offset; uint32_t hashcode = BaseString::ComputeHashcodeUtf8(utf8Data, utf8Len, true); auto readBarrier = [](void* obj, size_t offset)-> BaseObject* { return BaseObject::Cast( @@ -87,24 +87,24 @@ BaseString* BaseStringTableInternal::GetOrInternStringFromCompr if (loadResult.value != nullptr) { return loadResult.value; } - auto allocator = [](size_t size, CommonType type)-> BaseString* { - ASSERT(type == CommonType::LINE_STRING); + auto allocator = [](size_t size, ObjectType type)-> BaseString* { + DCHECK_CC(type == ObjectType::LINE_STRING); return AllocateLineStringObject(size); }; BaseString* result = stringTable_.template StoreOrLoad( holder, hashcode, loadResult, [holder, string, offset, utf8Len, hashcode, handleCreator, allocator]() { - BaseString* str = BaseString::CreateFromUtf8CompressedSubString( + BaseString* str = LineString::CreateFromUtf8CompressedSubString( std::move(allocator), string, offset, utf8Len); str->SetRawHashcode(hashcode); - ASSERT(!str->IsInternString()); - ASSERT(str->NotTreeString()); + DCHECK_CC(!str->IsInternString()); + DCHECK_CC(!str->IsTreeString()); // Strings in string table should not be in the young space. ReadOnlyHandle strHandle = handleCreator(holder, str); return strHandle; }, [utf8Len, string, offset](const BaseString* foundString) { - const uint8_t* utf8Data = string->GetDataUtf8() + offset; + const uint8_t* utf8Data = ReadOnlyHandle::Cast(string)->GetDataUtf8() + offset; auto readBarrier = [](void* obj, size_t offset)-> BaseObject* { return BaseObject::Cast( reinterpret_cast(BaseRuntime::ReadBarrier( @@ -112,7 +112,7 @@ BaseString* BaseStringTableInternal::GetOrInternStringFromCompr }; return BaseString::StringIsEqualUint8Data(readBarrier, foundString, utf8Data, utf8Len, true); }); - ASSERT(result != nullptr); + DCHECK_CC(result != nullptr); return result; } @@ -124,17 +124,17 @@ BaseString* BaseStringTableInternal::GetOrInternString(ThreadHo bool canBeCompress) { uint32_t hashcode = BaseString::ComputeHashcodeUtf8(utf8Data, utf8Len, canBeCompress); - auto allocator = [](size_t size, CommonType type)-> BaseString* { - ASSERT(type == CommonType::LINE_STRING); + auto allocator = [](size_t size, ObjectType type)-> BaseString* { + DCHECK_CC(type == ObjectType::LINE_STRING); return AllocateLineStringObject(size); }; BaseString* result = stringTable_.template LoadOrStore( holder, hashcode, [holder, hashcode, utf8Data, utf8Len, canBeCompress, handleCreator, allocator]() { - BaseString* value = BaseString::CreateFromUtf8(std::move(allocator), utf8Data, utf8Len, canBeCompress); + BaseString* value = LineString::CreateFromUtf8(std::move(allocator), utf8Data, utf8Len, canBeCompress); value->SetRawHashcode(hashcode); - ASSERT(!value->IsInternString()); - ASSERT(value->NotTreeString()); + DCHECK_CC(!value->IsInternString()); + DCHECK_CC(!value->IsTreeString()); ReadOnlyHandle stringHandle = handleCreator(holder, value); return stringHandle; }, @@ -147,7 +147,7 @@ BaseString* BaseStringTableInternal::GetOrInternString(ThreadHo return BaseString::StringIsEqualUint8Data(readBarrier, foundString, utf8Data, utf8Len, canBeCompress); }); - ASSERT(result != nullptr); + DCHECK_CC(result != nullptr); return result; } @@ -158,18 +158,18 @@ BaseString* BaseStringTableInternal::GetOrInternString( bool canBeCompress) { uint32_t hashcode = BaseString::ComputeHashcodeUtf16(const_cast(utf16Data), utf16Len); - auto allocator = [](size_t size, CommonType type)-> BaseString* { - ASSERT(type == CommonType::LINE_STRING); + auto allocator = [](size_t size, ObjectType type)-> BaseString* { + DCHECK_CC(type == ObjectType::LINE_STRING); return AllocateLineStringObject(size); }; BaseString* result = stringTable_.template LoadOrStore( holder, hashcode, [holder, utf16Data, utf16Len, canBeCompress, hashcode, handleCreator, allocator]() { - BaseString* value = BaseString::CreateFromUtf16(std::move(allocator), utf16Data, utf16Len, + BaseString* value = LineString::CreateFromUtf16(std::move(allocator), utf16Data, utf16Len, canBeCompress); value->SetRawHashcode(hashcode); - ASSERT(!value->IsInternString()); - ASSERT(value->NotTreeString()); + DCHECK_CC(!value->IsInternString()); + DCHECK_CC(!value->IsTreeString()); // Strings in string table should not be in the young space. ReadOnlyHandle stringHandle = handleCreator(holder, value); return stringHandle; @@ -182,7 +182,7 @@ BaseString* BaseStringTableInternal::GetOrInternString( }; return BaseString::StringsAreEqualUtf16(readBarrier, foundString, utf16Data, utf16Len); }); - ASSERT(result != nullptr); + DCHECK_CC(result != nullptr); return result; } @@ -203,7 +203,7 @@ template > void BaseStringTableInternal::SweepWeakRef(const WeakRefFieldVisitor& visitor, uint32_t index, std::vector& waitDeleteEntries) { - ASSERT(index >= 0 && index < TrieMapConfig::INDIRECT_SIZE); + DCHECK_CC(index >= 0 && index < TrieMapConfig::INDIRECT_SIZE); auto* rootNode = stringTable_.root_.load(std::memory_order_relaxed); stringTable_.ClearNodeFromGC(rootNode, index, visitor, waitDeleteEntries); } @@ -219,7 +219,7 @@ template template > void BaseStringTableInternal::SweepWeakRef(const WeakRefFieldVisitor& visitor, uint32_t index) { - ASSERT(index >= 0 && index < TrieMapConfig::INDIRECT_SIZE); + DCHECK_CC(index >= 0 && index < TrieMapConfig::INDIRECT_SIZE); auto* rootNode = stringTable_.root_.load(std::memory_order_relaxed); stringTable_.ClearNodeFromGC(rootNode, index, visitor); } diff --git a/common_components/objects/composite_base_class.cpp b/common_components/objects/composite_base_class.cpp index c1d2b8fb9c..e014bdfb37 100644 --- a/common_components/objects/composite_base_class.cpp +++ b/common_components/objects/composite_base_class.cpp @@ -25,12 +25,12 @@ void BaseClassRoots::InitializeCompositeBaseClass(CompositeBaseClassAllocator &a if (initialized_.exchange(true)) { return; } - CreateCompositeBaseClass(CommonType::LINE_STRING, allocator); - CreateCompositeBaseClass(CommonType::SLICED_STRING, allocator); - CreateCompositeBaseClass(CommonType::TREE_STRING, allocator); + CreateCompositeBaseClass(ObjectType::LINE_STRING, allocator); + CreateCompositeBaseClass(ObjectType::SLICED_STRING, allocator); + CreateCompositeBaseClass(ObjectType::TREE_STRING, allocator); } -void BaseClassRoots::CreateCompositeBaseClass(CommonType type, CompositeBaseClassAllocator& allocator) +void BaseClassRoots::CreateCompositeBaseClass(ObjectType type, CompositeBaseClassAllocator& allocator) { CompositeBaseClass* classObject = allocator(); classObject->class_.ClearBitField(); @@ -40,7 +40,7 @@ void BaseClassRoots::CreateCompositeBaseClass(CommonType type, CompositeBaseClas baseClasses_[index] = &classObject->class_; } -BaseClass* BaseClassRoots::GetBaseClass(CommonType type) const +BaseClass* BaseClassRoots::GetBaseClass(ObjectType type) const { return baseClasses_[TypeToIndex[static_cast(type)]]; } diff --git a/common_components/objects/string_table/hashtriemap-inl.h b/common_components/objects/string_table/hashtriemap-inl.h index 8d25c64227..e771c3973f 100644 --- a/common_components/objects/string_table/hashtriemap-inl.h +++ b/common_components/objects/string_table/hashtriemap-inl.h @@ -18,7 +18,8 @@ #include "common_components/log/log.h" #include "common_interfaces/objects/readonly_handle.h" -#include "common_interfaces/objects/base_string.h" +#include "common_interfaces/objects/string/base_string.h" +#include "common_interfaces/objects/string/line_string-inl.h" #include "common_components/objects/string_table/hashtriemap.h" #include "common_components/objects/string_table/integer_cache.h" @@ -50,7 +51,7 @@ typename HashTrieMap::Node* HashTrieMap::Load(ReadBarrier&& re } LOG_COMMON(FATAL) << "StringTable: ran out of hash bits while iterating"; - UNREACHABLE(); + UNREACHABLE_CC(); } // LoadOrStore returns the existing value of the key, if it exists. @@ -173,7 +174,7 @@ BaseString* HashTrieMap::LoadOrStore(ThreadHol #ifndef NDEBUG if (!haveInsertPoint) { LOG_COMMON(FATAL) << "StringTable: ran out of hash bits while iterating"; - UNREACHABLE(); + UNREACHABLE_CC(); } #endif // invoke the callback to create str @@ -186,7 +187,7 @@ BaseString* HashTrieMap::LoadOrStore(ThreadHol GetMutex().LockWithThreadState(holder); } - ASSERT(slot != nullptr); + DCHECK_CC(slot != nullptr); node = slot->load(std::memory_order_acquire); if (node == nullptr || node->IsEntry()) { // see is still real, so can continue to insert. @@ -294,14 +295,14 @@ BaseString* HashTrieMap::LoadOrStoreForJit(Thr #ifndef NDEBUG if (!haveInsertPoint) { LOG_COMMON(FATAL) << "StringTable: ran out of hash bits while iterating"; - UNREACHABLE(); + UNREACHABLE_CC(); } #endif // Jit need to lock the object before creating the object GetMutex().LockWithThreadState(holder); // invoke the callback to create str value = std::invoke(std::forward(loaderCallback)); - ASSERT(slot != nullptr); + DCHECK_CC(slot != nullptr); node = slot->load(std::memory_order_acquire); if (node == nullptr || node->IsEntry()) { // see is still real, so can continue to insert. @@ -405,7 +406,7 @@ BaseString* HashTrieMap::StoreOrLoad(ThreadHol #ifndef NDEBUG if (!haveInsertPoint) { LOG_COMMON(FATAL) << "StringTable: ran out of hash bits while iterating"; - UNREACHABLE(); + UNREACHABLE_CC(); } #endif // lock and double-check @@ -495,7 +496,7 @@ HashTrieMapLoadResult HashTrieMap::Load(ReadBa } LOG_COMMON(FATAL) << "StringTable: ran out of hash bits while iterating"; - UNREACHABLE(); + UNREACHABLE_CC(); } // Load returns the value of the key stored in the mapping, or HashTrieMapLoadResult for StoreOrLoad @@ -507,7 +508,7 @@ HashTrieMapLoadResult HashTrieMap::Load(ReadBa { uint32_t hash = key; Indirect* current = root_.load(std::memory_order_relaxed); - const uint8_t* utf8Data = string->GetDataUtf8() + offset; + const uint8_t* utf8Data = ReadOnlyHandle::Cast(string)->GetDataUtf8() + offset; for (uint32_t hashShift = 0; hashShift < TrieMapConfig::TOTAL_HASH_BITS; hashShift += TrieMapConfig::N_CHILDREN_LOG2) { size_t index = (hash >> hashShift) & TrieMapConfig::N_CHILDREN_MASK; @@ -539,7 +540,7 @@ HashTrieMapLoadResult HashTrieMap::Load(ReadBa } LOG_COMMON(FATAL) << "StringTable: ran out of hash bits while iterating"; - UNREACHABLE(); + UNREACHABLE_CC(); } // Based on the loadResult, try the store first @@ -603,7 +604,7 @@ BaseString* HashTrieMap::StoreOrLoad(ThreadHol #ifndef NDEBUG if (!haveInsertPoint) { LOG_COMMON(FATAL) << "StringTable: ran out of hash bits while iterating"; - UNREACHABLE(); + UNREACHABLE_CC(); } #endif // lock and double-check @@ -682,7 +683,7 @@ template bool HashTrieMap::CheckValidity(ReadBarrier&& readBarrier, BaseString* value, bool& isValid) { - if (!value->NotTreeString()) { + if (value->IsTreeString()) { isValid = false; return false; } diff --git a/common_components/objects/string_table/hashtriemap.h b/common_components/objects/string_table/hashtriemap.h index e5e8eb0c18..f79c452bcc 100644 --- a/common_components/objects/string_table/hashtriemap.h +++ b/common_components/objects/string_table/hashtriemap.h @@ -18,8 +18,10 @@ #include "common_components/heap/heap.h" #include "common_components/log/log.h" +#include "common_interfaces/base/common.h" #include "common_interfaces/objects/readonly_handle.h" -#include "common_interfaces/objects/base_string.h" +#include "common_interfaces/objects/string/base_string.h" +#include "common_interfaces/objects/string/base_string-inl.h" namespace panda::ecmascript { class TaggedObject; @@ -141,13 +143,13 @@ struct HashTrieMapLoadResult { inline HashTrieMapEntry* HashTrieMapNode::AsEntry() { - ASSERT(isEntry_ && "HashTrieMap: called entry on non-entry node"); + DCHECK_CC(isEntry_ && "HashTrieMap: called entry on non-entry node"); return static_cast(this); } inline HashTrieMapIndirect* HashTrieMapNode::AsIndirect() { - ASSERT(!isEntry_ && "HashTrieMap: called indirect on entry node"); + DCHECK_CC(!isEntry_ && "HashTrieMap: called indirect on entry node"); return static_cast(this); } @@ -323,8 +325,8 @@ public: hashTrieMap_->DecreaseInuseCount(); } - NO_COPY_SEMANTIC(HashTrieMapInUseScope); - NO_MOVE_SEMANTIC(HashTrieMapInUseScope); + NO_COPY_SEMANTIC_CC(HashTrieMapInUseScope); + NO_MOVE_SEMANTIC_CC(HashTrieMapInUseScope); private: HashTrieMap* hashTrieMap_; diff --git a/common_components/objects/string_table/integer_cache.h b/common_components/objects/string_table/integer_cache.h index 0c875414bb..28b572cd3d 100644 --- a/common_components/objects/string_table/integer_cache.h +++ b/common_components/objects/string_table/integer_cache.h @@ -17,7 +17,7 @@ #define COMMON_COMPONENTS_OBJECTS_STRING_TABLE_INTEGER_CACHE_H #include -#include "common_interfaces/objects/base_string.h" +#include "common_interfaces/objects/string/line_string-inl.h" namespace common { @@ -30,8 +30,8 @@ namespace common { +--------------+--------------+ */ class IntegerCache final { -static constexpr size_t OBJECT_ALIGN = 8; -static_assert(LineString::DATA_OFFSET % OBJECT_ALIGN == 0); + static constexpr size_t OBJECT_ALIGN = 8; + static_assert(LineString::DATA_OFFSET % OBJECT_ALIGN == 0); public: NO_MOVE_SEMANTIC_CC(IntegerCache); @@ -42,7 +42,8 @@ public: static void InitIntegerCache(BaseString* string) { - if (string->IsUtf8() && string->GetLength() <= MAX_INTEGER_CACHE_SIZE && string->GetLength() > 0) { + if (string->IsUtf8() && string->GetLength() <= MAX_INTEGER_CACHE_SIZE && string->GetLength() > 0 && + string->IsLineString()) { IntegerCache* cache = Extract(string); cache->isInteger_ = 0; } @@ -50,9 +51,9 @@ public: static IntegerCache* Extract(BaseString* string) { - DCHECK_CC(string->IsUtf8() && string->GetLength() <= MAX_INTEGER_CACHE_SIZE - && string->GetLength() > 0 && string->IsInternString()); - IntegerCache* cache = reinterpret_cast(string->GetData()); + DCHECK_CC(string->IsUtf8() && string->GetLength() <= MAX_INTEGER_CACHE_SIZE && string->GetLength() > 0 && + string->IsLineString()); + IntegerCache* cache = reinterpret_cast(LineString::Cast(string)->GetData()); return cache; } diff --git a/common_components/objects/string_table_internal.h b/common_components/objects/string_table_internal.h index 1747c9e42a..6a61cd84a3 100644 --- a/common_components/objects/string_table_internal.h +++ b/common_components/objects/string_table_internal.h @@ -71,8 +71,8 @@ public: void CleanUp(); private: - NO_COPY_SEMANTIC(BaseStringTableCleaner); - NO_MOVE_SEMANTIC(BaseStringTableCleaner); + NO_COPY_SEMANTIC_CC(BaseStringTableCleaner); + NO_MOVE_SEMANTIC_CC(BaseStringTableCleaner); static void ProcessSweepWeakRef(IteratorPtr &iter, BaseStringTableCleaner *cleaner, const WeakRefFieldVisitor &visitor); @@ -100,8 +100,8 @@ private: bool Run(uint32_t threadIndex) override; - NO_COPY_SEMANTIC(CMCSweepWeakRefTask); - NO_MOVE_SEMANTIC(CMCSweepWeakRefTask); + NO_COPY_SEMANTIC_CC(CMCSweepWeakRefTask); + NO_MOVE_SEMANTIC_CC(CMCSweepWeakRefTask); private: IteratorPtr iter_; diff --git a/ecmascript/base/json_helper.cpp b/ecmascript/base/json_helper.cpp index 42e809eda3..35bb4d7b8d 100644 --- a/ecmascript/base/json_helper.cpp +++ b/ecmascript/base/json_helper.cpp @@ -68,7 +68,7 @@ bool DoNotEscape(uint16_t c) (c >= 0x23 && c != 0x5C && (c < 0xD800 || c > 0xDFFF)); } -bool JsonHelper::IsFastValueToQuotedString(const Span &sp) +bool JsonHelper::IsFastValueToQuotedString(const common::Span &sp) { for (const auto utf8Ch : sp) { if (!DoNotEscape(utf8Ch)) { @@ -105,7 +105,8 @@ bool JsonHelper::IsFastValueToQuotedString(const CString& str) #endif #if ENABLE_NEXT_OPTIMIZATION -void JsonHelper::AppendQuotedValueToC16String(const Span &sp, uint32_t &index, C16String &output) +void JsonHelper::AppendQuotedValueToC16String(const common::Span& sp, uint32_t& index, + C16String& output) { auto ch = sp[index]; if (common::utf_helper::IsUTF16Surrogate(ch)) { @@ -128,7 +129,7 @@ void JsonHelper::AppendQuotedValueToC16String(const Span &sp, ui } template -void JsonHelper::AppendValueToQuotedString(const Span &sp, DstType &output) +void JsonHelper::AppendValueToQuotedString(const common::Span &sp, DstType &output) { static_assert(sizeof(typename DstType::value_type) >= sizeof(SrcType)); AppendString(output, "\""); @@ -154,11 +155,11 @@ void JsonHelper::AppendValueToQuotedString(const Span &sp, DstTyp AppendString(output, "\""); } template void JsonHelper::AppendValueToQuotedString( - const Span &sp, CString &output); + const common::Span &sp, CString &output); template void JsonHelper::AppendValueToQuotedString( - const Span &sp, C16String &output); + const common::Span &sp, C16String &output); template void JsonHelper::AppendValueToQuotedString( - const Span &sp, C16String &output); + const common::Span &sp, C16String &output); #else void JsonHelper::AppendValueToQuotedString(const CString& str, CString& output) diff --git a/ecmascript/base/json_helper.h b/ecmascript/base/json_helper.h index d860523de9..413f4b359b 100644 --- a/ecmascript/base/json_helper.h +++ b/ecmascript/base/json_helper.h @@ -84,7 +84,7 @@ public: } #if ENABLE_NEXT_OPTIMIZATION - static bool IsFastValueToQuotedString(const Span &sp); + static bool IsFastValueToQuotedString(const common::Span &sp); #else static bool IsFastValueToQuotedString(const CString &str); #endif @@ -93,9 +93,10 @@ public: // Control characters code units are replaced with escape sequences \uHHHH, or with the shorter forms, // \b (BACKSPACE), \f (FORM FEED), \n (LINE FEED), \r (CARRIAGE RETURN), \t (CHARACTER TABULATION). #if ENABLE_NEXT_OPTIMIZATION - static void AppendQuotedValueToC16String(const Span &sp, uint32_t &index, C16String &output); + static void AppendQuotedValueToC16String(const common::Span& sp, uint32_t& index, + C16String& output); template - static void AppendValueToQuotedString(const Span &sp, DstType &output); + static void AppendValueToQuotedString(const common::Span &sp, DstType &output); #else static void AppendValueToQuotedString(const CString& str, CString& output); #endif diff --git a/ecmascript/base/number_helper.cpp b/ecmascript/base/number_helper.cpp index 53983b22df..7bb04248d7 100644 --- a/ecmascript/base/number_helper.cpp +++ b/ecmascript/base/number_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -571,7 +571,7 @@ JSTaggedValue NumberHelper::StringToNumber(EcmaString *string, int32_t radix) } } CVector buf; - Span str = EcmaStringAccessor(string).ToUtf8Span(buf); + common::Span str = EcmaStringAccessor(string).ToUtf8Span(buf); JSTaggedValue result = NumberHelper::StringToDoubleWithRadix(str.begin(), str.end(), radix, &negative); if (result.GetNumber() == 0 && negative == true) { @@ -1171,7 +1171,7 @@ JSTaggedValue NumberHelper::StringToBigInt(JSThread *thread, JSHandle buf; - Span str = EcmaStringAccessor(strObj).ToUtf8Span(buf); + common::Span str = EcmaStringAccessor(strObj).ToUtf8Span(buf); auto p = const_cast(str.begin()); auto end = str.end(); diff --git a/ecmascript/base/string_helper.h b/ecmascript/base/string_helper.h index e029fe18b1..e7588d7dd2 100644 --- a/ecmascript/base/string_helper.h +++ b/ecmascript/base/string_helper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -25,6 +25,7 @@ #include #include "common_components/base/utf_helper.h" +#include "common_interfaces/objects/utils/span.h" #include "ecmascript/mem/c_containers.h" #include "ecmascript/mem/c_string.h" #include "libpandabase/utils/span.h" @@ -367,7 +368,7 @@ public: } template - static inline uint32_t GetStart(Span &data, uint32_t length) + static inline uint32_t GetStart(common::Span &data, uint32_t length) { uint32_t start = 0; while (start < length && IsNonspace(data[start])) { @@ -377,7 +378,7 @@ public: } template - static inline int32_t GetEnd(Span &data, int32_t start, uint32_t length) + static inline int32_t GetEnd(common::Span &data, int32_t start, uint32_t length) { if (length == 0U) { return 0; diff --git a/ecmascript/base/tests/json_helper_test.cpp b/ecmascript/base/tests/json_helper_test.cpp index 2364d6e62d..e6ca461eca 100644 --- a/ecmascript/base/tests/json_helper_test.cpp +++ b/ecmascript/base/tests/json_helper_test.cpp @@ -32,9 +32,9 @@ class JsonHelperTest : public BaseTestWithScope { */ HWTEST_F_L0(JsonHelperTest, IsFastValueToQuotedString_001) { - Span sp1(reinterpret_cast("Hello World"), 11); - Span sp2(reinterpret_cast("0123456789"), 10); - Span sp3(reinterpret_cast("!#$%&'()*+,-./:;=?@[]^_`{|}~"), 28); + common::Span sp1(reinterpret_cast("Hello World"), 11); + common::Span sp2(reinterpret_cast("0123456789"), 10); + common::Span sp3(reinterpret_cast("!#$%&'()*+,-./:;=?@[]^_`{|}~"), 28); EXPECT_TRUE(JsonHelper::IsFastValueToQuotedString(sp1)); EXPECT_TRUE(JsonHelper::IsFastValueToQuotedString(sp2)); EXPECT_TRUE(JsonHelper::IsFastValueToQuotedString(sp3)); @@ -48,13 +48,13 @@ HWTEST_F_L0(JsonHelperTest, IsFastValueToQuotedString_001) */ HWTEST_F_L0(JsonHelperTest, IsFastValueToQuotedString_002) { - Span sp1(reinterpret_cast("\""), 1); - Span sp2(reinterpret_cast("\\"), 1); - Span sp3(reinterpret_cast("\b"), 1); - Span sp4(reinterpret_cast("\f"), 1); - Span sp5(reinterpret_cast("\n"), 1); - Span sp6(reinterpret_cast("\r"), 1); - Span sp7(reinterpret_cast("\t"), 1); + common::Span sp1(reinterpret_cast("\""), 1); + common::Span sp2(reinterpret_cast("\\"), 1); + common::Span sp3(reinterpret_cast("\b"), 1); + common::Span sp4(reinterpret_cast("\f"), 1); + common::Span sp5(reinterpret_cast("\n"), 1); + common::Span sp6(reinterpret_cast("\r"), 1); + common::Span sp7(reinterpret_cast("\t"), 1); EXPECT_FALSE(JsonHelper::IsFastValueToQuotedString(sp1)); EXPECT_FALSE(JsonHelper::IsFastValueToQuotedString(sp2)); EXPECT_FALSE(JsonHelper::IsFastValueToQuotedString(sp3)); @@ -66,7 +66,7 @@ HWTEST_F_L0(JsonHelperTest, IsFastValueToQuotedString_002) for (uint8_t c = 0; c < 32; c++) { EXPECT_FALSE(JsonHelper::IsFastValueToQuotedString( - Span(reinterpret_cast(&c), 1))); + common::Span(reinterpret_cast(&c), 1))); } } @@ -78,9 +78,9 @@ HWTEST_F_L0(JsonHelperTest, IsFastValueToQuotedString_002) */ HWTEST_F_L0(JsonHelperTest, IsFastValueToQuotedString_003) { - Span sp1(reinterpret_cast("Hello\nWorld"), 11); - Span sp2(reinterpret_cast("Test\"Quote"), 10); - Span sp3(reinterpret_cast("Test\\BackSlash"), 14); + common::Span sp1(reinterpret_cast("Hello\nWorld"), 11); + common::Span sp2(reinterpret_cast("Test\"Quote"), 10); + common::Span sp3(reinterpret_cast("Test\\BackSlash"), 14); EXPECT_FALSE(JsonHelper::IsFastValueToQuotedString(sp1)); EXPECT_FALSE(JsonHelper::IsFastValueToQuotedString(sp2)); diff --git a/ecmascript/base/tests/number_helper_test.cpp b/ecmascript/base/tests/number_helper_test.cpp index cb0acecc5f..c4825f71b2 100644 --- a/ecmascript/base/tests/number_helper_test.cpp +++ b/ecmascript/base/tests/number_helper_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -572,7 +572,7 @@ HWTEST_F_L0(NumberHelperTest, StringToDoubleWithRadix) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); int radix; - Span sp; + common::Span sp; CVector buf; JSHandle resultStr; @@ -922,10 +922,10 @@ HWTEST_F_L0(NumberHelperTest, FastStringToNumberForLineString) auto ecmaString = EcmaStringAccessor::CreateFromUtf8(instance, str.data(), str.size(), true); auto baseString = ecmaString->ToBaseString(); baseString->SetIsInternString(); - common::IntegerCache::InitIntegerCache(baseString); + common::IntegerCache::InitIntegerCache(LineString::Cast(baseString)); common::IntegerCache *cache = nullptr; if (baseString->GetLength() <= common::IntegerCache::MAX_INTEGER_CACHE_SIZE) { - cache = common::IntegerCache::Extract(ecmaString->ToBaseString()); + cache = common::IntegerCache::Extract(LineString::Cast(baseString)); } auto resCached = NumberHelper::FastStringToNumber(str.begin(), str.end(), cache); ASSERT_EQ(resCached.first, expectedIsSuccess[i]); diff --git a/ecmascript/builtins/builtins_number.cpp b/ecmascript/builtins/builtins_number.cpp index 767f0e66d6..17c62b542a 100644 --- a/ecmascript/builtins/builtins_number.cpp +++ b/ecmascript/builtins/builtins_number.cpp @@ -165,7 +165,7 @@ JSTaggedValue BuiltinsNumber::ParseFloat(EcmaRuntimeCallInfo *argv) // 2. ReturnIfAbrupt(inputString). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CVector buf; - Span str = EcmaStringAccessor(numberString).ToUtf8Span(buf); + common::Span str = EcmaStringAccessor(numberString).ToUtf8Span(buf); // 4. If neither trimmedString nor any prefix of trimmedString satisfies the syntax of a StrDecimalLiteral // (see 7.1.3.1), return NaN. if (NumberHelper::IsEmptyString(str.begin(), str.end())) { diff --git a/ecmascript/compiler/builtins/builtins_string_stub_builder.cpp b/ecmascript/compiler/builtins/builtins_string_stub_builder.cpp index 07fe017b53..829acfa59e 100644 --- a/ecmascript/compiler/builtins/builtins_string_stub_builder.cpp +++ b/ecmascript/compiler/builtins/builtins_string_stub_builder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -2257,8 +2257,7 @@ GateRef BuiltinsStringStubBuilder::StringAdd(GateRef glue, GateRef leftString, G builder_.Int32(SlicedString::MIN_SLICED_STRING_LENGTH)), &slowPath, &stringConcatOpt); builder_.Bind(&stringConcatOpt); { - GateRef backStoreLength = - builder_.Int32Mul(newLength, builder_.Int32(LineString::INIT_LENGTH_TIMES)); + GateRef backStoreLength = builder_.Int32Mul(newLength, builder_.Int32(INIT_LENGTH_TIMES)); GateRef leftIsUtf8 = builder_.IsUtf8String(left); GateRef rightIsUtf8 = builder_.IsUtf8String(right); GateRef canBeCompressed = builder_.BitAnd(leftIsUtf8, rightIsUtf8); diff --git a/ecmascript/compiler/circuit_builder.cpp b/ecmascript/compiler/circuit_builder.cpp index 2bfe1d9a64..cb7d97ab7a 100644 --- a/ecmascript/compiler/circuit_builder.cpp +++ b/ecmascript/compiler/circuit_builder.cpp @@ -702,8 +702,8 @@ GateRef CircuitBuilder::IsCompositeHClass(GateRef hClass) { GateRef objectType = GetObjectType(hClass); return BitAnd( - Int32LessThanOrEqual(objectType, Int32(static_cast(common::CommonType::LAST_OBJECT_TYPE))), - Int32GreaterThanOrEqual(objectType, Int32(static_cast(common::CommonType::FIRST_OBJECT_TYPE)))); + Int32LessThanOrEqual(objectType, Int32(static_cast(common::ObjectType::LAST_OBJECT_TYPE))), + Int32GreaterThanOrEqual(objectType, Int32(static_cast(common::ObjectType::FIRST_OBJECT_TYPE)))); } void CircuitBuilder::CheckHClassFieldInvalidAccess([[maybe_unused]]GateRef glue, [[maybe_unused]] GateRef hClass) diff --git a/ecmascript/compiler/mcr_circuit_builder.h b/ecmascript/compiler/mcr_circuit_builder.h index 74d883d77b..fdac9acc0d 100644 --- a/ecmascript/compiler/mcr_circuit_builder.h +++ b/ecmascript/compiler/mcr_circuit_builder.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -820,13 +820,13 @@ GateRef CircuitBuilder::TreeStringIsFlat(GateRef glue, GateRef string) GateRef CircuitBuilder::GetFirstFromTreeString(GateRef glue, GateRef string) { - GateRef offset = IntPtr(TreeString::FIRST_OFFSET); + GateRef offset = IntPtr(TreeString::LEFT_OFFSET); return Load(VariableType::JS_POINTER(), glue, string, offset); } GateRef CircuitBuilder::GetSecondFromTreeString(GateRef glue, GateRef string) { - GateRef offset = IntPtr(TreeString::SECOND_OFFSET); + GateRef offset = IntPtr(TreeString::RIGHT_OFFSET); return Load(VariableType::JS_POINTER(), glue, string, offset); } diff --git a/ecmascript/compiler/new_object_stub_builder.cpp b/ecmascript/compiler/new_object_stub_builder.cpp index 6867bb759b..e0216ec253 100644 --- a/ecmascript/compiler/new_object_stub_builder.cpp +++ b/ecmascript/compiler/new_object_stub_builder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1973,8 +1973,8 @@ void NewObjectStubBuilder::AllocTreeStringObject(Variable *result, Label *exit, StoreHClass(glue_, result->ReadVariable(), stringClass); InitStringLengthAndFlags(glue_, result->ReadVariable(), length, compressed); SetRawHashcode(glue_, result->ReadVariable(), Int32(0)); - Store(VariableType::JS_POINTER(), glue_, result->ReadVariable(), IntPtr(TreeString::FIRST_OFFSET), first); - Store(VariableType::JS_POINTER(), glue_, result->ReadVariable(), IntPtr(TreeString::SECOND_OFFSET), second); + Store(VariableType::JS_POINTER(), glue_, result->ReadVariable(), IntPtr(TreeString::LEFT_OFFSET), first); + Store(VariableType::JS_POINTER(), glue_, result->ReadVariable(), IntPtr(TreeString::RIGHT_OFFSET), second); Jump(exit); } diff --git a/ecmascript/dfx/hprof/tests/js_metadata_test.cpp b/ecmascript/dfx/hprof/tests/js_metadata_test.cpp index b69b7f46f7..81d0f00165 100644 --- a/ecmascript/dfx/hprof/tests/js_metadata_test.cpp +++ b/ecmascript/dfx/hprof/tests/js_metadata_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1031,8 +1031,8 @@ public: TransWithProtoHandler::TRANSITION_HCLASS_OFFSET, TransWithProtoHandler::PROTO_CELL_OFFSET, TransWithProtoHandler::SIZE - TransWithProtoHandler::HANDLER_INFO_OFFSET}}, - {JSType::TREE_STRING, {TreeString::FIRST_OFFSET, TreeString::SECOND_OFFSET, - TreeString::SIZE - TreeString::FIRST_OFFSET}}, + {JSType::TREE_STRING, {TreeString::LEFT_OFFSET, TreeString::RIGHT_OFFSET, + TreeString::SIZE - TreeString::LEFT_OFFSET}}, {JSType::VTABLE, {TaggedArray::LAST_OFFSET - TaggedArray::LENGTH_OFFSET}} }; // { typeName: [all parents of this type]} @@ -1766,8 +1766,8 @@ public: TransWithProtoHandler::TRANSITION_HCLASS_OFFSET - TransWithProtoHandler::HANDLER_INFO_OFFSET, TransWithProtoHandler::PROTO_CELL_OFFSET - TransWithProtoHandler::TRANSITION_HCLASS_OFFSET, TransWithProtoHandler::SIZE - TransWithProtoHandler::PROTO_CELL_OFFSET}}, - {JSType::TREE_STRING, {TreeString::SECOND_OFFSET - TreeString::FIRST_OFFSET, - TreeString::SIZE - TreeString::SECOND_OFFSET}}, + {JSType::TREE_STRING, {TreeString::RIGHT_OFFSET - TreeString::LEFT_OFFSET, + TreeString::SIZE - TreeString::RIGHT_OFFSET}}, {JSType::VTABLE, {}} }; } diff --git a/ecmascript/ecma_string-inl.h b/ecmascript/ecma_string-inl.h index 9894c252cb..860dc1c5be 100644 --- a/ecmascript/ecma_string-inl.h +++ b/ecmascript/ecma_string-inl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,7 +24,7 @@ #include "ecmascript/mem/space.h" #include "ecmascript/object_factory-inl.h" #include "ecmascript/debugger/js_debugger_manager.h" -#include "common_interfaces/objects/string/base_string-inl2.h" +#include "common_interfaces/objects/string/base_string-inl.h" namespace panda::ecmascript { /* static */ @@ -43,11 +43,11 @@ inline EcmaString *EcmaString::CreateFromUtf8(const EcmaVM *vm, const uint8_t *u if (utf8Len == 0) { return vm->GetFactory()->GetEmptyString().GetObject(); } - auto allocator = [vm, type](size_t size, common::CommonType stringType) -> BaseObject* { - ASSERT(stringType == common::CommonType::LINE_STRING && "Can only allocate line string"); + auto allocator = [vm, type](size_t size, common::ObjectType stringType) -> BaseObject* { + ASSERT(stringType == common::ObjectType::LINE_STRING && "Can only allocate line string"); return EcmaString::AllocLineString(vm, size, type)->ToBaseString(); }; - BaseString *str = BaseString::CreateFromUtf8(std::move(allocator), utf8Data, utf8Len, canBeCompress); + BaseString *str = LineString::CreateFromUtf8(std::move(allocator), utf8Data, utf8Len, canBeCompress); return EcmaString::FromBaseString(str); } @@ -59,11 +59,11 @@ inline EcmaString *EcmaString::CreateFromUtf8CompressedSubString(const EcmaVM *v return vm->GetFactory()->GetEmptyString().GetObject(); } - auto allocator = [vm, type](size_t size, common::CommonType stringType) -> BaseObject* { - ASSERT(stringType == common::CommonType::LINE_STRING && "Can only allocate line string"); + auto allocator = [vm, type](size_t size, common::ObjectType stringType) -> BaseObject* { + ASSERT(stringType == common::ObjectType::LINE_STRING && "Can only allocate line string"); return EcmaString::AllocLineString(vm, size, type)->ToBaseString(); }; - BaseString *str = BaseString::CreateFromUtf8CompressedSubString(std::move(allocator), string, offset, utf8Len); + BaseString *str = LineString::CreateFromUtf8CompressedSubString(std::move(allocator), string, offset, utf8Len); return EcmaString::FromBaseString(str); } @@ -112,36 +112,36 @@ inline EcmaString *EcmaString::CreateFromUtf16(const EcmaVM *vm, const uint16_t return vm->GetFactory()->GetEmptyString().GetObject(); } - auto allocator = [vm, type](size_t size, common::CommonType stringType) -> BaseObject* { - ASSERT(stringType == common::CommonType::LINE_STRING && "Can only allocate line string"); + auto allocator = [vm, type](size_t size, common::ObjectType stringType) -> BaseObject* { + ASSERT(stringType == common::ObjectType::LINE_STRING && "Can only allocate line string"); return EcmaString::AllocLineString(vm, size, type)->ToBaseString(); }; - BaseString *str = BaseString::CreateFromUtf16(std::move(allocator), utf16Data, utf16Len, canBeCompress); + BaseString *str = LineString::CreateFromUtf16(std::move(allocator), utf16Data, utf16Len, canBeCompress); return EcmaString::FromBaseString(str); } /* static */ inline EcmaString *EcmaString::CreateLineString(const EcmaVM *vm, size_t length, bool compressed) { - auto allocator = [vm](size_t size, common::CommonType stringType) -> BaseObject* { - ASSERT(stringType == common::CommonType::LINE_STRING && "Can only allocate line string"); + auto allocator = [vm](size_t size, common::ObjectType stringType) -> BaseObject* { + ASSERT(stringType == common::ObjectType::LINE_STRING && "Can only allocate line string"); EcmaString* string = vm->GetFactory()->AllocLineStringObject(size); return string; }; - BaseString *str = BaseString::CreateLineString(std::move(allocator), length, compressed); + BaseString *str = LineString::Create(std::move(allocator), length, compressed); return EcmaString::FromBaseString(str); } /* static */ inline EcmaString *EcmaString::CreateLineStringNoGC(const EcmaVM *vm, size_t length, bool compressed) { - auto allocator = [vm](size_t size, common::CommonType stringType) -> BaseObject* { - ASSERT(stringType == common::CommonType::LINE_STRING && "Can only allocate line string"); + auto allocator = [vm](size_t size, common::ObjectType stringType) -> BaseObject* { + ASSERT(stringType == common::ObjectType::LINE_STRING && "Can only allocate line string"); size = AlignUp(size, static_cast(MemAlignment::MEM_ALIGN_OBJECT)); EcmaString* string = vm->GetFactory()->AllocLineStringObjectNoGC(size); return string; }; - BaseString *str = BaseString::CreateLineString(std::move(allocator), length, compressed); + BaseString *str = LineString::Create(std::move(allocator), length, compressed); return EcmaString::FromBaseString(str); } @@ -169,27 +169,27 @@ inline EcmaString* EcmaString::AllocLineString(const EcmaVM* vm, size_t size, Me inline EcmaString *EcmaString::CreateLineStringWithSpaceType(const EcmaVM *vm, size_t length, bool compressed, MemSpaceType type) { - auto allocator = [vm, type](size_t size, common::CommonType stringType) -> BaseObject* { - ASSERT(stringType == common::CommonType::LINE_STRING && "Can only allocate line string"); + auto allocator = [vm, type](size_t size, common::ObjectType stringType) -> BaseObject* { + ASSERT(stringType == common::ObjectType::LINE_STRING && "Can only allocate line string"); ASSERT(IsSMemSpace(type)); return AllocLineString(vm, size, type); }; - BaseString *str = BaseString::CreateLineString(std::move(allocator), length, compressed); + BaseString *str = LineString::Create(std::move(allocator), length, compressed); return EcmaString::FromBaseString(str); } inline SlicedEcmaString* EcmaString::CreateSlicedString(const EcmaVM* vm, JSHandle parent, MemSpaceType type) { - auto allocator = [vm, type](size_t, common::CommonType stringType) -> BaseObject* { - ASSERT(stringType == common::CommonType::SLICED_STRING && "Can only allocate sliced string"); + auto allocator = [vm, type](size_t, common::ObjectType stringType) -> BaseObject* { + ASSERT(stringType == common::ObjectType::SLICED_STRING && "Can only allocate sliced string"); EcmaString* string = vm->GetFactory()->AllocSlicedStringObject(type); return string; }; auto writeBarrier = [vm](void* obj, size_t offset, BaseObject* str) { Barriers::SetObject(vm->GetJSThread(), obj, offset, reinterpret_cast(str)); }; - SlicedString* slicedString = BaseString::CreateSlicedString(std::move(allocator), std::move(writeBarrier), parent); + SlicedString* slicedString = SlicedString::Create(std::move(allocator), std::move(writeBarrier), parent); return SlicedEcmaString::FromBaseString(slicedString); } @@ -220,16 +220,16 @@ inline EcmaString *EcmaString::CreateTreeString(const EcmaVM *vm, JSThread *thread = nullptr; GetDebuggerThread(vm, &thread); - auto allocator = [vm](size_t, common::CommonType stringType) -> BaseObject* { - ASSERT(stringType == common::CommonType::TREE_STRING && "Can only allocate tree string"); + auto allocator = [vm](size_t, common::ObjectType stringType) -> BaseObject* { + ASSERT(stringType == common::ObjectType::TREE_STRING && "Can only allocate tree string"); EcmaString* string = vm->GetFactory()->AllocTreeStringObject(); return string; }; auto writeBarrier = [thread](void* obj, size_t offset, BaseObject* str) { Barriers::SetObject(thread, obj, offset, reinterpret_cast(str)); }; - TreeString* treeString = BaseString::CreateTreeString(std::move(allocator), std::move(writeBarrier), left, right, - length, compressed); + TreeString* treeString = TreeString::Create(std::move(allocator), std::move(writeBarrier), left, right, + length, compressed); return TreeEcmaString::FromBaseString(treeString); } @@ -240,8 +240,8 @@ EcmaString *EcmaString::FastSubUtf8String(const EcmaVM *vm, const JSHandle string(vm->GetJSThread(), CreateLineString(vm, length, true)); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) FlatStringInfo srcFlat = FlattenAllString(vm, src); - Span dst(string->GetDataUtf8Writable(), length); - Span source(srcFlat.GetDataUtf8() + start, length); + common::Span dst(string->GetDataUtf8Writable(), length); + common::Span source(srcFlat.GetDataUtf8() + start, length); EcmaString::MemCopyChars(dst, length, source, length); ASSERT_PRINT(CanBeCompressed(*string), "canBeCompresse does not match the real value!"); @@ -263,8 +263,8 @@ EcmaString *EcmaString::FastSubUtf16String(const EcmaVM *vm, const JSHandle dst(string->GetDataUtf16Writable(), length); - Span source(srcFlat.GetDataUtf16() + start, length); + common::Span dst(string->GetDataUtf16Writable(), length); + common::Span source(srcFlat.GetDataUtf16() + start, length); EcmaString::MemCopyChars(dst, len, source, len); } ASSERT_PRINT(canBeCompressed == CanBeCompressed(*string), "canBeCompresse does not match the real value!"); @@ -273,23 +273,23 @@ EcmaString *EcmaString::FastSubUtf16String(const EcmaVM *vm, const JSHandleGetDataUtf8(); + return LineString::ConstCast(this)->GetDataUtf8(); } inline const uint16_t* EcmaString::GetDataUtf16() const { - return ToBaseString()->GetDataUtf16(); + return LineString::ConstCast(this)->GetDataUtf16(); } // require is LineString inline uint8_t* EcmaString::GetDataUtf8Writable() { - return ToBaseString()->GetDataUtf8Writable(); + return LineString::Cast(this)->GetDataUtf8Writable(); } inline uint16_t* EcmaString::GetDataUtf16Writable() { - return ToBaseString()->GetDataUtf16Writable(); + return LineString::Cast(this)->GetDataUtf16Writable(); } inline size_t EcmaString::GetUtf8Length(bool modify, bool isGetBufferSize) const @@ -309,17 +309,23 @@ uint16_t EcmaString::At(int32_t index) const return ToBaseString()->At(std::move(readBarrier), index); } +template +bool EcmaString::StringsAreEquals(common::Span& str1, common::Span& str2) +{ + return BaseString::StringsAreEquals(str1, str2); +} + inline void EcmaString::WriteData(uint32_t index, uint16_t src) { - return ToBaseString()->WriteData(index, src); + return LineString::Cast(this)->Set(index, src); } -inline Span EcmaString::FastToUtf8Span() const +inline common::Span EcmaString::FastToUtf8Span() const { uint32_t len = GetLength(); ASSERT(IsUtf8()); const uint8_t *data = GetDataUtf8(); - return Span(data, len); + return common::Span(data, len); } inline bool EcmaString::IsFlat() const @@ -382,7 +388,7 @@ inline uint32_t EcmaString::CopyDataUtf16(uint16_t* buf, uint32_t maxLength) con return ToBaseString()->CopyDataUtf16(std::move(readBarrier), buf, maxLength); } -inline Span EcmaString::ToUtf8Span(CVector& buf, bool modify, bool cesu8) +inline common::Span EcmaString::ToUtf8Span(CVector& buf, bool modify, bool cesu8) { auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { return Barriers::GetTaggedObject(obj, offset); @@ -390,7 +396,7 @@ inline Span EcmaString::ToUtf8Span(CVector& buf, bool mo return ToBaseString()->ToUtf8Span(std::move(readBarrier), buf, modify, cesu8); } -inline Span EcmaString::DebuggerToUtf8Span(CVector& buf, bool modify) +inline common::Span EcmaString::DebuggerToUtf8Span(CVector& buf, bool modify) { auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { return Barriers::GetTaggedObject(obj, offset); @@ -440,9 +446,14 @@ inline void EcmaStringAccessor::ReadData(EcmaString *dst, EcmaString *src, dst->WriteData(src, start, destSize, length); } -inline Span EcmaStringAccessor::FastToUtf8Span() const +inline common::Span EcmaStringAccessor::FastToUtf8Span() const { return string_->FastToUtf8Span(); } + +inline bool EcmaStringAccessor::IsASCIICharacter(uint16_t data) +{ + return BaseString::IsASCIICharacter(data); +} } // namespace panda::ecmascript #endif diff --git a/ecmascript/ecma_string.cpp b/ecmascript/ecma_string.cpp index 25e68be28f..513c4d9369 100755 --- a/ecmascript/ecma_string.cpp +++ b/ecmascript/ecma_string.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,7 +15,7 @@ #include "ecmascript/ecma_string-inl.h" -#include "common_interfaces/objects/base_string.h" +#include "common_interfaces/objects/string/base_string-inl.h" #include "ecmascript/base/json_helper.h" namespace panda::ecmascript { @@ -65,20 +65,20 @@ EcmaString *EcmaString::Concat(const EcmaVM *vm, strRight = *right; if (compressed) { // copy left part - Span sp(newString->GetDataUtf8Writable(), newLength); - Span srcLeft(strLeft->GetDataUtf8(), leftLength); + common::Span sp(newString->GetDataUtf8Writable(), newLength); + common::Span srcLeft(strLeft->GetDataUtf8(), leftLength); EcmaString::MemCopyChars(sp, newLength, srcLeft, leftLength); // copy right part sp = sp.SubSpan(leftLength); - Span srcRight(strRight->GetDataUtf8(), rightLength); + common::Span srcRight(strRight->GetDataUtf8(), rightLength); EcmaString::MemCopyChars(sp, rightLength, srcRight, rightLength); } else { // copy left part - Span sp(newString->GetDataUtf16Writable(), newLength); + common::Span sp(newString->GetDataUtf16Writable(), newLength); if (strLeft->IsUtf8()) { BaseString::CopyChars(sp.data(), strLeft->GetDataUtf8(), leftLength); } else { - Span srcLeft(strLeft->GetDataUtf16(), leftLength); + common::Span srcLeft(strLeft->GetDataUtf16(), leftLength); EcmaString::MemCopyChars(sp, newLength << 1U, srcLeft, leftLength << 1U); } // copy right part @@ -86,7 +86,7 @@ EcmaString *EcmaString::Concat(const EcmaVM *vm, if (strRight->IsUtf8()) { BaseString::CopyChars(sp.data(), strRight->GetDataUtf8(), rightLength); } else { - Span srcRight(strRight->GetDataUtf16(), rightLength); + common::Span srcRight(strRight->GetDataUtf16(), rightLength); EcmaString::MemCopyChars(sp, rightLength << 1U, srcRight, rightLength << 1U); } } @@ -105,16 +105,16 @@ EcmaString *EcmaString::CopyStringToOldSpace(const EcmaVM *vm, const JSHandle sp(newString->GetDataUtf8Writable(), length); - Span srcSp(strOrigin.GetDataUtf8(), length); + common::Span sp(newString->GetDataUtf8Writable(), length); + common::Span srcSp(strOrigin.GetDataUtf8(), length); EcmaString::MemCopyChars(sp, length, srcSp, length); } else { // copy left part - Span sp(newString->GetDataUtf16Writable(), length); + common::Span sp(newString->GetDataUtf16Writable(), length); if (strOrigin.IsUtf8()) { BaseString::CopyChars(sp.data(), strOrigin.GetDataUtf8(), length); } else { - Span srcSp(strOrigin.GetDataUtf16(), length); + common::Span srcSp(strOrigin.GetDataUtf16(), length); EcmaString::MemCopyChars(sp, length << 1U, srcSp, length << 1U); } } @@ -212,30 +212,30 @@ int32_t EcmaString::Compare(const EcmaVM *vm, const JSHandle &left, int32_t countDiff = lhsCount - rhsCount; int32_t minCount = (countDiff < 0) ? lhsCount : rhsCount; if (!lhs.IsUtf16() && !rhs.IsUtf16()) { - Span lhsSp(lhs.GetDataUtf8(), lhsCount); - Span rhsSp(rhs.GetDataUtf8(), rhsCount); - int32_t charDiff = common::CompareStringSpan(lhsSp, rhsSp, minCount); + common::Span lhsSp(lhs.GetDataUtf8(), lhsCount); + common::Span rhsSp(rhs.GetDataUtf8(), rhsCount); + int32_t charDiff = CompareStringSpan(lhsSp, rhsSp, minCount); if (charDiff != 0) { return charDiff; } } else if (!lhs.IsUtf16()) { - Span lhsSp(lhs.GetDataUtf8(), lhsCount); - Span rhsSp(rhs.GetDataUtf16(), rhsCount); - int32_t charDiff = common::CompareStringSpan(lhsSp, rhsSp, minCount); + common::Span lhsSp(lhs.GetDataUtf8(), lhsCount); + common::Span rhsSp(rhs.GetDataUtf16(), rhsCount); + int32_t charDiff = CompareStringSpan(lhsSp, rhsSp, minCount); if (charDiff != 0) { return charDiff; } } else if (!rhs.IsUtf16()) { - Span lhsSp(lhs.GetDataUtf16(), rhsCount); - Span rhsSp(rhs.GetDataUtf8(), lhsCount); - int32_t charDiff = common::CompareStringSpan(lhsSp, rhsSp, minCount); + common::Span lhsSp(lhs.GetDataUtf16(), rhsCount); + common::Span rhsSp(rhs.GetDataUtf8(), lhsCount); + int32_t charDiff = CompareStringSpan(lhsSp, rhsSp, minCount); if (charDiff != 0) { return charDiff; } } else { - Span lhsSp(lhs.GetDataUtf16(), lhsCount); - Span rhsSp(rhs.GetDataUtf16(), rhsCount); - int32_t charDiff = common::CompareStringSpan(lhsSp, rhsSp, minCount); + common::Span lhsSp(lhs.GetDataUtf16(), lhsCount); + common::Span rhsSp(rhs.GetDataUtf16(), rhsCount); + int32_t charDiff = CompareStringSpan(lhsSp, rhsSp, minCount); if (charDiff != 0) { return charDiff; } @@ -259,34 +259,34 @@ bool EcmaString::IsSubStringAt(const EcmaVM *vm, const JSHandle& lef int32_t lhsCount = static_cast(lhs.GetLength()); int32_t rhsCount = static_cast(rhs.GetLength()); if (!lhs.IsUtf16() && !rhs.IsUtf16()) { - Span lhsSp(lhs.GetDataUtf8(), lhsCount); - Span rhsSp(rhs.GetDataUtf8(), rhsCount); - return common::IsSubStringAtSpan(lhsSp, rhsSp, offset); + common::Span lhsSp(lhs.GetDataUtf8(), lhsCount); + common::Span rhsSp(rhs.GetDataUtf8(), rhsCount); + return IsSubStringAtSpan(lhsSp, rhsSp, offset); } else if (!lhs.IsUtf16()) { - Span lhsSp(lhs.GetDataUtf8(), lhsCount); - Span rhsSp(rhs.GetDataUtf16(), rhsCount); - return common::IsSubStringAtSpan(lhsSp, rhsSp, offset); + common::Span lhsSp(lhs.GetDataUtf8(), lhsCount); + common::Span rhsSp(rhs.GetDataUtf16(), rhsCount); + return IsSubStringAtSpan(lhsSp, rhsSp, offset); } else if (!rhs.IsUtf16()) { - Span lhsSp(lhs.GetDataUtf16(), lhsCount); - Span rhsSp(rhs.GetDataUtf8(), rhsCount); - return common::IsSubStringAtSpan(lhsSp, rhsSp, offset); + common::Span lhsSp(lhs.GetDataUtf16(), lhsCount); + common::Span rhsSp(rhs.GetDataUtf8(), rhsCount); + return IsSubStringAtSpan(lhsSp, rhsSp, offset); } else { - Span lhsSp(lhs.GetDataUtf16(), lhsCount); - Span rhsSp(rhs.GetDataUtf16(), rhsCount); - return common::IsSubStringAtSpan(lhsSp, rhsSp, offset); + common::Span lhsSp(lhs.GetDataUtf16(), lhsCount); + common::Span rhsSp(rhs.GetDataUtf16(), rhsCount); + return IsSubStringAtSpan(lhsSp, rhsSp, offset); } return false; } /* static */ -template -int32_t EcmaString::IndexOf(Span &lhsSp, Span &rhsSp, int32_t pos, int32_t max) +template +int32_t EcmaString::IndexOf(common::Span& lhsSp, common::Span& rhsSp, int32_t pos, int32_t max) { - return BaseString::IndexOf(lhsSp, rhsSp, pos, max); + return BaseString::IndexOf(lhsSp, rhsSp, pos, max); } -template -int32_t EcmaString::LastIndexOf(Span &lhsSp, Span &rhsSp, int32_t pos) +template +int32_t EcmaString::LastIndexOf(common::Span& lhsSp, common::Span& rhsSp, int32_t pos) { return BaseString::LastIndexOf(lhsSp, rhsSp, pos); } @@ -329,18 +329,18 @@ int32_t EcmaString::IndexOf(const EcmaVM *vm, lhs.SetString(*string); if (rhs.IsUtf8() && lhs.IsUtf8()) { - Span lhsSp(lhs.GetDataUtf8(), lhsCount); - Span rhsSp(rhs.GetDataUtf8(), rhsCount); + common::Span lhsSp(lhs.GetDataUtf8(), lhsCount); + common::Span rhsSp(rhs.GetDataUtf8(), rhsCount); return EcmaString::IndexOf(lhsSp, rhsSp, pos, max); } else if (rhs.IsUtf16() && lhs.IsUtf16()) { // NOLINT(readability-else-after-return) - Span lhsSp(lhs.GetDataUtf16(), lhsCount); - Span rhsSp(rhs.GetDataUtf16(), rhsCount); + common::Span lhsSp(lhs.GetDataUtf16(), lhsCount); + common::Span rhsSp(rhs.GetDataUtf16(), rhsCount); return EcmaString::IndexOf(lhsSp, rhsSp, pos, max); } else if (rhs.IsUtf16()) { return -1; } else { // NOLINT(readability-else-after-return) - Span lhsSp(lhs.GetDataUtf16(), lhsCount); - Span rhsSp(rhs.GetDataUtf8(), rhsCount); + common::Span lhsSp(lhs.GetDataUtf16(), lhsCount); + common::Span rhsSp(rhs.GetDataUtf8(), rhsCount); return EcmaString::IndexOf(lhsSp, rhsSp, pos, max); } } @@ -381,18 +381,18 @@ int32_t EcmaString::LastIndexOf(const EcmaVM *vm, FlatStringInfo rhs = FlattenAllString(vm, search); lhs.SetString(*string); if (rhs.IsUtf8() && lhs.IsUtf8()) { - Span lhsSp(lhs.GetDataUtf8(), lhsCount); - Span rhsSp(rhs.GetDataUtf8(), rhsCount); + common::Span lhsSp(lhs.GetDataUtf8(), lhsCount); + common::Span rhsSp(rhs.GetDataUtf8(), rhsCount); return EcmaString::LastIndexOf(lhsSp, rhsSp, pos); } else if (rhs.IsUtf16() && lhs.IsUtf16()) { // NOLINT(readability-else-after-return) - Span lhsSp(lhs.GetDataUtf16(), lhsCount); - Span rhsSp(rhs.GetDataUtf16(), rhsCount); + common::Span lhsSp(lhs.GetDataUtf16(), lhsCount); + common::Span rhsSp(rhs.GetDataUtf16(), rhsCount); return EcmaString::LastIndexOf(lhsSp, rhsSp, pos); } else if (rhs.IsUtf16()) { return -1; } else { // NOLINT(readability-else-after-return) - Span lhsSp(lhs.GetDataUtf16(), lhsCount); - Span rhsSp(rhs.GetDataUtf8(), rhsCount); + common::Span lhsSp(lhs.GetDataUtf16(), lhsCount); + common::Span rhsSp(rhs.GetDataUtf8(), rhsCount); return EcmaString::LastIndexOf(lhsSp, rhsSp, pos); } } @@ -463,7 +463,7 @@ uint32_t EcmaString::CalculateConcatHashCode(const JSHandle &firstSt // static bool EcmaString::CanBeCompressed(const EcmaString *string) { - return BaseString::CanBeCompressed(string->ToBaseString()); + return LineString::CanBeCompressed(LineString::ConstCast(string)); } // static @@ -502,20 +502,20 @@ bool EcmaString::StringsAreEqualDiffUtfEncoding(const FlatStringInfo &left, cons int32_t lhsCount = static_cast(left.GetLength()); int32_t rhsCount = static_cast(right.GetLength()); if (!left.IsUtf16() && !right.IsUtf16()) { - Span lhsSp(left.GetDataUtf8(), lhsCount); - Span rhsSp(right.GetDataUtf8(), rhsCount); + common::Span lhsSp(left.GetDataUtf8(), lhsCount); + common::Span rhsSp(right.GetDataUtf8(), rhsCount); return EcmaString::StringsAreEquals(lhsSp, rhsSp); } else if (!left.IsUtf16()) { - Span lhsSp(left.GetDataUtf8(), lhsCount); - Span rhsSp(right.GetDataUtf16(), rhsCount); + common::Span lhsSp(left.GetDataUtf8(), lhsCount); + common::Span rhsSp(right.GetDataUtf16(), rhsCount); return EcmaString::StringsAreEquals(lhsSp, rhsSp); } else if (!right.IsUtf16()) { - Span lhsSp(left.GetDataUtf16(), rhsCount); - Span rhsSp(right.GetDataUtf8(), lhsCount); + common::Span lhsSp(left.GetDataUtf16(), rhsCount); + common::Span rhsSp(right.GetDataUtf8(), lhsCount); return EcmaString::StringsAreEquals(lhsSp, rhsSp); } else { - Span lhsSp(left.GetDataUtf16(), lhsCount); - Span rhsSp(right.GetDataUtf16(), rhsCount); + common::Span lhsSp(left.GetDataUtf16(), lhsCount); + common::Span rhsSp(right.GetDataUtf16(), rhsCount); return EcmaString::StringsAreEquals(lhsSp, rhsSp); } } @@ -571,7 +571,7 @@ bool EcmaString::StringsAreEqualUtf16(const EcmaString *str1, const uint16_t *ut } template -bool EcmaString::MemCopyChars(Span &dst, size_t dstMax, Span &src, size_t count) +bool EcmaString::MemCopyChars(common::Span &dst, size_t dstMax, common::Span &src, size_t count) { ASSERT(dstMax >= count); ASSERT(dst.Size() >= src.Size()); @@ -717,8 +717,9 @@ bool EcmaString::ToTypedArrayIndex(uint32_t *index) return false; } -template -EcmaString *EcmaString::TrimBody(const JSThread *thread, const JSHandle &src, Span &data, TrimMode mode) +template +EcmaString* EcmaString::TrimBody(const JSThread* thread, const JSHandle& src, common::Span& data, + TrimMode mode) { uint32_t srcLen = src->GetLength(); int32_t start = 0; @@ -730,7 +731,7 @@ EcmaString *EcmaString::TrimBody(const JSThread *thread, const JSHandleGetEcmaVM(), src, start, static_cast(end - start + 1)); + EcmaString* res = FastSubString(thread->GetEcmaVM(), src, start, static_cast(end - start + 1)); return res; } @@ -757,7 +758,7 @@ EcmaString *EcmaString::TryToLower(const EcmaVM *vm, const JSHandle const char start = 'A'; const char end = 'Z'; uint32_t upperIndex = srcLength; - Span data(srcFlat.GetDataUtf8Writable(), srcLength); + common::Span data(srcFlat.GetDataUtf8Writable(), srcLength); for (uint32_t index = 0; index < srcLength; ++index) { if (base::StringHelper::Utf8CharInRange(data[index], start, end)) { upperIndex = index; @@ -778,7 +779,7 @@ EcmaString *EcmaString::TryToUpper(const EcmaVM *vm, const JSHandle const char start = 'a'; const char end = 'z'; uint32_t lowerIndex = srcLength; - Span data(srcFlat.GetDataUtf8Writable(), srcLength); + common::Span data(srcFlat.GetDataUtf8Writable(), srcLength); for (uint32_t index = 0; index < srcLength; ++index) { if (base::StringHelper::Utf8CharInRange(data[index], start, end)) { lowerIndex = index; @@ -800,7 +801,7 @@ EcmaString *EcmaString::ConvertUtf8ToLowerOrUpper(const EcmaVM *vm, const JSHand uint32_t srcLength = src->GetLength(); JSHandle newString(vm->GetJSThread(), CreateLineString(vm, srcLength, true)); auto srcFlat = FlattenAllString(vm, src); - Span data(srcFlat.GetDataUtf8Writable(), srcLength); + common::Span data(srcFlat.GetDataUtf8Writable(), srcLength); auto newStringPtr = newString->GetDataUtf8Writable(); if (startIndex > 0) { if (memcpy_s(newStringPtr, startIndex * sizeof(uint8_t), data.data(), startIndex * sizeof(uint8_t)) != EOK) { @@ -861,10 +862,10 @@ EcmaString *EcmaString::Trim(const JSThread *thread, const JSHandle return EcmaString::Cast(thread->GlobalConstants()->GetEmptyString().GetTaggedObject()); } if (srcFlat.IsUtf8()) { - Span data(srcFlat.GetDataUtf8(), srcLen); + common::Span data(srcFlat.GetDataUtf8(), srcLen); return TrimBody(thread, src, data, mode); } else { - Span data(srcFlat.GetDataUtf16(), srcLen); + common::Span data(srcFlat.GetDataUtf16(), srcLen); return TrimBody(thread, src, data, mode); } } @@ -1037,7 +1038,7 @@ std::string EcmaStringAccessor::ToStdString(StringConvertedUsage usage) } bool modify = (usage != StringConvertedUsage::PRINT); CVector buf; - Span sp = string_->ToUtf8Span(buf, modify); + common::Span sp = string_->ToUtf8Span(buf, modify); #if ENABLE_NEXT_OPTIMIZATION return std::string(reinterpret_cast(sp.data()), sp.size()); #else @@ -1076,7 +1077,7 @@ std::string EcmaStringAccessor::DebuggerToStdString(StringConvertedUsage usage) bool modify = (usage != StringConvertedUsage::PRINT); CVector buf; - Span sp = string_->DebuggerToUtf8Span(buf, modify); + common::Span sp = string_->DebuggerToUtf8Span(buf, modify); #if ENABLE_NEXT_OPTIMIZATION return std::string(reinterpret_cast(sp.data()), sp.size()); #else @@ -1096,7 +1097,7 @@ CString EcmaStringAccessor::ToCString(StringConvertedUsage usage, bool cesu8) } bool modify = (usage != StringConvertedUsage::PRINT); CVector buf; - Span sp = string_->ToUtf8Span(buf, modify, cesu8); + common::Span sp = string_->ToUtf8Span(buf, modify, cesu8); #if ENABLE_NEXT_OPTIMIZATION return CString(reinterpret_cast(sp.data()), sp.size()); #else @@ -1118,7 +1119,10 @@ void EcmaStringAccessor::AppendToCString(CString &str) size_t strLen = GetLength(); CVector buf; - const uint8_t *data = EcmaString::GetUtf8DataFlat(string_, buf); + auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(obj, offset); + }; + const uint8_t *data = LineString::GetUtf8DataFlat(std::move(readBarrier), BaseString::ConstCast(string_), buf); str.append(reinterpret_cast(data), strLen); } @@ -1127,17 +1131,21 @@ void EcmaStringAccessor::AppendToC16String(C16String &str) if (string_ == nullptr) { return; } + auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(obj, offset); + }; // used to append utf8 space to utf16 gap by stringify // In real world, space is usually utf8. if LIKELY(string_->IsUtf8()) { CVector buf; - const uint8_t *data = EcmaString::GetUtf8DataFlat(string_, buf); + const uint8_t* data = LineString::GetUtf8DataFlat(std::move(readBarrier), BaseString::ConstCast(string_), buf); // only ascii codes, no need to convert to UTF-16, just append. AppendString(str, reinterpret_cast(data), GetLength()); } else { CVector buf; - const uint16_t *data = EcmaString::GetUtf16DataFlat(string_, buf); - str.append(reinterpret_cast(data), GetLength()); + const uint16_t* data = + LineString::GetUtf16DataFlat(std::move(readBarrier), BaseString::ConstCast(string_), buf); + str.append(reinterpret_cast(data), GetLength()); } } #endif diff --git a/ecmascript/ecma_string.h b/ecmascript/ecma_string.h index c640d3f880..0b916bdcb6 100755 --- a/ecmascript/ecma_string.h +++ b/ecmascript/ecma_string.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -21,6 +21,8 @@ #include #include "common_components/base/utf_helper.h" +#include "common_interfaces/objects/string/base_string.h" +#include "common_interfaces/objects/string/base_string-inl.h" #include "common_interfaces/objects/string/line_string.h" #include "common_interfaces/objects/string/sliced_string.h" #include "common_interfaces/objects/string/tree_string.h" @@ -31,6 +33,9 @@ #include "ecmascript/mem/barriers.h" #include "ecmascript/mem/space.h" #include "ecmascript/mem/tagged_object.h" +#include "common_interfaces/objects/string/line_string.h" +#include "common_interfaces/objects/string/sliced_string.h" +#include "common_interfaces/objects/string/tree_string.h" #include "libpandabase/macros.h" #include "securec.h" #include "unicode/locid.h" @@ -164,7 +169,7 @@ private: inline const uint8_t *GetDataUtf8() const; inline const uint16_t *GetDataUtf16() const; - inline Span FastToUtf8Span() const; + inline common::Span FastToUtf8Span() const; // require is LineString inline uint8_t *GetDataUtf8Writable(); @@ -235,10 +240,7 @@ private: // Check that two spans are equal. Should have the same length. /* static */ template - static bool StringsAreEquals(Span &str1, Span &str2) - { - return BaseString::StringsAreEquals(str1, str2); - } + static bool StringsAreEquals(common::Span &str1, common::Span &str2); // Compares string1 + string2 by bytes, It doesn't check canonical unicode equivalence. bool EqualToSplicedString(const EcmaString *str1, const EcmaString *str2); @@ -288,9 +290,9 @@ private: std::u16string ToU16String(uint32_t len = 0); - Span ToUtf8Span(CVector &buf, bool modify = true, bool cesu8 = false); + common::Span ToUtf8Span(CVector &buf, bool modify = true, bool cesu8 = false); - Span DebuggerToUtf8Span(CVector &buf, bool modify = true); + common::Span DebuggerToUtf8Span(CVector &buf, bool modify = true); Span ToUtf16Span(CVector &buf) { @@ -319,7 +321,7 @@ private: auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { return Barriers::GetTaggedObject(obj, offset); }; - ToBaseString()->WriteData(std::move(readBarrier), src->ToBaseString(), start, destSize, length); + LineString::Cast(ToBaseString())->WriteData(std::move(readBarrier), src->ToBaseString(), start, destSize, length); } static bool CanBeCompressed(const uint8_t *utf8Data, uint32_t utf8Len); @@ -334,20 +336,21 @@ private: bool PUBLIC_API ToTypedArrayIndex(uint32_t *index); - template - static EcmaString *TrimBody(const JSThread *thread, const JSHandle &src, Span &data, TrimMode mode); + template + static EcmaString* TrimBody(const JSThread* thread, const JSHandle& src, common::Span& data, + TrimMode mode); - static EcmaString *Trim(const JSThread *thread, const JSHandle &src, TrimMode mode = TrimMode::TRIM); + static EcmaString* Trim(const JSThread* thread, const JSHandle& src, TrimMode mode = TrimMode::TRIM); // memory block copy template - static bool MemCopyChars(Span &dst, size_t dstMax, Span &src, size_t count); + static bool MemCopyChars(common::Span &dst, size_t dstMax, common::Span &src, size_t count); template - static int32_t IndexOf(Span &lhsSp, Span &rhsSp, int32_t pos, int32_t max); + static int32_t IndexOf(common::Span &lhsSp, common::Span &rhsSp, int32_t pos, int32_t max); template - static int32_t LastIndexOf(Span &lhsSp, Span &rhsSp, int32_t pos); + static int32_t LastIndexOf(common::Span &lhsSp, common::Span &rhsSp, int32_t pos); bool IsFlat() const; @@ -582,7 +585,7 @@ class TreeEcmaString : public EcmaString { private: using TaggedObject::SIZE; public: - DECL_VISIT_OBJECT(TreeString::FIRST_OFFSET, TreeString::SIZE); + DECL_VISIT_OBJECT(TreeString::LEFT_OFFSET, TreeString::SIZE); CAST_CHECK(TreeEcmaString, IsTreeString); @@ -616,7 +619,7 @@ public: auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { return Barriers::GetTaggedObject(obj, offset); }; - return JSTaggedValue(ToTreeString()->GetFirst(std::move(readBarrier))); + return JSTaggedValue(ToTreeString()->GetLeftSubString(std::move(readBarrier))); } template @@ -627,7 +630,7 @@ public: Barriers::SetObject(thread, obj, offset, reinterpret_cast(str)); } else { Barriers::SetPrimitive(obj, offset, reinterpret_cast(str)); } }; - ToTreeString()->SetFirst(std::move(writeBarrier), value->GetTaggedObject()); + ToTreeString()->SetLeftSubString(std::move(writeBarrier), value->GetTaggedObject()); } void SetFirst(const JSThread* thread, JSTaggedValue value, BarrierMode mode = WRITE_BARRIER) @@ -637,7 +640,7 @@ public: Barriers::SetObject(thread, obj, offset, reinterpret_cast(str)); } else { Barriers::SetPrimitive(obj, offset, reinterpret_cast(str)); } }; - ToTreeString()->SetFirst(std::move(writeBarrier), value.GetTaggedObject()); + ToTreeString()->SetLeftSubString(std::move(writeBarrier), value.GetTaggedObject()); }; JSTaggedValue GetSecond() const @@ -645,7 +648,7 @@ public: auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { return Barriers::GetTaggedObject(obj, offset); }; - return JSTaggedValue(ToTreeString()->GetSecond(std::move(readBarrier))); + return JSTaggedValue(ToTreeString()->GetRightSubString(std::move(readBarrier))); } template @@ -656,7 +659,7 @@ public: Barriers::SetObject(thread, obj, offset, reinterpret_cast(str)); } else { Barriers::SetPrimitive(obj, offset, reinterpret_cast(str)); } }; - ToTreeString()->SetSecond(std::move(writeBarrier), value->GetTaggedObject()); + ToTreeString()->SetRightSubString(std::move(writeBarrier), value->GetTaggedObject()); } void SetSecond(const JSThread* thread, JSTaggedValue value, BarrierMode mode = WRITE_BARRIER) @@ -666,7 +669,7 @@ public: Barriers::SetObject(thread, obj, offset, reinterpret_cast(str)); } else { Barriers::SetPrimitive(obj, offset, reinterpret_cast(str)); } }; - ToTreeString()->SetSecond(std::move(writeBarrier), value.GetTaggedObject()); + ToTreeString()->SetRightSubString(std::move(writeBarrier), value.GetTaggedObject()); }; bool IsFlat() const @@ -890,7 +893,7 @@ public: // not change string data structure. // if string is not flat, this func has low efficiency. - Span ToUtf8Span(CVector &buf) + common::Span ToUtf8Span(CVector &buf) { return string_->ToUtf8Span(buf); } @@ -1135,14 +1138,7 @@ public: return EcmaString::Trim(thread, src, mode); } - static bool IsASCIICharacter(uint16_t data) - { - if (data == 0) { - return false; - } - // \0 is not considered ASCII in Ecma-Modified-UTF8 [only modify '\u0000'] - return data <= common::utf_helper::UTF8_1B_MAX; - } + static bool IsASCIICharacter(uint16_t data); bool IsFlat() const { @@ -1169,7 +1165,7 @@ public: return string_->NotTreeString(); } - inline Span FastToUtf8Span() const; + inline common::Span FastToUtf8Span() const; // the returned string may be a linestring or slicestring!! PUBLIC_API static EcmaString *Flatten(const EcmaVM *vm, const JSHandle &string, diff --git a/ecmascript/ecma_string_table.h b/ecmascript/ecma_string_table.h index b3450f00ad..c6c8b2ac0a 100644 --- a/ecmascript/ecma_string_table.h +++ b/ecmascript/ecma_string_table.h @@ -28,7 +28,7 @@ #include "ecmascript/platform/mutex.h" #include "ecmascript/tagged_array.h" #include "common_interfaces/objects/base_string_table.h" -#include "common_interfaces/objects/string/base_string_declare.h" +#include "common_interfaces/objects/string/base_string.h" namespace panda::ecmascript { #if ENABLE_NEXT_OPTIMIZATION diff --git a/ecmascript/global_env_constants.cpp b/ecmascript/global_env_constants.cpp index e0ef402f5e..13f38b68dc 100644 --- a/ecmascript/global_env_constants.cpp +++ b/ecmascript/global_env_constants.cpp @@ -132,11 +132,11 @@ void GlobalEnvConstants::InitSharedRootsClasses(ObjectFactory *factory) factory->NewSEcmaReadOnlyHClass(hClass, FreeObject::SIZE, JSType::FREE_OBJECT_WITH_TWO_FIELD)); if (g_isEnableCMCGC) { SetConstant(ConstantIndex::LINE_STRING_CLASS_INDEX, - factory->InitHClassInCompositeBaseClass(hClass, common::CommonType::LINE_STRING)); + factory->InitHClassInCompositeBaseClass(hClass, common::ObjectType::LINE_STRING)); SetConstant(ConstantIndex::SLICED_STRING_CLASS_INDEX, - factory->InitHClassInCompositeBaseClass(hClass, common::CommonType::SLICED_STRING)); + factory->InitHClassInCompositeBaseClass(hClass, common::ObjectType::SLICED_STRING)); SetConstant(ConstantIndex::TREE_STRING_CLASS_INDEX, - factory->InitHClassInCompositeBaseClass(hClass, common::CommonType::TREE_STRING)); + factory->InitHClassInCompositeBaseClass(hClass, common::ObjectType::TREE_STRING)); } else { SetConstant(ConstantIndex::LINE_STRING_CLASS_INDEX, factory->NewSEcmaReadOnlyHClass(hClass, 0, JSType::LINE_STRING)); diff --git a/ecmascript/js_api/js_api_buffer.cpp b/ecmascript/js_api/js_api_buffer.cpp index 9c1fa5ce88..a14da264c0 100644 --- a/ecmascript/js_api/js_api_buffer.cpp +++ b/ecmascript/js_api/js_api_buffer.cpp @@ -178,7 +178,7 @@ string_view FromStringBase64(const JSHandle &str, string &stringD { auto strAccessor = EcmaStringAccessor(JSHandle(str)); CVector buf; - Span sp = strAccessor.ToUtf8Span(buf); + common::Span sp = strAccessor.ToUtf8Span(buf); StringConverter::Base64Decode(string_view(reinterpret_cast(sp.data()), sp.size()), stringDecoded); return std::string_view(stringDecoded); } diff --git a/ecmascript/js_hclass.h b/ecmascript/js_hclass.h index 9daea478de..8c706e4ae2 100644 --- a/ecmascript/js_hclass.h +++ b/ecmascript/js_hclass.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -350,11 +350,11 @@ enum class JSType : uint8_t { JSTYPE_DECL, }; -static_assert(static_cast(JSType::LINE_STRING) == static_cast(common::CommonType::LINE_STRING) && +static_assert(static_cast(JSType::LINE_STRING) == static_cast(common::ObjectType::LINE_STRING) && "line string type should be same with common type"); -static_assert(static_cast(JSType::SLICED_STRING) == static_cast(common::CommonType::SLICED_STRING) && +static_assert(static_cast(JSType::SLICED_STRING) == static_cast(common::ObjectType::SLICED_STRING) && "sliced string type should be same with common type"); -static_assert(static_cast(JSType::TREE_STRING) == static_cast(common::CommonType::TREE_STRING) && +static_assert(static_cast(JSType::TREE_STRING) == static_cast(common::ObjectType::TREE_STRING) && "tree string type should be same with common type"); struct TransitionResult { @@ -671,8 +671,8 @@ public: // These types are not complete hclass, does not has profile field. inline bool IsCompositeHClass() const { - common::CommonType jsType = static_cast(GetObjectType()); - return (common::CommonType::FIRST_OBJECT_TYPE <= jsType && jsType <= common::CommonType::LAST_OBJECT_TYPE); + common::ObjectType jsType = static_cast(GetObjectType()); + return common::ObjectType::FIRST_OBJECT_TYPE <= jsType && jsType <= common::ObjectType::LAST_OBJECT_TYPE; } inline bool IsString() const diff --git a/ecmascript/js_tagged_value-inl.h b/ecmascript/js_tagged_value-inl.h index a7cec8a611..70538a4839 100644 --- a/ecmascript/js_tagged_value-inl.h +++ b/ecmascript/js_tagged_value-inl.h @@ -1435,7 +1435,7 @@ inline JSTaggedNumber JSTaggedValue::StringToDouble(JSTaggedValue tagged) return JSTaggedNumber(0); } CVector buf; - Span str = EcmaStringAccessor(strObj).ToUtf8Span(buf); + common::Span str = EcmaStringAccessor(strObj).ToUtf8Span(buf); double d = base::NumberHelper::StringToDouble(str.begin(), str.end(), 0, base::ALLOW_BINARY + base::ALLOW_OCTAL + base::ALLOW_HEX); return JSTaggedNumber(d); diff --git a/ecmascript/js_tagged_value.cpp b/ecmascript/js_tagged_value.cpp index b38c053b2c..1f54a76c69 100644 --- a/ecmascript/js_tagged_value.cpp +++ b/ecmascript/js_tagged_value.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1764,13 +1764,13 @@ JSTaggedNumber JSTaggedValue::StringToNumber(JSTaggedValue tagged) common::IntegerCache* cache = nullptr; #if ENABLE_NEXT_OPTIMIZATION if ((strLen <= common::IntegerCache::MAX_INTEGER_CACHE_SIZE) && strAccessor.IsInternString()) { - cache = common::IntegerCache::Extract(EcmaString::Cast(tagged)->ToBaseString()); + cache = common::IntegerCache::Extract(LineEcmaString::Cast(tagged)->ToLineString()); if (cache->IsInteger()) { return JSTaggedNumber(cache->GetInteger()); } } #endif - Span str = strAccessor.FastToUtf8Span(); + common::Span str = strAccessor.FastToUtf8Span(); if (strAccessor.GetLength() == 0) { return JSTaggedNumber(0); } @@ -1780,7 +1780,7 @@ JSTaggedNumber JSTaggedValue::StringToNumber(JSTaggedValue tagged) } } CVector buf; - Span str = strAccessor.ToUtf8Span(buf); + common::Span str = strAccessor.ToUtf8Span(buf); double d = base::NumberHelper::StringToDouble(str.begin(), str.end(), 0, base::ALLOW_BINARY + base::ALLOW_OCTAL + base::ALLOW_HEX); return JSTaggedNumber(d); diff --git a/ecmascript/mem/c_string.cpp b/ecmascript/mem/c_string.cpp index ae29c2f4f5..87947fe7c3 100644 --- a/ecmascript/mem/c_string.cpp +++ b/ecmascript/mem/c_string.cpp @@ -260,7 +260,7 @@ void ConvertQuotedAndAppendToCString(CString &str, const EcmaString *s) uint32_t strLen = EcmaStringAccessor(const_cast(s)).GetLength(); CVector buf; const uint8_t *data = EcmaStringAccessor::GetUtf8DataFlat(s, buf); - const Span dataSpan(data, strLen); + const common::Span dataSpan(data, strLen); base::JsonHelper::AppendValueToQuotedString(dataSpan, str); } @@ -272,12 +272,12 @@ void ConvertQuotedAndAppendToC16String(C16String &str, const EcmaString *s) if (EcmaStringAccessor(const_cast(s)).IsUtf8()) { CVector buf; const uint8_t *data = EcmaStringAccessor::GetUtf8DataFlat(s, buf); - const Span dataSpan(data, strLen); + const common::Span dataSpan(data, strLen); base::JsonHelper::AppendValueToQuotedString(dataSpan, str); } else { CVector buf; const uint16_t *data = EcmaStringAccessor::GetUtf16DataFlat(s, buf); - const Span dataSpan(data, strLen); + const common::Span dataSpan(data, strLen); base::JsonHelper::AppendValueToQuotedString(dataSpan, str); } } diff --git a/ecmascript/mem/tagged_state_word.h b/ecmascript/mem/tagged_state_word.h index aec23f55a8..72390adf44 100644 --- a/ecmascript/mem/tagged_state_word.h +++ b/ecmascript/mem/tagged_state_word.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -100,7 +100,8 @@ private: friend class TaggedObject; }; static_assert(sizeof(TaggedStateWord) == sizeof(uint64_t), "Excepts 8 bytes"); -static_assert(common::BaseStateWord::PADDING_WIDTH == 60, "Excepts 60 bits"); +static_assert(common::BaseStateWord::BASECLASS_WIDTH == 48, "Excepts 48 bits"); +static_assert(common::BaseStateWord::PADDING_WIDTH == 12, "Excepts 12 bits"); static_assert(common::BaseStateWord::FORWARD_WIDTH == 2, "Excepts 2 bits"); static_assert(common::BaseStateWord::LANGUAGE_WIDTH == 2, "Excepts 2 bits"); } // namespace panda::ecmascript diff --git a/ecmascript/object_factory.h b/ecmascript/object_factory.h index 1ef278f303..bd7d60fc32 100644 --- a/ecmascript/object_factory.h +++ b/ecmascript/object_factory.h @@ -813,7 +813,7 @@ public: JSHandle NewSEcmaReadOnlyHClass(JSHClass *hclass, uint32_t size, JSType type, uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); - JSTaggedValue InitHClassInCompositeBaseClass(JSHClass* hclass, common::CommonType type); + JSTaggedValue InitHClassInCompositeBaseClass(JSHClass* hclass, common::ObjectType type); JSHandle NewSEcmaReadOnlySharedHClass(JSHClass *hclass, uint32_t size, JSType type, uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); diff --git a/ecmascript/shared_object_factory.cpp b/ecmascript/shared_object_factory.cpp index 9167860e3e..d318d25d9d 100644 --- a/ecmascript/shared_object_factory.cpp +++ b/ecmascript/shared_object_factory.cpp @@ -186,7 +186,7 @@ JSHandle ObjectFactory::NewSEcmaReadOnlySharedHClass(JSHClass *hclass, return newClass; } -JSTaggedValue ObjectFactory::InitHClassInCompositeBaseClass(JSHClass* hclass, common::CommonType type) +JSTaggedValue ObjectFactory::InitHClassInCompositeBaseClass(JSHClass* hclass, common::ObjectType type) { common::BaseClassRoots& classRoots = common::BaseRuntime::GetInstance()->GetBaseClassRoots(); auto* newClass = reinterpret_cast(classRoots.GetBaseClass(type)); diff --git a/ecmascript/stubs/runtime_stubs.cpp b/ecmascript/stubs/runtime_stubs.cpp index 03eb476d48..1030160b74 100644 --- a/ecmascript/stubs/runtime_stubs.cpp +++ b/ecmascript/stubs/runtime_stubs.cpp @@ -3185,7 +3185,6 @@ DEF_RUNTIME_STUBS(ContainerRBTreeForEach) return JSTaggedValue::True().GetRawData(); } - DEF_RUNTIME_STUBS(GetOrInternStringFromHashTrieTable) { RUNTIME_STUBS_HEADER(GetOrInternStringFromHashTrieTable); diff --git a/ecmascript/tests/base_string_test.cpp b/ecmascript/tests/base_string_test.cpp index 717fe301cf..3d554791c0 100644 --- a/ecmascript/tests/base_string_test.cpp +++ b/ecmascript/tests/base_string_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,7 +14,7 @@ */ #include "ecmascript/ecma_string-inl.h" -#include "common_interfaces/objects/string/base_string_impl.h" +#include "common_interfaces/objects/string/base_string-inl.h" #include "ecmascript/object_factory.h" #include "ecmascript/tests/ecma_test_common.h" @@ -536,9 +536,9 @@ namespace panda::test { arrayFrontU8[i]); } for (uint32_t i = 0; i < lengthEcmaStrBackU16NotComp; i++) { - EXPECT_EQ(handleEcmaStrConcatU8U16NotComp->ToBaseString()->At( - Barriers::GetTaggedObject<>, i + lengthEcmaStrFrontU8), - arrayBackU16NotComp[i]); + EXPECT_EQ( + handleEcmaStrConcatU8U16NotComp->ToBaseString()->At(Barriers::GetTaggedObject<>, i + lengthEcmaStrFrontU8 + ), arrayBackU16NotComp[i]); } EXPECT_EQ(handleEcmaStrConcatU8U16NotComp->ToBaseString()->GetLength(), lengthEcmaStrFrontU8 + lengthEcmaStrBackU16NotComp); @@ -638,14 +638,15 @@ namespace panda::test { HWTEST_F_L0(BaseStringTest, FastSubString_004) { ObjectFactory* factory = instance->GetFactory(); + auto readBarrier = Barriers::GetTaggedObject<>; { JSHandle sourceString = factory->NewFromUtf8("整数integer"); JSHandle tmpString = factory->NewFromASCII("integer"); EXPECT_TRUE(sourceString->ToBaseString()->IsUtf16()); EcmaString* res = EcmaStringAccessor::FastSubString(instance, sourceString, 2, 7); EXPECT_TRUE(res->ToBaseString()->IsUtf8()); - EXPECT_TRUE(BaseString::StringsAreEqual( - Barriers::GetTaggedObject<>, res->ToBaseString(), tmpString->ToBaseString())); + EXPECT_TRUE( + BaseString::StringsAreEqual(readBarrier, res->ToBaseString(), tmpString->ToBaseString())); } { JSHandle sourceString = factory->NewFromUtf8("整数integer"); @@ -653,8 +654,8 @@ namespace panda::test { EXPECT_TRUE(sourceString->ToBaseString()->IsUtf16()); EcmaString* res = EcmaStringAccessor::FastSubString(instance, sourceString, 0, 2); EXPECT_TRUE(res->ToBaseString()->IsUtf16()); - EXPECT_TRUE(BaseString::StringsAreEqual( - Barriers::GetTaggedObject<>, res->ToBaseString(), tmpString->ToBaseString())); + EXPECT_TRUE( + BaseString::StringsAreEqual(readBarrier, res->ToBaseString(), tmpString->ToBaseString())); } { JSHandle sourceString = factory->NewFromUtf8("整数integer"); @@ -662,8 +663,8 @@ namespace panda::test { EXPECT_TRUE(sourceString->ToBaseString()->IsUtf16()); EcmaString* res = EcmaStringAccessor::FastSubString(instance, sourceString, 1, 7); EXPECT_TRUE(res->ToBaseString()->IsUtf16()); - EXPECT_TRUE(BaseString::StringsAreEqual( - Barriers::GetTaggedObject<>, res->ToBaseString(), tmpString->ToBaseString())); + EXPECT_TRUE( + BaseString::StringsAreEqual(readBarrier, res->ToBaseString(), tmpString->ToBaseString())); } { JSHandle sourceString = factory->NewFromASCII("integer123"); @@ -671,8 +672,8 @@ namespace panda::test { EXPECT_TRUE(sourceString->ToBaseString()->IsUtf8()); EcmaString* res = EcmaStringAccessor::FastSubString(instance, sourceString, 0, 7); EXPECT_TRUE(res->ToBaseString()->IsUtf8()); - EXPECT_TRUE(BaseString::StringsAreEqual( - Barriers::GetTaggedObject<>, res->ToBaseString(), tmpString->ToBaseString())); + EXPECT_TRUE(BaseString::StringsAreEqual(readBarrier, res->ToBaseString(), + tmpString->ToBaseString())); } } @@ -694,12 +695,12 @@ namespace panda::test { instance, &arrayU8WriteFrom[0], lengthEcmaStrU8WriteFrom, true)); size_t sizeEcmaStrU8WriteTo = 5; - JSHandle handleEcmaStrAllocTrueWriteTo(thread, + JSHandle handleEcmaStrAllocTrueWriteTo(thread, EcmaStringAccessor::CreateLineString( instance, sizeEcmaStrU8WriteTo, true)); uint32_t indexStartWriteFromArrayU8 = 2; uint32_t lengthWriteFromArrayU8 = 2; - handleEcmaStrAllocTrueWriteTo->ToBaseString()->WriteData(Barriers::GetTaggedObject<>, + handleEcmaStrAllocTrueWriteTo->ToLineString()->WriteData(Barriers::GetTaggedObject<>, handleEcmaStrU8WriteFrom->ToBaseString(), indexStartWriteFromArrayU8, sizeEcmaStrU8WriteTo, lengthWriteFromArrayU8); @@ -724,11 +725,11 @@ namespace panda::test { // WriteData(). From char to EcmaString made by CreateLineString( , true, ). char u8Write = 'a'; size_t sizeEcmaStrU8WriteTo = 5; - JSHandle handleEcmaStrAllocTrueWriteTo(thread, + JSHandle handleEcmaStrAllocTrueWriteTo(thread, EcmaStringAccessor::CreateLineString( instance, sizeEcmaStrU8WriteTo, true)); uint32_t indexAtWriteFromU8 = 4; - handleEcmaStrAllocTrueWriteTo->ToBaseString()->WriteData(indexAtWriteFromU8, u8Write); + handleEcmaStrAllocTrueWriteTo->ToLineString()->Set(indexAtWriteFromU8, u8Write); EXPECT_EQ(handleEcmaStrAllocTrueWriteTo->ToBaseString()->At(Barriers::GetTaggedObject<>, indexAtWriteFromU8), u8Write); } @@ -752,12 +753,12 @@ namespace panda::test { instance, &arrayU16WriteFrom[0], lengthEcmaStrU16WriteFrom, false)); size_t sizeEcmaStrU16WriteTo = 10; - JSHandle handleEcmaStrU16WriteTo(thread, + JSHandle handleEcmaStrU16WriteTo(thread, EcmaStringAccessor::CreateLineString( instance, sizeEcmaStrU16WriteTo, false)); uint32_t indexStartWriteFromArrayU16 = 3; uint32_t numBytesWriteFromArrayU16 = 2 * 3; - handleEcmaStrU16WriteTo->ToBaseString()->WriteData(Barriers::GetTaggedObject<>, + handleEcmaStrU16WriteTo->ToLineString()->WriteData(Barriers::GetTaggedObject<>, handleEcmaStrU16WriteFrom->ToBaseString(), indexStartWriteFromArrayU16, sizeEcmaStrU16WriteTo, numBytesWriteFromArrayU16); @@ -785,12 +786,12 @@ namespace panda::test { instance, &arrayU8WriteFrom[0], lengthEcmaStrU8WriteFrom, true)); size_t sizeEcmaStrU16WriteTo = 10; - JSHandle handleEcmaStrU16WriteTo(thread, + JSHandle handleEcmaStrU16WriteTo(thread, EcmaStringAccessor::CreateLineString( instance, sizeEcmaStrU16WriteTo, false)); uint32_t indexStartWriteFromU8ToU16 = 1; uint32_t numBytesWriteFromU8ToU16 = 4; - handleEcmaStrU16WriteTo->ToBaseString()->WriteData(Barriers::GetTaggedObject<>, + handleEcmaStrU16WriteTo->ToLineString()->WriteData(Barriers::GetTaggedObject<>, handleEcmaStrU8WriteFrom->ToBaseString(), indexStartWriteFromU8ToU16, sizeEcmaStrU16WriteTo, numBytesWriteFromU8ToU16); @@ -812,12 +813,12 @@ namespace panda::test { { // WriteData(). From char to EcmaString made by CreateLineString( , false, ). size_t sizeEcmaStrU16WriteTo = 10; - JSHandle handleEcmaStrU16WriteTo(thread, + JSHandle handleEcmaStrU16WriteTo(thread, EcmaStringAccessor::CreateLineString( instance, sizeEcmaStrU16WriteTo, false)); char u8Write = 'a'; uint32_t indexAt = 4; - handleEcmaStrU16WriteTo->ToBaseString()->WriteData(indexAt, u8Write); + handleEcmaStrU16WriteTo->ToLineString()->Set(indexAt, u8Write); EXPECT_EQ(handleEcmaStrU16WriteTo->ToBaseString()->At(Barriers::GetTaggedObject<>, indexAt), u8Write); } @@ -863,21 +864,21 @@ namespace panda::test { // From EcmaString made by CreateFromUtf8(). uint8_t arrayU8[] = {"abcde"}; uint32_t lengthEcmaStrU8 = sizeof(arrayU8) - 1; - JSHandle handleEcmaStrU8(thread, + JSHandle handleEcmaStrU8(thread, EcmaStringAccessor::CreateFromUtf8( instance, &arrayU8[0], lengthEcmaStrU8, true)); for (uint32_t i = 0; i < lengthEcmaStrU8; i++) { - EXPECT_EQ(*(handleEcmaStrU8->ToBaseString()->GetDataUtf8() + i), arrayU8[i]); + EXPECT_EQ(*(handleEcmaStrU8->ToLineString()->GetDataUtf8() + i), arrayU8[i]); } // From EcmaString made by CreateFromUtf16( , , , true). uint16_t arrayU16Comp[] = {3, 1, 34, 123, 127, 111, 42, 3, 20, 10}; uint32_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]); - JSHandle handleEcmaStrU16Comp(thread, + JSHandle handleEcmaStrU16Comp(thread, EcmaStringAccessor::CreateFromUtf16( instance, &arrayU16Comp[0], lengthEcmaStrU16Comp, true)); for (uint32_t i = 0; i < sizeof(arrayU16Comp) / arrayU16Comp[0]; i++) { - EXPECT_EQ(*(handleEcmaStrU16Comp->ToBaseString()->GetDataUtf8() + i), arrayU16Comp[i]); + EXPECT_EQ(*(handleEcmaStrU16Comp->ToLineString()->GetDataUtf8() + i), arrayU16Comp[i]); } } @@ -892,12 +893,12 @@ namespace panda::test { // From EcmaString made by CreateFromUtf16( , , , false). uint16_t arrayU16NotComp[] = {67, 777, 1999, 1, 45, 66, 23456, 65535, 127, 333}; uint32_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]); - JSHandle handleEcmaStrU16NotComp(thread, + JSHandle handleEcmaStrU16NotComp(thread, EcmaStringAccessor::CreateFromUtf16( instance, &arrayU16NotComp[0], lengthEcmaStrU16NotComp, false)); for (uint32_t i = 0; i < lengthEcmaStrU16NotComp; i++) { - EXPECT_EQ(*(handleEcmaStrU16NotComp->ToBaseString()->GetDataUtf16() + i), arrayU16NotComp[i]); + EXPECT_EQ(*(handleEcmaStrU16NotComp->ToLineString()->GetDataUtf16() + i), arrayU16NotComp[i]); } } @@ -913,9 +914,8 @@ namespace panda::test { // CopyDataRegionUtf8(). From EcmaString made by CreateFromUtf8(). uint8_t arrayU8CopyFrom[6] = {1, 12, 34, 56, 127}; uint32_t lengthEcmaStrU8CopyFrom = sizeof(arrayU8CopyFrom) - 1; - JSHandle handleEcmaStrU8CopyFrom(thread, - EcmaStringAccessor::CreateFromUtf8( - instance, &arrayU8CopyFrom[0], lengthEcmaStrU8CopyFrom, true)); + JSHandle handleEcmaStrU8CopyFrom(thread, EcmaStringAccessor::CreateFromUtf8( + instance, &arrayU8CopyFrom[0], lengthEcmaStrU8CopyFrom, true)); const size_t lengthArrayU8Target = 7; uint8_t defaultByteForU8CopyTo = 1; uint8_t arrayU8CopyTo[lengthArrayU8Target]; @@ -926,13 +926,14 @@ namespace panda::test { size_t indexStartFromArrayU8 = 2; size_t lengthCopyToEcmaStrU8 = 3; size_t lengthReturnU8 = handleEcmaStrU8CopyFrom->ToBaseString()->CopyDataRegionUtf8( - Barriers::GetTaggedObject<>, arrayU8CopyTo, indexStartFromArrayU8, - lengthCopyToEcmaStrU8, lengthArrayU8Target); + Barriers::GetTaggedObject<>, arrayU8CopyTo, indexStartFromArrayU8, lengthCopyToEcmaStrU8, + lengthArrayU8Target); EXPECT_EQ(lengthReturnU8, lengthCopyToEcmaStrU8); for (uint32_t i = 0; i < lengthCopyToEcmaStrU8; i++) { EXPECT_EQ(arrayU8CopyTo[i], - handleEcmaStrU8CopyFrom->ToBaseString()->At(Barriers::GetTaggedObject<>, i + indexStartFromArrayU8)); + handleEcmaStrU8CopyFrom->ToBaseString()->At(Barriers::GetTaggedObject<>, i + indexStartFromArrayU8 + )); } for (uint32_t i = lengthCopyToEcmaStrU8; i < lengthArrayU8Target; i++) { EXPECT_EQ(arrayU8CopyTo[i], defaultByteForU8CopyTo); @@ -941,10 +942,8 @@ namespace panda::test { // CopyDataRegionUtf8(). From EcmaString made by CreateFromUtf16( , , , true). uint16_t arrayU16CompCopyFrom[] = {1, 12, 34, 56, 127}; uint32_t lengthEcmaStrU16CompCopyFrom = sizeof(arrayU16CompCopyFrom) / sizeof(arrayU16CompCopyFrom[0]); - JSHandle handleEcmaStrU16CompCopyFrom(thread, - EcmaStringAccessor::CreateFromUtf16( - instance, &arrayU16CompCopyFrom[0], - lengthEcmaStrU16CompCopyFrom, true)); + JSHandle handleEcmaStrU16CompCopyFrom(thread, EcmaStringAccessor::CreateFromUtf16( + instance, &arrayU16CompCopyFrom[0], lengthEcmaStrU16CompCopyFrom, true)); const size_t lengthArrayU16Target = 8; uint8_t defaultByteForU16CompCopyTo = 1; uint8_t arrayU16CompCopyTo[lengthArrayU16Target]; @@ -1236,14 +1235,17 @@ namespace panda::test { EcmaStringAccessor::CreateFromUtf8( instance, &arrayU8No3[0], lengthEcmaStrU8No3, true)); EXPECT_TRUE( - BaseString::StringIsEqualUint8Data(Barriers::GetTaggedObject<>, handleEcmaStrU8No1->ToBaseString(), & - arrayU8No1[0], lengthEcmaStrU8No1, true)); - EXPECT_FALSE(BaseString::StringIsEqualUint8Data(Barriers::GetTaggedObject<>, handleEcmaStrU8No1->ToBaseString(), - &arrayU8No1[0], lengthEcmaStrU8No1, false)); - EXPECT_FALSE(BaseString::StringIsEqualUint8Data( - Barriers::GetTaggedObject<>, handleEcmaStrU8No2->ToBaseString(), &arrayU8No1[0], lengthEcmaStrU8No1, true)); - EXPECT_FALSE(BaseString::StringIsEqualUint8Data( - Barriers::GetTaggedObject<>, handleEcmaStrU8No3->ToBaseString(), &arrayU8No1[0], lengthEcmaStrU8No1, true)); + BaseString::StringIsEqualUint8Data(Barriers::GetTaggedObject<>, handleEcmaStrU8No1->ToBaseString(), + &arrayU8No1[0], lengthEcmaStrU8No1, true)); + EXPECT_FALSE( + BaseString::StringIsEqualUint8Data(Barriers::GetTaggedObject<>, handleEcmaStrU8No1->ToBaseString(), + &arrayU8No1[0], lengthEcmaStrU8No1, false)); + EXPECT_FALSE( + BaseString::StringIsEqualUint8Data(Barriers::GetTaggedObject<>, handleEcmaStrU8No2->ToBaseString(), + &arrayU8No1[0], lengthEcmaStrU8No1, true)); + EXPECT_FALSE( + BaseString::StringIsEqualUint8Data(Barriers::GetTaggedObject<>, handleEcmaStrU8No3->ToBaseString(), + &arrayU8No1[0], lengthEcmaStrU8No1, true)); } /* @@ -1617,7 +1619,7 @@ namespace panda::test { * @tc.type: FUNC * @tc.require: */ - HWTEST_F_L0(BaseStringTest, EqualToSplicedString) + HWTEST_F_L0(BaseStringTest, EqualToSplicedString001) { ObjectFactory* factory = instance->GetFactory(); { @@ -1667,7 +1669,18 @@ namespace panda::test { Barriers::GetTaggedObject<>, firstString->ToBaseString(), secondString->ToBaseString()); EXPECT_TRUE(result); } + } + /* + * @tc.name: EqualToSplicedString + * @tc.desc: Tests whether the source string is equal to the concatenated string. + * is within expectations. + * @tc.type: FUNC + * @tc.require: + */ + HWTEST_F_L0(BaseStringTest, EqualToSplicedString002) + { + ObjectFactory* factory = instance->GetFactory(); { JSHandle sourceString = factory->NewFromUtf8("Startstart"); JSHandle firstString = factory->NewFromASCII("Start"); diff --git a/ecmascript/tests/dynamic_type_converter_test.cpp b/ecmascript/tests/dynamic_type_converter_test.cpp index 42f0bc44ed..d55466d20f 100644 --- a/ecmascript/tests/dynamic_type_converter_test.cpp +++ b/ecmascript/tests/dynamic_type_converter_test.cpp @@ -206,7 +206,7 @@ HWTEST_F_L0(DynamicTypeConverterTest, WrapTagged_Test2) EcmaString* str1 = EcmaString::Cast(result.GetTaggedObject()); // Verify BigInt properties EXPECT_EQ(EcmaStringAccessor(str1).GetLength(), str->ToBaseString()->GetLength()); - EXPECT_EQ(EcmaStringAccessor(str1).GetDataUtf8(), str->ToBaseString()->GetDataUtf8()); + EXPECT_EQ(EcmaStringAccessor(str1).GetDataUtf8(), LineString::Cast(str->ToBaseString())->GetDataUtf8()); } } diff --git a/ecmascript/tests/js_hclass_test.cpp b/ecmascript/tests/js_hclass_test.cpp index 4ee9fafdc3..46ef36f847 100644 --- a/ecmascript/tests/js_hclass_test.cpp +++ b/ecmascript/tests/js_hclass_test.cpp @@ -72,10 +72,18 @@ HWTEST_F_L0(JSHClassTest, SizeFromJSHClass) EXPECT_EQ(objectSize, 96U); EcmaString *string = EcmaStringAccessor::CreateEmptyString(vm); objectSize = string->GetSize(); +#if defined(ARK_HYBRID) || defined(USE_CMC_GC) + EXPECT_EQ(objectSize, 24U); +#else EXPECT_EQ(objectSize, 16U); +#endif string = factory->AllocTreeStringObject(); objectSize = string->GetClass()->SizeFromJSHClass(string); +#if defined(ARK_HYBRID) || defined(USE_CMC_GC) + EXPECT_EQ(objectSize, 40U); +#else EXPECT_EQ(objectSize, 32U); +#endif MachineCodeDesc desc; desc.codeType = MachineCodeType::BASELINE_CODE; desc.instructionsSize = 100; -- Gitee From 54b07f6a7c8a1c132165a8efdf7f70ed06ca8c91 Mon Sep 17 00:00:00 2001 From: lhc Date: Wed, 9 Jul 2025 19:04:18 +0800 Subject: [PATCH 29/54] Resolving git conflicts Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICK92F?from=project-issue Signed-off-by: lhc Change-Id: I488b9c47e1a5dbe650d451401f5a06b5e29c8dda --- ecmascript/base/json_helper.h | 2 +- ecmascript/builtins/builtins_promise_job.cpp | 2 +- .../builtins/tests/builtins_number_test.cpp | 4 +-- .../compiler/aot_file/tests/aot_file_test.cpp | 4 +-- .../builtins/builtins_string_stub_builder.h | 1 + ecmascript/dynamic_type_converter.cpp | 2 +- ecmascript/js_function.cpp | 2 +- ecmascript/js_runtime_options.h | 2 +- ecmascript/mem/cmc_gc/hooks.cpp | 32 ++++++++++--------- ecmascript/mem/dynamic_object_operator.cpp | 2 +- .../module/static/static_module_loader.cpp | 3 +- .../static/static_module_proxy_handler.cpp | 1 - ecmascript/serializer/value_serializer.h | 2 +- ecmascript/stubs/runtime_stubs.cpp | 10 +++--- ecmascript/tagged_dictionary.cpp | 4 +-- 15 files changed, 36 insertions(+), 37 deletions(-) diff --git a/ecmascript/base/json_helper.h b/ecmascript/base/json_helper.h index 413f4b359b..c39297367e 100644 --- a/ecmascript/base/json_helper.h +++ b/ecmascript/base/json_helper.h @@ -19,7 +19,7 @@ #include "ecmascript/js_handle.h" #include "ecmascript/mem/c_string.h" #include "ecmascript/property_attributes.h" -#include "libpandabase/utils/span.h" +#include "common_interfaces/objects/utils/span.h" namespace panda::ecmascript::base { constexpr int HEX_DIGIT_MASK = 0xF; diff --git a/ecmascript/builtins/builtins_promise_job.cpp b/ecmascript/builtins/builtins_promise_job.cpp index 435f8aa5e6..b1dfdc7466 100644 --- a/ecmascript/builtins/builtins_promise_job.cpp +++ b/ecmascript/builtins/builtins_promise_job.cpp @@ -309,7 +309,7 @@ JSTaggedValue BuiltinsPromiseJob::HandelModuleException(JSThread *thread, JSHand } // try load 1.2 module; Local getEsModuleFunc = getEsModule; - ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager(); + ModuleManager *moduleManager = thread->GetModuleManager(); JSHandle exportObject = StaticModuleLoader::LoadStaticModule(thread, getEsModuleFunc, requestPath); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); LOG_ECMA(DEBUG) << "load static module successfull, requestPath: " << requestPath; diff --git a/ecmascript/builtins/tests/builtins_number_test.cpp b/ecmascript/builtins/tests/builtins_number_test.cpp index bf24174e0e..2cce8e4a47 100644 --- a/ecmascript/builtins/tests/builtins_number_test.cpp +++ b/ecmascript/builtins/tests/builtins_number_test.cpp @@ -461,7 +461,7 @@ HWTEST_F_L0(BuiltinsNumberTest, parseInt) HWTEST_F_L0(BuiltinsNumberTest, StringToDoubleFlags) { JSHandle str; - Span sp; + common::Span sp; CVector buf; // flags of IGNORE_TRAILING @@ -543,7 +543,7 @@ HWTEST_F_L0(BuiltinsNumberTest, StringToDoubleFlags) HWTEST_F_L0(BuiltinsNumberTest, StringToDoubleRadix) { JSHandle str; - Span sp; + common::Span sp; CVector buf; int radix; diff --git a/ecmascript/compiler/aot_file/tests/aot_file_test.cpp b/ecmascript/compiler/aot_file/tests/aot_file_test.cpp index dc311d04c3..cdc950e9c8 100644 --- a/ecmascript/compiler/aot_file/tests/aot_file_test.cpp +++ b/ecmascript/compiler/aot_file/tests/aot_file_test.cpp @@ -316,7 +316,7 @@ protected: // Ensure AOT file exists ASSERT_TRUE(AOTFileManager::AOTFileExist(testAotPath_, AOTFileManager::FILE_EXTENSION_AN)); std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - vm->GetJSThread(), CString(testAbcPath_.c_str()), testRecordName_, false, false, ExecuteTypes::STATIC); + vm->GetJSThread(), CString(testAbcPath_.c_str()), testRecordName_, false, ExecuteTypes::STATIC); ASSERT_TRUE(jsPandaFile != nullptr); // Perform binding vm->GetAOTFileManager()->BindPreloadedPandaFilesInAotFile(testRecordName_); @@ -368,7 +368,6 @@ protected: CString(testAbcPath.c_str()), testRecordName, false, - false, ExecuteTypes::STATIC); ASSERT_TRUE(jsPandaFile.get() != nullptr); // Test command-line mode branch @@ -401,7 +400,6 @@ protected: CString(testAbcPath.c_str()), testRecordName, false, - false, ExecuteTypes::STATIC); ASSERT_TRUE(jsPandaFile.get() != nullptr); // Verify WasAOTOutputFileSet is false diff --git a/ecmascript/compiler/builtins/builtins_string_stub_builder.h b/ecmascript/compiler/builtins/builtins_string_stub_builder.h index 5e4eae6741..c99b03541b 100644 --- a/ecmascript/compiler/builtins/builtins_string_stub_builder.h +++ b/ecmascript/compiler/builtins/builtins_string_stub_builder.h @@ -98,6 +98,7 @@ private: GateRef GetSingleCharCodeFromSlicedString(GateRef glue, GateRef str, GateRef index); void CheckParamsAndGetPosition(GateRef glue, GateRef thisValue, GateRef numArgs, Variable* pos, Label *exit, Label *slowPath, Label *posIsValid); + static constexpr uint32_t INIT_LENGTH_TIMES = 4; }; class FlatStringStubBuilder : public StubBuilder { diff --git a/ecmascript/dynamic_type_converter.cpp b/ecmascript/dynamic_type_converter.cpp index bbaaaff7c1..e78bd6185f 100644 --- a/ecmascript/dynamic_type_converter.cpp +++ b/ecmascript/dynamic_type_converter.cpp @@ -71,7 +71,7 @@ JSTaggedValue DynamicTypeConverter::WrapTagged(ThreadHolder *thread, BaseType va return result; } -PandaType DynamicTypeConverter::UnwrapTagged(JSTaggedValue value) +BaseType DynamicTypeConverter::UnWrapTagged(JSTaggedValue value) { if (value.IsBoolean()) { return value.ToBoolean(); diff --git a/ecmascript/js_function.cpp b/ecmascript/js_function.cpp index d7ff7e2cd8..682340a2c5 100644 --- a/ecmascript/js_function.cpp +++ b/ecmascript/js_function.cpp @@ -111,7 +111,7 @@ void JSFunction::InitializeWithDefaultValueCommon(JSThread *thread, const JSHand func->SetRawProfileTypeInfo(thread, thread->GlobalConstants()->GetEmptyProfileTypeInfoCell()); func->SetMethod(thread, JSTaggedValue::Undefined()); func->SetModule(thread, JSTaggedValue::Undefined()); - func->SetInterfaceType(thread, JSTaggedValue::Undefined(), SKIP_BARRIER); + func->SetInterfaceType(thread, JSTaggedValue::Undefined()); func->SetCodeEntry(reinterpret_cast(nullptr)); func->ClearCompiledCodeFlags(); func->SetTaskConcurrentFuncFlag(0); // 0 : default value diff --git a/ecmascript/js_runtime_options.h b/ecmascript/js_runtime_options.h index 2aeeb7be5b..dabeafd0d2 100644 --- a/ecmascript/js_runtime_options.h +++ b/ecmascript/js_runtime_options.h @@ -253,7 +253,7 @@ enum CommandValues { class PUBLIC_API JSRuntimeOptions { public: JSRuntimeOptions(); - JSRuntimeOptions(const RuntimeParam ¶m) : param_(param) {} + JSRuntimeOptions(const common::RuntimeParam ¶m) : param_(param) {} ~JSRuntimeOptions() = default; DEFAULT_COPY_SEMANTIC(JSRuntimeOptions); DEFAULT_MOVE_SEMANTIC(JSRuntimeOptions); diff --git a/ecmascript/mem/cmc_gc/hooks.cpp b/ecmascript/mem/cmc_gc/hooks.cpp index e0a750bcf2..15d43ffcd8 100644 --- a/ecmascript/mem/cmc_gc/hooks.cpp +++ b/ecmascript/mem/cmc_gc/hooks.cpp @@ -39,7 +39,7 @@ using panda::ecmascript::JSThread; using panda::ecmascript::TaggedType; // A fake EcmaVM which will never used, only for unify the BaseRuntime::Init&Fini -static ecmascript::EcmaVM *g_fakeEcmaVM = nullptr; +static panda::ecmascript::EcmaVM *g_fakeEcmaVM = nullptr; static std::mutex g_rtMutexForStatic; class CMCRootVisitor final : public panda::ecmascript::RootVisitor { @@ -108,7 +108,7 @@ private: void VisitBaseRoots(const RefFieldVisitor &visitorFunc) { // todo 梁婷婷 - if (!ecmascript::Runtime::HasInstance()) { + if (!panda::ecmascript::Runtime::HasInstance()) { return; } @@ -120,7 +120,7 @@ void VisitBaseRoots(const RefFieldVisitor &visitorFunc) void VisitDynamicGlobalRoots(const RefFieldVisitor &visitorFunc) { - if (!ecmascript::Runtime::HasInstance()) { + if (!panda::ecmascript::Runtime::HasInstance()) { return; } @@ -139,7 +139,7 @@ void VisitDynamicGlobalRoots(const RefFieldVisitor &visitorFunc) void VisitDynamicLocalRoots(const RefFieldVisitor &visitorFunc) { - if (!ecmascript::Runtime::HasInstance()) { + if (!panda::ecmascript::Runtime::HasInstance()) { return; } OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::VisitDynamicLocalRoots", ""); @@ -151,13 +151,15 @@ void VisitDynamicLocalRoots(const RefFieldVisitor &visitorFunc) auto profiler = vm->GetPGOProfiler(); if (profiler != nullptr) { + profiler->IteratePGOPreFuncList(visitor); } + }); } void VisitDynamicWeakGlobalRoots(const common::WeakRefFieldVisitor &visitorFunc) { OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::VisitDynamicWeakGlobalRoots", ""); - if (!ecmascript::Runtime::HasInstance()) { + if (!panda::ecmascript::Runtime::HasInstance()) { return; } CMCWeakVisitor visitor(visitorFunc); @@ -176,7 +178,7 @@ void VisitDynamicWeakGlobalRoots(const common::WeakRefFieldVisitor &visitorFunc) void VisitDynamicWeakLocalRoots(const common::WeakRefFieldVisitor &visitorFunc) { - if (!ecmascript::Runtime::HasInstance()) { + if (!panda::ecmascript::Runtime::HasInstance()) { return; } OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::VisitDynamicWeakLocalRoots", ""); @@ -194,7 +196,7 @@ void VisitDynamicWeakLocalRoots(const common::WeakRefFieldVisitor &visitorFunc) void VisitDynamicThreadRoot(const RefFieldVisitor &visitorFunc, void *vm) { - if (!ecmascript::Runtime::HasInstance()) { + if (!panda::ecmascript::Runtime::HasInstance()) { return; } OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::VisitDynamicThreadRoot", ""); @@ -213,7 +215,7 @@ void VisitDynamicThreadRoot(const RefFieldVisitor &visitorFunc, void *vm) void VisitDynamicWeakThreadRoot(const WeakRefFieldVisitor &visitorFunc, void *vm) { - if (!ecmascript::Runtime::HasInstance()) { + if (!panda::ecmascript::Runtime::HasInstance()) { return; } OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::VisitDynamicWeakThreadRoot", ""); @@ -294,8 +296,8 @@ void CheckAndInitBaseRuntime(const RuntimeParam ¶m) // BaseRuntime is inited from Dynamic return; } - ecmascript::JSRuntimeOptions options(param); - g_fakeEcmaVM = ecmascript::EcmaVM::Create(options); + panda::ecmascript::JSRuntimeOptions options(param); + g_fakeEcmaVM = panda::ecmascript::EcmaVM::Create(options); } void CheckAndFiniBaseRuntime() @@ -306,7 +308,7 @@ void CheckAndFiniBaseRuntime() return; } g_fakeEcmaVM->GetJSThread()->ManagedCodeBegin(); - ecmascript::EcmaVM::Destroy(g_fakeEcmaVM); + panda::ecmascript::EcmaVM::Destroy(g_fakeEcmaVM); g_fakeEcmaVM = nullptr; } @@ -330,17 +332,17 @@ bool IsMachineCodeObject(uintptr_t objPtr) void AddXRefToDynamicRoots() { - ecmascript::Runtime *runtime = ecmascript::Runtime::GetInstance(); + panda::ecmascript::Runtime *runtime = panda::ecmascript::Runtime::GetInstance(); runtime->GCIterateThreadList([&](JSThread *thread) { - thread->SetNodeKind(ecmascript::NodeKind::NORMAL_NODE); + thread->SetNodeKind(panda::ecmascript::NodeKind::NORMAL_NODE); }); } void RemoveXRefFromDynamicRoots() { - ecmascript::Runtime *runtime = ecmascript::Runtime::GetInstance(); + panda::ecmascript::Runtime *runtime = panda::ecmascript::Runtime::GetInstance(); runtime->GCIterateThreadList([&](JSThread *thread) { - thread->SetNodeKind(ecmascript::NodeKind::UNIFIED_NODE); + thread->SetNodeKind(panda::ecmascript::NodeKind::UNIFIED_NODE); }); } diff --git a/ecmascript/mem/dynamic_object_operator.cpp b/ecmascript/mem/dynamic_object_operator.cpp index 618bb47107..82191a4171 100644 --- a/ecmascript/mem/dynamic_object_operator.cpp +++ b/ecmascript/mem/dynamic_object_operator.cpp @@ -32,7 +32,7 @@ void DynamicObjectOperator::Initialize() void DynamicObjectOperator::IterateXRef([[maybe_unused]] const BaseObject *object, [[maybe_unused]] const common::RefFieldVisitor &visitor) const { -#if defined(PANDA_JS_ETS_HYBRID_MODE) + #if defined(PANDA_JS_ETS_HYBRID_MODE) && defined(USE_CMC_GC) if (g_isEnableCMCGC) { JSTaggedValue value(reinterpret_cast(const_cast(object))); if (value.IsJSXRefObject()) { diff --git a/ecmascript/module/static/static_module_loader.cpp b/ecmascript/module/static/static_module_loader.cpp index b4bd0e8619..2701ae9245 100644 --- a/ecmascript/module/static/static_module_loader.cpp +++ b/ecmascript/module/static/static_module_loader.cpp @@ -16,7 +16,6 @@ #include "ecmascript/module/static/static_module_loader.h" #include "ecmascript/global_env.h" #include "ecmascript/object_factory-inl.h" -#include "ecmascript/module/module_manager_helper.h" #include "ecmascript/module/module_path_helper.h" #include "ecmascript/module/js_module_deregister.h" #include "ecmascript/module/js_shared_module_manager.h" @@ -65,7 +64,7 @@ Local StaticModuleLoader::GetStaticModuleLoadFunc(EcmaVM *vm) JSHandle StaticModuleLoader::LoadStaticModule(JSThread *thread, Local getEsModuleFunc, const CString &key) { - auto moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager(); + auto moduleManager = thread->GetModuleManager(); if (moduleManager->IsModuleLoaded(key)) { LOG_ECMA(INFO) << "load static module from cache."; JSHandle moduleRecord = moduleManager->HostGetImportedModule(key); diff --git a/ecmascript/module/static/static_module_proxy_handler.cpp b/ecmascript/module/static/static_module_proxy_handler.cpp index e2169594ea..181a45dbf0 100644 --- a/ecmascript/module/static/static_module_proxy_handler.cpp +++ b/ecmascript/module/static/static_module_proxy_handler.cpp @@ -16,7 +16,6 @@ #include "ecmascript/module/static/static_module_proxy_handler.h" #include "ecmascript/global_env.h" #include "ecmascript/object_factory-inl.h" -#include "ecmascript/module/module_manager_helper.h" #include "ecmascript/module/module_path_helper.h" #include "ecmascript/module/js_module_deregister.h" #include "ecmascript/module/js_shared_module_manager.h" diff --git a/ecmascript/serializer/value_serializer.h b/ecmascript/serializer/value_serializer.h index 6fa72155c8..1c3c78f431 100644 --- a/ecmascript/serializer/value_serializer.h +++ b/ecmascript/serializer/value_serializer.h @@ -69,7 +69,7 @@ private: bool SerializeModuleCNativeObjects(TaggedObject *object); protected: - void SerializeObjectImpl(TaggedObject *object) override; + void SerializeObjectImpl(TaggedObject *object, bool isWeak = false) override; bool notSupport_ {false}; private: diff --git a/ecmascript/stubs/runtime_stubs.cpp b/ecmascript/stubs/runtime_stubs.cpp index 1030160b74..95e27c3fdc 100644 --- a/ecmascript/stubs/runtime_stubs.cpp +++ b/ecmascript/stubs/runtime_stubs.cpp @@ -3573,7 +3573,7 @@ JSTaggedValue RuntimeStubs::NumberHelperStringToDouble(EcmaString *numberString) { DISALLOW_GARBAGE_COLLECTION; CVector buf; - Span str = EcmaStringAccessor(numberString).ToUtf8Span(buf); + common::Span str = EcmaStringAccessor(numberString).ToUtf8Span(buf); if (base::NumberHelper::IsEmptyString(str.begin(), str.end())) { return base::BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); } @@ -3856,10 +3856,10 @@ int32_t RuntimeStubs::StringGetStart(bool isUtf8, EcmaString *srcString, int32_t { DISALLOW_GARBAGE_COLLECTION; if (isUtf8) { - Span data(EcmaStringAccessor(srcString).GetDataUtf8() + startIndex, length); + common::Span data(EcmaStringAccessor(srcString).GetDataUtf8() + startIndex, length); return static_cast(base::StringHelper::GetStart(data, length)); } else { - Span data(EcmaStringAccessor(srcString).GetDataUtf16() + startIndex, length); + common::Span data(EcmaStringAccessor(srcString).GetDataUtf16() + startIndex, length); return static_cast(base::StringHelper::GetStart(data, length)); } } @@ -3869,10 +3869,10 @@ int32_t RuntimeStubs::StringGetEnd(bool isUtf8, EcmaString *srcString, { DISALLOW_GARBAGE_COLLECTION; if (isUtf8) { - Span data(EcmaStringAccessor(srcString).GetDataUtf8() + startIndex, length); + common::Span data(EcmaStringAccessor(srcString).GetDataUtf8() + startIndex, length); return base::StringHelper::GetEnd(data, start, length); } else { - Span data(EcmaStringAccessor(srcString).GetDataUtf16() + startIndex, length); + common::Span data(EcmaStringAccessor(srcString).GetDataUtf16() + startIndex, length); return base::StringHelper::GetEnd(data, start, length); } } diff --git a/ecmascript/tagged_dictionary.cpp b/ecmascript/tagged_dictionary.cpp index fe4ba21854..d229331c39 100644 --- a/ecmascript/tagged_dictionary.cpp +++ b/ecmascript/tagged_dictionary.cpp @@ -54,8 +54,8 @@ bool NameDictionary::IsMatch(const uint8_t* str, int size, const JSTaggedValue & } EcmaString *keyString = reinterpret_cast(other.GetTaggedObject()); - Span data1(EcmaStringAccessor(keyString).GetDataUtf8(), keyString->GetLength()); - Span data2(str, size); + common::Span data1(EcmaStringAccessor(keyString).GetDataUtf8(), keyString->GetLength()); + common::Span data2(str, size); if (data1.Size() != data2.Size()) { return false; } -- Gitee From c3feac71503717bfd1c0e6efa4876fe5dbd1dc5e Mon Sep 17 00:00:00 2001 From: lhc Date: Wed, 9 Jul 2025 19:04:18 +0800 Subject: [PATCH 30/54] Resolving git conflicts Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICK92F?from=project-issue Signed-off-by: lhc Change-Id: I488b9c47e1a5dbe650d451401f5a06b5e29c8dda --- ecmascript/base/json_helper.h | 2 +- ecmascript/builtins/builtins_promise_job.cpp | 2 +- .../builtins/tests/builtins_number_test.cpp | 4 +-- .../compiler/aot_file/tests/aot_file_test.cpp | 4 +-- .../builtins/builtins_string_stub_builder.h | 1 + .../dfx/hprof/tests/js_metadata_test.cpp | 20 ++++++------ ecmascript/dynamic_type_converter.cpp | 2 +- ecmascript/js_function.cpp | 2 +- ecmascript/js_runtime_options.h | 2 +- ecmascript/mem/cmc_gc/hooks.cpp | 32 ++++++++++--------- ecmascript/mem/dynamic_object_operator.cpp | 2 +- .../module/static/static_module_loader.cpp | 3 +- .../static/static_module_proxy_handler.cpp | 1 - ecmascript/serializer/value_serializer.h | 2 +- ecmascript/stubs/runtime_stubs.cpp | 10 +++--- ecmascript/tagged_dictionary.cpp | 4 +-- 16 files changed, 46 insertions(+), 47 deletions(-) diff --git a/ecmascript/base/json_helper.h b/ecmascript/base/json_helper.h index 413f4b359b..c39297367e 100644 --- a/ecmascript/base/json_helper.h +++ b/ecmascript/base/json_helper.h @@ -19,7 +19,7 @@ #include "ecmascript/js_handle.h" #include "ecmascript/mem/c_string.h" #include "ecmascript/property_attributes.h" -#include "libpandabase/utils/span.h" +#include "common_interfaces/objects/utils/span.h" namespace panda::ecmascript::base { constexpr int HEX_DIGIT_MASK = 0xF; diff --git a/ecmascript/builtins/builtins_promise_job.cpp b/ecmascript/builtins/builtins_promise_job.cpp index 435f8aa5e6..b1dfdc7466 100644 --- a/ecmascript/builtins/builtins_promise_job.cpp +++ b/ecmascript/builtins/builtins_promise_job.cpp @@ -309,7 +309,7 @@ JSTaggedValue BuiltinsPromiseJob::HandelModuleException(JSThread *thread, JSHand } // try load 1.2 module; Local getEsModuleFunc = getEsModule; - ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager(); + ModuleManager *moduleManager = thread->GetModuleManager(); JSHandle exportObject = StaticModuleLoader::LoadStaticModule(thread, getEsModuleFunc, requestPath); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); LOG_ECMA(DEBUG) << "load static module successfull, requestPath: " << requestPath; diff --git a/ecmascript/builtins/tests/builtins_number_test.cpp b/ecmascript/builtins/tests/builtins_number_test.cpp index bf24174e0e..2cce8e4a47 100644 --- a/ecmascript/builtins/tests/builtins_number_test.cpp +++ b/ecmascript/builtins/tests/builtins_number_test.cpp @@ -461,7 +461,7 @@ HWTEST_F_L0(BuiltinsNumberTest, parseInt) HWTEST_F_L0(BuiltinsNumberTest, StringToDoubleFlags) { JSHandle str; - Span sp; + common::Span sp; CVector buf; // flags of IGNORE_TRAILING @@ -543,7 +543,7 @@ HWTEST_F_L0(BuiltinsNumberTest, StringToDoubleFlags) HWTEST_F_L0(BuiltinsNumberTest, StringToDoubleRadix) { JSHandle str; - Span sp; + common::Span sp; CVector buf; int radix; diff --git a/ecmascript/compiler/aot_file/tests/aot_file_test.cpp b/ecmascript/compiler/aot_file/tests/aot_file_test.cpp index dc311d04c3..cdc950e9c8 100644 --- a/ecmascript/compiler/aot_file/tests/aot_file_test.cpp +++ b/ecmascript/compiler/aot_file/tests/aot_file_test.cpp @@ -316,7 +316,7 @@ protected: // Ensure AOT file exists ASSERT_TRUE(AOTFileManager::AOTFileExist(testAotPath_, AOTFileManager::FILE_EXTENSION_AN)); std::shared_ptr jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( - vm->GetJSThread(), CString(testAbcPath_.c_str()), testRecordName_, false, false, ExecuteTypes::STATIC); + vm->GetJSThread(), CString(testAbcPath_.c_str()), testRecordName_, false, ExecuteTypes::STATIC); ASSERT_TRUE(jsPandaFile != nullptr); // Perform binding vm->GetAOTFileManager()->BindPreloadedPandaFilesInAotFile(testRecordName_); @@ -368,7 +368,6 @@ protected: CString(testAbcPath.c_str()), testRecordName, false, - false, ExecuteTypes::STATIC); ASSERT_TRUE(jsPandaFile.get() != nullptr); // Test command-line mode branch @@ -401,7 +400,6 @@ protected: CString(testAbcPath.c_str()), testRecordName, false, - false, ExecuteTypes::STATIC); ASSERT_TRUE(jsPandaFile.get() != nullptr); // Verify WasAOTOutputFileSet is false diff --git a/ecmascript/compiler/builtins/builtins_string_stub_builder.h b/ecmascript/compiler/builtins/builtins_string_stub_builder.h index 5e4eae6741..c99b03541b 100644 --- a/ecmascript/compiler/builtins/builtins_string_stub_builder.h +++ b/ecmascript/compiler/builtins/builtins_string_stub_builder.h @@ -98,6 +98,7 @@ private: GateRef GetSingleCharCodeFromSlicedString(GateRef glue, GateRef str, GateRef index); void CheckParamsAndGetPosition(GateRef glue, GateRef thisValue, GateRef numArgs, Variable* pos, Label *exit, Label *slowPath, Label *posIsValid); + static constexpr uint32_t INIT_LENGTH_TIMES = 4; }; class FlatStringStubBuilder : public StubBuilder { diff --git a/ecmascript/dfx/hprof/tests/js_metadata_test.cpp b/ecmascript/dfx/hprof/tests/js_metadata_test.cpp index 81d0f00165..5cf39991d7 100644 --- a/ecmascript/dfx/hprof/tests/js_metadata_test.cpp +++ b/ecmascript/dfx/hprof/tests/js_metadata_test.cpp @@ -3156,16 +3156,16 @@ HWTEST_F_L0(JSMetadataTest, TestJsFloat64ArrayMetadata) ASSERT_TRUE(tester.Test(JSType::JS_FLOAT64_ARRAY, metadata)); } -HWTEST_F_L0(JSMetadataTest, TestJsForinIteratorMetadata) -{ - JSMetadataTestHelper tester {}; - std::string metadataFilePath = METADATA_SOURCE_FILE_DIR"js_forin_iterator.json"; - JSMetadataTestHelper::Metadata metadata {}; - - tester.ReadAndParseMetadataJson(metadataFilePath, metadata); - ASSERT_TRUE(metadata.status == JSMetadataTestHelper::INITIALIZED); - ASSERT_TRUE(tester.Test(JSType::JS_FORIN_ITERATOR, metadata)); -} +// HWTEST_F_L0(JSMetadataTest, TestJsForinIteratorMetadata) +// { +// JSMetadataTestHelper tester {}; +// std::string metadataFilePath = METADATA_SOURCE_FILE_DIR"js_forin_iterator.json"; +// JSMetadataTestHelper::Metadata metadata {}; + +// tester.ReadAndParseMetadataJson(metadataFilePath, metadata); +// ASSERT_TRUE(metadata.status == JSMetadataTestHelper::INITIALIZED); +// ASSERT_TRUE(tester.Test(JSType::JS_FORIN_ITERATOR, metadata)); +// } HWTEST_F_L0(JSMetadataTest, TestJsFunctionMetadata) { diff --git a/ecmascript/dynamic_type_converter.cpp b/ecmascript/dynamic_type_converter.cpp index bbaaaff7c1..e78bd6185f 100644 --- a/ecmascript/dynamic_type_converter.cpp +++ b/ecmascript/dynamic_type_converter.cpp @@ -71,7 +71,7 @@ JSTaggedValue DynamicTypeConverter::WrapTagged(ThreadHolder *thread, BaseType va return result; } -PandaType DynamicTypeConverter::UnwrapTagged(JSTaggedValue value) +BaseType DynamicTypeConverter::UnWrapTagged(JSTaggedValue value) { if (value.IsBoolean()) { return value.ToBoolean(); diff --git a/ecmascript/js_function.cpp b/ecmascript/js_function.cpp index d7ff7e2cd8..682340a2c5 100644 --- a/ecmascript/js_function.cpp +++ b/ecmascript/js_function.cpp @@ -111,7 +111,7 @@ void JSFunction::InitializeWithDefaultValueCommon(JSThread *thread, const JSHand func->SetRawProfileTypeInfo(thread, thread->GlobalConstants()->GetEmptyProfileTypeInfoCell()); func->SetMethod(thread, JSTaggedValue::Undefined()); func->SetModule(thread, JSTaggedValue::Undefined()); - func->SetInterfaceType(thread, JSTaggedValue::Undefined(), SKIP_BARRIER); + func->SetInterfaceType(thread, JSTaggedValue::Undefined()); func->SetCodeEntry(reinterpret_cast(nullptr)); func->ClearCompiledCodeFlags(); func->SetTaskConcurrentFuncFlag(0); // 0 : default value diff --git a/ecmascript/js_runtime_options.h b/ecmascript/js_runtime_options.h index 2aeeb7be5b..dabeafd0d2 100644 --- a/ecmascript/js_runtime_options.h +++ b/ecmascript/js_runtime_options.h @@ -253,7 +253,7 @@ enum CommandValues { class PUBLIC_API JSRuntimeOptions { public: JSRuntimeOptions(); - JSRuntimeOptions(const RuntimeParam ¶m) : param_(param) {} + JSRuntimeOptions(const common::RuntimeParam ¶m) : param_(param) {} ~JSRuntimeOptions() = default; DEFAULT_COPY_SEMANTIC(JSRuntimeOptions); DEFAULT_MOVE_SEMANTIC(JSRuntimeOptions); diff --git a/ecmascript/mem/cmc_gc/hooks.cpp b/ecmascript/mem/cmc_gc/hooks.cpp index e0a750bcf2..15d43ffcd8 100644 --- a/ecmascript/mem/cmc_gc/hooks.cpp +++ b/ecmascript/mem/cmc_gc/hooks.cpp @@ -39,7 +39,7 @@ using panda::ecmascript::JSThread; using panda::ecmascript::TaggedType; // A fake EcmaVM which will never used, only for unify the BaseRuntime::Init&Fini -static ecmascript::EcmaVM *g_fakeEcmaVM = nullptr; +static panda::ecmascript::EcmaVM *g_fakeEcmaVM = nullptr; static std::mutex g_rtMutexForStatic; class CMCRootVisitor final : public panda::ecmascript::RootVisitor { @@ -108,7 +108,7 @@ private: void VisitBaseRoots(const RefFieldVisitor &visitorFunc) { // todo 梁婷婷 - if (!ecmascript::Runtime::HasInstance()) { + if (!panda::ecmascript::Runtime::HasInstance()) { return; } @@ -120,7 +120,7 @@ void VisitBaseRoots(const RefFieldVisitor &visitorFunc) void VisitDynamicGlobalRoots(const RefFieldVisitor &visitorFunc) { - if (!ecmascript::Runtime::HasInstance()) { + if (!panda::ecmascript::Runtime::HasInstance()) { return; } @@ -139,7 +139,7 @@ void VisitDynamicGlobalRoots(const RefFieldVisitor &visitorFunc) void VisitDynamicLocalRoots(const RefFieldVisitor &visitorFunc) { - if (!ecmascript::Runtime::HasInstance()) { + if (!panda::ecmascript::Runtime::HasInstance()) { return; } OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::VisitDynamicLocalRoots", ""); @@ -151,13 +151,15 @@ void VisitDynamicLocalRoots(const RefFieldVisitor &visitorFunc) auto profiler = vm->GetPGOProfiler(); if (profiler != nullptr) { + profiler->IteratePGOPreFuncList(visitor); } + }); } void VisitDynamicWeakGlobalRoots(const common::WeakRefFieldVisitor &visitorFunc) { OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::VisitDynamicWeakGlobalRoots", ""); - if (!ecmascript::Runtime::HasInstance()) { + if (!panda::ecmascript::Runtime::HasInstance()) { return; } CMCWeakVisitor visitor(visitorFunc); @@ -176,7 +178,7 @@ void VisitDynamicWeakGlobalRoots(const common::WeakRefFieldVisitor &visitorFunc) void VisitDynamicWeakLocalRoots(const common::WeakRefFieldVisitor &visitorFunc) { - if (!ecmascript::Runtime::HasInstance()) { + if (!panda::ecmascript::Runtime::HasInstance()) { return; } OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::VisitDynamicWeakLocalRoots", ""); @@ -194,7 +196,7 @@ void VisitDynamicWeakLocalRoots(const common::WeakRefFieldVisitor &visitorFunc) void VisitDynamicThreadRoot(const RefFieldVisitor &visitorFunc, void *vm) { - if (!ecmascript::Runtime::HasInstance()) { + if (!panda::ecmascript::Runtime::HasInstance()) { return; } OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::VisitDynamicThreadRoot", ""); @@ -213,7 +215,7 @@ void VisitDynamicThreadRoot(const RefFieldVisitor &visitorFunc, void *vm) void VisitDynamicWeakThreadRoot(const WeakRefFieldVisitor &visitorFunc, void *vm) { - if (!ecmascript::Runtime::HasInstance()) { + if (!panda::ecmascript::Runtime::HasInstance()) { return; } OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::VisitDynamicWeakThreadRoot", ""); @@ -294,8 +296,8 @@ void CheckAndInitBaseRuntime(const RuntimeParam ¶m) // BaseRuntime is inited from Dynamic return; } - ecmascript::JSRuntimeOptions options(param); - g_fakeEcmaVM = ecmascript::EcmaVM::Create(options); + panda::ecmascript::JSRuntimeOptions options(param); + g_fakeEcmaVM = panda::ecmascript::EcmaVM::Create(options); } void CheckAndFiniBaseRuntime() @@ -306,7 +308,7 @@ void CheckAndFiniBaseRuntime() return; } g_fakeEcmaVM->GetJSThread()->ManagedCodeBegin(); - ecmascript::EcmaVM::Destroy(g_fakeEcmaVM); + panda::ecmascript::EcmaVM::Destroy(g_fakeEcmaVM); g_fakeEcmaVM = nullptr; } @@ -330,17 +332,17 @@ bool IsMachineCodeObject(uintptr_t objPtr) void AddXRefToDynamicRoots() { - ecmascript::Runtime *runtime = ecmascript::Runtime::GetInstance(); + panda::ecmascript::Runtime *runtime = panda::ecmascript::Runtime::GetInstance(); runtime->GCIterateThreadList([&](JSThread *thread) { - thread->SetNodeKind(ecmascript::NodeKind::NORMAL_NODE); + thread->SetNodeKind(panda::ecmascript::NodeKind::NORMAL_NODE); }); } void RemoveXRefFromDynamicRoots() { - ecmascript::Runtime *runtime = ecmascript::Runtime::GetInstance(); + panda::ecmascript::Runtime *runtime = panda::ecmascript::Runtime::GetInstance(); runtime->GCIterateThreadList([&](JSThread *thread) { - thread->SetNodeKind(ecmascript::NodeKind::UNIFIED_NODE); + thread->SetNodeKind(panda::ecmascript::NodeKind::UNIFIED_NODE); }); } diff --git a/ecmascript/mem/dynamic_object_operator.cpp b/ecmascript/mem/dynamic_object_operator.cpp index 618bb47107..82191a4171 100644 --- a/ecmascript/mem/dynamic_object_operator.cpp +++ b/ecmascript/mem/dynamic_object_operator.cpp @@ -32,7 +32,7 @@ void DynamicObjectOperator::Initialize() void DynamicObjectOperator::IterateXRef([[maybe_unused]] const BaseObject *object, [[maybe_unused]] const common::RefFieldVisitor &visitor) const { -#if defined(PANDA_JS_ETS_HYBRID_MODE) + #if defined(PANDA_JS_ETS_HYBRID_MODE) && defined(USE_CMC_GC) if (g_isEnableCMCGC) { JSTaggedValue value(reinterpret_cast(const_cast(object))); if (value.IsJSXRefObject()) { diff --git a/ecmascript/module/static/static_module_loader.cpp b/ecmascript/module/static/static_module_loader.cpp index b4bd0e8619..2701ae9245 100644 --- a/ecmascript/module/static/static_module_loader.cpp +++ b/ecmascript/module/static/static_module_loader.cpp @@ -16,7 +16,6 @@ #include "ecmascript/module/static/static_module_loader.h" #include "ecmascript/global_env.h" #include "ecmascript/object_factory-inl.h" -#include "ecmascript/module/module_manager_helper.h" #include "ecmascript/module/module_path_helper.h" #include "ecmascript/module/js_module_deregister.h" #include "ecmascript/module/js_shared_module_manager.h" @@ -65,7 +64,7 @@ Local StaticModuleLoader::GetStaticModuleLoadFunc(EcmaVM *vm) JSHandle StaticModuleLoader::LoadStaticModule(JSThread *thread, Local getEsModuleFunc, const CString &key) { - auto moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager(); + auto moduleManager = thread->GetModuleManager(); if (moduleManager->IsModuleLoaded(key)) { LOG_ECMA(INFO) << "load static module from cache."; JSHandle moduleRecord = moduleManager->HostGetImportedModule(key); diff --git a/ecmascript/module/static/static_module_proxy_handler.cpp b/ecmascript/module/static/static_module_proxy_handler.cpp index e2169594ea..181a45dbf0 100644 --- a/ecmascript/module/static/static_module_proxy_handler.cpp +++ b/ecmascript/module/static/static_module_proxy_handler.cpp @@ -16,7 +16,6 @@ #include "ecmascript/module/static/static_module_proxy_handler.h" #include "ecmascript/global_env.h" #include "ecmascript/object_factory-inl.h" -#include "ecmascript/module/module_manager_helper.h" #include "ecmascript/module/module_path_helper.h" #include "ecmascript/module/js_module_deregister.h" #include "ecmascript/module/js_shared_module_manager.h" diff --git a/ecmascript/serializer/value_serializer.h b/ecmascript/serializer/value_serializer.h index 6fa72155c8..1c3c78f431 100644 --- a/ecmascript/serializer/value_serializer.h +++ b/ecmascript/serializer/value_serializer.h @@ -69,7 +69,7 @@ private: bool SerializeModuleCNativeObjects(TaggedObject *object); protected: - void SerializeObjectImpl(TaggedObject *object) override; + void SerializeObjectImpl(TaggedObject *object, bool isWeak = false) override; bool notSupport_ {false}; private: diff --git a/ecmascript/stubs/runtime_stubs.cpp b/ecmascript/stubs/runtime_stubs.cpp index 1030160b74..95e27c3fdc 100644 --- a/ecmascript/stubs/runtime_stubs.cpp +++ b/ecmascript/stubs/runtime_stubs.cpp @@ -3573,7 +3573,7 @@ JSTaggedValue RuntimeStubs::NumberHelperStringToDouble(EcmaString *numberString) { DISALLOW_GARBAGE_COLLECTION; CVector buf; - Span str = EcmaStringAccessor(numberString).ToUtf8Span(buf); + common::Span str = EcmaStringAccessor(numberString).ToUtf8Span(buf); if (base::NumberHelper::IsEmptyString(str.begin(), str.end())) { return base::BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); } @@ -3856,10 +3856,10 @@ int32_t RuntimeStubs::StringGetStart(bool isUtf8, EcmaString *srcString, int32_t { DISALLOW_GARBAGE_COLLECTION; if (isUtf8) { - Span data(EcmaStringAccessor(srcString).GetDataUtf8() + startIndex, length); + common::Span data(EcmaStringAccessor(srcString).GetDataUtf8() + startIndex, length); return static_cast(base::StringHelper::GetStart(data, length)); } else { - Span data(EcmaStringAccessor(srcString).GetDataUtf16() + startIndex, length); + common::Span data(EcmaStringAccessor(srcString).GetDataUtf16() + startIndex, length); return static_cast(base::StringHelper::GetStart(data, length)); } } @@ -3869,10 +3869,10 @@ int32_t RuntimeStubs::StringGetEnd(bool isUtf8, EcmaString *srcString, { DISALLOW_GARBAGE_COLLECTION; if (isUtf8) { - Span data(EcmaStringAccessor(srcString).GetDataUtf8() + startIndex, length); + common::Span data(EcmaStringAccessor(srcString).GetDataUtf8() + startIndex, length); return base::StringHelper::GetEnd(data, start, length); } else { - Span data(EcmaStringAccessor(srcString).GetDataUtf16() + startIndex, length); + common::Span data(EcmaStringAccessor(srcString).GetDataUtf16() + startIndex, length); return base::StringHelper::GetEnd(data, start, length); } } diff --git a/ecmascript/tagged_dictionary.cpp b/ecmascript/tagged_dictionary.cpp index fe4ba21854..d229331c39 100644 --- a/ecmascript/tagged_dictionary.cpp +++ b/ecmascript/tagged_dictionary.cpp @@ -54,8 +54,8 @@ bool NameDictionary::IsMatch(const uint8_t* str, int size, const JSTaggedValue & } EcmaString *keyString = reinterpret_cast(other.GetTaggedObject()); - Span data1(EcmaStringAccessor(keyString).GetDataUtf8(), keyString->GetLength()); - Span data2(str, size); + common::Span data1(EcmaStringAccessor(keyString).GetDataUtf8(), keyString->GetLength()); + common::Span data2(str, size); if (data1.Size() != data2.Size()) { return false; } -- Gitee From 3526245e00743b1a522191bad2b94d04905de0cf Mon Sep 17 00:00:00 2001 From: lhc Date: Thu, 10 Jul 2025 22:21:03 +0800 Subject: [PATCH 31/54] Resolving git conflicts Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICK92F?from=project-issue Signed-off-by: lhc Change-Id: If51938c48b18848e609d776c18a22f98b45320b1 --- ecmascript/napi/jsnapi_class_creation_helper.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/ecmascript/napi/jsnapi_class_creation_helper.cpp b/ecmascript/napi/jsnapi_class_creation_helper.cpp index 526dedbc42..0699f88fda 100644 --- a/ecmascript/napi/jsnapi_class_creation_helper.cpp +++ b/ecmascript/napi/jsnapi_class_creation_helper.cpp @@ -54,7 +54,6 @@ bool JSNApiClassCreationHelper::TryAddOriKeyAndOriAttrToHClass(const JSThread *t // update string stable key.Update(JSTaggedValue(vm->GetFactory()->InternString(key))); } - ASSERT(EcmaStringAccessor(key->GetTaggedObject()).IsInternString()); ConstructDescByAttr(thread, oriAttr, &desc); // If property key is element index, property must be add by slow path(DefinePropertyOrThrow). if (UNLIKELY(!JSTaggedValue::IsPureString(keyValue))) { -- Gitee From 8e9825fd15202498e4644ca90d46f47285a6c27a Mon Sep 17 00:00:00 2001 From: lijunru Date: Sat, 12 Jul 2025 15:01:27 +0800 Subject: [PATCH 32/54] add LD_LIBRARY_PATH Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICLU78 Signed-off-by: lijunru Change-Id: Id6ab86ca4067c28a69346a2a2d6927cd6c04c2e3 --- ecmascript/compiler/BUILD.gn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ecmascript/compiler/BUILD.gn b/ecmascript/compiler/BUILD.gn index 7e5cf72ade..47cd045bce 100644 --- a/ecmascript/compiler/BUILD.gn +++ b/ecmascript/compiler/BUILD.gn @@ -616,6 +616,8 @@ action("gen_stub_file") { "/${icu_subsystem_name}/${icu_part_name}:" + rebase_path(root_out_dir_with_host_toolchain) + "/thirdparty/zlib:" + rebase_path(root_out_dir_with_host_toolchain) + + "/hmosbundlemanager/zlib_override:" + + rebase_path(root_out_dir_with_host_toolchain) + "/resourceschedule/frame_aware_sched:" + rebase_path(root_out_dir_with_host_toolchain) + "/hiviewdfx/hilog:" + rebase_path(root_out_dir_with_host_toolchain) + -- Gitee From b02670b4837d8165ccebfd95659f5731ce118ae2 Mon Sep 17 00:00:00 2001 From: ZhouGuangyuan Date: Sat, 12 Jul 2025 15:33:59 +0800 Subject: [PATCH 33/54] fix testcase for cmcgc Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICLUED Signed-off-by: ZhouGuangyuan Change-Id: Iccd0c2f959edabeace2f6d0dd999fea657aeb2ce --- ecmascript/tests/js_stable_array_test.cpp | 24 ++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ecmascript/tests/js_stable_array_test.cpp b/ecmascript/tests/js_stable_array_test.cpp index d2b142c732..2d10ac7131 100644 --- a/ecmascript/tests/js_stable_array_test.cpp +++ b/ecmascript/tests/js_stable_array_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -422,6 +422,27 @@ HWTEST_F_L0(JSStableArrayTest, Join_StringElements_ManyTiny) */ HWTEST_F_L0(JSStableArrayTest, Join_StringElements_LargeString) { +#if defined(ARK_HYBRID) || defined(USE_CMC_GC) + int32_t lengthArr = 8; + std::string sep = ""; + // large string should use tree string. + ObjectFactory* objFactory = thread->GetEcmaVM()->GetFactory(); + JSHandle handleTagArr(objFactory->NewTaggedArray(lengthArr)); + // 40 x a + JSHandle + handleTagValElementEcmaStr(objFactory->NewFromStdString("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); + for (int i = 0; i < lengthArr; i++) { + handleTagArr->Set(thread, i, handleTagValElementEcmaStr.GetTaggedValue()); + } + JSHandle handleTagValEcmaStrRet = CallJoin(handleTagArr, sep, lengthArr); + JSHandle handleEcmaStrRet(handleTagValEcmaStrRet); + EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString().c_str(), + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + EXPECT_TRUE(EcmaStringAccessor(handleEcmaStrRet).IsTreeString()); +#else int32_t lengthArr = 8; std::string sep = ""; // large string should use tree string. @@ -441,6 +462,7 @@ HWTEST_F_L0(JSStableArrayTest, Join_StringElements_LargeString) "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); EXPECT_TRUE(EcmaStringAccessor(handleEcmaStrRet).IsTreeString()); +#endif } /** -- Gitee From fc3df3380acab65d6cad26fb631d357ceaf2c87f Mon Sep 17 00:00:00 2001 From: lijunru Date: Sat, 12 Jul 2025 22:57:17 +0800 Subject: [PATCH 34/54] cherry-pick 0328 to 0702 Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICLUQW Signed-off-by: lijunru Change-Id: I5420d708a94ca1d3dec07b988684294eab02ef1a --- ecmascript/js_hclass-inl.h | 1 + ecmascript/regexp/regexp_parser_cache.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/ecmascript/js_hclass-inl.h b/ecmascript/js_hclass-inl.h index cb3eeff19c..9a9847bd7b 100644 --- a/ecmascript/js_hclass-inl.h +++ b/ecmascript/js_hclass-inl.h @@ -18,6 +18,7 @@ #include "ecmascript/js_hclass.h" +#include "common_interfaces/objects/string/line_string-inl.h" #include "ecmascript/byte_array.h" #include "ecmascript/ic/proto_change_details.h" #include "ecmascript/js_bigint.h" diff --git a/ecmascript/regexp/regexp_parser_cache.cpp b/ecmascript/regexp/regexp_parser_cache.cpp index 55db272a6d..aa4d0e8172 100644 --- a/ecmascript/regexp/regexp_parser_cache.cpp +++ b/ecmascript/regexp/regexp_parser_cache.cpp @@ -14,6 +14,7 @@ */ #include "ecmascript/regexp/regexp_parser_cache.h" +#include "common_interfaces/objects/string/line_string-inl.h" namespace panda::ecmascript { RegExpParserCache::RegExpParserCache() -- Gitee From c963069c84628c702a86822d88cd00f71de96ac8 Mon Sep 17 00:00:00 2001 From: zhao1d Date: Mon, 14 Jul 2025 09:43:47 +0800 Subject: [PATCH 35/54] adapt 1.2runtime cherrypick to 0702 Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICLZK4 Signed-off-by: zhao1d Change-Id: I8eae1e1e1db25826d4a972496d20dcc7fe79295e --- ecmascript/builtins/builtins.cpp | 14 +++++- ecmascript/compiler/aot_file/aot_version.h | 6 +-- .../builtins_function_stub_builder.cpp | 4 +- ecmascript/compiler/stub_builder-inl.h | 9 +--- ecmascript/compiler/stub_builder.h | 4 +- .../dfx/hprof/tests/js_metadata_test.cpp | 8 ++-- ecmascript/global_env_fields.h | 3 +- ecmascript/js_function.cpp | 3 +- ecmascript/js_function.h | 5 +-- ecmascript/js_type_metadata/global_env.json | 2 +- ecmascript/js_type_metadata/js_function.json | 13 ++---- ecmascript/napi/include/jsnapi_expo.h | 1 + ecmascript/napi/jsnapi_expo.cpp | 27 ++++++++++-- ecmascript/napi/test/jsnapi_third_tests.cpp | 13 +++++- ecmascript/runtime.h | 13 ++++++ ecmascript/serializer/base_serializer.cpp | 4 +- ecmascript/stubs/runtime_stubs-inl.h | 44 +++++++++++++++---- ecmascript/stubs/runtime_stubs.h | 10 ++++- ecmascript/tests/dump_test.cpp | 4 +- 19 files changed, 128 insertions(+), 59 deletions(-) diff --git a/ecmascript/builtins/builtins.cpp b/ecmascript/builtins/builtins.cpp index 0caf942673..c07d9e4e1e 100644 --- a/ecmascript/builtins/builtins.cpp +++ b/ecmascript/builtins/builtins.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -812,6 +812,12 @@ BUILTIN_ALL_SYMBOLS(REGISTER_SYMBOL) env->SetHoleySymbol(thread_, holeySymbol.GetTaggedValue()); JSHandle elementIcSymbol(factory_->NewPrivateNameSymbolWithChar("element-ic")); env->SetElementICSymbol(thread_, elementIcSymbol.GetTaggedValue()); + if (Runtime::GetInstance()->IsHybridVm() && env->GetInterfaceTypeSymbol().GetTaggedValue().IsUndefined()) { + JSHandle interfaceTypeSymbol(factory_->NewPrivateNameSymbolWithChar("interfaceType")); + env->SetInterfaceTypeSymbol(thread_, interfaceTypeSymbol.GetTaggedValue()); + } else { + env->SetInterfaceTypeSymbol(thread_, JSTaggedValue::Undefined()); + } } void Builtins::InitializeSymbolWithRealm(const JSHandle &realm, @@ -875,6 +881,12 @@ void Builtins::InitializeSymbolWithRealm(const JSHandle &realm, realm->SetHoleySymbol(thread_, holeySymbol.GetTaggedValue()); JSHandle elementIcSymbol(factory_->NewPrivateNameSymbolWithChar("element-ic")); realm->SetElementICSymbol(thread_, elementIcSymbol.GetTaggedValue()); + if (Runtime::GetInstance()->IsHybridVm() && env->GetInterfaceTypeSymbol().GetTaggedValue().IsUndefined()) { + JSHandle interfaceTypeSymbol(factory_->NewPrivateNameSymbolWithChar("interfaceType")); + realm->SetInterfaceTypeSymbol(thread_, interfaceTypeSymbol.GetTaggedValue()); + } else { + realm->SetInterfaceTypeSymbol(thread_, JSTaggedValue::Undefined()); + } } #undef BUILTIN_SYMBOL_CREATE_WITH_REALM diff --git a/ecmascript/compiler/aot_file/aot_version.h b/ecmascript/compiler/aot_file/aot_version.h index 1a3143992c..418759c0a8 100644 --- a/ecmascript/compiler/aot_file/aot_version.h +++ b/ecmascript/compiler/aot_file/aot_version.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -25,9 +25,9 @@ public: // Release Version Snapshot Version // 3.2 0.0.0.x // 4.0 4.0.0.x - static constexpr base::FileHeaderBase::VersionType AN_VERSION = {4, 0, 1, 5}; + static constexpr base::FileHeaderBase::VersionType AN_VERSION = {4, 0, 1, 6}; static constexpr bool AN_STRICT_MATCH = true; - static constexpr base::FileHeaderBase::VersionType AI_VERSION = {4, 0, 1, 2}; + static constexpr base::FileHeaderBase::VersionType AI_VERSION = {4, 0, 1, 3}; static constexpr bool AI_STRICT_MATCH = true; constexpr static const int VERSION_MULTIPLE_SIZE = 2; static PUBLIC_API std::string GetAOTVersion() diff --git a/ecmascript/compiler/builtins/builtins_function_stub_builder.cpp b/ecmascript/compiler/builtins/builtins_function_stub_builder.cpp index 8a3f1c7f65..45902fbe5f 100644 --- a/ecmascript/compiler/builtins/builtins_function_stub_builder.cpp +++ b/ecmascript/compiler/builtins/builtins_function_stub_builder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -558,7 +558,6 @@ void BuiltinsFunctionStubBuilder::InitializeSFunction(GateRef glue, GateRef func auto emptyProfileTypeInfoCell = GetGlobalConstantValue(VariableType::JS_POINTER(), glue, ConstantIndex::EMPTY_PROFILE_TYPE_INFO_CELL_INDEX); SetRawProfileTypeInfoToFunction(glue, func, emptyProfileTypeInfoCell, MemoryAttribute::NoBarrier()); - SetInterfaceTypeToFunction(glue, func, Undefined(), MemoryAttribute::NoBarrier()); env->SubCfgExit(); return; } @@ -688,7 +687,6 @@ void BuiltinsFunctionStubBuilder::InitializeJSFunction(GateRef glue, GateRef fun auto emptyProfileTypeInfoCell = GetGlobalConstantValue(VariableType::JS_POINTER(), glue, ConstantIndex::EMPTY_PROFILE_TYPE_INFO_CELL_INDEX); SetRawProfileTypeInfoToFunction(glue, func, emptyProfileTypeInfoCell, MemoryAttribute::NoBarrier()); - SetInterfaceTypeToFunction(glue, func, Undefined(), MemoryAttribute::NoBarrier()); env->SubCfgExit(); return; } diff --git a/ecmascript/compiler/stub_builder-inl.h b/ecmascript/compiler/stub_builder-inl.h index 23b3b73f95..6fc282dae3 100644 --- a/ecmascript/compiler/stub_builder-inl.h +++ b/ecmascript/compiler/stub_builder-inl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -3613,13 +3613,6 @@ inline void StubBuilder::SetMachineCodeToFunction(GateRef glue, GateRef function Store(VariableType::JS_ANY(), glue, function, offset, value, mAttr); } -inline void StubBuilder::SetInterfaceTypeToFunction(GateRef glue, GateRef function, GateRef value, - MemoryAttribute mAttr) -{ - GateRef offset = IntPtr(JSFunction::INTERFACETYPE_OFFSET); - Store(VariableType::JS_ANY(), glue, function, offset, value, mAttr); -} - inline void StubBuilder::SetBaselineJitCodeToFunction(GateRef glue, GateRef function, GateRef value, MemoryAttribute mAttr) { diff --git a/ecmascript/compiler/stub_builder.h b/ecmascript/compiler/stub_builder.h index dc7c8bab54..ceea7af561 100644 --- a/ecmascript/compiler/stub_builder.h +++ b/ecmascript/compiler/stub_builder.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -922,8 +922,6 @@ public: MemoryAttribute mAttr = MemoryAttribute::Default()); void SetMachineCodeToFunction(GateRef glue, GateRef function, GateRef value, MemoryAttribute mAttr = MemoryAttribute::Default()); - void SetInterfaceTypeToFunction(GateRef glue, GateRef function, GateRef value, - MemoryAttribute mAttr = MemoryAttribute::Default()); void SetBaselineJitCodeToFunction(GateRef glue, GateRef function, GateRef value, MemoryAttribute mAttr = MemoryAttribute::Default()); void SetTypedArrayName(GateRef glue, GateRef typedArray, GateRef name, diff --git a/ecmascript/dfx/hprof/tests/js_metadata_test.cpp b/ecmascript/dfx/hprof/tests/js_metadata_test.cpp index d3914cbcbc..c9f8edd528 100644 --- a/ecmascript/dfx/hprof/tests/js_metadata_test.cpp +++ b/ecmascript/dfx/hprof/tests/js_metadata_test.cpp @@ -255,8 +255,8 @@ public: {JSType::JS_FLOAT32_ARRAY, {"ViewedArrayBufferOrByteArray", "TypedArrayName", "JS_FLOAT32_ARRAY"}}, {JSType::JS_FLOAT64_ARRAY, {"ViewedArrayBufferOrByteArray", "TypedArrayName", "JS_FLOAT64_ARRAY"}}, {JSType::JS_FORIN_ITERATOR, {"Object", "CachedHClass", "Keys", "JS_FORIN_ITERATOR"}}, - {JSType::JS_FUNCTION, {"ProtoOrHClass", "LexicalEnv", "MachineCode", "BaselineCode", "InterfaceType", - "RawProfileTypeInfo", "HomeObject", "Module", "JS_FUNCTION"}}, + {JSType::JS_FUNCTION, {"ProtoOrHClass", "LexicalEnv", "MachineCode", "BaselineCode", "RawProfileTypeInfo", + "HomeObject", "Module", "JS_FUNCTION"}}, {JSType::JS_FUNCTION_BASE, {"Method", "JS_FUNCTION_BASE"}}, {JSType::JS_GENERATOR_CONTEXT, {"RegsArray", "Method", "This", "Acc", "GeneratorObject", "LexicalEnv", "JS_GENERATOR_CONTEXT"}}, @@ -672,7 +672,6 @@ public: JSFunction::LEXICAL_ENV_OFFSET, JSFunction::MACHINECODE_OFFSET, JSFunction::BASELINECODE_OFFSET, - JSFunction::INTERFACETYPE_OFFSET, JSFunction::RAW_PROFILE_TYPE_INFO_OFFSET, JSFunction::HOME_OBJECT_OFFSET, JSFunction::ECMA_MODULE_OFFSET, @@ -1456,8 +1455,7 @@ public: JSFunction::LEXICAL_ENV_OFFSET - JSFunction::PROTO_OR_DYNCLASS_OFFSET, JSFunction::MACHINECODE_OFFSET - JSFunction::LEXICAL_ENV_OFFSET, JSFunction::BASELINECODE_OFFSET - JSFunction::MACHINECODE_OFFSET, - JSFunction::INTERFACETYPE_OFFSET - JSFunction::BASELINECODE_OFFSET, - JSFunction::RAW_PROFILE_TYPE_INFO_OFFSET - JSFunction::INTERFACETYPE_OFFSET, + JSFunction::RAW_PROFILE_TYPE_INFO_OFFSET - JSFunction::BASELINECODE_OFFSET, JSFunction::HOME_OBJECT_OFFSET - JSFunction::RAW_PROFILE_TYPE_INFO_OFFSET, JSFunction::ECMA_MODULE_OFFSET - JSFunction::HOME_OBJECT_OFFSET, JSFunction::WORK_NODE_POINTER_OFFSET - JSFunction::ECMA_MODULE_OFFSET}}, diff --git a/ecmascript/global_env_fields.h b/ecmascript/global_env_fields.h index 31fe2f9942..4e36e30101 100644 --- a/ecmascript/global_env_fields.h +++ b/ecmascript/global_env_fields.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -188,6 +188,7 @@ V(JSTaggedValue, SharedArrayIteratorPrototype, SHARED_ARRAY_ITERATOR_PROTOTYPE_INDEX) \ V(JSTaggedValue, StringIteratorPrototype, STRING_ITERATOR_PROTOTYPE_INDEX) \ V(JSTaggedValue, AsyncFromSyncIteratorPrototype, ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE_INDEX) \ + V(JSTaggedValue, InterfaceTypeSymbol, INTERFACE_TYPE_SYMBOL_OFFSET) \ V(JSTaggedValue, ThrowTypeError, THROW_TYPE_ERROR_INDEX) \ V(JSTaggedValue, PromiseFunction, PROMISE_FUNCTION_INDEX) \ V(JSTaggedValue, PromiseReactionJob, PROMISE_REACTION_JOB_INDEX) \ diff --git a/ecmascript/js_function.cpp b/ecmascript/js_function.cpp index 682340a2c5..5bc2ad5258 100644 --- a/ecmascript/js_function.cpp +++ b/ecmascript/js_function.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -111,7 +111,6 @@ void JSFunction::InitializeWithDefaultValueCommon(JSThread *thread, const JSHand func->SetRawProfileTypeInfo(thread, thread->GlobalConstants()->GetEmptyProfileTypeInfoCell()); func->SetMethod(thread, JSTaggedValue::Undefined()); func->SetModule(thread, JSTaggedValue::Undefined()); - func->SetInterfaceType(thread, JSTaggedValue::Undefined()); func->SetCodeEntry(reinterpret_cast(nullptr)); func->ClearCompiledCodeFlags(); func->SetTaskConcurrentFuncFlag(0); // 0 : default value diff --git a/ecmascript/js_function.h b/ecmascript/js_function.h index 1cc483b341..94a9d933d4 100644 --- a/ecmascript/js_function.h +++ b/ecmascript/js_function.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -427,8 +427,7 @@ public: // For runtime native function, the LexicalEnv field is used to store GlobalEnv, such as RegExp's native function ACCESSORS(LexicalEnv, LEXICAL_ENV_OFFSET, MACHINECODE_OFFSET) ACCESSORS(MachineCode, MACHINECODE_OFFSET, BASELINECODE_OFFSET) - ACCESSORS(BaselineCode, BASELINECODE_OFFSET, INTERFACETYPE_OFFSET) - ACCESSORS(InterfaceType, INTERFACETYPE_OFFSET, RAW_PROFILE_TYPE_INFO_OFFSET) + ACCESSORS(BaselineCode, BASELINECODE_OFFSET, RAW_PROFILE_TYPE_INFO_OFFSET) ACCESSORS(RawProfileTypeInfo, RAW_PROFILE_TYPE_INFO_OFFSET, HOME_OBJECT_OFFSET) ACCESSORS(HomeObject, HOME_OBJECT_OFFSET, ECMA_MODULE_OFFSET) ACCESSORS(Module, ECMA_MODULE_OFFSET, WORK_NODE_POINTER_OFFSET) diff --git a/ecmascript/js_type_metadata/global_env.json b/ecmascript/js_type_metadata/global_env.json index d2afd6cc11..9c193ec832 100644 --- a/ecmascript/js_type_metadata/global_env.json +++ b/ecmascript/js_type_metadata/global_env.json @@ -1 +1 @@ -{"name": "GLOBAL_ENV", "offsets": [], "end_offset": 4352, "parents": ["TAGGED_ARRAY"]} +{"name": "GLOBAL_ENV", "offsets": [], "end_offset": 4360, "parents": ["TAGGED_ARRAY"]} diff --git a/ecmascript/js_type_metadata/js_function.json b/ecmascript/js_type_metadata/js_function.json index abdb679da3..182c61241a 100644 --- a/ecmascript/js_type_metadata/js_function.json +++ b/ecmascript/js_type_metadata/js_function.json @@ -21,28 +21,23 @@ "offset": 24, "size": 8 }, - { - "name": "InterfaceType", - "offset": 32, - "size": 8 - }, { "name": "RawProfileTypeInfo", - "offset": 40, + "offset": 32, "size": 8 }, { "name": "HomeObject", - "offset": 48, + "offset": 40, "size": 8 }, { "name": "Module", - "offset": 56, + "offset": 48, "size": 8 } ], - "end_offset": 72, + "end_offset": 64, "parents": [ "JS_FUNCTION_BASE" ] diff --git a/ecmascript/napi/include/jsnapi_expo.h b/ecmascript/napi/include/jsnapi_expo.h index 5a896e9ffa..9bb3095020 100644 --- a/ecmascript/napi/include/jsnapi_expo.h +++ b/ecmascript/napi/include/jsnapi_expo.h @@ -1940,6 +1940,7 @@ public: // 1.2runtime interface info static Local GetImplements(const EcmaVM *vm, Local instance); + static void InitHybridVMEnv(const EcmaVM *vm); private: static bool isForked_; diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index d41f4387f8..c8c80d7c0d 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -2830,16 +2830,18 @@ Local JSNApi::GetImplements(const EcmaVM *vm, Local inst return JSValueRef::Undefined(vm); } JSHandle obj(JSNApiHelper::ToJSHandle(instance)); - OperationResult ret = JSTaggedValue::GetProperty( + OperationResult constructorValue = JSTaggedValue::GetProperty( thread, obj, thread->GlobalConstants()->GetHandledConstructorString()); RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Undefined(vm)); - result = ret.GetValue().GetTaggedValue(); + result = constructorValue.GetValue().GetTaggedValue(); if (!result.IsJSFunction()) { return JSValueRef::Undefined(vm); } JSHandle resultValue(thread, result); - JSHandle objFunc = JSHandle::Cast(resultValue); - result = objFunc->GetInterfaceType(); + JSHandle env = vm->GetGlobalEnv(); + JSHandle interfaceTypeSymbol = env->GetInterfaceTypeSymbol(); + OperationResult interfaceTypeValue = JSObject::GetProperty(thread, resultValue, interfaceTypeSymbol); + result = interfaceTypeValue.GetValue().GetTaggedValue(); if (result.IsUndefined()) { return JSValueRef::Undefined(vm); } @@ -2848,6 +2850,23 @@ Local JSNApi::GetImplements(const EcmaVM *vm, Local inst return JSNApiHelper::ToLocal(implementRet); } +void JSNApi::InitHybridVMEnv(const EcmaVM *vm) +{ + auto instance = ecmascript::Runtime::GetInstance(); + ASSERT(instance != nullptr); + + CROSS_THREAD_AND_EXCEPTION_CHECK(vm); + ecmascript::ThreadManagedScope managedScope(thread); + + instance->SetHybridVm(true); + ObjectFactory *factory = vm->GetFactory(); + JSHandle env = vm->GetGlobalEnv(); + if (env->GetInterfaceTypeSymbol().GetTaggedValue().IsUndefined()) { + JSHandle interfaceTypeSymbol(factory->NewPrivateNameSymbolWithChar("interfaceType")); + env->SetInterfaceTypeSymbol(thread, interfaceTypeSymbol.GetTaggedValue()); + } +} + bool ObjectRef::Set(const EcmaVM *vm, uint32_t key, Local value) { CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, false); diff --git a/ecmascript/napi/test/jsnapi_third_tests.cpp b/ecmascript/napi/test/jsnapi_third_tests.cpp index 160c3cc6ae..656354ec74 100644 --- a/ecmascript/napi/test/jsnapi_third_tests.cpp +++ b/ecmascript/napi/test/jsnapi_third_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1725,4 +1725,15 @@ HWTEST_F_L0(JSNApiTests, XRefGlobalHandleAddr) vm_->SetEnableForceGC(true); EXPECT_TRUE(weakRefArray->Get(0).IsUndefined()); } + +HWTEST_F_L0(JSNApiTests, InitHybridVMEnv) +{ + LocalScope scope(vm_); + JSNApi::InitHybridVMEnv(vm_); + + auto instance = ecmascript::Runtime::GetInstance(); + ASSERT(instance != nullptr); + + EXPECT_TRUE(instance->IsHybridVm()); +} } // namespace panda::test diff --git a/ecmascript/runtime.h b/ecmascript/runtime.h index f14e56f05a..5d54c455b1 100644 --- a/ecmascript/runtime.h +++ b/ecmascript/runtime.h @@ -298,6 +298,16 @@ public: } #endif + bool IsHybridVm() const + { + return isHybridVm_; + } + + void SetHybridVm(bool isHybridVm) + { + isHybridVm_ = isHybridVm; + } + private: static constexpr int32_t WORKER_DESTRUCTION_COUNT = 3; static constexpr int32_t MIN_GC_TRIGGER_VM_COUNT = 4; @@ -391,6 +401,9 @@ private: // release secure mem after jspandafile released. ReleaseSecureMemCallback releaseSecureMemCallback_ {nullptr}; + // for 1.2runtime interface type + bool isHybridVm_ {false}; + friend class EcmaVM; friend class JSThread; friend class SharedHeap; diff --git a/ecmascript/serializer/base_serializer.cpp b/ecmascript/serializer/base_serializer.cpp index ef0bb992ff..98f6c7030b 100644 --- a/ecmascript/serializer/base_serializer.cpp +++ b/ecmascript/serializer/base_serializer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -194,7 +194,6 @@ void BaseSerializer::SerializeSFunctionFieldIndividually(TaggedObject *root, Obj switch (fieldOffset) { case JSFunction::MACHINECODE_OFFSET: case JSFunction::BASELINECODE_OFFSET: - case JSFunction::INTERFACETYPE_OFFSET: case JSFunction::RAW_PROFILE_TYPE_INFO_OFFSET: { data_->WriteEncodeFlag(EncodeFlag::PRIMITIVE); data_->WriteJSTaggedValue(JSTaggedValue::Undefined()); @@ -325,7 +324,6 @@ void BaseSerializer::SerializeAsyncFunctionFieldIndividually(TaggedObject *root, case JSFunction::PROTO_OR_DYNCLASS_OFFSET: case JSFunction::MACHINECODE_OFFSET: case JSFunction::BASELINECODE_OFFSET: - case JSFunction::INTERFACETYPE_OFFSET: case JSFunction::RAW_PROFILE_TYPE_INFO_OFFSET: case JSFunction::HOME_OBJECT_OFFSET: case JSFunction::ECMA_MODULE_OFFSET: { diff --git a/ecmascript/stubs/runtime_stubs-inl.h b/ecmascript/stubs/runtime_stubs-inl.h index cc68674bae..7c6c9578b3 100644 --- a/ecmascript/stubs/runtime_stubs-inl.h +++ b/ecmascript/stubs/runtime_stubs-inl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -934,6 +934,27 @@ bool RuntimeStubs::MaybeHasInterfacesType(JSThread *thread, const JSHandleGetLength() != 0 && arrayHandle->Get(thread, arrayHandle->GetLength() - 1).IsString(); } +void RuntimeStubs::DefineInterfaceTypeOwnProperty(JSThread *thread, JSHandle &cls, + const JSHandle &base, + const JSHandle &lexenv, + JSHandle &extractor, + const JSHandle &ihc, + const JSHandle &chc, + const JSHandle &arrayHandle, + const JSHandle &classLiteral) +{ + // set 1.2runtie interfaceType no property. + ClassInfoExtractor::BuildClassInfoExtractorFromLiteral( + thread, extractor, arrayHandle, arrayHandle->GetLength(), ClassKind::NON_SENDABLE, 1); + cls = EntranceForDefineClass(thread, base, lexenv, extractor, ihc, chc, classLiteral); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + JSHandle interfaceTypeSymbol = env->GetInterfaceTypeSymbol(); + JSHandle interfaceTypeValue(thread, arrayHandle->Get(thread, arrayHandle->GetLength() - 1)); + PropertyDescriptor desc(thread, interfaceTypeValue, false, false, false); + JSObject::DefineOwnProperty( + thread, JSHandle::Cast(cls), interfaceTypeSymbol, desc); +} + JSHandle RuntimeStubs::EntranceForDefineClass(JSThread *thread, const JSHandle &base, const JSHandle &lexenv, @@ -987,15 +1008,20 @@ JSTaggedValue RuntimeStubs::RuntimeCreateClassWithBuffer(JSThread *thread, JSHandle classLiteral(thread, literalObj); JSHandle arrayHandle(thread, classLiteral->GetArray()); JSHandle extractor = factory->NewClassInfoExtractor(method); - if (MaybeHasInterfacesType(thread, arrayHandle)) { - ClassInfoExtractor::BuildClassInfoExtractorFromLiteral( - thread, extractor, arrayHandle, arrayHandle->GetLength(), ClassKind::NON_SENDABLE, 1); - cls = EntranceForDefineClass(thread, base, lexenv, extractor, ihc, chc, classLiteral); - cls->SetInterfaceType(thread, arrayHandle->Get(thread, arrayHandle->GetLength() - 1)); + auto instance = ecmascript::Runtime::GetInstance(); + ASSERT(instance != nullptr); + if (instance->IsHybridVm() && MaybeHasInterfacesType(thread, arrayHandle)) { + DefineInterfaceTypeOwnProperty(thread, cls, base, lexenv, extractor, ihc, chc, arrayHandle, classLiteral); } else { - ClassInfoExtractor::BuildClassInfoExtractorFromLiteral( - thread, extractor, arrayHandle, arrayHandle->GetLength()); - cls = EntranceForDefineClass(thread, base, lexenv, extractor, ihc, chc, classLiteral); + auto literalLength = arrayHandle->GetLength(); + ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(thread, extractor, arrayHandle, literalLength); + + if (ShouldUseAOTHClass(ihc, chc, classLiteral)) { + classLiteral->SetIsAOTUsed(true); + cls = ClassHelper::DefineClassWithIHClass(thread, base, extractor, lexenv, ihc, chc); + } else { + cls = ClassHelper::DefineClassFromExtractor(thread, base, extractor, lexenv); + } } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); diff --git a/ecmascript/stubs/runtime_stubs.h b/ecmascript/stubs/runtime_stubs.h index 4fb9e1ae44..98eb502b2b 100644 --- a/ecmascript/stubs/runtime_stubs.h +++ b/ecmascript/stubs/runtime_stubs.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -568,6 +568,14 @@ private: const JSHandle &ihc, const JSHandle &chc, const JSHandle &classLiteral); + static inline void DefineInterfaceTypeOwnProperty(JSThread *thread, JSHandle &cls, + const JSHandle &base, + const JSHandle &lexenv, + JSHandle &extractor, + const JSHandle &ihc, + const JSHandle &chc, + const JSHandle &arrayHandle, + const JSHandle &classLiteral); friend class SlowRuntimeStub; }; } // namespace panda::ecmascript diff --git a/ecmascript/tests/dump_test.cpp b/ecmascript/tests/dump_test.cpp index f94189458f..b3ae079422 100644 --- a/ecmascript/tests/dump_test.cpp +++ b/ecmascript/tests/dump_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -541,7 +541,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) } case JSType::JS_FUNCTION: case JSType::JS_SHARED_FUNCTION: { - CHECK_DUMP_FIELDS(JSFunctionBase::SIZE, JSFunction::SIZE, 9U); + CHECK_DUMP_FIELDS(JSFunctionBase::SIZE, JSFunction::SIZE, 8U); JSHandle jsFunc = globalEnv->GetFunctionFunction(); DUMP_FOR_HANDLE(jsFunc); break; -- Gitee From 1774b234e5e150568f62d4d3b9dece237a3a0d8a Mon Sep 17 00:00:00 2001 From: herongpeng Date: Fri, 18 Jul 2025 11:16:50 +0800 Subject: [PATCH 36/54] change codeLanguage to ArkTsMode change codeLanguage to ArkTsMode Issue:https://gitee.com/openharmony/ability_ability_runtime/issues/ICN47S Signed-off-by: herongpeng Change-Id: If3e337d30fe20c4a3d169d177c14352547ab8f0d --- compiler_service/include/aot_compiler_constants.h | 2 +- compiler_service/src/aot_args_handler.cpp | 12 ++++++------ .../aotcompilerargshandler_unit.cpp | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/compiler_service/include/aot_compiler_constants.h b/compiler_service/include/aot_compiler_constants.h index aedecd69cd..98f3c21223 100644 --- a/compiler_service/include/aot_compiler_constants.h +++ b/compiler_service/include/aot_compiler_constants.h @@ -37,7 +37,7 @@ const std::string COMPILER_AN_FILE_MAX_SIZE = "compiler-an-file-max-size"; const std::string AOT_FILE = "aot-file"; const std::string IS_SYSTEM_COMPONENT = "isSysComp"; -const std::string CODE_LANGUAGE = "codeLanguage"; +const std::string ARKTS_MODE = "moduleArkTSMode"; } // namespace ArgsIdx // UID and GID of system users diff --git a/compiler_service/src/aot_args_handler.cpp b/compiler_service/src/aot_args_handler.cpp index c4ebb323bd..88ec60d99d 100644 --- a/compiler_service/src/aot_args_handler.cpp +++ b/compiler_service/src/aot_args_handler.cpp @@ -44,8 +44,8 @@ const std::string STATIC_PAOC_USE_PROFILE = "paoc-use-profile"; const std::string STATIC_BOOT_PATH = "/system/framework/bootpath.json"; const std::string AN_FILE_NAME = "anFileName"; -const std::string ARKTS_1_1 = "1.1"; -const std::string ARKTS_1_2 = "1.2"; +const std::string ARKTS_DYNAMIC = "dynamic"; +const std::string ARKTS_STATIC = "static"; const std::string ARKTS_HYBRID = "hybrid"; const std::string AN_SUFFIX = ".an"; @@ -332,15 +332,15 @@ std::optional> AOTArgsParserFactory::GetParse if (isSystemComponent) { return std::make_unique(); } - std::string codeLanguage = ARKTS_1_1; - if (AOTArgsParserBase::FindArgsIdxToString(argsMap, ArgsIdx::CODE_LANGUAGE, codeLanguage) != ERR_OK) { + std::string codeLanguage = ARKTS_DYNAMIC; + if (AOTArgsParserBase::FindArgsIdxToString(argsMap, ArgsIdx::ARKTS_MODE, codeLanguage) != ERR_OK) { LOG_SA(INFO) << "aot sa failed to get language version"; } - if (codeLanguage == ARKTS_1_1) { + if (codeLanguage == ARKTS_DYNAMIC) { LOG_SA(INFO) << "aot sa use default compiler"; return std::make_unique(); - } else if (codeLanguage == ARKTS_1_2 || codeLanguage == ARKTS_HYBRID) { + } else if (codeLanguage == ARKTS_STATIC || codeLanguage == ARKTS_HYBRID) { LOG_SA(INFO) << "aot sa use static compiler"; return std::make_unique(); } diff --git a/compiler_service/test/unittest/aotcompilerargshandler_unit/aotcompilerargshandler_unit.cpp b/compiler_service/test/unittest/aotcompilerargshandler_unit/aotcompilerargshandler_unit.cpp index 1c59c7d003..39d1e1490a 100644 --- a/compiler_service/test/unittest/aotcompilerargshandler_unit/aotcompilerargshandler_unit.cpp +++ b/compiler_service/test/unittest/aotcompilerargshandler_unit/aotcompilerargshandler_unit.cpp @@ -167,7 +167,7 @@ const std::unordered_map argsMapForTest { HWTEST_F(AotArgsHandlerTest, AotArgsHandlerTest_007, TestSize.Level0) { std::unordered_map argsMap(argsMapForTest); - argsMap.emplace(ArgsIdx::CODE_LANGUAGE, "1.1"); + argsMap.emplace(ArgsIdx::ARKTS_MODE, "dynamic"); std::unique_ptr argsHandler = std::make_unique(argsMap); int32_t ret = argsHandler->Handle(0); EXPECT_EQ(ret, ERR_OK); @@ -183,7 +183,7 @@ HWTEST_F(AotArgsHandlerTest, AotArgsHandlerTest_007, TestSize.Level0) HWTEST_F(AotArgsHandlerTest, AotArgsHandlerTest_008, TestSize.Level0) { std::unordered_map argsMap(argsMapForTest); - argsMap.emplace(ArgsIdx::CODE_LANGUAGE, "1.2"); + argsMap.emplace(ArgsIdx::ARKTS_MODE, "static"); std::unique_ptr argsHandler = std::make_unique(argsMap); int32_t ret = argsHandler->Handle(0); EXPECT_EQ(ret, ERR_OK); -- Gitee From c8211aa9914613553e230ec870f121fe865656ad Mon Sep 17 00:00:00 2001 From: fangting Date: Wed, 16 Jul 2025 16:14:14 +0800 Subject: [PATCH 37/54] fix code error Issue:#ICMQEW Signed-off-by: fangting --- ecmascript/napi/jsnapi_expo.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index d41f4387f8..5308ee688c 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -5123,15 +5123,15 @@ bool JSNApi::StartDebuggerForSocketPair([[maybe_unused]] int tid, [[maybe_unused return false; } - using StartDebugForSocketpair = bool (*)(int, int); + using StartDebugForSocketpair = bool (*)(int, int, bool); auto sym = panda::os::library_loader::ResolveSymbol(handle, "StartDebugForSocketpair"); if (!sym) { LOG_ECMA(ERROR) << "[StartDebuggerForSocketPair] Resolve symbol fail: " << sym.Error().ToString(); return false; } - - bool ret = reinterpret_cast(sym.Value())(tid, socketfd); + // false: not hybrid + bool ret = reinterpret_cast(sym.Value())(tid, socketfd, false); if (!ret) { // Reset the config jsDebuggerManager->SetDebugMode(false); @@ -5206,7 +5206,7 @@ bool JSNApi::NotifyDebugMode([[maybe_unused]] int tid, #ifndef PANDA_TARGET_ARM32 // Initialize debugger - using InitializeDebuggerForSocketpair = bool(*)(void*); + using InitializeDebuggerForSocketpair = bool(*)(void*, bool); auto sym = panda::os::library_loader::ResolveSymbol( jsDebuggerManager->GetDebugLibraryHandle(), "InitializeDebuggerForSocketpair"); if (!sym) { @@ -5214,7 +5214,8 @@ bool JSNApi::NotifyDebugMode([[maybe_unused]] int tid, << sym.Error().ToString(); return false; } - if (!reinterpret_cast(sym.Value())(vm)) { + // false: not hybrid + if (!reinterpret_cast(sym.Value())(vm, false)) { LOG_ECMA(ERROR) << "[NotifyDebugMode] InitializeDebuggerForSocketpair fail"; return false; } @@ -5287,13 +5288,14 @@ bool JSNApi::StoreDebugInfo([[maybe_unused]] int tid, } reinterpret_cast(symOfStoreDebuggerInfo.Value())(tid, vm, debuggerPostTask); bool ret = false; - using InitializeDebuggerForSocketpair = bool(*)(void*); + using InitializeDebuggerForSocketpair = bool(*)(void*, bool); auto sym = panda::os::library_loader::ResolveSymbol(handler, "InitializeDebuggerForSocketpair"); if (!sym) { LOG_ECMA(ERROR) << "[InitializeDebuggerForSocketpair] Resolve symbol fail: " << sym.Error().ToString(); return false; } - ret = reinterpret_cast(sym.Value())(vm); + // false: not hybrid + ret = reinterpret_cast(sym.Value())(vm, false); if (!ret) { // Reset the config vm->GetJsDebuggerManager()->SetDebugMode(false); @@ -5319,15 +5321,15 @@ bool JSNApi::StopDebugger([[maybe_unused]] EcmaVM *vm) const auto &handle = vm->GetJsDebuggerManager()->GetDebugLibraryHandle(); - using StopDebug = void (*)(void *); + using StopDebug = void (*)(void *, bool); auto sym = panda::os::library_loader::ResolveSymbol(handle, "StopDebug"); if (!sym) { LOG_ECMA(ERROR) << sym.Error().ToString(); return false; } - - reinterpret_cast(sym.Value())(vm); + // false: not hybrid + reinterpret_cast(sym.Value())(vm, false); vm->GetJsDebuggerManager()->SetDebugMode(false); uint32_t tid = vm->GetTid(); -- Gitee From d3e441530fc80b02d15b7abdef9f294e890f785f Mon Sep 17 00:00:00 2001 From: chentianyu Date: Mon, 21 Jul 2025 13:01:16 +0800 Subject: [PATCH 38/54] dispatch serializer Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICNN7V Signed-off-by: chentianyu Change-Id: I0105841fb57021b1ce777db0861eab1c29cfe3f4 --- BUILD.gn | 8 +++----- ecmascript/napi/jsnapi_expo.cpp | 30 +++++++++++------------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 2dec2fe271..23ca0b6917 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1093,6 +1093,8 @@ ecma_source = [ "ecmascript/property_accessor.cpp", "ecmascript/serializer/base_deserializer.cpp", "ecmascript/serializer/base_serializer.cpp", + "ecmascript/serializer/inter_op_value_deserializer.cpp", + "ecmascript/serializer/inter_op_value_serializer.cpp", "ecmascript/serializer/module_deserializer.cpp", "ecmascript/serializer/module_serializer.cpp", "ecmascript/serializer/value_serializer.cpp", @@ -1156,11 +1158,7 @@ ecma_source += [ ] if (ark_js_hybrid) { - ecma_source += [ - "ecmascript/cross_vm/cross_vm_operator.cpp", - "ecmascript/serializer/inter_op_value_deserializer.cpp", - "ecmascript/serializer/inter_op_value_serializer.cpp", - ] + ecma_source += [ "ecmascript/cross_vm/cross_vm_operator.cpp" ] } if (!is_arkui_x) { diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index 19cf7f2542..325ccc11c5 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -43,6 +43,8 @@ #endif #include "ecmascript/regexp/regexp_parser.h" #include "ecmascript/serializer/base_deserializer.h" +#include "ecmascript/serializer/inter_op_value_deserializer.h" +#include "ecmascript/serializer/inter_op_value_serializer.h" #include "ecmascript/serializer/value_serializer.h" #include "ecmascript/platform/aot_crash_info.h" #include "ecmascript/platform/dfx_crash_obj.h" @@ -55,10 +57,6 @@ #if defined(ENABLE_LOCAL_HANDLE_LEAK_DETECT) #include "ecmascript/dfx/hprof/heap_profiler.h" #endif -#ifdef PANDA_JS_ETS_HYBRID_MODE -#include "ecmascript/serializer/inter_op_value_deserializer.h" -#include "ecmascript/serializer/inter_op_value_serializer.h" -#endif namespace panda { using ecmascript::AccessorData; @@ -6090,12 +6088,13 @@ bool JSNApi::IsValidHeapObject(const EcmaVM *vm, uintptr_t addr) } #endif // PANDA_JS_ETS_HYBRID_MODE -void *JSNApi::InterOpSerializeValue([[maybe_unused]] const EcmaVM *vm, [[maybe_unused]] Local value, - [[maybe_unused]] Local transfer, [[maybe_unused]] Local cloneList, - [[maybe_unused]] bool defaultTransfer, [[maybe_unused]] bool defaultCloneShared) +void *JSNApi::InterOpSerializeValue(const EcmaVM *vm, Local value, Local transfer, + Local cloneList, bool defaultTransfer, bool defaultCloneShared) { + if (!ecmascript::Runtime::GetInstance()->IsHybridVm()) { + return SerializeValue(vm, value, transfer, cloneList, defaultTransfer, defaultCloneShared); + } CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, nullptr); -#ifdef PANDA_JS_ETS_HYBRID_MODE ecmascript::ThreadManagedScope scope(thread); JSHandle arkValue = JSNApiHelper::ToJSHandle(value); JSHandle arkTransfer = JSNApiHelper::ToJSHandle(transfer); @@ -6120,17 +6119,14 @@ void *JSNApi::InterOpSerializeValue([[maybe_unused]] const EcmaVM *vm, [[maybe_u } else { return reinterpret_cast(data.release()); } -#else - LOG_FULL(FATAL) << "Only support in inter-op"; - UNREACHABLE(); -#endif } -Local JSNApi::InterOpDeserializeValue([[maybe_unused]] const EcmaVM *vm, [[maybe_unused]] void *recoder, - [[maybe_unused]] void *hint) +Local JSNApi::InterOpDeserializeValue(const EcmaVM *vm, void *recoder, void *hint) { + if (!ecmascript::Runtime::GetInstance()->IsHybridVm()) { + return DeserializeValue(vm, recoder, hint); + } CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); -#ifdef PANDA_JS_ETS_HYBRID_MODE ecmascript::ThreadManagedScope scope(thread); std::unique_ptr data(reinterpret_cast(recoder)); ecmascript::InterOpValueDeserializer deserializer(thread, data.release(), hint); @@ -6146,10 +6142,6 @@ Local JSNApi::InterOpDeserializeValue([[maybe_unused]] const EcmaVM GenerateTimeoutTraceIfNeeded(vm, startTime, endTime, false); } return JSNApiHelper::ToLocal(result); -#else - LOG_FULL(FATAL) << "Only support in inter-op"; - UNREACHABLE(); -#endif } void *JSNApi::SerializeValue(const EcmaVM *vm, Local value, Local transfer, -- Gitee From 514417e1a99e0dc85cce99f79d73f27ccbe24bc4 Mon Sep 17 00:00:00 2001 From: wangyuzhong Date: Mon, 21 Jul 2025 23:17:09 +0800 Subject: [PATCH 39/54] check abc file type is static or not Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICMC4U Signed-off-by: wangyuzhong --- ecmascript/napi/include/jsnapi_expo.h | 15 +++++++++++++++ ecmascript/napi/jsnapi_expo.cpp | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/ecmascript/napi/include/jsnapi_expo.h b/ecmascript/napi/include/jsnapi_expo.h index 9bb3095020..877695f943 100644 --- a/ecmascript/napi/include/jsnapi_expo.h +++ b/ecmascript/napi/include/jsnapi_expo.h @@ -1688,6 +1688,12 @@ public: HIGH, }; + enum class PUBLIC_API PandaFileType : int8_t { + FILE_FORMAT_INVALID = -1, + FILE_DYNAMIC = 0, + FILE_STATIC = 1, + }; + static EcmaVM *CreateJSVM(const RuntimeOption &option); static void DestroyJSVM(EcmaVM *ecmaVm); static void SetStackInfo(const EcmaVM *vm, const panda::StackInfo &info); @@ -1719,6 +1725,15 @@ public: static bool ExecuteModuleBuffer(EcmaVM *vm, const uint8_t *data, int32_t size, const std::string &filename = "", bool needUpdate = false); static bool ExecuteModuleFromBuffer(EcmaVM *vm, const void *data, int32_t size, const std::string &file); + + /** + * @brief Return input abc file type + * @param[in] filename : absolute file path + * return -1 , indicates open file failed or file format invalid + * 0 , indicates input abc file is dynamic file + * 1 , indicates input abc file is static file + */ + static PandaFileType GetFileType(const std::string &filename); static Local GetExportObject(EcmaVM *vm, const std::string &file, const std::string &key); static Local GetExportObjectFromBuffer(EcmaVM *vm, const std::string &file, const std::string &key); static Local GetExportObjectFromOhmUrl(EcmaVM *vm, const std::string &ohmUrl, const std::string &key); diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index 19cf7f2542..2e374ffdd3 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -6394,6 +6394,26 @@ bool JSNApi::ExecuteModuleFromBuffer(EcmaVM *vm, const void *data, int32_t size, return true; } +JSNApi::PandaFileType JSNApi::GetFileType(const std::string &filename) +{ + panda::ecmascript::CString normalFilename = PathHelper::NormalizePath(filename.c_str()); + panda_file::PandaFileType fileType = panda_file::GetFileType(normalFilename); + switch (fileType) { + case panda_file::PandaFileType::FILE_FORMAT_INVALID: { + return JSNApi::PandaFileType::FILE_FORMAT_INVALID; + } + case panda_file::PandaFileType::FILE_DYNAMIC: { + return JSNApi::PandaFileType::FILE_DYNAMIC; + } + case panda_file::PandaFileType::FILE_STATIC: { + return JSNApi::PandaFileType::FILE_STATIC; + } + default: { + UNREACHABLE(); + } + } +} + Local JSNApi::NapiHasProperty(const EcmaVM *vm, uintptr_t nativeObj, uintptr_t key) { CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); -- Gitee From 3508265ad2975391880268a28b3594980c24a46d Mon Sep 17 00:00:00 2001 From: lijianfei Date: Wed, 23 Jul 2025 17:16:17 +0800 Subject: [PATCH 40/54] fix Builtins_Promise_Job_Test Suite Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICOC2I Signed-off-by: lijianfei --- .../tests/builtins_promise_job_test.cpp | 18 ++++++++++++------ test/resource/js_runtime/ohos_test.xml | 5 +++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ecmascript/builtins/tests/builtins_promise_job_test.cpp b/ecmascript/builtins/tests/builtins_promise_job_test.cpp index 2f5bd8736d..451949373c 100644 --- a/ecmascript/builtins/tests/builtins_promise_job_test.cpp +++ b/ecmascript/builtins/tests/builtins_promise_job_test.cpp @@ -86,15 +86,18 @@ HWTEST_F_L0(BuiltinsPromiseJobTest, DynamicImportJobCatchException) JSHandle reject(thread, resolvingFunctions->GetRejectFunction()); JSHandle dirPath(factory->NewFromASCII("./main.abc")); JSHandle specifier(factory->NewFromASCII("exportFile")); - JSHandle recordName(factory->NewFromASCII("main")); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 14); - ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + Local contextValue = JSNApi::GetCurrentContext(vm); + JSHandle lexicalEnv(JSNApiHelper::ToJSHandle(contextValue)); + JSHandle funHandle = factory->NewJSFunction(env); + funHandle->SetLexicalEnv(thread, lexicalEnv.GetTaggedValue()); + ecmaRuntimeCallInfo->SetFunction(funHandle.GetTaggedValue()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, resolve.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, reject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(2, dirPath.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(3, specifier.GetTaggedValue()); - ecmaRuntimeCallInfo->SetCallArg(4, recordName.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(4, JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); BuiltinsPromiseJob::DynamicImportJob(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); @@ -133,15 +136,18 @@ HWTEST_F_L0(BuiltinsPromiseJobTest, DynamicImportJobCatchException2) JSHandle reject(thread, resolvingFunctions->GetRejectFunction()); JSHandle dirPath(factory->NewFromASCII("./main.abc")); JSHandle specifier(factory->NewFromASCII("exportFile")); - JSHandle recordName(factory->NewFromASCII("main")); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 14); - ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + Local contextValue = JSNApi::GetCurrentContext(vm); + JSHandle lexicalEnv(JSNApiHelper::ToJSHandle(contextValue)); + JSHandle funHandle = factory->NewJSFunction(env); + funHandle->SetLexicalEnv(thread, lexicalEnv.GetTaggedValue()); + ecmaRuntimeCallInfo->SetFunction(funHandle.GetTaggedValue()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, resolve.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, reject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(2, dirPath.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(3, specifier.GetTaggedValue()); - ecmaRuntimeCallInfo->SetCallArg(4, recordName.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(4, JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); BuiltinsPromiseJob::DynamicImportJob(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); diff --git a/test/resource/js_runtime/ohos_test.xml b/test/resource/js_runtime/ohos_test.xml index 64c7d1ed10..33eb3df512 100755 --- a/test/resource/js_runtime/ohos_test.xml +++ b/test/resource/js_runtime/ohos_test.xml @@ -293,6 +293,11 @@