SA compiler log domainID

Signed-off-by: ChenYC009 <chenyongchun5@huawei.com>
Change-Id: I990e9d9667c2dfdf1854bcc3824e6206c37cb019
This commit is contained in:
ChenYC009 2024-06-08 22:23:15 +08:00
parent 8568fea44c
commit 343785b5af
14 changed files with 147 additions and 169 deletions

View File

@ -29,6 +29,7 @@ ohos_shared_library("libcompiler_service") {
shlib_type = "sa"
version_script = "libaot_compiler_service.map"
sources = [
"${js_root}/ecmascript/log.cpp",
"interface/aot_compiler_interface_proxy.cpp",
"interface/aot_compiler_interface_stub.cpp",
"src/aot_compiler_client.cpp",

View File

@ -14,13 +14,10 @@
*/
#include "aot_compiler_interface_proxy.h"
#include "hilog/log.h"
#include "ecmascript/log_wrapper.h"
#include "hitrace_meter.h"
using OHOS::HiviewDFX::HiLog;
namespace OHOS {
namespace ArkCompiler {
namespace OHOS::ArkCompiler {
ErrCode AotCompilerInterfaceProxy::AotCompiler(
const std::unordered_map<std::string, std::string>& argsMap,
std::vector<int16_t>& sigData)
@ -31,47 +28,47 @@ ErrCode AotCompilerInterfaceProxy::AotCompiler(
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
HiLog::Error(LABEL, "Write interface token failed!");
LOG_SA(ERROR) << "Write interface token failed!";
return ERR_INVALID_VALUE;
}
if (argsMap.size() > mapMaxSize) {
HiLog::Error(LABEL, "The map size exceeds the security limit!");
LOG_SA(ERROR) << "The map size exceeds the security limit!";
return ERR_INVALID_DATA;
}
data.WriteInt32(argsMap.size());
for (auto it = argsMap.begin(); it != argsMap.end(); ++it) {
if (!data.WriteString16(Str8ToStr16((it->first)))) {
HiLog::Error(LABEL, "Write [(it->first)] failed!");
LOG_SA(ERROR) << "Write [(it->first)] failed!";
return ERR_INVALID_DATA;
}
if (!data.WriteString16(Str8ToStr16((it->second)))) {
HiLog::Error(LABEL, "Write [(it->second)] failed!");
LOG_SA(ERROR) << "Write [(it->second)] failed!";
return ERR_INVALID_DATA;
}
}
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
HiLog::Error(LABEL, "Remote is nullptr!");
LOG_SA(ERROR) << "Remote is nullptr!";
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(COMMAND_AOT_COMPILER, data, reply, option);
if (FAILED(result)) {
HiLog::Error(LABEL, "Send request failed!");
LOG_SA(ERROR) << "Send request failed!";
return result;
}
ErrCode errCode = reply.ReadInt32();
if (FAILED(errCode)) {
HiLog::Error(LABEL, "Read Int32 failed!");
LOG_SA(ERROR) << "Read Int32 failed!";
return errCode;
}
int32_t sigDataSize = reply.ReadInt32();
if (static_cast<unsigned long>(sigDataSize) > vectorMaxSize) {
HiLog::Error(LABEL, "The vector/array size exceeds the security limit!");
LOG_SA(ERROR) << "The vector/array size exceeds the security limit!";
return ERR_INVALID_DATA;
}
for (int32_t i = 0; i < sigDataSize; ++i) {
@ -89,24 +86,24 @@ ErrCode AotCompilerInterfaceProxy::StopAotCompiler()
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
HiLog::Error(LABEL, "Write interface token failed!");
LOG_SA(ERROR) << "Write interface token failed!";
return ERR_INVALID_VALUE;
}
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
HiLog::Error(LABEL, "Remote is nullptr!");
LOG_SA(ERROR) << "Remote is nullptr!";
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(COMMAND_STOP_AOT_COMPILER, data, reply, option);
if (FAILED(result)) {
HiLog::Error(LABEL, "Send request failed!");
LOG_SA(ERROR) << "Send request failed!";
return result;
}
ErrCode errCode = reply.ReadInt32();
if (FAILED(errCode)) {
HiLog::Error(LABEL, "Read Int32 failed!");
LOG_SA(ERROR) << "Read Int32 failed!";
return errCode;
}
@ -121,24 +118,24 @@ ErrCode AotCompilerInterfaceProxy::GetAOTVersion(std::string& sigData)
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
HiLog::Error(LABEL, "Write interface token failed!");
LOG_SA(ERROR) << "Write interface token failed!";
return ERR_INVALID_VALUE;
}
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
HiLog::Error(LABEL, "Remote is nullptr!");
LOG_SA(ERROR) << "Remote is nullptr!";
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(COMMAND_GET_AOT_VERSION, data, reply, option);
if (FAILED(result)) {
HiLog::Error(LABEL, "Send request failed!");
LOG_SA(ERROR) << "Send request failed!";
return result;
}
ErrCode errCode = reply.ReadInt32();
if (FAILED(errCode)) {
HiLog::Error(LABEL, "Read Int32 failed!");
LOG_SA(ERROR) << "Read Int32 failed!";
return errCode;
}
@ -155,7 +152,7 @@ ErrCode AotCompilerInterfaceProxy::NeedReCompile(const std::string& args, bool&
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
HiLog::Error(LABEL, "Write interface token failed!");
LOG_SA(ERROR) << "Write interface token failed!";
return ERR_INVALID_VALUE;
}
@ -163,18 +160,18 @@ ErrCode AotCompilerInterfaceProxy::NeedReCompile(const std::string& args, bool&
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
HiLog::Error(LABEL, "Remote is nullptr!");
LOG_SA(ERROR) << "Remote is nullptr!";
return ERR_INVALID_DATA;
}
int32_t result = remote->SendRequest(COMMAND_NEED_RE_COMPILE, data, reply, option);
if (FAILED(result)) {
HiLog::Error(LABEL, "Send request failed!");
LOG_SA(ERROR) << "Send request failed!";
return result;
}
ErrCode errCode = reply.ReadInt32();
if (FAILED(errCode)) {
HiLog::Error(LABEL, "Read Int32 failed!");
LOG_SA(ERROR) << "Read Int32 failed!";
return errCode;
}
@ -182,5 +179,4 @@ ErrCode AotCompilerInterfaceProxy::NeedReCompile(const std::string& args, bool&
return ERR_OK;
}
} // namespace ArkCompiler
} // namespace OHOS
} // namespace OHOS::ArkCompiler

View File

@ -19,8 +19,7 @@
#include <iremote_proxy.h>
#include "iaot_compiler_interface.h"
namespace OHOS {
namespace ArkCompiler {
namespace OHOS::ArkCompiler {
class AotCompilerInterfaceProxy : public IRemoteProxy<IAotCompilerInterface> {
public:
explicit AotCompilerInterfaceProxy(
@ -49,7 +48,6 @@ private:
static inline BrokerDelegator<AotCompilerInterfaceProxy> delegator_;
};
} // namespace ArkCompiler
} // namespace OHOS
} // namespace OHOS::ArkCompiler
#endif // OHOS_ARKCOMPILER_AOTCOMPILER_INTERFACE_PROXY_H

View File

@ -14,13 +14,10 @@
*/
#include "aot_compiler_interface_stub.h"
#include "hilog/log.h"
#include "ecmascript/log_wrapper.h"
#include "hitrace_meter.h"
using OHOS::HiviewDFX::HiLog;
namespace OHOS {
namespace ArkCompiler {
namespace OHOS::ArkCompiler {
int32_t AotCompilerInterfaceStub::OnRemoteRequest(
uint32_t code,
MessageParcel& data,
@ -58,7 +55,7 @@ int32_t AotCompilerInterfaceStub::CommandAOTCompiler(MessageParcel &data,
std::unordered_map<std::string, std::string> argsMap;
int32_t argsMapSize = data.ReadInt32();
if (static_cast<unsigned long>(argsMapSize) > mapMaxSize) {
HiLog::Error(LABEL, "The map size exceeds ths security limit!");
LOG_SA(ERROR) << "The map size exceeds ths security limit!";
return ERR_INVALID_DATA;
}
for (int32_t i = 0; i < argsMapSize; ++i) {
@ -69,18 +66,18 @@ int32_t AotCompilerInterfaceStub::CommandAOTCompiler(MessageParcel &data,
std::vector<int16_t> sigData;
ErrCode errCode = AotCompiler(argsMap, sigData);
if (!reply.WriteInt32(errCode)) {
HiLog::Error(LABEL, "Write Int32 failed!");
LOG_SA(ERROR) << "Write Int32 failed!";
return ERR_INVALID_VALUE;
}
if (SUCCEEDED(errCode)) {
if (sigData.size() > vectorMaxSize) {
HiLog::Error(LABEL, "The vector size exceeds the security limit!");
LOG_SA(ERROR) << "The vector size exceeds the security limit!";
return ERR_INVALID_DATA;
}
reply.WriteInt32(sigData.size());
for (auto it = sigData.begin(); it != sigData.end(); ++it) {
if (!reply.WriteInt32(*it)) {
HiLog::Error(LABEL, "Write sigData array failed!");
LOG_SA(ERROR) << "Write sigData array failed!";
return ERR_INVALID_DATA;
}
}
@ -92,7 +89,7 @@ int32_t AotCompilerInterfaceStub::CommandStopAOTCompiler(MessageParcel& reply)
{
ErrCode errCode = StopAotCompiler();
if (!reply.WriteInt32(errCode)) {
HiLog::Error(LABEL, "Write Int32 failed!");
LOG_SA(ERROR) << "Write Int32 failed!";
return ERR_INVALID_VALUE;
}
return ERR_NONE;
@ -103,7 +100,7 @@ int32_t AotCompilerInterfaceStub::CommandGetAOTVersion(MessageParcel& reply)
std::string sigData;
ErrCode errCode = GetAOTVersion(sigData);
if (!reply.WriteInt32(errCode)) {
HiLog::Error(LABEL, "Write Int32 failed!");
LOG_SA(ERROR) << "Write Int32 failed!";
return ERR_INVALID_VALUE;
}
if (SUCCEEDED(errCode)) {
@ -120,7 +117,7 @@ int32_t AotCompilerInterfaceStub::CommandNeedReCompile(MessageParcel& data,
bool sigData;
ErrCode errCode = NeedReCompile(regs, sigData);
if (!reply.WriteInt32(errCode)) {
HiLog::Error(LABEL, "Write Int32 failed!");
LOG_SA(ERROR) << "Write Int32 failed!";
return ERR_INVALID_VALUE;
}
if (SUCCEEDED(errCode)) {
@ -129,5 +126,4 @@ int32_t AotCompilerInterfaceStub::CommandNeedReCompile(MessageParcel& data,
return ERR_NONE;
}
} // namespace ArkCompiler
} // namespace OHOS
} // namespace OHOS::ArkCompiler

View File

@ -19,8 +19,7 @@
#include <iremote_stub.h>
#include "iaot_compiler_interface.h"
namespace OHOS {
namespace ArkCompiler {
namespace OHOS::ArkCompiler {
class AotCompilerInterfaceStub : public IRemoteStub<IAotCompilerInterface> {
public:
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
@ -35,7 +34,6 @@ private:
static constexpr int32_t COMMAND_GET_AOT_VERSION = MIN_TRANSACTION_ID + 2;
static constexpr int32_t COMMAND_NEED_RE_COMPILE = MIN_TRANSACTION_ID + 3;
};
} // namespace ArkCompiler
} // namespace OHOS
} // namespace OHOS::ArkCompiler
#endif // OHOS_ARKCOMPILER_AOTCOMPILER_INTERFACE_STUB_H

View File

@ -26,10 +26,8 @@
#elif defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif
#include "hilog/log.h"
namespace OHOS {
namespace ArkCompiler {
namespace OHOS::ArkCompiler {
class IAotCompilerInterface : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ArkCompiler.IAotCompilerInterface");
@ -42,13 +40,9 @@ public:
virtual ErrCode GetAOTVersion(std::string& sigData) = 0;
virtual ErrCode NeedReCompile(const std::string& argsString, bool& sigData) = 0;
protected:
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
LOG_CORE, 0xD003900, "AotCompilerInterfaceService"
};
const unsigned long vectorMaxSize = 102400;
const unsigned long mapMaxSize = 102400;
};
} // namespace ArkCompiler
} // namespace OHOS
} // namespace OHOS::ArkCompiler
#endif // OHOS_ARKCOMPILER_IAOTCOMPILER_INTERFACE_H

View File

@ -16,7 +16,7 @@
#include "aot_compiler_client.h"
#include "aot_compiler_error_utils.h"
#include "aot_compiler_load_callback.h"
#include "hilog/log.h"
#include "ecmascript/log_wrapper.h"
#include "hitrace_meter.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
@ -24,14 +24,13 @@
namespace OHOS::ArkCompiler {
namespace {
const int LOAD_SA_TIMEOUT_MS = 6 * 1000;
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0xD001800, "aot_compiler_service"};
} // namespace
AotCompilerClient::AotCompilerClient()
{
aotCompilerDiedRecipient_ = new (std::nothrow) AotCompilerDiedRecipient();
if (aotCompilerDiedRecipient_ == nullptr) {
HiviewDFX::HiLog::Error(LABEL, "create aot compiler died recipient failed");
LOG_SA(ERROR) << "create aot compiler died recipient failed";
}
}
@ -45,10 +44,10 @@ int32_t AotCompilerClient::AotCompiler(const std::unordered_map<std::string, std
std::vector<int16_t> &sigData)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HiviewDFX::HiLog::Debug(LABEL, "aot compiler function called");
LOG_SA(DEBUG) << "aot compiler function called";
auto aotCompilerProxy = GetAotCompilerProxy();
if (aotCompilerProxy == nullptr) {
HiviewDFX::HiLog::Error(LABEL, "get aot compiler service failed");
LOG_SA(ERROR) << "get aot compiler service failed";
return ERR_AOT_COMPILER_CONNECT_FAILED;
}
return aotCompilerProxy->AotCompiler(argsMap, sigData);
@ -57,10 +56,10 @@ int32_t AotCompilerClient::AotCompiler(const std::unordered_map<std::string, std
int32_t AotCompilerClient::StopAotCompiler()
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HiviewDFX::HiLog::Debug(LABEL, "aot compiler function called");
LOG_SA(DEBUG) << "aot compiler function called";
auto aotCompilerProxy = GetAotCompilerProxy();
if (aotCompilerProxy == nullptr) {
HiviewDFX::HiLog::Error(LABEL, "get aot compiler service failed");
LOG_SA(ERROR) << "get aot compiler service failed";
return ERR_AOT_COMPILER_CONNECT_FAILED;
}
return aotCompilerProxy->StopAotCompiler();
@ -69,10 +68,10 @@ int32_t AotCompilerClient::StopAotCompiler()
int32_t AotCompilerClient::GetAOTVersion(std::string& sigData)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HiviewDFX::HiLog::Debug(LABEL, "aot compiler get AOT version called");
LOG_SA(DEBUG) << "aot compiler get AOT version called";
auto aotCompilerProxy = GetAotCompilerProxy();
if (aotCompilerProxy == nullptr) {
HiviewDFX::HiLog::Error(LABEL, "get aot compiler service failed");
LOG_SA(ERROR) << "get aot compiler service failed";
return ERR_AOT_COMPILER_CONNECT_FAILED;
}
@ -82,10 +81,10 @@ int32_t AotCompilerClient::GetAOTVersion(std::string& sigData)
int32_t AotCompilerClient::NeedReCompile(const std::string& oldVersion, bool& sigData)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HiviewDFX::HiLog::Debug(LABEL, "aot compiler check need re-compile called");
LOG_SA(DEBUG) << "aot compiler check need re-compile called";
auto aotCompilerProxy = GetAotCompilerProxy();
if (aotCompilerProxy == nullptr) {
HiviewDFX::HiLog::Error(LABEL, "get aot compiler service failed");
LOG_SA(ERROR) << "get aot compiler service failed";
return ERR_AOT_COMPILER_CONNECT_FAILED;
}
return aotCompilerProxy->NeedReCompile(oldVersion, sigData);
@ -93,15 +92,15 @@ int32_t AotCompilerClient::NeedReCompile(const std::string& oldVersion, bool& si
sptr<IAotCompilerInterface> AotCompilerClient::GetAotCompilerProxy()
{
HiviewDFX::HiLog::Debug(LABEL, "get aot compiler proxy function called");
LOG_SA(DEBUG) << "get aot compiler proxy function called";
auto aotCompilerProxy = GetAotCompiler();
if (aotCompilerProxy != nullptr) {
HiviewDFX::HiLog::Debug(LABEL, "aot compiler service proxy has been started");
LOG_SA(DEBUG) << "aot compiler service proxy has been started";
return aotCompilerProxy;
}
auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (systemAbilityMgr == nullptr) {
HiviewDFX::HiLog::Error(LABEL, "failed to get system ability manager");
LOG_SA(ERROR) << "failed to get system ability manager";
return nullptr;
}
auto remoteObject = systemAbilityMgr->CheckSystemAbility(AOT_COMPILER_SERVICE_ID);
@ -110,15 +109,15 @@ sptr<IAotCompilerInterface> AotCompilerClient::GetAotCompilerProxy()
return aotCompilerProxy;
}
if (!LoadAotCompilerService()) {
HiviewDFX::HiLog::Error(LABEL, "load aot compiler service failed");
LOG_SA(ERROR) << "load aot compiler service failed";
return nullptr;
}
aotCompilerProxy = GetAotCompiler();
if (aotCompilerProxy == nullptr || aotCompilerProxy->AsObject() == nullptr) {
HiviewDFX::HiLog::Error(LABEL, "failed to get aot compiler service");
LOG_SA(ERROR) << "failed to get aot compiler service";
return nullptr;
}
HiviewDFX::HiLog::Debug(LABEL, "get aot compiler proxy function finished");
LOG_SA(DEBUG) << "get aot compiler proxy function finished";
return aotCompilerProxy;
}
@ -130,18 +129,17 @@ bool AotCompilerClient::LoadAotCompilerService()
}
auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (systemAbilityMgr == nullptr) {
HiviewDFX::HiLog::Error(LABEL, "failed to get system ability manager");
LOG_SA(ERROR) << "failed to get system ability manager";
return false;
}
sptr<AotCompilerLoadCallback> loadCallback = new (std::nothrow) AotCompilerLoadCallback();
if (loadCallback == nullptr) {
HiviewDFX::HiLog::Error(LABEL, "failed to create load callback.");
LOG_SA(ERROR) << "failed to create load callback";
return false;
}
auto ret = systemAbilityMgr->LoadSystemAbility(AOT_COMPILER_SERVICE_ID, loadCallback);
if (ret != 0) {
HiviewDFX::HiLog::Error(LABEL, "load system ability %{public}d failed with %{public}d",
AOT_COMPILER_SERVICE_ID, ret);
LOG_SA(ERROR) << "load system ability " << AOT_COMPILER_SERVICE_ID << " failed with " << ret;
return false;
}
{
@ -151,7 +149,7 @@ bool AotCompilerClient::LoadAotCompilerService()
return loadSaFinished_;
});
if (!waitStatus) {
HiviewDFX::HiLog::Error(LABEL, "wait for load SA timeout");
LOG_SA(ERROR) << "wait for load SA timeout";
return false;
}
}
@ -173,11 +171,11 @@ sptr<IAotCompilerInterface> AotCompilerClient::GetAotCompiler()
void AotCompilerClient::OnLoadSystemAbilitySuccess(const sptr<IRemoteObject> &remoteObject)
{
if (aotCompilerDiedRecipient_ == nullptr) {
HiviewDFX::HiLog::Error(LABEL, "register aot compiler died recipient failed");
LOG_SA(ERROR) << "register aot compiler died recipient failed";
return;
}
if (!remoteObject->AddDeathRecipient(aotCompilerDiedRecipient_)) {
HiviewDFX::HiLog::Error(LABEL, "add aot compiler died recipient failed");
LOG_SA(ERROR) << "add aot compiler died recipient failed";
return;
}
SetAotCompiler(remoteObject);
@ -197,7 +195,7 @@ void AotCompilerClient::OnLoadSystemAbilityFail()
void AotCompilerClient::AotCompilerDiedRecipient::OnRemoteDied(const wptr<IRemoteObject> &remoteObject)
{
if (remoteObject == nullptr) {
HiviewDFX::HiLog::Error(LABEL, "remote object of aot compiler died recipient is nullptr");
LOG_SA(ERROR) << "remote object of aot compiler died recipient is nullptr";
return;
}
AotCompilerClient::GetInstance().AotCompilerOnRemoteDied(remoteObject);
@ -205,19 +203,19 @@ void AotCompilerClient::AotCompilerDiedRecipient::OnRemoteDied(const wptr<IRemot
void AotCompilerClient::AotCompilerOnRemoteDied(const wptr<IRemoteObject> &remoteObject)
{
HiviewDFX::HiLog::Info(LABEL, "remote object of aot compiler died recipient is died");
LOG_SA(INFO) << "remote object of aot compiler died recipient is died";
auto aotCompilerProxy = GetAotCompiler();
if (aotCompilerProxy == nullptr) {
HiviewDFX::HiLog::Error(LABEL, "aot compiler proxy is nullptr");
LOG_SA(ERROR) << "aot compiler proxy is nullptr";
return;
}
sptr<IRemoteObject> remotePromote = remoteObject.promote();
if (remotePromote == nullptr) {
HiviewDFX::HiLog::Error(LABEL, "remote object of aot compiler promote fail");
LOG_SA(ERROR) << "remote object of aot compiler promote fail";
return;
}
if (aotCompilerProxy->AsObject() != remotePromote) {
HiviewDFX::HiLog::Error(LABEL, "aot compiler died recipient not find remote object");
LOG_SA(ERROR) << "aot compiler died recipient not find remote object";
return;
}
remotePromote->RemoveDeathRecipient(aotCompilerDiedRecipient_);

View File

@ -29,16 +29,12 @@
#include "aot_compiler_constants.h"
#include "aot_compiler_error_utils.h"
#include "aot_compiler_service.h"
#include "hilog/log.h"
#include "ecmascript/log_wrapper.h"
#include "hitrace_meter.h"
#include "local_code_sign_kit.h"
#include "system_ability_definition.h"
namespace OHOS::ArkCompiler {
namespace {
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0xD001800, "aot_compiler_service"};
} // namespace
AotCompilerImpl& AotCompilerImpl::GetInstance()
{
static AotCompilerImpl aotCompiler;
@ -54,7 +50,7 @@ inline int32_t AotCompilerImpl::FindArgsIdxToInteger(const std::unordered_map<st
size_t sz;
bundleID = static_cast<int32_t>(std::stoi(argsMap.at(keyName), &sz));
if (sz < static_cast<size_t>(argsMap.at(keyName).size())) {
HiviewDFX::HiLog::Error(LABEL, "trigger exception as converting string to integer");
LOG_SA(ERROR) << "trigger exception as converting string to integer";
return ERR_AOT_COMPILER_PARAM_FAILED;
}
return ERR_OK;
@ -73,7 +69,7 @@ inline int32_t AotCompilerImpl::FindArgsIdxToString(const std::unordered_map<std
int32_t AotCompilerImpl::PrepareArgs(const std::unordered_map<std::string, std::string> &argsMap)
{
for (const auto &arg : argsMap) {
HiviewDFX::HiLog::Debug(LABEL, "%{public}s: %{public}s", arg.first.c_str(), arg.second.c_str());
LOG_SA(DEBUG) << arg.first << ": " << arg.second;
}
std::string abcPath;
if ((FindArgsIdxToInteger(argsMap, ArgsIdx::BUNDLE_UID, hapArgs.bundleUid) != ERR_OK) ||
@ -81,6 +77,7 @@ int32_t AotCompilerImpl::PrepareArgs(const std::unordered_map<std::string, std::
(FindArgsIdxToString(argsMap, ArgsIdx::AN_FILE_NAME, hapArgs.fileName) != ERR_OK) ||
(FindArgsIdxToString(argsMap, ArgsIdx::APP_SIGNATURE, hapArgs.signature) != ERR_OK) ||
(FindArgsIdxToString(argsMap, ArgsIdx::ABC_PATH, abcPath) != ERR_OK)) {
LOG_SA(ERROR) << "aot compiler Args parsing error";
return ERR_AOT_COMPILER_PARAM_FAILED;
}
hapArgs.argVector.clear();
@ -97,16 +94,16 @@ int32_t AotCompilerImpl::PrepareArgs(const std::unordered_map<std::string, std::
void AotCompilerImpl::DropCapabilities(const int32_t &bundleUid, const int32_t &bundleGid) const
{
if (setuid(bundleUid)) {
HiviewDFX::HiLog::Error(LABEL, "dropCapabilities setuid failed : %{public}s", strerror(errno));
LOG_SA(ERROR) << "dropCapabilities setuid failed : " << strerror(errno);
exit(-1);
}
if (setgid(bundleGid)) {
HiviewDFX::HiLog::Error(LABEL, "dropCapabilities setgid failed : %{public}s", strerror(errno));
LOG_SA(ERROR) << "dropCapabilities setgid failed : " << strerror(errno);
exit(-1);
}
struct __user_cap_header_struct capHeader;
if (memset_s(&capHeader, sizeof(capHeader), 0, sizeof(capHeader)) != EOK) {
HiviewDFX::HiLog::Error(LABEL, "memset_s capHeader failed : %{public}s", strerror(errno));
LOG_SA(ERROR) << "memset_s capHeader failed : " << strerror(errno);
exit(-1);
}
capHeader.version = _LINUX_CAPABILITY_VERSION_3;
@ -114,11 +111,11 @@ void AotCompilerImpl::DropCapabilities(const int32_t &bundleUid, const int32_t &
struct __user_cap_data_struct capData[2];
if (memset_s(&capData, sizeof(capData), 0, sizeof(capData)) != EOK) {
HiviewDFX::HiLog::Error(LABEL, "memset_s capData failed : %{public}s", strerror(errno));
LOG_SA(ERROR) << "memset_s capData failed : " << strerror(errno);
exit(-1);
}
if (capset(&capHeader, capData) != 0) {
HiviewDFX::HiLog::Error(LABEL, "capset failed : %{public}s", strerror(errno));
LOG_SA(ERROR) << "capset failed : " << strerror(errno);
exit(-1);
}
}
@ -131,12 +128,12 @@ void AotCompilerImpl::ExecuteInChildProcess(const std::vector<std::string> &aotV
argv.emplace_back(arg.c_str());
}
argv.emplace_back(nullptr);
HiviewDFX::HiLog::Debug(LABEL, "argv size : %{public}zu", argv.size());
LOG_SA(DEBUG) << "argv size : " << argv.size();
for (const auto &arg : argv) {
HiviewDFX::HiLog::Debug(LABEL, "%{public}s", arg);
LOG_SA(DEBUG) << arg;
}
execv(argv[0], const_cast<char* const*>(argv.data()));
HiviewDFX::HiLog::Error(LABEL, "execv failed : %{public}s", strerror(errno));
LOG_SA(ERROR) << "execv failed : " << strerror(errno);
exit(-1);
}
@ -149,11 +146,11 @@ void AotCompilerImpl::ExecuteInParentProcess(const pid_t childPid, int32_t &ret)
int status;
int waitRet = waitpid(childPid, &status, 0);
if (waitRet == -1) {
HiviewDFX::HiLog::Error(LABEL, "waitpid failed");
LOG_SA(ERROR) << "waitpid failed";
ret = ERR_AOT_COMPILER_CALL_FAILED;
} else if (WIFEXITED(status)) {
int exit_status = WEXITSTATUS(status);
HiviewDFX::HiLog::Info(LABEL, "child process exited with status: %{public}d", exit_status);
LOG_SA(INFO) << "child process exited with status: %{public}d" << exit_status;
switch (exit_status) {
case static_cast<int>(ErrOfCompile::COMPILE_OK):
ret = ERR_OK; break;
@ -164,17 +161,17 @@ void AotCompilerImpl::ExecuteInParentProcess(const pid_t childPid, int32_t &ret)
}
} else if (WIFSIGNALED(status)) {
int signal_number = WTERMSIG(status);
HiviewDFX::HiLog::Warn(LABEL, "child process terminated by signal: %{public}d", signal_number);
LOG_SA(WARN) << "child process terminated by signal: " << signal_number;
ret = ERR_AOT_COMPILER_CALL_FAILED;
} else if (WIFSTOPPED(status)) {
int signal_number = WSTOPSIG(status);
HiviewDFX::HiLog::Warn(LABEL, "child process was stopped by signal: %{public}d", signal_number);
LOG_SA(WARN) << "child process was stopped by signal: " << signal_number;
ret = ERR_AOT_COMPILER_CALL_FAILED;
} else if (WIFCONTINUED(status)) {
HiviewDFX::HiLog::Warn(LABEL, "child process was resumed");
LOG_SA(WARN) << "child process was resumed";
ret = ERR_AOT_COMPILER_CALL_FAILED;
} else {
HiviewDFX::HiLog::Warn(LABEL, "unknown");
LOG_SA(WARN) << "unknown";
ret = ERR_AOT_COMPILER_CALL_FAILED;
}
{
@ -190,15 +187,15 @@ int32_t AotCompilerImpl::EcmascriptAotCompiler(const std::unordered_map<std::str
return ERR_AOT_COMPILER_PARAM_FAILED;
}
if (argsMap.empty() || (PrepareArgs(argsMap) != ERR_OK)) {
HiviewDFX::HiLog::Error(LABEL, "aot compiler arguments error");
LOG_SA(ERROR) << "aot compiler arguments error";
return ERR_AOT_COMPILER_PARAM_FAILED;
}
int32_t ret = ERR_OK;
std::lock_guard<std::mutex> lock(mutex_);
HiviewDFX::HiLog::Debug(LABEL, "begin to fork");
LOG_SA(DEBUG) << "begin to fork";
pid_t pid = fork();
if (pid == -1) {
HiviewDFX::HiLog::Error(LABEL, "fork process failed : %{public}s", strerror(errno));
LOG_SA(ERROR) << "fork process failed : " << strerror(errno);
return ERR_AOT_COMPILER_CALL_FAILED;
} else if (pid == 0) {
DropCapabilities(hapArgs.bundleUid, hapArgs.bundleGid);
@ -214,7 +211,7 @@ int32_t AotCompilerImpl::EcmascriptAotCompiler(const std::unordered_map<std::str
int32_t AotCompilerImpl::GetAOTVersion(std::string& sigData)
{
HiviewDFX::HiLog::Info(LABEL, "AotCompilerImpl::GetAOTVersion");
LOG_SA(INFO) << "AotCompilerImpl::GetAOTVersion";
sigData = panda::ecmascript::AOTFileVersion::GetAOTVersion();
return ERR_OK;
@ -222,7 +219,7 @@ int32_t AotCompilerImpl::GetAOTVersion(std::string& sigData)
int32_t AotCompilerImpl::NeedReCompile(const std::string& args, bool& sigData)
{
HiviewDFX::HiLog::Info(LABEL, "AotCompilerImpl::NeedReCompile");
LOG_SA(INFO) << "AotCompilerImpl::NeedReCompile";
sigData = panda::ecmascript::AOTFileVersion::CheckAOTVersion(args);
return ERR_OK;
}
@ -233,10 +230,10 @@ int32_t AotCompilerImpl::AOTLocalCodeSign(const std::string &fileName, const std
Security::CodeSign::ByteBuffer sig;
if (Security::CodeSign::LocalCodeSignKit::SignLocalCode(appSignature, fileName, sig)
!= CommonErrCode::CS_SUCCESS) {
HiviewDFX::HiLog::Error(LABEL, "failed to sign the aot file");
LOG_SA(ERROR) << "failed to sign the aot file";
return ERR_AOT_COMPILER_SIGNATURE_FAILED;
}
HiviewDFX::HiLog::Debug(LABEL, "aot file local sign success");
LOG_SA(DEBUG) << "aot file local sign success";
uint8_t *dataPtr = sig.GetBuffer();
for (uint32_t i = 0; i < sig.GetSize(); ++i) {
sigData.emplace_back(static_cast<int16_t>(dataPtr[i]));
@ -246,22 +243,22 @@ int32_t AotCompilerImpl::AOTLocalCodeSign(const std::string &fileName, const std
int32_t AotCompilerImpl::StopAotCompiler()
{
HiviewDFX::HiLog::Info(LABEL, "begin to stop AOT");
LOG_SA(INFO) << "begin to stop AOT";
std::lock_guard<std::mutex> lock(stateMutex_);
if (!state_.running) {
HiviewDFX::HiLog::Info(LABEL, "AOT not running, return directly");
LOG_SA(INFO) << "AOT not running, return directly";
return ERR_AOT_COMPILER_STOP_FAILED;
}
if (state_.childPid <= 0) {
HiviewDFX::HiLog::Error(LABEL, "invalid child pid");
LOG_SA(ERROR) << "invalid child pid";
return ERR_AOT_COMPILER_STOP_FAILED;
}
HiviewDFX::HiLog::Info(LABEL, "begin to kill child process : %{public}d", state_.childPid);
LOG_SA(INFO) << "begin to kill child process : " << state_.childPid;
auto result = kill(state_.childPid, SIGKILL);
if (result != 0) {
HiviewDFX::HiLog::Info(LABEL, "kill child process failed: %{public}d", result);
LOG_SA(INFO) << "kill child process failed: " << result;
} else {
HiviewDFX::HiLog::Info(LABEL, "kill child process success");
LOG_SA(INFO) << "kill child process success";
}
ResetState();
return ERR_OK;
@ -269,7 +266,7 @@ int32_t AotCompilerImpl::StopAotCompiler()
void AotCompilerImpl::HandlePowerDisconnected()
{
HiviewDFX::HiLog::Info(LABEL, "AotCompilerImpl::HandlePowerDisconnected");
LOG_SA(INFO) << "AotCompilerImpl::HandlePowerDisconnected";
PauseAotCompiler();
auto task = []() {
AotCompilerImpl::GetInstance().StopAotCompiler();
@ -281,13 +278,13 @@ void AotCompilerImpl::HandlePowerDisconnected()
void AotCompilerImpl::PauseAotCompiler()
{
HiviewDFX::HiLog::Info(LABEL, "AotCompilerImpl::PauseAotCompiler");
LOG_SA(INFO) << "AotCompilerImpl::PauseAotCompiler";
allowAotCompiler_ = false;
}
void AotCompilerImpl::AllowAotCompiler()
{
HiviewDFX::HiLog::Info(LABEL, "AotCompilerImpl::AllowAotCompiler");
LOG_SA(INFO) << "AotCompilerImpl::AllowAotCompiler";
allowAotCompiler_ = true;
}

View File

@ -15,39 +15,35 @@
#include "aot_compiler_load_callback.h"
#include "aot_compiler_client.h"
#include "hilog/log.h"
#include "ecmascript/log_wrapper.h"
#include "system_ability_definition.h"
namespace OHOS::ArkCompiler {
namespace {
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0xD001800, "aot_compiler_service"};
} // namespace
void AotCompilerLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId,
const sptr<IRemoteObject> &remoteObject)
{
if (systemAbilityId != AOT_COMPILER_SERVICE_ID) {
HiviewDFX::HiLog::Error(LABEL, "system ability id %{public}d mismatch", systemAbilityId);
LOG_SA(ERROR) << "system ability id " << systemAbilityId << " mismatch";
return;
}
if (remoteObject == nullptr) {
HiviewDFX::HiLog::Error(LABEL, "remoteObject is nullptr");
LOG_SA(ERROR) << "remoteObject is nullptr";
return;
}
HiviewDFX::HiLog::Debug(LABEL, "load system ability %{public}d succeed", systemAbilityId);
LOG_SA(DEBUG) << "load system ability " << systemAbilityId << " succeed";
AotCompilerClient::GetInstance().OnLoadSystemAbilitySuccess(remoteObject);
}
void AotCompilerLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId)
{
if (systemAbilityId != AOT_COMPILER_SERVICE_ID) {
HiviewDFX::HiLog::Error(LABEL, "system ability id %{public}d mismatch", systemAbilityId);
LOG_SA(ERROR) << "system ability id " << systemAbilityId << " mismatch";
return;
}
HiviewDFX::HiLog::Debug(LABEL, "load system ability %{public}d failed", systemAbilityId);
LOG_SA(DEBUG) << "load system ability " << systemAbilityId << " failed";
AotCompilerClient::GetInstance().OnLoadSystemAbilityFail();
}
} // namespace OHOS::ArkCompiler

View File

@ -16,7 +16,7 @@
#include "aot_compiler_service.h"
#include "aot_compiler_error_utils.h"
#include "aot_compiler_impl.h"
#include "hilog/log.h"
#include "ecmascript/log_wrapper.h"
#include "iservice_registry.h"
#include "ipc_skeleton.h"
#include "iremote_object.h"
@ -53,18 +53,18 @@ AotCompilerService::~AotCompilerService()
void AotCompilerService::OnStart()
{
HiviewDFX::HiLog::Info(LABEL, "aot compiler service is onStart");
LOG_SA(INFO) << "aot compiler service is onStart";
if (state_ == ServiceRunningState::STATE_RUNNING) {
HiviewDFX::HiLog::Info(LABEL, "aot compiler service has already started");
LOG_SA(INFO) << "aot compiler service has already started";
return;
}
if (!Init()) {
HiviewDFX::HiLog::Info(LABEL, "init aot compiler service failed");
LOG_SA(INFO) << "init aot compiler service failed";
return;
}
bool ret = Publish(this);
if (!ret) {
HiviewDFX::HiLog::Error(LABEL, "publish service failed");
LOG_SA(ERROR) << "publish service failed";
return;
}
state_ = ServiceRunningState::STATE_RUNNING;
@ -86,12 +86,12 @@ void AotCompilerService::DelayUnloadTask()
sptr<ISystemAbilityManager> samgr =
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgr == nullptr) {
HiviewDFX::HiLog::Error(LABEL, "fail to get system ability manager");
LOG_SA(ERROR) << "fail to get system ability manager";
return;
}
int32_t ret = samgr->UnloadSystemAbility(AOT_COMPILER_SERVICE_ID);
if (ret != ERR_OK) {
HiviewDFX::HiLog::Error(LABEL, "remove system ability failed");
LOG_SA(ERROR) << "remove system ability failed";
return;
}
};
@ -101,7 +101,7 @@ void AotCompilerService::DelayUnloadTask()
void AotCompilerService::OnStop()
{
HiviewDFX::HiLog::Info(LABEL, "aot compiler service has been onStop");
LOG_SA(INFO) << "aot compiler service has been onStop";
state_ = ServiceRunningState::STATE_NOT_START;
UnRegisterPowerDisconnectedListener();
}
@ -109,37 +109,37 @@ void AotCompilerService::OnStop()
int32_t AotCompilerService::AotCompiler(const std::unordered_map<std::string, std::string> &argsMap,
std::vector<int16_t> &sigData)
{
HiviewDFX::HiLog::Debug(LABEL, "begin to call aot compiler");
LOG_SA(DEBUG) << "begin to call aot compiler";
unLoadHandler_->RemoveTask(TASK_ID);
int32_t ret = AotCompilerImpl::GetInstance().EcmascriptAotCompiler(argsMap, sigData);
HiviewDFX::HiLog::Debug(LABEL, "finish aot compiler");
LOG_SA(DEBUG) << "finish aot compiler";
DelayUnloadTask();
return ret;
}
int32_t AotCompilerService::GetAOTVersion(std::string& sigData)
{
HiviewDFX::HiLog::Debug(LABEL, "begin to get AOT version");
LOG_SA(DEBUG) << "begin to get AOT version";
unLoadHandler_->RemoveTask(TASK_ID);
int32_t ret = AotCompilerImpl::GetInstance().GetAOTVersion(sigData);
HiviewDFX::HiLog::Debug(LABEL, "finish get AOT Version");
LOG_SA(DEBUG) << "finish get AOT Version";
DelayUnloadTask();
return ret;
}
int32_t AotCompilerService::NeedReCompile(const std::string& args, bool& sigData)
{
HiviewDFX::HiLog::Debug(LABEL, "begin to check need to re-compile version");
LOG_SA(DEBUG) << "begin to check need to re-compile version";
unLoadHandler_->RemoveTask(TASK_ID);
int32_t ret = AotCompilerImpl::GetInstance().NeedReCompile(args, sigData);
HiviewDFX::HiLog::Debug(LABEL, "finish check need re-compile");
LOG_SA(DEBUG) << "finish check need re-compile";
DelayUnloadTask();
return ret;
}
int32_t AotCompilerService::StopAotCompiler()
{
HiviewDFX::HiLog::Debug(LABEL, "stop aot compiler service");
LOG_SA(DEBUG) << "stop aot compiler service";
unLoadHandler_->RemoveTask(TASK_ID);
int32_t ret = AotCompilerImpl::GetInstance().StopAotCompiler();
DelayUnloadTask();
@ -148,31 +148,31 @@ int32_t AotCompilerService::StopAotCompiler()
void AotCompilerService::RegisterPowerDisconnectedListener()
{
HiviewDFX::HiLog::Info(LABEL, "AotCompilerService::RegisterPowerDisconnectedListener");
LOG_SA(INFO) << "AotCompilerService::RegisterPowerDisconnectedListener";
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_POWER_DISCONNECTED);
EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills);
powerDisconnectedListener_ = std::make_shared<PowerDisconnectedListener>(subscribeInfo);
if (!EventFwk::CommonEventManager::SubscribeCommonEvent(powerDisconnectedListener_)) {
HiviewDFX::HiLog::Info(LABEL, "AotCompilerService::RegisterPowerDisconnectedListener failed");
LOG_SA(INFO) << "AotCompilerService::RegisterPowerDisconnectedListener failed";
powerDisconnectedListener_ = nullptr;
} else {
HiviewDFX::HiLog::Info(LABEL, "AotCompilerService::RegisterPowerDisconnectedListener success");
LOG_SA(INFO) << "AotCompilerService::RegisterPowerDisconnectedListener success";
isPowerEventSubscribered_ = true;
}
}
void AotCompilerService::UnRegisterPowerDisconnectedListener()
{
HiviewDFX::HiLog::Info(LABEL, "AotCompilerService::UnRegisterPowerDisconnectedListener");
LOG_SA(INFO) << "AotCompilerService::UnRegisterPowerDisconnectedListener";
if (!isPowerEventSubscribered_) {
return;
}
if (!EventFwk::CommonEventManager::UnSubscribeCommonEvent(powerDisconnectedListener_)) {
HiviewDFX::HiLog::Info(LABEL, "AotCompilerService::UnRegisterPowerDisconnectedListener failed");
LOG_SA(INFO) << "AotCompilerService::UnRegisterPowerDisconnectedListener failed";
}
powerDisconnectedListener_ = nullptr;
isPowerEventSubscribered_ = false;
HiviewDFX::HiLog::Info(LABEL, "AotCompilerService::UnRegisterPowerDisconnectedListener done");
LOG_SA(INFO) << "AotCompilerService::UnRegisterPowerDisconnectedListener done";
}
} // namespace OHOS::ArkCompiler

View File

@ -14,18 +14,10 @@
*/
#include "power_disconnected_listener.h"
#include "aot_compiler_impl.h"
#include "ecmascript/log_wrapper.h"
#include "hilog/log.h"
namespace OHOS {
namespace ArkCompiler {
namespace {
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0xD001800, "aot_compiler_service"};
} // namespace
namespace OHOS::ArkCompiler {
PowerDisconnectedListener::PowerDisconnectedListener(const EventFwk::CommonEventSubscribeInfo &subscribeInfo)
: EventFwk::CommonEventSubscriber(subscribeInfo)
{
@ -33,9 +25,7 @@ PowerDisconnectedListener::PowerDisconnectedListener(const EventFwk::CommonEvent
void PowerDisconnectedListener::OnReceiveEvent(const EventFwk::CommonEventData &data)
{
HiviewDFX::HiLog::Info(LABEL, "PowerDisconnectedListener::OnReceiveEvent");
LOG_SA(INFO) << "PowerDisconnectedListener::OnReceiveEvent";
AotCompilerImpl::GetInstance().HandlePowerDisconnected();
}
} // namespace ArkCompiler
} // namespace OHOS
} // namespace OHOS::ArkCompiler

View File

@ -187,6 +187,10 @@ void Log::SetLogComponentFromString(const std::vector<std::string>& components)
components_ |= Component::TRACE;
continue;
}
if (component == "sa") {
components_ |= Component::SA;
continue;
}
}
}

View File

@ -59,6 +59,7 @@ enum Component {
TRACE = 1ULL << 6ULL,
JIT = 1UL << 7ULL,
BASELINEJIT = 1UL << 8ULL,
SA = 1ULL << 9ULL,
NO_TAG = 0xFFFFFFFFULL >> 1ULL,
ALL = 0xFFFFFFFFULL,
};
@ -80,7 +81,13 @@ public:
static void Initialize(const JSRuntimeOptions &options);
static inline bool LogIsLoggable(Level level, Component component)
{
return (level >= level_) && ((components_ & component) != 0ULL);
switch (component)
{
case Component::SA:
return ((components_ & component) != 0ULL);
default:
return (level >= level_) && ((components_ & component) != 0ULL);
}
}
static inline std::string GetComponentStr(Component component)
{
@ -106,6 +113,8 @@ public:
return "[jit] ";
case Component::BASELINEJIT:
return "[baselinejit] ";
case Component::SA:
return "[sa] ";
case Component::ALL:
return "[default] ";
default:

View File

@ -30,6 +30,7 @@
#define LOG_TRACE(level) ARK_LOG(level, Component::TRACE)
#define LOG_JIT(level) ARK_LOG(level, Component::JIT)
#define LOG_BASELINEJIT(level) ARK_LOG(level, Component::BASELINEJIT)
#define LOG_SA(level) ARK_LOG(level, Component::SA)
#define LOG_ECMA_IF(cond, level) (cond) && ARK_LOG(level, Component::ALL)
// When the AOT compiler is integrated into the IDE, tag the output error messages for developers
#define LOG_HOST_TOOL_ERROR ARK_LOG(ERROR, Component::NO_TAG) << "[HostTool] "