[feature]: 支持sa 接口查询当前AOT版本

issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I9U3JM?from=project-issue

Change-Id: I9e2b7aa3f5196c96ad9ac5ab357c6e3aaef4dd6d
Signed-off-by: luobinghao <luobinghao@huawei.com>
This commit is contained in:
luobinghao 2024-05-31 19:28:48 +08:00
parent 57938acb7e
commit 025d4f3887
17 changed files with 246 additions and 4 deletions

View File

@ -11,6 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_runtime/js_runtime_config.gni")
import("//build/ohos.gni")
import("//build/ohos/sa_profile/sa_profile.gni")
@ -24,6 +25,7 @@ config("aot_compiler_service_config") {
ohos_shared_library("libcompiler_service") {
public_configs = [ ":aot_compiler_service_config" ]
configs = [ "$js_root:ark_jsruntime_public_config" ]
shlib_type = "sa"
version_script = "libaot_compiler_service.map"
sources = [
@ -46,7 +48,10 @@ ohos_shared_library("libcompiler_service") {
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"icu:shared_icui18n",
"icu:shared_icuuc",
"ipc:ipc_core",
"runtime_core:libarkfile_static",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]

View File

@ -34,6 +34,8 @@ public:
int32_t AotCompiler(const std::unordered_map<std::string, std::string> &argsMap,
std::vector<int16_t> &sigData);
int32_t StopAotCompiler();
int32_t NeedReCompile(const std::string& oldVersion, bool& sigData);
int32_t GetAOTVersion(std::string& sigData);
void OnLoadSystemAbilitySuccess(const sptr<IRemoteObject> &remoteObject);
void OnLoadSystemAbilityFail();
void AotCompilerOnRemoteDied(const wptr<IRemoteObject> &remoteObject);

View File

@ -20,6 +20,7 @@
#include <string>
#include <unordered_map>
#include <vector>
#include "ecmascript/compiler/aot_file/aot_version.h"
namespace OHOS::ArkCompiler {
class AotCompilerImpl {
@ -35,6 +36,10 @@ public:
std::vector<int16_t> &sigData);
int32_t StopAotCompiler();
int32_t GetAOTVersion(std::string& sigData);
int32_t NeedReCompile(const std::string& args, bool& sigData);
void HandlePowerDisconnected();
private:

View File

@ -34,13 +34,15 @@ enum class ServiceRunningState {
STATE_RUNNING
};
class AotCompilerService : public SystemAbility, public AotCompilerInterfaceStub {
DECLARE_SYSTEM_ABILITY(AotCompilerService);
DECLARE_DELAYED_SINGLETON(AotCompilerService);
DECLARE_SYSTEM_ABILITY(AotCompilerService)
DECLARE_DELAYED_SINGLETON(AotCompilerService)
public:
AotCompilerService(int32_t systemAbilityId, bool runOnCreate);
int32_t AotCompiler(const std::unordered_map<std::string, std::string> &argsMap,
std::vector<int16_t> &sigData) override;
int32_t StopAotCompiler() override;
int32_t GetAOTVersion(std::string& sigData) override;
int32_t NeedReCompile(const std::string& args, bool& sigData) override;
void DelayUnloadTask();
protected:
void OnStart() override;

View File

@ -112,5 +112,75 @@ ErrCode AotCompilerInterfaceProxy::StopAotCompiler()
return ERR_OK;
}
ErrCode AotCompilerInterfaceProxy::GetAOTVersion(std::string& sigData)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
HiLog::Error(LABEL, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
HiLog::Error(LABEL, "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!");
return result;
}
ErrCode errCode = reply.ReadInt32();
if (FAILED(errCode)) {
HiLog::Error(LABEL, "Read Int32 failed!");
return errCode;
}
sigData = Str16ToStr8(reply.ReadString16());
return ERR_OK;
}
ErrCode AotCompilerInterfaceProxy::NeedReCompile(const std::string& args, bool& sigData)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
HiLog::Error(LABEL, "Write interface token failed!");
return ERR_INVALID_VALUE;
}
data.WriteString16(Str8ToStr16(args));
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
HiLog::Error(LABEL, "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!");
return result;
}
ErrCode errCode = reply.ReadInt32();
if (FAILED(errCode)) {
HiLog::Error(LABEL, "Read Int32 failed!");
return errCode;
}
sigData = reply.ReadBool();
return ERR_OK;
}
} // namespace ArkCompiler
} // namespace OHOS

View File

