diff options
author | 2023-01-18 20:20:27 +0000 | |
---|---|---|
committer | 2023-01-18 20:20:27 +0000 | |
commit | e7a8a48ffe393cd99b7ddee34dc41b65da8866ac (patch) | |
tree | 2952f1413b16a5c5bf04a9e7372ecc60291f8b0f | |
parent | 5e04e6e0b706351bac966563844454d7131b7802 (diff) | |
parent | acb6adddd487eec9c34c699d8234b6ff7dd0049d (diff) |
Merge changes Ia612ce7f,Id49c3811
* changes:
Use ART Service for package install compilation if enabled.
Call into ART Service for profile snapshotting when it is enabled.
-rw-r--r-- | services/core/java/com/android/server/pm/InstallPackageHelper.java | 29 | ||||
-rw-r--r-- | services/core/java/com/android/server/pm/dex/ArtManagerService.java | 119 |
2 files changed, 105 insertions, 43 deletions
diff --git a/services/core/java/com/android/server/pm/InstallPackageHelper.java b/services/core/java/com/android/server/pm/InstallPackageHelper.java index a16aa47abf56..db3aae555854 100644 --- a/services/core/java/com/android/server/pm/InstallPackageHelper.java +++ b/services/core/java/com/android/server/pm/InstallPackageHelper.java @@ -158,6 +158,8 @@ import com.android.internal.util.ArrayUtils; import com.android.internal.util.CollectionUtils; import com.android.internal.util.FrameworkStatsLog; import com.android.server.EventLogTags; +import com.android.server.LocalManagerRegistry; +import com.android.server.art.model.DexoptParams; import com.android.server.pm.Installer.LegacyDexoptDisabledException; import com.android.server.pm.dex.ArtManagerService; import com.android.server.pm.dex.DexManager; @@ -2385,6 +2387,7 @@ final class InstallPackageHelper { || installRequest.getInstallReason() == INSTALL_REASON_DEVICE_SETUP; final int dexoptFlags = DexoptOptions.DEXOPT_BOOT_COMPLETE + | DexoptOptions.DEXOPT_CHECK_FOR_PROFILES_UPDATES | DexoptOptions.DEXOPT_INSTALL_WITH_DEX_METADATA_FILE | (isBackupOrRestore ? DexoptOptions.DEXOPT_FOR_RESTORE : 0); DexoptOptions dexoptOptions = @@ -2445,13 +2448,25 @@ final class InstallPackageHelper { realPkgSetting.getPkgState().setUpdatedSystemApp(isUpdatedSystemApp); - // TODO(b/251903639): Call into ART Service. - try { - mPackageDexOptimizer.performDexOpt(pkg, realPkgSetting, - null /* instructionSets */, mPm.getOrCreateCompilerPackageStats(pkg), - mDexManager.getPackageUseInfoOrDefault(packageName), dexoptOptions); - } catch (LegacyDexoptDisabledException e) { - throw new RuntimeException(e); + if (useArtService()) { + PackageManagerLocal packageManagerLocal = + LocalManagerRegistry.getManager(PackageManagerLocal.class); + try (PackageManagerLocal.FilteredSnapshot snapshot = + packageManagerLocal.withFilteredSnapshot()) { + DexoptParams params = + dexoptOptions.convertToDexoptParams(0 /* extraFlags */); + DexOptHelper.getArtManagerLocal().dexoptPackage( + snapshot, packageName, params); + } + } else { + try { + mPackageDexOptimizer.performDexOpt(pkg, realPkgSetting, + null /* instructionSets */, + mPm.getOrCreateCompilerPackageStats(pkg), + mDexManager.getPackageUseInfoOrDefault(packageName), dexoptOptions); + } catch (LegacyDexoptDisabledException e) { + throw new RuntimeException(e); + } } Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); } diff --git a/services/core/java/com/android/server/pm/dex/ArtManagerService.java b/services/core/java/com/android/server/pm/dex/ArtManagerService.java index b4cedfb335cd..d8b6cd5bb7e3 100644 --- a/services/core/java/com/android/server/pm/dex/ArtManagerService.java +++ b/services/core/java/com/android/server/pm/dex/ArtManagerService.java @@ -50,11 +50,15 @@ import com.android.internal.os.RoSystemProperties; import com.android.internal.util.ArrayUtils; import com.android.internal.util.Preconditions; import com.android.server.LocalServices; +import com.android.server.art.ArtManagerLocal; +import com.android.server.pm.DexOptHelper; import com.android.server.pm.Installer; import com.android.server.pm.Installer.InstallerException; import com.android.server.pm.Installer.LegacyDexoptDisabledException; +import com.android.server.pm.PackageManagerLocal; import com.android.server.pm.PackageManagerService; import com.android.server.pm.PackageManagerServiceCompilerMapping; +import com.android.server.pm.PackageManagerServiceUtils; import com.android.server.pm.parsing.PackageInfoUtils; import com.android.server.pm.pkg.AndroidPackage; import com.android.server.pm.pkg.PackageState; @@ -210,20 +214,15 @@ public class ArtManagerService extends android.content.pm.dex.IArtManager.Stub { Slog.d(TAG, "Requested snapshot for " + packageName + ":" + codePath); } - // TODO(b/251903639): Call into ART Service. - try { - if (bootImageProfile) { - snapshotBootImageProfile(callback); - } else { - snapshotAppProfile(packageName, codePath, callback); - } - } catch (LegacyDexoptDisabledException e) { - throw new RuntimeException(e); + if (bootImageProfile) { + snapshotBootImageProfile(callback); + } else { + snapshotAppProfile(packageName, codePath, callback); } } - private void snapshotAppProfile(String packageName, String codePath, - ISnapshotRuntimeProfileCallback callback) throws LegacyDexoptDisabledException { + private void snapshotAppProfile( + String packageName, String codePath, ISnapshotRuntimeProfileCallback callback) { PackageInfo info = null; try { // Note that we use the default user 0 to retrieve the package info. @@ -260,17 +259,45 @@ public class ArtManagerService extends android.content.pm.dex.IArtManager.Stub { } // All good, create the profile snapshot. - int appId = UserHandle.getAppId(info.applicationInfo.uid); - if (appId < 0) { - postError(callback, packageName, ArtManager.SNAPSHOT_FAILED_INTERNAL_ERROR); - Slog.wtf(TAG, "AppId is -1 for package: " + packageName); - return; - } + if (DexOptHelper.useArtService()) { + ParcelFileDescriptor fd; + + try (PackageManagerLocal.FilteredSnapshot snapshot = + PackageManagerServiceUtils.getPackageManagerLocal() + .withFilteredSnapshot()) { + fd = DexOptHelper.getArtManagerLocal().snapshotAppProfile( + snapshot, packageName, splitName); + } catch (IllegalArgumentException e) { + // ArtManagerLocal.snapshotAppProfile couldn't find the package or split. Since + // we've checked them above this can only happen due to race, i.e. the package got + // removed. So let's report it as SNAPSHOT_FAILED_PACKAGE_NOT_FOUND even if it was + // for the split. + // TODO(mast): Reuse the same snapshot to avoid this race. + postError(callback, packageName, ArtManager.SNAPSHOT_FAILED_PACKAGE_NOT_FOUND); + return; + } catch (IllegalStateException | ArtManagerLocal.SnapshotProfileException e) { + postError(callback, packageName, ArtManager.SNAPSHOT_FAILED_INTERNAL_ERROR); + return; + } + + postSuccess(packageName, fd, callback); + } else { + int appId = UserHandle.getAppId(info.applicationInfo.uid); + if (appId < 0) { + postError(callback, packageName, ArtManager.SNAPSHOT_FAILED_INTERNAL_ERROR); + Slog.wtf(TAG, "AppId is -1 for package: " + packageName); + return; + } - createProfileSnapshot(packageName, ArtManager.getProfileName(splitName), codePath, - appId, callback); - // Destroy the snapshot, we no longer need it. - destroyProfileSnapshot(packageName, ArtManager.getProfileName(splitName)); + try { + createProfileSnapshot(packageName, ArtManager.getProfileName(splitName), codePath, + appId, callback); + // Destroy the snapshot, we no longer need it. + destroyProfileSnapshot(packageName, ArtManager.getProfileName(splitName)); + } catch (LegacyDexoptDisabledException e) { + throw new RuntimeException(e); + } + } } private void createProfileSnapshot(String packageName, String profileName, String classpath, @@ -340,23 +367,43 @@ public class ArtManagerService extends android.content.pm.dex.IArtManager.Stub { } } - private void snapshotBootImageProfile(ISnapshotRuntimeProfileCallback callback) - throws LegacyDexoptDisabledException { - // Combine the profiles for boot classpath and system server classpath. - // This avoids having yet another type of profiles and simplifies the processing. - String classpath = String.join(":", Os.getenv("BOOTCLASSPATH"), - Os.getenv("SYSTEMSERVERCLASSPATH")); + private void snapshotBootImageProfile(ISnapshotRuntimeProfileCallback callback) { + if (DexOptHelper.useArtService()) { + ParcelFileDescriptor fd; + + try (PackageManagerLocal.FilteredSnapshot snapshot = + PackageManagerServiceUtils.getPackageManagerLocal() + .withFilteredSnapshot()) { + fd = DexOptHelper.getArtManagerLocal().snapshotBootImageProfile(snapshot); + } catch (IllegalStateException | ArtManagerLocal.SnapshotProfileException e) { + postError(callback, BOOT_IMAGE_ANDROID_PACKAGE, + ArtManager.SNAPSHOT_FAILED_INTERNAL_ERROR); + return; + } - final String standaloneSystemServerJars = Os.getenv("STANDALONE_SYSTEMSERVER_JARS"); - if (standaloneSystemServerJars != null) { - classpath = String.join(":", classpath, standaloneSystemServerJars); - } + postSuccess(BOOT_IMAGE_ANDROID_PACKAGE, fd, callback); + } else { + // Combine the profiles for boot classpath and system server classpath. + // This avoids having yet another type of profiles and simplifies the processing. + String classpath = String.join( + ":", Os.getenv("BOOTCLASSPATH"), Os.getenv("SYSTEMSERVERCLASSPATH")); + + final String standaloneSystemServerJars = Os.getenv("STANDALONE_SYSTEMSERVER_JARS"); + if (standaloneSystemServerJars != null) { + classpath = String.join(":", classpath, standaloneSystemServerJars); + } - // Create the snapshot. - createProfileSnapshot(BOOT_IMAGE_ANDROID_PACKAGE, BOOT_IMAGE_PROFILE_NAME, classpath, - /*appId*/ -1, callback); - // Destroy the snapshot, we no longer need it. - destroyProfileSnapshot(BOOT_IMAGE_ANDROID_PACKAGE, BOOT_IMAGE_PROFILE_NAME); + try { + // Create the snapshot. + createProfileSnapshot(BOOT_IMAGE_ANDROID_PACKAGE, BOOT_IMAGE_PROFILE_NAME, + classpath, + /*appId*/ -1, callback); + // Destroy the snapshot, we no longer need it. + destroyProfileSnapshot(BOOT_IMAGE_ANDROID_PACKAGE, BOOT_IMAGE_PROFILE_NAME); + } catch (LegacyDexoptDisabledException e) { + throw new RuntimeException(e); + } + } } /** |