!15167 App warm startup support SmartGC

Merge pull request !15167 from QiangShaowei/warmGC-ability_runtime
This commit is contained in:
openharmony_ci
2025-06-29 07:51:03 +00:00
committed by Gitee
15 changed files with 77 additions and 11 deletions
+6 -1
View File
@@ -1712,6 +1712,11 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
static_cast<int32_t>(hapModuleInfo.aotCompileStatus);
}
}
options.enableWarmStartupSmartGC =
(appLaunchData.GetAppPreloadMode() == AppExecFwk::PreloadMode::PRE_MAKE ||
appLaunchData.GetAppPreloadMode() == AppExecFwk::PreloadMode::PRELOAD_MODULE);
TAG_LOGI(AAFwkTag::APPKIT, "SmartGC: process is start. enable warm startup SmartGC: %{public}d",
static_cast<int32_t>(options.enableWarmStartupSmartGC));
auto runtime = AbilityRuntime::Runtime::Create(options);
if (!runtime) {
TAG_LOGE(AAFwkTag::APPKIT, "null runtime");
@@ -1939,7 +1944,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
HandleNWebPreload();
}
#endif
if (appLaunchData.IsNeedPreloadModule()) {
if (appLaunchData.GetAppPreloadMode() == AppExecFwk::PreloadMode::PRELOAD_MODULE) {
PreloadModule(entryHapModuleInfo, application_->GetRuntime());
}
}
+2
View File
@@ -637,6 +637,8 @@ void JsRuntime::PostPreload(const Options& options)
TAG_LOGD(AAFwkTag::JSRUNTIME, "ASMM JIT Verify PostFork, jitEnabled: %{public}d", options.jitEnabled);
postOption.SetEnableJIT(options.jitEnabled);
postOption.SetAOTCompileStatusMap(options.aotCompileStatusMap);
TAG_LOGD(AAFwkTag::JSRUNTIME, "SmartGC: set options enableWarmStartupSmartGC to RuntimeOption");
postOption.SetEnableWarmStartupSmartGC(options.enableWarmStartupSmartGC);
{
HITRACE_METER_NAME(HITRACE_TAG_APP, "panda::JSNApi::PostFork");
panda::JSNApi::PostFork(vm, postOption);
@@ -309,6 +309,20 @@ public:
*/
bool IsNeedPreloadModule() const;
/**
* @brief Setting preload mode.
*
* @param preloadMode PreloadMode enum
*/
void SetAppPreloadMode(PreloadMode preloadMode);
/**
* @brief Obtains preload mode.
*
* @return Returns preloadMode enum
*/
PreloadMode GetAppPreloadMode() const;
/**
* @brief Setting if allow nweb preload.
*
@@ -342,6 +356,7 @@ private:
bool isMultiThread_ = false;
bool isErrorInfoEnhance_ = false;
bool isNeedPreloadModule_ = false;
PreloadMode appPreloadMode_ = PreloadMode::PRELOAD_NONE;
bool isAllowedNWebPreload_ = false;
int32_t recordId_ = 0;
int32_t uId_ = 0;
@@ -79,6 +79,7 @@ struct RunningProcessInfo : public Parcelable {
static RunningProcessInfo *Unmarshalling(Parcel &parcel);
ProcessType processType_ = ProcessType::NORMAL;
ExtensionAbilityType extensionType_ = ExtensionAbilityType::UNSPECIFIED;
bool isCached = false;
};
} // namespace AppExecFwk
} // namespace OHOS
@@ -117,7 +117,12 @@ bool AppLaunchData::MarshallingExtend(Parcel &parcel) const
}
if (!parcel.WriteBool(isNeedPreloadModule_)) {
TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write instance key.");
TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write is need preload module.");
return false;
}
if (!parcel.WriteInt32(static_cast<int32_t>(appPreloadMode_))) {
TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write app preload mode");
return false;
}
@@ -190,6 +195,7 @@ bool AppLaunchData::ReadFromParcel(Parcel &parcel)
isErrorInfoEnhance_ = parcel.ReadBool();
instanceKey_ = parcel.ReadString();
isNeedPreloadModule_ = parcel.ReadBool();
appPreloadMode_ = static_cast<PreloadMode>(parcel.ReadInt32());
isAllowedNWebPreload_ = parcel.ReadBool();
preloadModuleName_ = parcel.ReadString();
isDebugFromLocal_ = parcel.ReadBool();
@@ -311,6 +317,16 @@ bool AppLaunchData::IsNeedPreloadModule() const
return isNeedPreloadModule_;
}
void AppLaunchData::SetAppPreloadMode(PreloadMode preloadMode)
{
appPreloadMode_ = preloadMode;
}
PreloadMode AppLaunchData::GetAppPreloadMode() const
{
return appPreloadMode_;
}
void AppLaunchData::SetNWebPreload(const bool isAllowedNWebPreload)
{
isAllowedNWebPreload_ = isAllowedNWebPreload;
@@ -71,6 +71,7 @@ bool RunningProcessInfo::ReadFromParcel(Parcel &parcel)
int32_t pssData;
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pssData);
pssValue = static_cast<int32_t>(pssData);
isCached = parcel.ReadBool();
return true;
}
@@ -111,6 +112,7 @@ bool RunningProcessInfo::Marshalling(Parcel &parcel) const
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(appMode));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(rssValue));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(pssValue));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isCached);
return true;
}
} // namespace AppExecFwk
@@ -75,6 +75,7 @@ public:
std::map<std::string, std::string> packageNameList;
std::map<std::string, int32_t> aotCompileStatusMap;
uint32_t versionCode = 0;
bool enableWarmStartupSmartGC = false;
};
struct DebugOption {
@@ -3718,7 +3718,7 @@ int32_t AbilityConnectManager::ReportAbilityStartInfoToRSS(const AppExecFwk::Abi
}
}
TAG_LOGI(AAFwkTag::SERVICE_EXT, "ReportAbilityStartInfoToRSS, abilityName:%{public}s", abilityInfo.name.c_str());
ResSchedUtil::GetInstance().ReportAbilityStartInfoToRSS(abilityInfo, pid, isColdStart, -1); // -1代表与预加载无关
ResSchedUtil::GetInstance().ReportAbilityStartInfoToRSS(abilityInfo, pid, isColdStart, false);
return ERR_OK;
}
@@ -2944,19 +2944,25 @@ void AbilityManagerService::ReportAbilityStartInfoToRSS(const AppExecFwk::Abilit
}
bool isColdStart = true;
int32_t pid = 0;
int32_t warmStartType = -1;
bool supportWarmSmartGC = false;
for (auto const &info : runningProcessInfos) {
if (info.uid_ == abilityInfo.applicationInfo.uid &&
info.processType_ == AppExecFwk::ProcessType::NORMAL &&
std::find(info.bundleNames.begin(), info.bundleNames.end(),
std::find(info.bundleNames.begin(), info.bundleNames.end(),
abilityInfo.applicationInfo.bundleName) != info.bundleNames.end()) {
isColdStart = info.isExiting ? true : info.preloadMode_ == AppExecFwk::PreloadMode::PRESS_DOWN;
pid = info.isExiting ? 0 : info.pid_;
warmStartType = static_cast<int32_t>(info.preloadMode_);
AppExecFwk::PreloadMode mode = info.preloadMode_;
bool isSuggestCache = info.isCached;
bool supportWarmSmartGC = (isSuggestCache ||
mode == AppExecFwk::PreloadMode::PRE_MAKE ||
mode == AppExecFwk::PreloadMode::PRELOAD_MODULE);
TAG_LOGI(AAFwkTag::ABILITYMGR, "SmartGC: Process %{public}d report to RSS, start type: %{public}d, isCached: %{public}d, supportWarmGC: %{public}d",
pid, static_cast<int32_t>(mode), static_cast<int32_t>(isSuggestCache), static_cast<int32_t>(supportWarmSmartGC));
break;
}
}
ResSchedUtil::GetInstance().ReportAbilityStartInfoToRSS(abilityInfo, pid, isColdStart, warmStartType);
ResSchedUtil::GetInstance().ReportAbilityStartInfoToRSS(abilityInfo, pid, isColdStart, supportWarmSmartGC);
}
}
@@ -2717,6 +2717,7 @@ void AppMgrServiceInner::GetRunningProcess(const std::shared_ptr<AppRunningRecor
info.isDebugApp = appRecord->IsDebug();
info.isExiting = appRecord->IsTerminating() || appRecord->IsKilling()
|| appRecord->GetRestartAppFlag() || appRecord->IsUserRequestCleaning();
info.isCached = DelayedSingleton<CacheProcessManager>::GetInstance()->IsCachedProcess(appRecord);
if (appRecord->GetUserTestInfo() != nullptr && system::GetBoolParameter(DEVELOPER_MODE_STATE, false)) {
info.isTestMode = true;
}
@@ -355,6 +355,7 @@ void AppRunningRecord::LaunchApplication(const Configuration &config)
launchData.SetNativeStart(isNativeStart_);
launchData.SetAppRunningUniqueId(std::to_string(startTimeMillis_));
launchData.SetIsNeedPreloadModule(isNeedPreloadModule_);
launchData.SetAppPreloadMode(preloadMode_);
launchData.SetNWebPreload(isAllowedNWebPreload_);
launchData.SetPreloadModuleName(preloadModuleName_);
launchData.SetDebugFromLocal(isDebugFromLocal_);
+1 -1
View File
@@ -49,7 +49,7 @@ class ResSchedUtil final {
public:
static ResSchedUtil &GetInstance();
void ReportAbilityStartInfoToRSS(const AbilityInfo &abilityInfo, int32_t pid, bool isColdStart,
int32_t warmStartType);
bool supportWarmSmartGC);
void ReportPreloadApplicationToRSS(const std::shared_ptr<AbilityInfo>& abilityInfo, int32_t preloadMode);
void ReportAbilityAssociatedStartInfoToRSS(
const AbilityInfo &abilityInfo, int64_t resSchedType, int32_t callerUid, int32_t callerPid);
+2 -2
View File
@@ -63,7 +63,7 @@ void ResSchedUtil::ReportSubHealtyPerfInfoToRSS()
}
void ResSchedUtil::ReportAbilityStartInfoToRSS(const AbilityInfo &abilityInfo, int32_t pid, bool isColdStart,
int32_t warmStartType)
bool supportWarmSmartGC)
{
#ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
uint32_t resType = ResourceSchedule::ResType::RES_TYPE_APP_ABILITY_START;
@@ -73,7 +73,7 @@ void ResSchedUtil::ReportAbilityStartInfoToRSS(const AbilityInfo &abilityInfo, i
{ "bundleName", abilityInfo.applicationInfo.bundleName },
{ "abilityName", abilityInfo.name },
{ "pid", std::to_string(pid) },
{ "warmStartType", std::to_string(warmStartType) }
{ "supportWarmSmartGC", supportWarmSmartGC ? "1": "0" }
};
TAG_LOGD(AAFwkTag::DEFAULT, "call");
ResourceSchedule::ResSchedClient::GetInstance().ReportData(resType, isColdStart ? 1 : 0, eventParams);
@@ -147,5 +147,21 @@ HWTEST_F(AppLaunchDataTest, ReadFromParcel_0100, TestSize.Level1)
EXPECT_EQ(launchData_->appIndex_, appIndex);
EXPECT_EQ(launchData_->debugApp_, isDebug);
}
/**
* @tc.name: GetAppPreloadMode_0100
* @tc.desc: AppLaunchData SetAppPreloadMode, verify if AppLaunchData startup successfully.
* @tc.type: FUNC
*/
HWTEST_F(AppLaunchDataTest, GetAppPreloadMode_0100, TestSize.Level1)
{
EXPECT_NE(launchData_, nullptr);
PreloadMode premakeMode = PreloadMode::PRE_MAKE;
launchData_->SetAppPreloadMode(premakeMode);
EXPECT_EQ(premakeMode, launchData_->GetAppPreloadMode());
launchData_->SetAppPreloadMode(PreloadMode::PRELOAD_MODULE);
EXPECT_NE(premakeMode, launchData_->GetAppPreloadMode());
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -58,7 +58,7 @@ HWTEST_F(ResSchedUtilTest, ResSchedUtilTest_0100, TestSize.Level2)
TAG_LOGI(AAFwkTag::TEST, "ResSchedUtilTest_0100 called.");
AbilityInfo abilityInfo;
int64_t resSchedType = -1;
AAFwk::ResSchedUtil::GetInstance().ReportAbilityStartInfoToRSS(abilityInfo, -1, false, -1);
AAFwk::ResSchedUtil::GetInstance().ReportAbilityStartInfoToRSS(abilityInfo, -1, false, false);
AAFwk::ResSchedUtil::GetInstance().ReportAbilityAssociatedStartInfoToRSS(abilityInfo, resSchedType, 0, 0);
int64_t ret = AAFwk::ResSchedUtil::GetInstance().convertType(resSchedType);
EXPECT_EQ(resSchedType, ret);