!4951 add white list for aot compiling

Merge pull request !4951 from hzzhouzebin/AddWhiteListFileForAot
This commit is contained in:
openharmony_ci 2023-10-12 12:01:54 +00:00 committed by Gitee
commit f1745ca38f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
13 changed files with 159 additions and 28 deletions

View File

@ -1219,3 +1219,12 @@ ohos_shared_library("libark_jsruntime_test") {
}
subsystem_name = "test"
}
ohos_prebuilt_etc("app_aot_white_list") {
relative_install_dir = "ark"
source = "$js_root/ecmascript/ohos/app_aot_white_list.conf"
# Set the subsystem name
part_name = "ets_runtime"
subsystem_name = "arkcompiler"
}

View File

@ -38,6 +38,7 @@
},
"build": {
"sub_component": [
"//arkcompiler/ets_runtime:app_aot_white_list",
"//arkcompiler/ets_runtime:ark_js_packages"
],
"inner_kits": [

View File

@ -15,7 +15,7 @@
#ifndef ECMASCRIPT_COMPILER_AOT_COMPILER_H
#define ECMASCRIPT_COMPILER_AOT_COMPILER_H
#include "ecmascript/compiler/ohos_pkg_args.h"
#include "ecmascript/ohos/ohos_pkg_args.h"
#include "ecmascript/compiler/pass_manager.h"
#include "ecmascript/ecma_vm.h"

View File

@ -699,13 +699,4 @@ void EcmaVM::ResumeWorkerVm(uint32_t tid)
}
}
}
bool EcmaVM::RequestAot(const std::string &bundleName, const std::string &moduleName, RequestAotMode triggerMode) const
{
if (requestAotCallback_ == nullptr) {
LOG_ECMA(ERROR) << "Trigger aot failed. callback is null.";
return false;
}
return (requestAotCallback_(bundleName, moduleName, static_cast<int32_t>(triggerMode)) == 0);
}
} // namespace panda::ecmascript

View File

@ -272,13 +272,6 @@ public:
return resolveBufferCallback_;
}
bool RequestAot(const std::string &bundleName, const std::string &moduleName, RequestAotMode triggerMode) const;
void SetRequestAotCallback(const RequestAotCallback &cb)
{
requestAotCallback_ = cb;
}
void SetUnloadNativeModuleCallback(const UnloadNativeModuleCallback &cb)
{
unloadNativeModuleCallback_ = cb;
@ -530,9 +523,6 @@ private:
// delete the native module and dlclose so from NativeModuleManager
UnloadNativeModuleCallback unloadNativeModuleCallback_ {nullptr};
// trigger local aot
RequestAotCallback requestAotCallback_ {nullptr};
// Concurrent taskpool callback and data
ConcurrentCallback concurrentCallback_ {nullptr};
void *concurrentData_ {nullptr};

View File

@ -654,6 +654,7 @@ void JSNApi::PostFork(EcmaVM *vm, const RuntimeOption &option)
<< ", aot: " << jsOption.GetEnableAOT()
<< ", bundle name: " << option.GetBundleName();
jsOption.SetEnablePGOProfiler(option.GetEnableProfile());
ecmascript::pgo::PGOProfilerManager::GetInstance()->SetBundleName(option.GetBundleName());
vm->ResetPGOProfiler();
JSRuntimeOptions runtimeOptions;
runtimeOptions.SetLogLevel(Log::LevelToString(Log::ConvertFromRuntime(option.GetLogLevel())));
@ -855,11 +856,10 @@ void JSNApi::SetHostResolveBufferTracker(EcmaVM *vm,
vm->SetResolveBufferCallback(cb);
}
void JSNApi::SetRequestAotCallback(EcmaVM *vm, const std::function<int32_t(const std::string &bundleName,
const std::string &moduleName,
int32_t triggerMode)> &cb)
void JSNApi::SetRequestAotCallback([[maybe_unused]] EcmaVM *vm, const std::function<int32_t
(const std::string &bundleName, const std::string &moduleName, int32_t triggerMode)> &cb)
{
vm->SetRequestAotCallback(cb);
ecmascript::pgo::PGOProfilerManager::GetInstance()->SetRequestAotCallback(cb);
}
void JSNApi::SetUnloadNativeModuleCallback(EcmaVM *vm, const std::function<bool(const std::string &moduleKey)> &cb)

View File

@ -26,6 +26,7 @@
#include "ecmascript/napi/include/jsnapi.h"
#include "ecmascript/napi/jsnapi_helper.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/pgo_profiler/pgo_profiler_manager.h"
#include "ecmascript/tagged_array.h"
#include "ecmascript/tests/test_helper.h"
#include "ecmascript/js_generator_object.h"
@ -1531,7 +1532,8 @@ HWTEST_F_L0(JSNApiTests, AotTrigger)
trigger = triggerMode;
return 100;
});
ASSERT_FALSE(vm_->RequestAot("com.test.test", "requestAot", RequestAotMode::RE_COMPILE_ON_IDLE));
ASSERT_FALSE(ecmascript::pgo::PGOProfilerManager::GetInstance()->RequestAot("com.test.test", "requestAot",
RequestAotMode::RE_COMPILE_ON_IDLE));
ASSERT_EQ(bundle, "com.test.test");
ASSERT_EQ(module, "requestAot");
ASSERT_EQ(trigger, 0);

