Add aot white and black list

Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I8ZNB8

Signed-off-by: h30044958 <herongpeng@huawei.com>
Change-Id: I11ae7010f1d291a7ac37e6c4495fa1ccbd41ada0
This commit is contained in:
h30044958 2024-01-29 15:34:21 +08:00
parent 2b34481563
commit 6c4a24334f
11 changed files with 207 additions and 151 deletions

View File

@ -603,6 +603,7 @@ ecma_source = [
"ecmascript/builtins/builtins_weak_set.cpp",
"ecmascript/byte_array.cpp",
"ecmascript/ohos/code_decrypt.cpp",
"ecmascript/ohos/enable_aot_list_helper.cpp",
"ecmascript/compiler/aot_file/elf_builder.cpp",
"ecmascript/compiler/aot_file/elf_reader.cpp",
"ecmascript/compiler/aot_file/elf_checker.cpp",
@ -1296,9 +1297,18 @@ ohos_shared_library("libark_jsruntime_test") {
subsystem_name = "test"
}
ohos_prebuilt_etc("app_aot_white_list") {
ohos_prebuilt_etc("app_aot_enable_list") {
relative_install_dir = "ark"
source = "$js_root/ecmascript/ohos/app_aot_white_list.conf"
source = "$js_root/ecmascript/ohos/app_aot_enable_list.conf"
# Set the subsystem name
part_name = "ets_runtime"
subsystem_name = "arkcompiler"
}
ohos_prebuilt_etc("app_aot_disable_list") {
relative_install_dir = "ark"
source = "$js_root/ecmascript/ohos/app_aot_disable_list.conf"
# Set the subsystem name
part_name = "ets_runtime"

View File

@ -39,7 +39,8 @@
},
"build": {
"sub_component": [
"//arkcompiler/ets_runtime:app_aot_white_list",
"//arkcompiler/ets_runtime:app_aot_enable_list",
"//arkcompiler/ets_runtime:app_aot_disable_list",
"//arkcompiler/ets_runtime:ark_js_packages",
"//arkcompiler/ets_runtime/etc:arkcompiler.para.dac"
],

View File

@ -91,7 +91,7 @@
#include "ecmascript/taskpool/taskpool.h"
#include "ecmascript/ts_types/ts_manager.h"
#include "ecmascript/ohos/white_list_helper.h"
#include "ecmascript/ohos/enable_aot_list_helper.h"
namespace panda::ecmascript {
using RandomGenerator = base::RandomGenerator;
@ -150,8 +150,10 @@ void EcmaVM::PostFork()
GetAssociatedJSThread()->SetThreadId();
heap_->EnableParallelGC();
std::string bundleName = PGOProfilerManager::GetInstance()->GetBundleName();
if (!WhiteListHelper::GetInstance()->IsEnable(bundleName)) {
if (ohos::EnableAotListHelper::GetInstance()->IsDisableBlackList(bundleName)) {
options_.SetEnablePGOProfiler(false);
} else if (ohos::EnableAotListHelper::GetInstance()->IsEnableList(bundleName)) {
options_.SetEnablePGOProfiler(true);
}
ResetPGOProfiler();
#ifdef ENABLE_POSTFORK_FORCEEXPAND

View File

@ -0,0 +1,3 @@
# Apps in this configuration file can be compiled by aot compiler, disable list can be written as below:
# {bundleName}:{moduleName}
# {bundleName}

View File

@ -1,3 +1,3 @@
# Apps in this configuration file can be compiled by aot compiler, white list can be written as below:
# Apps in this configuration file can be compiled by aot compiler, enable list can be written as below:
# {bundleName}:{moduleName}
# {bundleName}

View File

@ -0,0 +1,20 @@
/*
* Copyright (c) 2024 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.P
*/
#include "ecmascript/ohos/enable_aot_list_helper.h"
namespace panda::ecmascript::ohos {
const std::string EnableAotListHelper::ENABLE_LIST_NAME = "/etc/ark/app_aot_enable_list.conf";
const std::string EnableAotListHelper::DISABLE_LIST_NAME = "/etc/ark/app_aot_disable_list.conf";
} // namespace panda::ecmascript::ohos

View File

@ -0,0 +1,141 @@
/*
* Copyright (c) 2024 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_OHOS_ENABLE_AOT_LIST_HELPER_H
#define ECMASCRIPT_OHOS_ENABLE_AOT_LIST_HELPER_H
#include <fstream>
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "ecmascript/log_wrapper.h"
#include "ecmascript/platform/file.h"
#include "macros.h"
namespace panda::ecmascript::ohos {
class EnableAotListHelper {
public:
static std::shared_ptr<EnableAotListHelper> GetInstance()
{
static auto helper = std::make_shared<EnableAotListHelper>(ENABLE_LIST_NAME, DISABLE_LIST_NAME);
return helper;
}
explicit EnableAotListHelper(const std::string &enableListName, const std::string &disableListName)
{
ReadEnableAotList(enableListName);
ReadEnableAotList(disableListName);
}
EnableAotListHelper() = default;
~EnableAotListHelper() = default;
bool IsEnableList(const std::string &candidate)
{
return enableList_.find(candidate) != enableList_.end();
}
bool IsEnableList(const std::string &bundleName, const std::string &moduleName)
{
if (IsEnableList(bundleName)) {
return true;
}
return IsEnableList(bundleName + ":" + moduleName);
}
bool IsDisableBlackList(const std::string &candidate)
{
return disableList_.find(candidate) != disableList_.end();
}
bool IsDisableBlackList(const std::string &bundleName, const std::string &moduleName)
{
if (IsDisableBlackList(bundleName)) {
return true;
}
return IsDisableBlackList(bundleName + ":" + moduleName);
}
void AddEnableListEntry(const std::string &entry)
{
enableList_.insert(entry);
}
void AddDisableListEntry(const std::string &entry)
{
disableList_.insert(entry);
}
void Clear()
{
disableList_.clear();
enableList_.clear();
}
private:
NO_COPY_SEMANTIC(EnableAotListHelper);
NO_MOVE_SEMANTIC(EnableAotListHelper);
static void Trim(std::string &data)
{
if (data.empty()) {
return;
}
data.erase(0, data.find_first_not_of(' '));
data.erase(data.find_last_not_of(' ') + 1);
}
void ReadEnableAotList(const std::string &aotListName)
{
if (!panda::ecmascript::FileExist(aotListName.c_str())) {
LOG_ECMA(INFO) << "bundle enable list not exist and will pass by all. file: " << aotListName;
return;
}
std::ifstream inputFile(aotListName);
if (!inputFile.is_open()) {
LOG_ECMA(ERROR) << "bundle enable list open failed! file: " << aotListName << ", errno: " << errno;
return;
}
std::string line;
while (getline(inputFile, line)) {
auto appName = line;
Trim(appName);
// skip empty line
if (appName.empty()) {
continue;
}
// skip comment line
if (appName.at(0) == '#') {
continue;
}
if (aotListName == ENABLE_LIST_NAME) {
AddEnableListEntry(appName);
}
if (aotListName == DISABLE_LIST_NAME) {
AddDisableListEntry(appName);
}
}
}
std::set<std::string> enableList_ {};
std::set<std::string> disableList_ {};
static const std::string ENABLE_LIST_NAME;
static const std::string DISABLE_LIST_NAME;
};
} // namespace panda::ecmascript::ohos
#endif // ECMASCRIPT_OHOS_ENABLE_AOT_LIST_HELPER_H

View File

@ -34,7 +34,7 @@
#include "ecmascript/log_wrapper.h"
#include "ecmascript/mem/c_string.h"
#include "ecmascript/module/module_path_helper.h"
#include "ecmascript/ohos/white_list_helper.h"
#include "ecmascript/ohos/enable_aot_list_helper.h"
#include "ecmascript/pgo_profiler/pgo_utils.h"
#include "ecmascript/platform/file.h"
#if defined(CODE_ENCRYPTION_ENABLE)
@ -356,10 +356,7 @@ public:
{
pgoPaths.clear();
needMerge = false;
// 1. use target aps when app in white list
if (WhiteListHelper::GetInstance()->IsEnable(bundleName_, moduleName_)) {
pgoPaths = GetTargetApPaths();
}
pgoPaths = GetTargetApPaths();
if (!pgoPaths.empty()) {
needMerge = true;
return;

View File

@ -23,7 +23,7 @@
#include "ecmascript/napi/include/jsnapi.h"
#include "ecmascript/ohos/ohos_pkg_args.h"
#include "ecmascript/ohos/white_list_helper.h"
#include "ecmascript/ohos/enable_aot_list_helper.h"
#include "ecmascript/platform/file.h"
#include "ecmascript/tests/test_helper.h"
@ -58,7 +58,7 @@ public:
void TearDown() override
{
WhiteListHelper::GetInstance()->Clear();
ohos::EnableAotListHelper::GetInstance()->Clear();
JSNApi::DestroyJSVM(vm_);
vm_ = nullptr;
}
@ -92,38 +92,41 @@ protected:
HWTEST_F_L0(OhosTest, AotWhiteListTest)
{
const char *whiteListTestDir = "ohos-whiteList/";
const char *whiteListName = "ohos-whiteList/app_aot_white_list.conf";
const char *enableListName = "ohos-whiteList/app_aot_enable_list.conf";
const char *disableListName = "ohos-whiteList/app_aot_disable_list.conf";
std::string bundleScope = "com.bundle.scope.test";
std::string moduleScope = "com.module.scope.test";
mkdir(whiteListTestDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
std::ofstream file(whiteListName);
std::ofstream file(disableListName);
file << bundleScope << std::endl;
file << moduleScope << ":entry" << std::endl;
file << " # " <<moduleScope << ":entryComment" << std::endl;
file.close();
auto helper = std::make_unique<WhiteListHelper>(whiteListName);
ASSERT_FALSE(helper->IsEnable(bundleScope));
ASSERT_FALSE(helper->IsEnable(bundleScope, "entry"));
ASSERT_FALSE(helper->IsEnable(moduleScope, "entry"));
ASSERT_TRUE(helper->IsEnable(moduleScope, "entry1"));
ASSERT_TRUE(helper->IsEnable(moduleScope, "entryComment"));
unlink(whiteListName);
auto helper = std::make_unique<ohos::EnableAotListHelper>(enableListName, disableListName);
ASSERT_FALSE(helper->IsDisableBlackList(bundleScope));
ASSERT_FALSE(helper->IsDisableBlackList(bundleScope, "entry"));
ASSERT_FALSE(helper->IsDisableBlackList(moduleScope, "entry"));
ASSERT_FALSE(helper->IsDisableBlackList(moduleScope, "entry1"));
ASSERT_FALSE(helper->IsDisableBlackList(moduleScope, "entryComment"));
unlink(disableListName);
unlink(enableListName);
rmdir(whiteListTestDir);
}
HWTEST_F_L0(OhosTest, AotWhiteListPassBy)
{
const char *whiteListName = "ohos-AotWhiteListPassBy/app_aot_white_list.conf";
const char *enableListName = "ohos-AotWhiteListPassBy/app_aot_enable_list.conf";
const char *disableListName = "ohos-AotWhiteListPassBy/app_aot_disable_list.conf";
std::string bundleScope = "com.bundle.scope.test";
std::string moduleScope = "com.module.scope.test";
auto helper = std::make_unique<WhiteListHelper>(whiteListName);
ASSERT_TRUE(helper->IsEnable(bundleScope));
ASSERT_TRUE(helper->IsEnable(bundleScope, "entry"));
ASSERT_TRUE(helper->IsEnable(moduleScope, "entry"));
ASSERT_TRUE(helper->IsEnable(moduleScope, "entry1"));
ASSERT_TRUE(helper->IsEnable(moduleScope, "entryCommentNotExist"));
auto helper = std::make_unique<ohos::EnableAotListHelper>(enableListName, disableListName);
ASSERT_FALSE(helper->IsDisableBlackList(bundleScope));
ASSERT_FALSE(helper->IsDisableBlackList(bundleScope, "entry"));
ASSERT_FALSE(helper->IsDisableBlackList(moduleScope, "entry"));
ASSERT_FALSE(helper->IsDisableBlackList(moduleScope, "entry1"));
ASSERT_FALSE(helper->IsDisableBlackList(moduleScope, "entryCommentNotExist"));
}
HWTEST_F_L0(OhosTest, OhosPkgArgsParse)

View File

@ -1,115 +0,0 @@
/*
* Copyright (c) 2023 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_OHOS_WHITE_LIST_HELPER_H
#define ECMASCRIPT_OHOS_WHITE_LIST_HELPER_H
#include <fstream>
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "ecmascript/log_wrapper.h"
#include "ecmascript/platform/file.h"
#include "macros.h"
class WhiteListHelper {
public:
static std::shared_ptr<WhiteListHelper> GetInstance()
{
static const std::string WHITE_LIST_NAME = "/etc/ark/app_aot_white_list.conf";
static auto helper = std::make_shared<WhiteListHelper>(WHITE_LIST_NAME);
return helper;
}
explicit WhiteListHelper(const std::string &whiteListName)
{
ReadWhiteList(whiteListName);
}
~WhiteListHelper() = default;
bool IsEnable(const std::string &candidate)
{
return passBy_ || whiteList_.find(candidate) == whiteList_.end();
}
bool IsEnable(const std::string &bundleName, const std::string &moduleName)
{
if (!IsEnable(bundleName)) {
return false;
}
return IsEnable(bundleName + ":" + moduleName);
}
void AddWhiteListEntry(const std::string &entry)
{
whiteList_.insert(entry);
}
void Clear()
{
passBy_ = false;
whiteList_.clear();
}
private:
NO_COPY_SEMANTIC(WhiteListHelper);
NO_MOVE_SEMANTIC(WhiteListHelper);
static void Trim(std::string &data)
{
if (data.empty()) {
return;
}
data.erase(0, data.find_first_not_of(' '));
data.erase(data.find_last_not_of(' ') + 1);
}
void ReadWhiteList(const std::string &whiteListName)
{
if (!panda::ecmascript::FileExist(whiteListName.c_str())) {
LOG_ECMA(INFO) << "bundle white list not exist and will pass by all. file: " << whiteListName;
passBy_ = true;
return;
}
std::ifstream inputFile(whiteListName);
if (!inputFile.is_open()) {
LOG_ECMA(ERROR) << "bundle white list open failed! file: " << whiteListName << ", errno: " << errno;
return;
}
std::string line;
while (getline(inputFile, line)) {
auto appName = line;
Trim(appName);
// skip empty line
if (appName.empty()) {
continue;
}
// skip comment line
if (appName.at(0) == '#') {
continue;
}
AddWhiteListEntry(appName);
}
}
bool passBy_ {false};
std::set<std::string> whiteList_ {};
};
#endif

View File

@ -20,7 +20,7 @@
#include <string>
#include "ecmascript/log_wrapper.h"
#include "ecmascript/ohos/white_list_helper.h"
#include "ecmascript/ohos/enable_aot_list_helper.h"
#include "ecmascript/mem/c_string.h"
#include "ecmascript/pgo_profiler/ap_file/pgo_file_info.h"
#include "ecmascript/pgo_profiler/pgo_profiler_decoder.h"
@ -221,12 +221,6 @@ void PGOProfilerEncoder::RequestAot()
return;
}
if (!WhiteListHelper::GetInstance()->IsEnable(bundleName_, moduleName_)) {
LOG_ECMA(INFO) << "Request local aot failed. App Not in whitelist, bundle: " << bundleName_
<< ", module: " << moduleName_;
return;
}
LOG_ECMA(INFO) << "Request local aot, bundle: " << bundleName_ << ", module: " << moduleName_;
if (!PGOProfilerManager::GetInstance()->RequestAot(bundleName_, moduleName_, RequestAotMode::RE_COMPILE_ON_IDLE)) {
LOG_ECMA(ERROR) << "Request aot failed, bundle: " << bundleName_ << ", module: " << moduleName_;