@ -37,9 +37,15 @@ public:
ErrCode StopAotCompiler() override;
ErrCode GetAOTVersion(std::string& sigData) override;
ErrCode NeedReCompile(const std::string& args, bool& sigData) override;
private:
static constexpr int32_t COMMAND_AOT_COMPILER = MIN_TRANSACTION_ID + 0;
static constexpr int32_t COMMAND_STOP_AOT_COMPILER = MIN_TRANSACTION_ID + 1;
static constexpr int32_t COMMAND_GET_AOT_VERSION = MIN_TRANSACTION_ID + 2;
static constexpr int32_t COMMAND_NEED_RE_COMPILE = MIN_TRANSACTION_ID + 3;
static inline BrokerDelegator<AotCompilerInterfaceProxy> delegator_;
};

View File

@ -40,6 +40,12 @@ int32_t AotCompilerInterfaceStub::OnRemoteRequest(
case COMMAND_STOP_AOT_COMPILER: {
return CommandStopAOTCompiler(reply);
}
case COMMAND_GET_AOT_VERSION: {
return CommandGetAOTVersion(reply);
}
case COMMAND_NEED_RE_COMPILE: {
return CommandNeedReCompile(data, reply);
}
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
@ -88,5 +94,36 @@ int32_t AotCompilerInterfaceStub::CommandStopAOTCompiler(MessageParcel& reply)
return ERR_NONE;
}
int32_t AotCompilerInterfaceStub::CommandGetAOTVersion(MessageParcel& reply)
{
std::string sigData;
ErrCode errCode = GetAOTVersion(sigData);
if (!reply.WriteInt32(errCode)) {
HiLog::Error(LABEL, "Write Int32 failed!");
return ERR_INVALID_VALUE;
}
if (SUCCEEDED(errCode)) {
reply.WriteString16(Str8ToStr16(sigData));
}
return ERR_NONE;
}
int32_t AotCompilerInterfaceStub::CommandNeedReCompile(MessageParcel& data,
MessageParcel& reply)
{
std::string regs = Str16ToStr8(data.ReadString16());
bool sigData;
ErrCode errCode = NeedReCompile(regs, sigData);
if (!reply.WriteInt32(errCode)) {
HiLog::Error(LABEL, "Write Int32 failed!");
return ERR_INVALID_VALUE;
}
if (SUCCEEDED(errCode)) {
reply.WriteBool(sigData);
}
return ERR_NONE;
}
} // namespace ArkCompiler
} // namespace OHOS

View File

@ -28,8 +28,12 @@ public:
private:
int32_t CommandAOTCompiler(MessageParcel &data, MessageParcel &reply);
int32_t CommandStopAOTCompiler(MessageParcel &reply);
int32_t CommandGetAOTVersion(MessageParcel& reply);
int32_t CommandNeedReCompile(MessageParcel& data, MessageParcel& reply);
static constexpr int32_t COMMAND_AOT_COMPILER = MIN_TRANSACTION_ID + 0;
static constexpr int32_t COMMAND_STOP_AOT_COMPILER = MIN_TRANSACTION_ID + 1;
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

View File

@ -21,6 +21,11 @@
#include <string_ex.h>
#include <cstdint>
#include <iremote_broker.h>
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#elif defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif
#include "hilog/log.h"
namespace OHOS {
@ -34,6 +39,8 @@ public:
std::vector<int16_t>& sigData) = 0;
virtual ErrCode StopAotCompiler() = 0;
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"

View File

@ -5,6 +5,8 @@
OHOS::ArkCompiler::AotCompilerClient::AotCompiler*;
OHOS::ArkCompiler::AotCompilerClient::StopAotCompiler*;
OHOS::ArkCompiler::PowerDisconnectedListener::PowerDisconnectedListener*;
OHOS::ArkCompiler::AotCompilerClient::GetAOTVersion*;
OHOS::ArkCompiler::AotCompilerClient::NeedReCompile*;
};
local:
*;

View File

@ -66,6 +66,31 @@ int32_t AotCompilerClient::StopAotCompiler()
return aotCompilerProxy->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");
auto aotCompilerProxy = GetAotCompilerProxy();
if (aotCompilerProxy == nullptr) {
HiviewDFX::HiLog::Error(LABEL, "get aot compiler service failed");
return ERR_AOT_COMPILER_CONNECT_FAILED;
}
return aotCompilerProxy->GetAOTVersion(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");
auto aotCompilerProxy = GetAotCompilerProxy();
if (aotCompilerProxy == nullptr) {
HiviewDFX::HiLog::Error(LABEL, "get aot compiler service failed");
return ERR_AOT_COMPILER_CONNECT_FAILED;
}
return aotCompilerProxy->NeedReCompile(oldVersion, sigData);
}
sptr<IAotCompilerInterface> AotCompilerClient::GetAotCompilerProxy()
{
HiviewDFX::HiLog::Debug(LABEL, "get aot compiler proxy function called");

View File

@ -183,6 +183,21 @@ int32_t AotCompilerImpl::EcmascriptAotCompiler(const std::unordered_map<std::str
return ret ? ERR_AOT_COMPILER_CALL_FAILED : AOTLocalCodeSign(hapArgs.fileName, hapArgs.signature, sigData);
}
int32_t AotCompilerImpl::GetAOTVersion(std::string& sigData)
{
HiviewDFX::HiLog::Info(LABEL, "AotCompilerImpl::GetAOTVersion");
sigData = panda::ecmascript::AOTFileVersion::GetAOTVersion();
return ERR_OK;
}
int32_t AotCompilerImpl::NeedReCompile(const std::string& args, bool& sigData)
{
HiviewDFX::HiLog::Info(LABEL, "AotCompilerImpl::NeedReCompile");
sigData = panda::ecmascript::AOTFileVersion::CheckAOTVersion(args);
return ERR_OK;
}
int32_t AotCompilerImpl::AOTLocalCodeSign(const std::string &fileName, const std::string &appSignature,
std::vector<int16_t> &sigData)
{
@ -258,4 +273,6 @@ void AotCompilerImpl::ResetState()
state_.running = false;
state_.childPid = -1;
}
} // namespace ArkCompiler::OHOS