View File

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

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef ECMASCRIPT_COMPILER_OHOS_PKG_ARGS_H
#define ECMASCRIPT_COMPILER_OHOS_PKG_ARGS_H
#ifndef ECMASCRIPT_OHOS_OHOS_PKG_ARGS_H
#define ECMASCRIPT_OHOS_OHOS_PKG_ARGS_H
#include <limits>
#include <vector>

View File

@ -0,0 +1,87 @@
/*
* 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 <set>
#include <string>
#include <vector>
#include "ecmascript/log_wrapper.h"
#include "macros.h"
class WhiteListHelper {
public:
static std::shared_ptr<WhiteListHelper> GetInstance()
{
static auto helper = std::make_shared<WhiteListHelper>();
return helper;
}
WhiteListHelper()
{
ReadWhiteList();
}
~WhiteListHelper() = default;
bool IsEnable(const std::string &bundleName, const std::string &moduleName)
{
return whiteList_.find(bundleName + ":" + moduleName) != whiteList_.end();
}
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()
{
static const std::string WHITE_LIST_NAME = "/etc/ark/app_aot_white_list.conf";
std::ifstream inputFile(WHITE_LIST_NAME);
if (!inputFile.is_open()) {
LOG_ECMA(ERROR) << "bundle white list not exist!";
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.find_first_of('#') == 0) {
continue;
}
whiteList_.insert(appName);
}
}
std::set<std::string> whiteList_;
};
#endif

View File

@ -20,10 +20,11 @@
#include <string>
#include "ecmascript/log_wrapper.h"
#include "ecmascript/ohos/white_list_helper.h"
#include "ecmascript/pgo_profiler/ap_file/pgo_file_info.h"
#include "ecmascript/pgo_profiler/pgo_profiler_decoder.h"
#include "ecmascript/pgo_profiler/pgo_profiler_encoder.h"
#include "ecmascript/pgo_profiler/pgo_profiler_manager.h"
#include "ecmascript/pgo_profiler/pgo_utils.h"
#include "ecmascript/platform/file.h"
#include "os/mutex.h"
@ -172,9 +173,28 @@ bool PGOProfilerEncoder::SaveAndRename(const SaveTask *task)
LOG_ECMA(ERROR) << "Rename " << tmpOutPath << " --> " << realOutPath_ << " failure!, errno: " << errno;
return false;
}
RequestAot();
return true;
}
void PGOProfilerEncoder::RequestAot()
{
if (bundleName_.empty() || moduleName_.empty()) {
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_;
}
}
bool PGOProfilerEncoder::InternalSave(const SaveTask *task)
{
ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "PGOProfilerEncoder::InternalSave");

View File

@ -39,6 +39,11 @@ public:
void PUBLIC_API Destroy();
void SetBundleName(const std::string &bundleName)
{
bundleName_ = bundleName;
}
bool IsInitialized() const
{
return isInitialized_;
@ -68,6 +73,7 @@ private:
void StartSaveTask(const SaveTask *task);
bool InternalSave(const SaveTask *task = nullptr);
bool SaveAndRename(const SaveTask *task = nullptr);
void RequestAot();
bool ResetOutPath(const std::string& profileFileName);
bool isInitialized_ {false};
@ -81,6 +87,7 @@ private:
Mutex mutex_;
RWLock rwLock_;
std::string moduleName_;
std::string bundleName_;
ApGenMode mode_ {OVERWRITE};
friend SaveTask;
};

View File

@ -48,6 +48,27 @@ public:
encoder_ = std::make_unique<PGOProfilerEncoder>(outDir, hotnessThreshold, ApGenMode::OVERWRITE);
}
void SetBundleName(const std::string &bundleName)
{
if (encoder_) {
encoder_->SetBundleName(bundleName);
}
}
void SetRequestAotCallback(const RequestAotCallback &cb)
{
requestAotCallback_ = cb;
}
bool RequestAot(const std::string &bundleName, const std::string &moduleName, RequestAotMode triggerMode) const
{
if (requestAotCallback_ == nullptr) {
LOG_ECMA(ERROR) << "Trigger aot failed. callback is null.";
return false;
}
return (requestAotCallback_(bundleName, moduleName, static_cast<int32_t>(triggerMode)) == 0);
}
void Destroy()
{
if (encoder_) {
@ -188,6 +209,7 @@ private:
}
std::unique_ptr<PGOProfilerEncoder> encoder_;
RequestAotCallback requestAotCallback_;
std::atomic_bool enableSignalSaving_ { false };
};
} // namespace panda::ecmascript::pgo