Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c5d1b90f authored by Mathieu Chartier's avatar Mathieu Chartier
Browse files

Revert "Revert "Add preopt profile logic for compiling during first boot""

Disabled the logic for first boot profile compilation for non-extracted APKs.
This prevents going from speed-profile->speed-profile if things are preopted.

Test: build, flash, verify no speed/speed-profile compilation during first boot

Bug: 66903791

This reverts commit 4a299d56.

Change-Id: Iaa526e605cf57b2f24ba72d6786b35d5347cd3c5
parent e545f00e
Loading
Loading
Loading
Loading
+50 −2
Original line number Diff line number Diff line
@@ -3312,6 +3312,24 @@ public class PackageManagerService extends IPackageManager.Stub
            removeCodePathLI(dstCodePath);
            return null;
        }
        // If we have a profile for a compressed APK, copy it to the reference location.
        // Since the package is the stub one, remove the stub suffix to get the normal package and
        // APK name.
        File profileFile = new File(getPrebuildProfilePath(pkg).replace(STUB_SUFFIX, ""));
        if (profileFile.exists()) {
            try {
                // We could also do this lazily before calling dexopt in
                // PackageDexOptimizer to prevent this happening on first boot. The issue
                // is that we don't have a good way to say "do this only once".
                if (!mInstaller.copySystemProfile(profileFile.getAbsolutePath(),
                        pkg.applicationInfo.uid, pkg.packageName)) {
                    Log.e(TAG, "decompressPackage failed to copy system profile!");
                }
            } catch (Exception e) {
                Log.e(TAG, "Failed to copy profile " + profileFile.getAbsolutePath() + " ", e);
            }
        }
        return dstCodePath;
    }
@@ -9723,7 +9741,7 @@ public class PackageManagerService extends IPackageManager.Stub
     * and {@code numberOfPackagesFailed}.
     */
    private int[] performDexOptUpgrade(List<PackageParser.Package> pkgs, boolean showDialog,
            String compilerFilter, boolean bootComplete) {
            final String compilerFilter, boolean bootComplete) {
        int numberOfPackagesVisited = 0;
        int numberOfPackagesOptimized = 0;
@@ -9734,6 +9752,8 @@ public class PackageManagerService extends IPackageManager.Stub
        for (PackageParser.Package pkg : pkgs) {
            numberOfPackagesVisited++;
            boolean useProfileForDexopt = false;
            if ((isFirstBoot() || isUpgrade()) && isSystemApp(pkg)) {
                // Copy over initial preopt profiles since we won't get any JIT samples for methods
                // that are already compiled.
@@ -9747,11 +9767,30 @@ public class PackageManagerService extends IPackageManager.Stub
                        if (!mInstaller.copySystemProfile(profileFile.getAbsolutePath(),
                                pkg.applicationInfo.uid, pkg.packageName)) {
                            Log.e(TAG, "Installer failed to copy system profile!");
                        } else {
                            // Disabled as this causes speed-profile compilation during first boot
                            // even if things are already compiled.
                            // useProfileForDexopt = true;
                        }
                    } catch (Exception e) {
                        Log.e(TAG, "Failed to copy profile " + profileFile.getAbsolutePath() + " ",
                                e);
                    }
                } else {
                    PackageSetting disabledPs = mSettings.getDisabledSystemPkgLPr(pkg.packageName);
                    // Handle compressed APKs in this path. Only do this for stubs with profiles to
                    // minimize the number off apps being speed-profile compiled during first boot.
                    // The other paths will not change the filter.
                    if (disabledPs != null && disabledPs.pkg.isStub) {
                        // The package is the stub one, remove the stub suffix to get the normal
                        // package and APK names.
                        String systemProfilePath =
                                getPrebuildProfilePath(disabledPs.pkg).replace(STUB_SUFFIX, "");
                        File systemProfile = new File(systemProfilePath);
                        // Use the profile for compilation if there exists one for the same package
                        // in the system partition.
                        useProfileForDexopt = systemProfile.exists();
                    }
                }
            }
@@ -9780,6 +9819,15 @@ public class PackageManagerService extends IPackageManager.Stub
                }
            }
            String pkgCompilerFilter = compilerFilter;
            if (useProfileForDexopt) {
                // Use background dexopt mode to try and use the profile. Note that this does not
                // guarantee usage of the profile.
                pkgCompilerFilter =
                        PackageManagerServiceCompilerMapping.getCompilerFilterForReason(
                                PackageManagerService.REASON_BACKGROUND_DEXOPT);
            }
            // checkProfiles is false to avoid merging profiles during boot which
            // might interfere with background compilation (b/28612421).
            // Unfortunately this will also means that "pm.dexopt.boot=speed-profile" will
@@ -9788,7 +9836,7 @@ public class PackageManagerService extends IPackageManager.Stub
            int dexoptFlags = bootComplete ? DexoptOptions.DEXOPT_BOOT_COMPLETE : 0;
            int primaryDexOptStaus = performDexOptTraced(new DexoptOptions(
                    pkg.packageName,
                    compilerFilter,
                    pkgCompilerFilter,
                    dexoptFlags));
            switch (primaryDexOptStaus) {