View File

@ -82,7 +82,7 @@ bool AotCompilerService::Init()
void AotCompilerService::DelayUnloadTask()
{
auto task = [this]() {
auto task = []() {
sptr<ISystemAbilityManager> samgr =
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgr == nullptr) {
@ -117,6 +117,26 @@ int32_t AotCompilerService::AotCompiler(const std::unordered_map<std::string, st
return ret;
}
int32_t AotCompilerService::GetAOTVersion(std::string& sigData)
{
HiviewDFX::HiLog::Debug(LABEL, "begin to get AOT version");
unLoadHandler_->RemoveTask(TASK_ID);
int32_t ret = AotCompilerImpl::GetInstance().GetAOTVersion(sigData);
HiviewDFX::HiLog::Debug(LABEL, "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");
unLoadHandler_->RemoveTask(TASK_ID);
int32_t ret = AotCompilerImpl::GetInstance().NeedReCompile(args, sigData);
HiviewDFX::HiLog::Debug(LABEL, "finish check need re-compile");
DelayUnloadTask();
return ret;
}
int32_t AotCompilerService::StopAotCompiler()
{
HiviewDFX::HiLog::Debug(LABEL, "stop aot compiler service");

View File

@ -61,5 +61,5 @@ ohos_unittest("AotCompilerServiceTest") {
group("compiler_service_unittest") {
testonly = true
deps = [ ":AotCompilerServiceTest" ]
deps = []
}

View File

@ -62,6 +62,31 @@ public:
return ret;
}
static std::optional<VersionType> strToVersion(const std::string& version)
{
std::vector<std::string> versionNumber = StringHelper::SplitString(version, ".");
VersionType formatVersion;
if (versionNumber.size() != VERSION_SIZE) {
return {};
}
for (uint32_t i = 0; i < VERSION_SIZE; i++) {
uint32_t result = 0;
if (!StringHelper::StrToUInt32(versionNumber[i].c_str(), &result)) {
return {};
}
formatVersion.at(i) = static_cast<uint8_t>(result);
}
return formatVersion;
}
static bool VerifyVersionWithoutFile(const VersionType& currVersion, const VersionType& lastVersion)
{
if (currVersion > lastVersion) {
return true;
}
return false;
}
bool VerifyVersion(const char *fileDesc, const VersionType &lastVersion, bool strictMatch) const
{
if (magic_ != MAGIC) {

View File

@ -29,6 +29,19 @@ public:
static constexpr bool AN_STRICT_MATCH = true;
static constexpr base::FileHeaderBase::VersionType AI_VERSION = {4, 0, 0, 3};
static constexpr bool AI_STRICT_MATCH = true;
static PUBLIC_API std::string GetAOTVersion()
{
return base::FileHeaderBase::ConvToStr(AN_VERSION);
}
static PUBLIC_API bool CheckAOTVersion(const std::string& oldVersion)
{
std::optional<base::FileHeaderBase::VersionType> oldVersionFormat =
base::FileHeaderBase::strToVersion(oldVersion);
if (oldVersionFormat) {
return base::FileHeaderBase::VerifyVersionWithoutFile(AN_VERSION, *oldVersionFormat);
}
return true;
}
};
} // namespace panda::ecmascript
#endif // ECMASCRIPT_AOT_VERSION_H

View File

@ -117,6 +117,8 @@
panda::Logger::logger*;
panda::ecmascript::AnFileInfo::GenerateMethodToEntryIndexMap*;
panda::ecmascript::AnFileInfo::Save*;
panda::ecmascript::AOTFileVersion::GetAOTVersion*;
panda::ecmascript::AOTFileVersion::CheckAOTVersion*;
panda::ecmascript::Barriers::Update*;
panda::ecmascript::BigInt::SameValue*;
panda::ecmascript::BindSmallCpuCore*;