diff --git a/compiler_service/include/aot_args_handler.h b/compiler_service/include/aot_args_handler.h index fc873d0e9102ddc8cad24f9429c8b831963435d6..79af0c563340ea9f3edb6865703460bb0aec2a07 100644 --- a/compiler_service/include/aot_args_handler.h +++ b/compiler_service/include/aot_args_handler.h @@ -87,16 +87,16 @@ class StaticAOTArgsParser final : public AOTArgsParserBase { public: int32_t Parse(const std::unordered_map &argsMap, HapArgs &hapArgs, int32_t thermalLevel) override; -}; -enum class LanguageVersion { - DEFAULT = 0, // JS, TS, dynamic ArkTS - STATIC = 1 // static ArkTS + bool ParseBootPandaFiles(std::string &bootfiles); + + std::string ParseLocation(std::string &anfilePath); }; class AOTArgsParserFactory { public: - static std::unique_ptr GetParser(const std::unordered_map &argsMap); + static std::optional> GetParser(const std::unordered_map &argsMap); }; } // namespace OHOS::ArkCompiler #endif // OHOS_ARKCOMPILER_AOT_ARGS_HANDLER_H diff --git a/compiler_service/include/aot_args_list.h b/compiler_service/include/aot_args_list.h index 092c9f376dfd9610c0c00abee667177827c52422..6a32295e7538a3377ca2b345759287e7d43d2a1d 100644 --- a/compiler_service/include/aot_args_list.h +++ b/compiler_service/include/aot_args_list.h @@ -144,12 +144,18 @@ std::unordered_set AotArgsList { "compiler-baseline-pgo", }; -std::unordered_set StaicAotArgsList { +std::unordered_set StaticAotArgsList { "boot-panda-files", "paoc-panda-files", "paoc-output", "load-runtimes", "paoc-use-cha", }; + +std::vector StaticAotDefaultArgs { + "--load-runtimes=ets", + "--compiler-enable-fast-interop=false", + "--paoc-zip-panda-file=ets/modules_static.abc" +}; } // 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 1d8a572fef6d68b3a046ee30be559a8ce9548115..a4917e16d1a3a0903670aa36d34ade8f784f03ae 100644 --- a/compiler_service/include/aot_compiler_constants.h +++ b/compiler_service/include/aot_compiler_constants.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 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 @@ -34,7 +34,7 @@ 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 LANGUAGE_VERSION = "language-version"; +const std::string CODE_LANGUAGE = "codeLanguage"; } // namespace ArgsIdx namespace Symbols { diff --git a/compiler_service/src/aot_args_handler.cpp b/compiler_service/src/aot_args_handler.cpp index 1cef3c952bbfdf801bfad2e252c04b5b887ebe68..a507973b818c160c8ad1ede46166215d8498fb69 100644 --- a/compiler_service/src/aot_args_handler.cpp +++ b/compiler_service/src/aot_args_handler.cpp @@ -14,6 +14,10 @@ */ #include "aot_args_handler.h" + +#include +#include + #include "aot_args_list.h" #include "aot_compiler_constants.h" #include "ecmascript/log_wrapper.h" @@ -23,9 +27,25 @@ #endif namespace OHOS::ArkCompiler { +const std::string AOT_FILE = "aot-file"; + +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_BOOT_PATH = "/system/framework/bootpath.json"; + +const std::string ARKTS_1_1 = "1.1"; +const std::string ARKTS_1_2 = "1.2"; +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"; + AOTArgsHandler::AOTArgsHandler(const std::unordered_map &argsMap) : argsMap_(argsMap) { - parser_ = AOTArgsParserFactory::GetParser(argsMap); + parser_ = *AOTArgsParserFactory::GetParser(argsMap); } int32_t AOTArgsHandler::Handle(int32_t thermalLevel) @@ -179,33 +199,103 @@ int32_t StaticAOTArgsParser::Parse(const std::unordered_map AOTArgsParserFactory::GetParser( +bool StaticAOTArgsParser::ParseBootPandaFiles(std::string &bootfiles) +{ + std::ifstream inFile; + inFile.open(STATIC_BOOT_PATH, std::ios::in); + if (!inFile.is_open()) { + LOG_SA(ERROR) << "read json error"; + return false; + } + nlohmann::json jsonObject = nlohmann::json::parse(inFile); + if (jsonObject.is_discarded()) { + LOG_SA(ERROR) << "json discarded error"; + inFile.close(); + return false; + } + + if (jsonObject.is_null() || jsonObject.empty()) { + LOG_SA(ERROR) << "invalid json"; + inFile.close(); + return false; + } + + for (const auto &[key, value] : jsonObject.items()) { + if (!value.is_null() && value.is_string()) { + std::string jsonValue = value.get(); + if (jsonValue.empty()) { + LOG_SA(ERROR) << "json value of " << key << " is empty"; + continue; + } + if (!bootfiles.empty()) { + bootfiles += ":"; + } + bootfiles += jsonValue.c_str(); + } + } + inFile.close(); + return true; +} + +std::string StaticAOTArgsParser::ParseLocation(std::string &anFilePath) +{ + size_t pos = anFilePath.find_last_of("/"); + if (pos == std::string::npos) { + LOG_SA(FATAL) << "aot sa parse invalid location"; + } + std::string moduleName = anFilePath.substr(pos + 1); + std::string location = APP_SANBOX_PATH_PREFIX + moduleName + ETS_PATH; + return location; +} + +std::optional> AOTArgsParserFactory::GetParser( const std::unordered_map &argsMap) { - int32_t languageVersion = 0; - if (AOTArgsParserBase::FindArgsIdxToInteger(argsMap, ArgsIdx::LANGUAGE_VERSION, languageVersion) != ERR_OK) { + 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"; } - switch (static_cast(languageVersion)) { - case LanguageVersion::DEFAULT: - LOG_SA(INFO) << "aot sa use default compiler"; - return std::make_unique(); - case LanguageVersion::STATIC: - LOG_SA(INFO) << "aot sa use static compiler"; - return std::make_unique(); - default: - LOG_SA(FATAL) << "aot sa get invalid language version"; + if (codeLanguage == ARKTS_1_1) { + LOG_SA(INFO) << "aot sa use default compiler"; + return std::make_unique(); + } else if (codeLanguage == ARKTS_1_2 || codeLanguage == ARKTS_HYBRID) { + LOG_SA(INFO) << "aot sa use static compiler"; + return std::make_unique(); } + LOG_SA(FATAL) << "aot sa get invalid code language version"; + return std::nullopt; } } // namespace OHOS::ArkCompiler diff --git a/compiler_service/src/aot_compiler_impl.cpp b/compiler_service/src/aot_compiler_impl.cpp index ddf6104e11e2304e0f822edecba4f43a7db2a0ac..35531790c53081341e83d9aeeca89a94a45d8db3 100644 --- a/compiler_service/src/aot_compiler_impl.cpp +++ b/compiler_service/src/aot_compiler_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 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 @@ -209,7 +209,7 @@ int32_t AotCompilerImpl::AOTLocalCodeSign(std::vector &sigData) const LOG_SA(ERROR) << "failed to sign the aot file"; return ERR_AOT_COMPILER_SIGNATURE_FAILED; } - LOG_SA(DEBUG) << "aot file local sign success"; + LOG_SA(INFO) << "aot file local sign success"; uint8_t *dataPtr = sig.GetBuffer(); for (uint32_t i = 0; i < sig.GetSize(); ++i) { sigData.emplace_back(static_cast(dataPtr[i])); diff --git a/compiler_service/test/unittest/aotcompilerargshandler_unit/aotcompilerargshandler_unit.cpp b/compiler_service/test/unittest/aotcompilerargshandler_unit/aotcompilerargshandler_unit.cpp index 66de26c5f96b2874248614d794fe76dddf1989f0..f726b8dc3fc41f15e9bfce2cbd90295f114661ee 100644 --- a/compiler_service/test/unittest/aotcompilerargshandler_unit/aotcompilerargshandler_unit.cpp +++ b/compiler_service/test/unittest/aotcompilerargshandler_unit/aotcompilerargshandler_unit.cpp @@ -166,7 +166,7 @@ const std::unordered_map argsMapForTest { HWTEST_F(AotArgsHandlerTest, AotArgsHandlerTest_007, TestSize.Level0) { std::unordered_map argsMap(argsMapForTest); - argsMap.emplace("language-version", "0"); + argsMap.emplace(ArgsIdx::CODE_LANGUAGE, "1.1"); std::unique_ptr argsHandler = std::make_unique(argsMap); int32_t ret = argsHandler->Handle(0); EXPECT_EQ(ret, ERR_OK); @@ -182,7 +182,7 @@ HWTEST_F(AotArgsHandlerTest, AotArgsHandlerTest_007, TestSize.Level0) HWTEST_F(AotArgsHandlerTest, AotArgsHandlerTest_008, TestSize.Level0) { std::unordered_map argsMap(argsMapForTest); - argsMap.emplace("language-version", "1"); + argsMap.emplace(ArgsIdx::CODE_LANGUAGE, "1.2"); std::unique_ptr argsHandler = std::make_unique(argsMap); int32_t ret = argsHandler->Handle(0); EXPECT_EQ(ret, ERR_OK);