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

Commit 6d674496 authored by Andreas Gampe's avatar Andreas Gampe Committed by android-build-merger
Browse files

Merge "Installd: Separate profile merging and compilation" into nyc-dev am: 950aa7c8

am: d517cde1

* commit 'd517cde1':
  Installd: Separate profile merging and compilation
parents 38aa47e1 d517cde1
Loading
Loading
Loading
Loading
+39 −36
Original line number Original line Diff line number Diff line
@@ -714,7 +714,7 @@ static void run_patchoat(int input_fd, int oat_fd, const char* input_file_name,


static void run_dex2oat(int zip_fd, int oat_fd, int image_fd, const char* input_file_name,
static void run_dex2oat(int zip_fd, int oat_fd, int image_fd, const char* input_file_name,
        const char* output_file_name, int swap_fd, const char *instruction_set,
        const char* output_file_name, int swap_fd, const char *instruction_set,
        bool vm_safe_mode, bool debuggable, bool post_bootcomplete, bool extract_only,
        const char* compiler_filter, bool vm_safe_mode, bool debuggable, bool post_bootcomplete,
        int profile_fd) {
        int profile_fd) {
    static const unsigned int MAX_INSTRUCTION_SET_LEN = 7;
    static const unsigned int MAX_INSTRUCTION_SET_LEN = 7;


@@ -730,10 +730,6 @@ static void run_dex2oat(int zip_fd, int oat_fd, int image_fd, const char* input_
    char dex2oat_Xmx_flag[kPropertyValueMax];
    char dex2oat_Xmx_flag[kPropertyValueMax];
    bool have_dex2oat_Xmx_flag = get_property("dalvik.vm.dex2oat-Xmx", dex2oat_Xmx_flag, NULL) > 0;
    bool have_dex2oat_Xmx_flag = get_property("dalvik.vm.dex2oat-Xmx", dex2oat_Xmx_flag, NULL) > 0;


    char dex2oat_compiler_filter_flag[kPropertyValueMax];
    bool have_dex2oat_compiler_filter_flag = get_property("dalvik.vm.dex2oat-filter",
                                                          dex2oat_compiler_filter_flag, NULL) > 0;

    char dex2oat_threads_buf[kPropertyValueMax];
    char dex2oat_threads_buf[kPropertyValueMax];
    bool have_dex2oat_threads_flag = get_property(post_bootcomplete
    bool have_dex2oat_threads_flag = get_property(post_bootcomplete
                                                      ? "dalvik.vm.dex2oat-threads"
                                                      ? "dalvik.vm.dex2oat-threads"
@@ -825,6 +821,10 @@ static void run_dex2oat(int zip_fd, int oat_fd, int image_fd, const char* input_
    if (have_dex2oat_Xmx_flag) {
    if (have_dex2oat_Xmx_flag) {
        sprintf(dex2oat_Xmx_arg, "-Xmx%s", dex2oat_Xmx_flag);
        sprintf(dex2oat_Xmx_arg, "-Xmx%s", dex2oat_Xmx_flag);
    }
    }

    // Compute compiler filter.

    bool have_dex2oat_compiler_filter_flag;
    if (skip_compilation) {
    if (skip_compilation) {
        strcpy(dex2oat_compiler_filter_arg, "--compiler-filter=verify-none");
        strcpy(dex2oat_compiler_filter_arg, "--compiler-filter=verify-none");
        have_dex2oat_compiler_filter_flag = true;
        have_dex2oat_compiler_filter_flag = true;
@@ -832,13 +832,20 @@ static void run_dex2oat(int zip_fd, int oat_fd, int image_fd, const char* input_
    } else if (vm_safe_mode) {
    } else if (vm_safe_mode) {
        strcpy(dex2oat_compiler_filter_arg, "--compiler-filter=interpret-only");
        strcpy(dex2oat_compiler_filter_arg, "--compiler-filter=interpret-only");
        have_dex2oat_compiler_filter_flag = true;
        have_dex2oat_compiler_filter_flag = true;
    } else if (extract_only) {
    } else if (compiler_filter != nullptr &&
        // Temporarily make extract-only mean interpret-only, so extracted files will be verified.
            strlen(compiler_filter) + strlen("--compiler-filter=") <
        // b/26833007
                    arraysize(dex2oat_compiler_filter_arg)) {
        strcpy(dex2oat_compiler_filter_arg, "--compiler-filter=interpret-only");
        sprintf(dex2oat_compiler_filter_arg, "--compiler-filter=%s", compiler_filter);
        have_dex2oat_compiler_filter_flag = true;
        have_dex2oat_compiler_filter_flag = true;
    } else if (have_dex2oat_compiler_filter_flag) {
    } else {
        sprintf(dex2oat_compiler_filter_arg, "--compiler-filter=%s", dex2oat_compiler_filter_flag);
        char dex2oat_compiler_filter_flag[kPropertyValueMax];
        have_dex2oat_compiler_filter_flag = get_property("dalvik.vm.dex2oat-filter",
                                                         dex2oat_compiler_filter_flag, NULL) > 0;
        if (have_dex2oat_compiler_filter_flag) {
            sprintf(dex2oat_compiler_filter_arg,
                    "--compiler-filter=%s",
                    dex2oat_compiler_filter_flag);
        }
    }
    }


    // Check whether all apps should be compiled debuggable.
    // Check whether all apps should be compiled debuggable.
@@ -1283,9 +1290,14 @@ static bool create_oat_out_path(const char* apk_path, const char* instruction_se
    return true;
    return true;
}
}


// TODO: Consider returning error codes.
bool merge_profiles(uid_t uid, const char *pkgname) {
    return analyse_profiles(uid, pkgname);
}

int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* instruction_set,
int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* instruction_set,
           int dexopt_needed, const char* oat_dir, int dexopt_flags,
           int dexopt_needed, const char* oat_dir, int dexopt_flags, const char* compiler_filter,
           const char* volume_uuid ATTRIBUTE_UNUSED, bool use_profiles)
           const char* volume_uuid ATTRIBUTE_UNUSED)
{
{
    struct utimbuf ut;
    struct utimbuf ut;
    struct stat input_stat;
    struct stat input_stat;
@@ -1300,29 +1312,18 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins
    bool vm_safe_mode = (dexopt_flags & DEXOPT_SAFEMODE) != 0;
    bool vm_safe_mode = (dexopt_flags & DEXOPT_SAFEMODE) != 0;
    bool debuggable = (dexopt_flags & DEXOPT_DEBUGGABLE) != 0;
    bool debuggable = (dexopt_flags & DEXOPT_DEBUGGABLE) != 0;
    bool boot_complete = (dexopt_flags & DEXOPT_BOOTCOMPLETE) != 0;
    bool boot_complete = (dexopt_flags & DEXOPT_BOOTCOMPLETE) != 0;
    bool extract_only = (dexopt_flags & DEXOPT_EXTRACTONLY) != 0;
    bool profile_guided = (dexopt_flags & DEXOPT_PROFILE_GUIDED) != 0;
    fd_t reference_profile_fd = -1;


    if (is_public && use_profiles) {
    CHECK(pkgname != nullptr);
        // We should not give public access to apks compiled with profile information.
    CHECK(pkgname[0] != 0);
        // Log an error and return early if are asked to do so.
        ALOGE("use_profiles should not be used with is_public.");
        return -1;
    }


    if (use_profiles) {
    fd_t reference_profile_fd = -1;
        if (analyse_profiles(uid, pkgname)) {
    // Public apps should not be compiled with profile information ever. Same goes for the special
            // Open again reference profile in read only mode as dex2oat does not get write
    // package '*' used for the system server.
            // permissions.
    if (!is_public && pkgname[0] != '*') {
        // Open reference profile in read only mode as dex2oat does not get write permissions.
        reference_profile_fd = open_reference_profile(uid, pkgname, /*read_write*/ false);
        reference_profile_fd = open_reference_profile(uid, pkgname, /*read_write*/ false);
            if (reference_profile_fd == -1) {
        // Note: it's OK to not find a profile here.
                PLOG(WARNING) << "Couldn't open reference profile in read only mode " << pkgname;
                exit(72);
            }
        } else {
            // No need to (re)compile. Return early.
            return 0;
        }
    }
    }


    if ((dexopt_flags & ~DEXOPT_MASK) != 0) {
    if ((dexopt_flags & ~DEXOPT_MASK) != 0) {
@@ -1397,7 +1398,9 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins
      char app_image_format[kPropertyValueMax];
      char app_image_format[kPropertyValueMax];
      bool have_app_image_format =
      bool have_app_image_format =
              get_property("dalvik.vm.appimageformat", app_image_format, NULL) > 0;
              get_property("dalvik.vm.appimageformat", app_image_format, NULL) > 0;
      if (!extract_only && have_app_image_format) {
      // Use app images only if it is enabled (by a set image format) and we are compiling
      // profile-guided (so the app image doesn't conservatively contain all classes).
      if (profile_guided && have_app_image_format) {
          // Recreate is false since we want to avoid deleting the image in case dex2oat decides to
          // Recreate is false since we want to avoid deleting the image in case dex2oat decides to
          // not compile anything.
          // not compile anything.
          image_fd = open_output_file(image_path, /*recreate*/false);
          image_fd = open_output_file(image_path, /*recreate*/false);
@@ -1440,7 +1443,7 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins
                input_file_name++;
                input_file_name++;
            }
            }
            run_dex2oat(input_fd, out_fd, image_fd, input_file_name, out_path, swap_fd,
            run_dex2oat(input_fd, out_fd, image_fd, input_file_name, out_path, swap_fd,
                        instruction_set, vm_safe_mode, debuggable, boot_complete, extract_only,
                        instruction_set, compiler_filter, vm_safe_mode, debuggable, boot_complete,
                        reference_profile_fd);
                        reference_profile_fd);
        } else {
        } else {
            ALOGE("Invalid dexopt needed: %d\n", dexopt_needed);
            ALOGE("Invalid dexopt needed: %d\n", dexopt_needed);
+5 −2
Original line number Original line Diff line number Diff line
@@ -48,9 +48,12 @@ int make_user_config(userid_t userid);
int delete_user(const char *uuid, userid_t userid);
int delete_user(const char *uuid, userid_t userid);
int rm_dex(const char *path, const char *instruction_set);
int rm_dex(const char *path, const char *instruction_set);
int free_cache(const char *uuid, int64_t free_size);
int free_cache(const char *uuid, int64_t free_size);

bool merge_profiles(uid_t uid, const char *pkgname);

int dexopt(const char *apk_path, uid_t uid, const char *pkgName, const char *instruction_set,
int dexopt(const char *apk_path, uid_t uid, const char *pkgName, const char *instruction_set,
           int dexopt_needed, const char* oat_dir, int dexopt_flags,
           int dexopt_needed, const char* oat_dir, int dexopt_flags, const char* compiler_filter,
           const char* volume_uuid, bool use_profiles);
           const char* volume_uuid);
int mark_boot_complete(const char *instruction_set);
int mark_boot_complete(const char *instruction_set);
int linklib(const char* uuid, const char* pkgname, const char* asecLibDir, int userId);
int linklib(const char* uuid, const char* pkgname, const char* asecLibDir, int userId);
int idmap(const char *target_path, const char *overlay_path, uid_t uid);
int idmap(const char *target_path, const char *overlay_path, uid_t uid);
+22 −4
Original line number Original line Diff line number Diff line
@@ -258,10 +258,27 @@ static int do_dexopt(char **arg, char reply[REPLY_MAX])
    if ((dexopt_flags & DEXOPT_OTA) != 0) {
    if ((dexopt_flags & DEXOPT_OTA) != 0) {
      return do_ota_dexopt(arg, reply);
      return do_ota_dexopt(arg, reply);
    }
    }
    /* apk_path, uid, pkgname, instruction_set, dexopt_needed, oat_dir, dexopt_flags, volume_uuid,
    return dexopt(arg[0],                      // apk_path
            use_profiles */
                  atoi(arg[1]),                // uid
    return dexopt(arg[0], atoi(arg[1]), arg[2], arg[3], atoi(arg[4]),
                  arg[2],                      // pkgname
                  arg[5], dexopt_flags, parse_null(arg[7]), (atoi(arg[8]) == 0 ? false : true));
                  arg[3],                      // instruction_set
                  atoi(arg[4]),                // dexopt_needed
                  arg[5],                      // oat_dir
                  dexopt_flags,
                  arg[7],                      // compiler_filter
                  parse_null(arg[8]));         // volume_uuid
}

static int do_merge_profiles(char **arg, char reply[REPLY_MAX])
{
    uid_t uid = static_cast<uid_t>(atoi(arg[0]));
    const char* pkgname = arg[1];
    if (merge_profiles(uid, pkgname)) {
        strncpy(reply, "true", REPLY_MAX);
    } else {
        strncpy(reply, "false", REPLY_MAX);
    }
    return 0;
}
}


static int do_mark_boot_complete(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED)
static int do_mark_boot_complete(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED)
@@ -388,6 +405,7 @@ struct cmdinfo cmds[] = {
    { "rmprofiles",           1, do_rm_profiles },
    { "rmprofiles",           1, do_rm_profiles },
    { "linkfile",             3, do_link_file },
    { "linkfile",             3, do_link_file },
    { "move_ab",              3, do_move_ab },
    { "move_ab",              3, do_move_ab },
    { "merge_profiles",       2, do_merge_profiles },
};
};


static int readx(int s, void *_buf, int count)
static int readx(int s, void *_buf, int count)
+7 −7
Original line number Original line Diff line number Diff line
@@ -79,7 +79,7 @@ constexpr int DEXOPT_PUBLIC = 1 << 1;
constexpr int DEXOPT_SAFEMODE       = 1 << 2;
constexpr int DEXOPT_SAFEMODE       = 1 << 2;
constexpr int DEXOPT_DEBUGGABLE     = 1 << 3;
constexpr int DEXOPT_DEBUGGABLE     = 1 << 3;
constexpr int DEXOPT_BOOTCOMPLETE   = 1 << 4;
constexpr int DEXOPT_BOOTCOMPLETE   = 1 << 4;
constexpr int DEXOPT_EXTRACTONLY  = 1 << 5;
constexpr int DEXOPT_PROFILE_GUIDED = 1 << 5;
constexpr int DEXOPT_OTA            = 1 << 6;
constexpr int DEXOPT_OTA            = 1 << 6;


/* all known values for dexopt flags */
/* all known values for dexopt flags */
@@ -88,7 +88,7 @@ constexpr int DEXOPT_MASK =
    | DEXOPT_SAFEMODE
    | DEXOPT_SAFEMODE
    | DEXOPT_DEBUGGABLE
    | DEXOPT_DEBUGGABLE
    | DEXOPT_BOOTCOMPLETE
    | DEXOPT_BOOTCOMPLETE
    | DEXOPT_EXTRACTONLY
    | DEXOPT_PROFILE_GUIDED
    | DEXOPT_OTA;
    | DEXOPT_OTA;


#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
+9 −11
Original line number Original line Diff line number Diff line
@@ -357,17 +357,15 @@ private:
    }
    }


    int RunPreopt() {
    int RunPreopt() {
        /* apk_path, uid, pkgname, instruction_set, dexopt_needed, oat_dir, dexopt_flags,
        int ret = dexopt(package_parameters_[0],          // apk_path
           volume_uuid, use_profiles */
                atoi(package_parameters_[1]),             // uid
        int ret = dexopt(package_parameters_[0],
                package_parameters_[2],                   // pkgname
                atoi(package_parameters_[1]),
                package_parameters_[3],                   // instruction_set
                package_parameters_[2],
                atoi(package_parameters_[4]),             // dexopt_needed
                package_parameters_[3],
                package_parameters_[5],                   // oat_dir
                atoi(package_parameters_[4]),
                atoi(package_parameters_[6]),             // dexopt_flags
                package_parameters_[5],
                package_parameters_[7],                   // compiler_filter
                atoi(package_parameters_[6]),
                ParseNull(package_parameters_[8]));       // volume_uuid
                ParseNull(package_parameters_[7]),
                (atoi(package_parameters_[8]) == 0 ? false : true));
        return ret;
        return ret;
    }
    }