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

Commit 72d4a5be authored by Andreas Gampe's avatar Andreas Gampe
Browse files

Installd: Run debug tools when using libartd

When ART is requested to run through libartd, use dex2oatd instead
of dex2oat to compile apps (profmand instead of profman,
dexoptanalyzerd instead of dexoptanalyzer).

Bug: 15735795
Test: m
Test: manual test with libartd
Merged-In: I33a12198566f5d979207e1edd4460b839a0f55f1
Change-Id: I33a12198566f5d979207e1edd4460b839a0f55f1
parent b640357b
Loading
Loading
Loading
Loading
+22 −13
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include <unistd.h>

#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
@@ -67,6 +68,10 @@ static unique_fd invalid_unique_fd() {
    return unique_fd(-1);
}

static bool is_debug_runtime() {
    return android::base::GetProperty("persist.sys.dalvik.vm.lib.2", "") == "libartd.so";
}

static bool clear_profile(const std::string& profile) {
    unique_fd ufd(open(profile.c_str(), O_WRONLY | O_NOFOLLOW | O_CLOEXEC));
    if (ufd.get() < 0) {
@@ -267,7 +272,8 @@ static void run_dex2oat(int zip_fd, int oat_fd, int input_vdex_fd, int output_vd
                dex2oat_large_app_threshold);
    }

    static const char* DEX2OAT_BIN = "/system/bin/dex2oat";
    // If the runtime was requested to use libartd.so, we'll run dex2oatd, otherwise dex2oat.
    const char* dex2oat_bin = is_debug_runtime() ? "/system/bin/dex2oatd" : "/system/bin/dex2oat";

    static const char* RUNTIME_ARG = "--runtime-arg";

@@ -376,7 +382,7 @@ static void run_dex2oat(int zip_fd, int oat_fd, int input_vdex_fd, int output_vd
    }


    ALOGV("Running %s in=%s out=%s\n", DEX2OAT_BIN, relative_input_file_name, output_file_name);
    ALOGV("Running %s in=%s out=%s\n", dex2oat_bin, relative_input_file_name, output_file_name);

    const char* argv[9  // program name, mandatory arguments and the final NULL
                     + (have_dex2oat_isa_variant ? 1 : 0)
@@ -397,7 +403,7 @@ static void run_dex2oat(int zip_fd, int oat_fd, int input_vdex_fd, int output_vd
                     + (has_base_dir ? 1 : 0)
                     + (have_dex2oat_large_app_threshold ? 1 : 0)];
    int i = 0;
    argv[i++] = DEX2OAT_BIN;
    argv[i++] = dex2oat_bin;
    argv[i++] = zip_fd_arg;
    argv[i++] = zip_location_arg;
    argv[i++] = input_vdex_fd_arg;
@@ -463,8 +469,8 @@ static void run_dex2oat(int zip_fd, int oat_fd, int input_vdex_fd, int output_vd
    // Do not add after dex2oat_flags, they should override others for debugging.
    argv[i] = NULL;

    execv(DEX2OAT_BIN, (char * const *)argv);
    ALOGE("execv(%s) failed: %s\n", DEX2OAT_BIN, strerror(errno));
    execv(dex2oat_bin, (char * const *)argv);
    ALOGE("execv(%s) failed: %s\n", dex2oat_bin, strerror(errno));
}

/*
@@ -643,7 +649,7 @@ static constexpr int PROFMAN_BIN_RETURN_CODE_ERROR_LOCKING = 4;
static void run_profman_merge(const std::vector<unique_fd>& profiles_fd,
        const unique_fd& reference_profile_fd) {
    static const size_t MAX_INT_LEN = 32;
    static const char* PROFMAN_BIN = "/system/bin/profman";
    const char* profman_bin = is_debug_runtime() ? "/system/bin/profmand" : "/system/bin/profman";

    std::vector<std::string> profile_args(profiles_fd.size());
    char profile_buf[strlen("--profile-file-fd=") + MAX_INT_LEN];
@@ -657,7 +663,7 @@ static void run_profman_merge(const std::vector<unique_fd>& profiles_fd,
    // program name, reference profile fd, the final NULL and the profile fds
    const char* argv[3 + profiles_fd.size()];
    int i = 0;
    argv[i++] = PROFMAN_BIN;
    argv[i++] = profman_bin;
    argv[i++] = reference_profile_arg;
    for (size_t k = 0; k < profile_args.size(); k++) {
        argv[i++] = profile_args[k].c_str();
@@ -665,8 +671,8 @@ static void run_profman_merge(const std::vector<unique_fd>& profiles_fd,
    // Do not add after dex2oat_flags, they should override others for debugging.
    argv[i] = NULL;

    execv(PROFMAN_BIN, (char * const *)argv);
    ALOGE("execv(%s) failed: %s\n", PROFMAN_BIN, strerror(errno));
    execv(profman_bin, (char * const *)argv);
    ALOGE("execv(%s) failed: %s\n", profman_bin, strerror(errno));
    exit(68);   /* only get here on exec failure */
}

@@ -1364,7 +1370,10 @@ void update_out_oat_access_times(const char* apk_path, const char* out_oat_path)
// the profile has changed.
static void exec_dexoptanalyzer(const std::string& dex_file, const std::string& instruction_set,
        const std::string& compiler_filter, bool profile_was_updated, bool downgrade) {
    static const char* DEXOPTANALYZER_BIN = "/system/bin/dexoptanalyzer";
    const char* dexoptanalyzer_bin =
            is_debug_runtime()
                    ? "/system/bin/dexoptanalyzerd"
                    : "/system/bin/dexoptanalyzer";
    static const unsigned int MAX_INSTRUCTION_SET_LEN = 7;

    if (instruction_set.size() >= MAX_INSTRUCTION_SET_LEN) {
@@ -1385,7 +1394,7 @@ static void exec_dexoptanalyzer(const std::string& dex_file, const std::string&
        (downgrade ? 1 : 0);
    const char* argv[argc];
    int i = 0;
    argv[i++] = DEXOPTANALYZER_BIN;
    argv[i++] = dexoptanalyzer_bin;
    argv[i++] = dex_file_arg.c_str();
    argv[i++] = isa_arg.c_str();
    argv[i++] = compiler_filter_arg.c_str();
@@ -1397,8 +1406,8 @@ static void exec_dexoptanalyzer(const std::string& dex_file, const std::string&
    }
    argv[i] = NULL;

    execv(DEXOPTANALYZER_BIN, (char * const *)argv);
    ALOGE("execv(%s) failed: %s\n", DEXOPTANALYZER_BIN, strerror(errno));
    execv(dexoptanalyzer_bin, (char * const *)argv);
    ALOGE("execv(%s) failed: %s\n", dexoptanalyzer_bin, strerror(errno));
}

// Prepares the oat dir for the secondary dex files.