Java Code Examples for dalvik.system.VMRuntime#registerAppInfo()

The following examples show how to use dalvik.system.VMRuntime#registerAppInfo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZygoteInit.java    From android_9.0.0_r45 with Apache License 2.0 7 votes vote down vote up
/**
 * Note that preparing the profiles for system server does not require special
 * selinux permissions. From the installer perspective the system server is a regular package
 * which can capture profile information.
 */
private static void prepareSystemServerProfile(String systemServerClasspath)
        throws RemoteException {
    if (systemServerClasspath.isEmpty()) {
        return;
    }
    String[] codePaths = systemServerClasspath.split(":");

    final IInstalld installd = IInstalld.Stub
            .asInterface(ServiceManager.getService("installd"));

    String systemServerPackageName = "android";
    String systemServerProfileName = "primary.prof";
    installd.prepareAppProfile(
            systemServerPackageName,
            UserHandle.USER_SYSTEM,
            UserHandle.getAppId(Process.SYSTEM_UID),
            systemServerProfileName,
            codePaths[0],
            /*dexMetadata*/ null);

    File profileDir = Environment.getDataProfilesDePackageDirectory(
            UserHandle.USER_SYSTEM, systemServerPackageName);
    String profilePath = new File(profileDir, systemServerProfileName).getAbsolutePath();
    VMRuntime.registerAppInfo(profilePath, codePaths);
}
 
Example 2
Source File: LoadedApk.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
private void setupJitProfileSupport() {
    if (!SystemProperties.getBoolean("dalvik.vm.usejitprofiles", false)) {
        return;
    }
    // Only set up profile support if the loaded apk has the same uid as the
    // current process.
    // Currently, we do not support profiling across different apps.
    // (e.g. application's uid might be different when the code is
    // loaded by another app via createApplicationContext)
    if (mApplicationInfo.uid != Process.myUid()) {
        return;
    }

    final List<String> codePaths = new ArrayList<>();
    if ((mApplicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0) {
        codePaths.add(mApplicationInfo.sourceDir);
    }
    if (mApplicationInfo.splitSourceDirs != null) {
        Collections.addAll(codePaths, mApplicationInfo.splitSourceDirs);
    }

    if (codePaths.isEmpty()) {
        // If there are no code paths there's no need to setup a profile file and register with
        // the runtime,
        return;
    }

    final File profileFile = getPrimaryProfileFile(mPackageName);

    VMRuntime.registerAppInfo(profileFile.getPath(),
            codePaths.toArray(new String[codePaths.size()]));

    // Register the app data directory with the reporter. It will
    // help deciding whether or not a dex file is the primary apk or a
    // secondary dex.
    DexLoadReporter.getInstance().registerAppDataDir(mPackageName, mDataDir);
}
 
Example 3
Source File: DexLoadReporter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void registerSecondaryDexForProfiling(String dexPath, String[] dataDirs) {
    if (!isSecondaryDexFile(dexPath, dataDirs)) {
        // The dex path is not a secondary dex file. Nothing to do.
        return;
    }

    // Secondary dex profiles are stored in the oat directory, next to dex file
    // and have the same name with 'cur.prof' appended.
    // NOTE: Keep this in sync with installd expectations.
    File dexPathFile = new File(dexPath);
    File secondaryProfileDir = new File(dexPathFile.getParent(), "oat");
    File secondaryProfile = new File(secondaryProfileDir, dexPathFile.getName() + ".cur.prof");

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

    try {
        boolean created = secondaryProfile.createNewFile();
        if (DEBUG && created) {
            Slog.i(TAG, "Created profile for secondary dex: " + secondaryProfile);
        }
    } catch (IOException ex) {
        Slog.e(TAG, "Failed to create profile for secondary dex " + dexPath
                + ":" + ex.getMessage());
        // Do not continue with registration if we could not create the profile files.
        return;
    }

    // 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.
    VMRuntime.registerAppInfo(secondaryProfile.getPath(), new String[] { dexPath });
}
 
Example 4
Source File: LoadedApk.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void setupJitProfileSupport() {
    if (!SystemProperties.getBoolean("dalvik.vm.usejitprofiles", false)) {
        return;
    }
    // Only set up profile support if the loaded apk has the same uid as the
    // current process.
    // Currently, we do not support profiling across different apps.
    // (e.g. application's uid might be different when the code is
    // loaded by another app via createApplicationContext)
    if (mApplicationInfo.uid != Process.myUid()) {
        return;
    }

    final List<String> codePaths = new ArrayList<>();
    if ((mApplicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0) {
        codePaths.add(mApplicationInfo.sourceDir);
    }
    if (mApplicationInfo.splitSourceDirs != null) {
        Collections.addAll(codePaths, mApplicationInfo.splitSourceDirs);
    }

    if (codePaths.isEmpty()) {
        // If there are no code paths there's no need to setup a profile file and register with
        // the runtime,
        return;
    }

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

    // Register the app data directory with the reporter. It will
    // help deciding whether or not a dex file is the primary apk or a
    // secondary dex.
    DexLoadReporter.getInstance().registerAppDataDir(mPackageName, mDataDir);
}