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

Commit 83e844bb authored by Calin Juravle's avatar Calin Juravle Committed by Automerger Merge Worker
Browse files

Merge "Update the use of registerAppInfo" into sc-dev am: dd8b9455

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14669173

Change-Id: I29769ce32c0f5401bdb25bbbfd688aca5c2c695a
parents d492dabe dd8b9455
Loading
Loading
Loading
Loading
+12 −5
Original line number Original line Diff line number Diff line
@@ -138,23 +138,25 @@ import java.util.Set;
        // NOTE: Keep this in sync with installd expectations.
        // NOTE: Keep this in sync with installd expectations.
        File dexPathFile = new File(dexPath);
        File dexPathFile = new File(dexPath);
        File secondaryProfileDir = new File(dexPathFile.getParent(), "oat");
        File secondaryProfileDir = new File(dexPathFile.getParent(), "oat");
        File secondaryProfile = new File(secondaryProfileDir, dexPathFile.getName() + ".cur.prof");
        File secondaryCurProfile =
                new File(secondaryProfileDir, dexPathFile.getName() + ".cur.prof");
        File secondaryRefProfile = new File(secondaryProfileDir, dexPathFile.getName() + ".prof");


        // Create the profile if not already there.
        // Create the profile if not already there.
        // Returns true if the file was created, false if the file already exists.
        // Returns true if the file was created, false if the file already exists.
        // or throws exceptions in case of errors.
        // or throws exceptions in case of errors.
        if (!secondaryProfileDir.exists()) {
        if (!secondaryProfileDir.exists()) {
            if (!secondaryProfileDir.mkdir()) {
            if (!secondaryProfileDir.mkdir()) {
                Slog.e(TAG, "Could not create the profile directory: " + secondaryProfile);
                Slog.e(TAG, "Could not create the profile directory: " + secondaryCurProfile);
                // Do not continue with registration if we could not create the oat dir.
                // Do not continue with registration if we could not create the oat dir.
                return;
                return;
            }
            }
        }
        }


        try {
        try {
            boolean created = secondaryProfile.createNewFile();
            boolean created = secondaryCurProfile.createNewFile();
            if (DEBUG && created) {
            if (DEBUG && created) {
                Slog.i(TAG, "Created profile for secondary dex: " + secondaryProfile);
                Slog.i(TAG, "Created profile for secondary dex: " + secondaryCurProfile);
            }
            }
        } catch (IOException ex) {
        } catch (IOException ex) {
            Slog.e(TAG, "Failed to create profile for secondary dex " + dexPath
            Slog.e(TAG, "Failed to create profile for secondary dex " + dexPath
@@ -165,7 +167,12 @@ import java.util.Set;


        // If we got here, the dex paths is a secondary dex and we were able to create the profile.
        // If we got here, the dex paths is a secondary dex and we were able to create the profile.
        // Register the path to the runtime.
        // Register the path to the runtime.
        VMRuntime.registerAppInfo(secondaryProfile.getPath(), new String[] { dexPath });
        VMRuntime.registerAppInfo(
                ActivityThread.currentPackageName(),
                secondaryCurProfile.getPath(),
                secondaryRefProfile.getPath(),
                new String[] { dexPath },
                VMRuntime.CODE_PATH_TYPE_SECONDARY_DEX);
    }
    }


    // A dex file is a secondary dex file if it is in any of the registered app
    // A dex file is a secondary dex file if it is in any of the registered app
+19 −13
Original line number Original line Diff line number Diff line
@@ -930,7 +930,7 @@ public final class LoadedApk {
        if (DEBUG) Slog.v(ActivityThread.TAG, "Class path: " + zip +
        if (DEBUG) Slog.v(ActivityThread.TAG, "Class path: " + zip +
                    ", JNI path: " + librarySearchPath);
                    ", JNI path: " + librarySearchPath);


        boolean needToSetupJitProfiles = false;
        boolean registerAppInfoToArt = false;
        if (mDefaultClassLoader == null) {
        if (mDefaultClassLoader == null) {
            // Temporarily disable logging of disk reads on the Looper thread
            // Temporarily disable logging of disk reads on the Looper thread
            // as this is early and necessary.
            // as this is early and necessary.
@@ -957,7 +957,7 @@ public final class LoadedApk {


            setThreadPolicy(oldPolicy);
            setThreadPolicy(oldPolicy);
            // Setup the class loader paths for profiling.
            // Setup the class loader paths for profiling.
            needToSetupJitProfiles = true;
            registerAppInfoToArt = true;
        }
        }


        if (!libPaths.isEmpty()) {
        if (!libPaths.isEmpty()) {
@@ -974,7 +974,7 @@ public final class LoadedApk {
            final String add = TextUtils.join(File.pathSeparator, addedPaths);
            final String add = TextUtils.join(File.pathSeparator, addedPaths);
            ApplicationLoaders.getDefault().addPath(mDefaultClassLoader, add);
            ApplicationLoaders.getDefault().addPath(mDefaultClassLoader, add);
            // Setup the new code paths for profiling.
            // Setup the new code paths for profiling.
            needToSetupJitProfiles = true;
            registerAppInfoToArt = true;
        }
        }


        // Setup jit profile support.
        // Setup jit profile support.
@@ -988,8 +988,8 @@ public final class LoadedApk {
        // loads code from) so we explicitly disallow it there.
        // loads code from) so we explicitly disallow it there.
        //
        //
        // It is not ok to call this in a zygote context where mActivityThread is null.
        // It is not ok to call this in a zygote context where mActivityThread is null.
        if (needToSetupJitProfiles && !ActivityThread.isSystem() && mActivityThread != null) {
        if (registerAppInfoToArt && !ActivityThread.isSystem() && mActivityThread != null) {
            setupJitProfileSupport();
            registerAppInfoToArt();
        }
        }


        // Call AppComponentFactory to select/create the main class loader of this app.
        // Call AppComponentFactory to select/create the main class loader of this app.
@@ -1046,12 +1046,8 @@ public final class LoadedApk {
        }
        }
    }
    }


    private void setupJitProfileSupport() {
    private void registerAppInfoToArt() {
        if (!SystemProperties.getBoolean("dalvik.vm.usejitprofiles", false)) {
        // Setup the dex reporter to notify package manager
            return;
        }

        // If we use profiles, setup the dex reporter to notify package manager
        // of any relevant dex loads. The idle maintenance job will use the information
        // of any relevant dex loads. The idle maintenance job will use the information
        // reported to optimize the loaded dex files.
        // reported to optimize the loaded dex files.
        // Note that we only need one global reporter per app.
        // Note that we only need one global reporter per app.
@@ -1084,9 +1080,19 @@ public final class LoadedApk {


        for (int i = codePaths.size() - 1; i >= 0; i--) {
        for (int i = codePaths.size() - 1; i >= 0; i--) {
            String splitName = i == 0 ? null : mApplicationInfo.splitNames[i - 1];
            String splitName = i == 0 ? null : mApplicationInfo.splitNames[i - 1];
            String profileFile = ArtManager.getCurrentProfilePath(
            String curProfileFile = ArtManager.getCurrentProfilePath(
                    mPackageName, UserHandle.myUserId(), splitName);
                    mPackageName, UserHandle.myUserId(), splitName);
            VMRuntime.registerAppInfo(profileFile, new String[] {codePaths.get(i)});
            String refProfileFile = ArtManager.getReferenceProfilePath(
                    mPackageName, UserHandle.myUserId(), splitName);
            int codePathType = codePaths.get(i).equals(mApplicationInfo.sourceDir)
                    ? VMRuntime.CODE_PATH_TYPE_PRIMARY_APK
                    : VMRuntime.CODE_PATH_TYPE_SPLIT_APK;
            VMRuntime.registerAppInfo(
                    mPackageName,
                    curProfileFile,
                    refProfileFile,
                    new String[] {codePaths.get(i)},
                    codePathType);
        }
        }


        // Register the app data directory with the reporter. It will
        // Register the app data directory with the reporter. It will
+10 −0
Original line number Original line Diff line number Diff line
@@ -200,6 +200,16 @@ public class ArtManager {
        return new File(profileDir, getProfileName(splitName)).getAbsolutePath();
        return new File(profileDir, getProfileName(splitName)).getAbsolutePath();
    }
    }


    /**
     * Return the path to the current profile corresponding to given package and split.
     *
     * @hide
     */
    public static String getReferenceProfilePath(String packageName, int userId, String splitName) {
        File profileDir = Environment.getDataRefProfilesDePackageDirectory(packageName);
        return new File(profileDir, getProfileName(splitName)).getAbsolutePath();
    }

    /**
    /**
     * Return the snapshot profile file for the given package and profile name.
     * Return the snapshot profile file for the given package and profile name.
     *
     *
+11 −3
Original line number Original line Diff line number Diff line
@@ -583,10 +583,18 @@ public class ZygoteInit {
                codePaths[0],
                codePaths[0],
                /*dexMetadata*/ null);
                /*dexMetadata*/ null);


        File profileDir = Environment.getDataProfilesDePackageDirectory(
        File curProfileDir = Environment.getDataProfilesDePackageDirectory(
                UserHandle.USER_SYSTEM, systemServerPackageName);
                UserHandle.USER_SYSTEM, systemServerPackageName);
        String profilePath = new File(profileDir, systemServerProfileName).getAbsolutePath();
        String curProfilePath = new File(curProfileDir, systemServerProfileName).getAbsolutePath();
        VMRuntime.registerAppInfo(profilePath, codePaths);
        File refProfileDir = Environment.getDataProfilesDePackageDirectory(
                UserHandle.USER_SYSTEM, systemServerPackageName);
        String refProfilePath = new File(refProfileDir, systemServerProfileName).getAbsolutePath();
        VMRuntime.registerAppInfo(
                systemServerPackageName,
                curProfilePath,
                refProfilePath,
                codePaths,
                VMRuntime.CODE_PATH_TYPE_PRIMARY_APK);
    }
    }


    /**
    /**