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

Commit 640a0fa4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Update JIT Zygote image option for installd and otapreopt." am:...

Merge "Update JIT Zygote image option for installd and otapreopt." am: 9a869c9c am: 1f6dbdcf am: 2556fc0a am: fcf748db

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1931837

Change-Id: I50aea9bb77f184f18a69b9ea784f269b6d2c373a
parents 1b2c42cd fcf748db
Loading
Loading
Loading
Loading
+4 −13
Original line number Diff line number Diff line
@@ -140,8 +140,8 @@ class OTAPreoptService {

        PrepareEnvironmentVariables();

        if (!EnsureBootImageAndDalvikCache()) {
            LOG(ERROR) << "Bad boot image.";
        if (!EnsureDalvikCache()) {
            LOG(ERROR) << "Bad dalvik cache.";
            return 5;
        }

@@ -349,8 +349,8 @@ private:
        }
    }

    // Ensure that we have the right boot image and cache file structures.
    bool EnsureBootImageAndDalvikCache() const {
    // Ensure that we have the right cache file structures.
    bool EnsureDalvikCache() const {
        if (parameters_.instruction_set == nullptr) {
            LOG(ERROR) << "Instruction set missing.";
            return false;
@@ -376,15 +376,6 @@ private:
            }
        }

        // Check whether we have a boot image.
        // TODO: check that the files are correct wrt/ jars.
        std::string preopted_boot_art_path =
            StringPrintf("/apex/com.android.art/javalib/%s/boot.art", isa);
        if (access(preopted_boot_art_path.c_str(), F_OK) != 0) {
            PLOG(ERROR) << "Bad access() to " << preopted_boot_art_path;
            return false;
        }

        return true;
    }

+8 −12
Original line number Diff line number Diff line
@@ -50,10 +50,6 @@ static constexpr bool kMinidebugInfoSystemPropertyDefault = false;
static constexpr const char* kMinidebugDex2oatFlag = "--generate-mini-debug-info";
static constexpr const char* kDisableCompactDexFlag = "--compact-dex-level=none";

// Location of the JIT Zygote image.
static const char* kJitZygoteImage =
    "boot.art:/nonx/boot-framework.art!/system/etc/boot-image.prof";

std::vector<std::string> SplitBySpaces(const std::string& str) {
    if (str.empty()) {
        return {};
@@ -84,9 +80,9 @@ void RunDex2Oat::Initialize(const UniqueFile& output_oat,
                            int target_sdk_version,
                            bool enable_hidden_api_checks,
                            bool generate_compact_dex,
                            bool use_jitzygote_image,
                            bool use_jitzygote,
                            const char* compilation_reason) {
    PrepareBootImageFlags(use_jitzygote_image);
    PrepareBootImageFlags(use_jitzygote);

    PrepareInputFileFlags(output_oat, output_vdex, output_image, input_dex, input_vdex,
                          dex_metadata, profile, swap_fd, class_loader_context,
@@ -112,14 +108,14 @@ void RunDex2Oat::Initialize(const UniqueFile& output_oat,

RunDex2Oat::~RunDex2Oat() {}

void RunDex2Oat::PrepareBootImageFlags(bool use_jitzygote_image) {
    std::string boot_image;
    if (use_jitzygote_image) {
        boot_image = StringPrintf("--boot-image=%s", kJitZygoteImage);
void RunDex2Oat::PrepareBootImageFlags(bool use_jitzygote) {
    if (use_jitzygote) {
        // Don't pass a boot image because JIT Zygote should decide which image to use. Typically,
        // it does not use any boot image on disk.
        AddArg("--force-jit-zygote");
    } else {
        boot_image = MapPropertyToArg("dalvik.vm.boot-image", "--boot-image=%s");
        AddArg(MapPropertyToArg("dalvik.vm.boot-image", "--boot-image=%s"));
    }
    AddArg(boot_image);
}

void RunDex2Oat::PrepareInputFileFlags(const UniqueFile& output_oat,
+2 −2
Original line number Diff line number Diff line
@@ -50,13 +50,13 @@ class RunDex2Oat {
                    int target_sdk_version,
                    bool enable_hidden_api_checks,
                    bool generate_compact_dex,
                    bool use_jitzygote_image,
                    bool use_jitzygote,
                    const char* compilation_reason);

    void Exec(int exit_code);

  protected:
    void PrepareBootImageFlags(bool use_jitzygote_image);
    void PrepareBootImageFlags(bool use_jitzygote);
    void PrepareInputFileFlags(const UniqueFile& output_oat,
                               const UniqueFile& output_vdex,
                               const UniqueFile& output_image,
+21 −2
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ class RunDex2OatTest : public testing::Test {
        int target_sdk_version = 0;
        bool enable_hidden_api_checks = false;
        bool generate_compact_dex = true;
        bool use_jitzygote_image = false;
        bool use_jitzygote = false;
        const char* compilation_reason = nullptr;
    };

@@ -175,6 +175,7 @@ class RunDex2OatTest : public testing::Test {
        default_expected_flags_["--swap-fd"] = FLAG_UNUSED;
        default_expected_flags_["--class-loader-context"] = FLAG_UNUSED;
        default_expected_flags_["--class-loader-context-fds"] = FLAG_UNUSED;
        default_expected_flags_["--boot-image"] = FLAG_UNUSED;

        // Arch
        default_expected_flags_["--instruction-set"] = "=arm64";
@@ -190,6 +191,7 @@ class RunDex2OatTest : public testing::Test {
        default_expected_flags_["--max-image-block-size"] = FLAG_UNUSED;
        default_expected_flags_["--very-large-app-threshold"] = FLAG_UNUSED;
        default_expected_flags_["--resolve-startup-const-strings"] = FLAG_UNUSED;
        default_expected_flags_["--force-jit-zygote"] = FLAG_UNUSED;

        // Debug
        default_expected_flags_["--debuggable"] = FLAG_UNUSED;
@@ -256,7 +258,7 @@ class RunDex2OatTest : public testing::Test {
                          args->target_sdk_version,
                          args->enable_hidden_api_checks,
                          args->generate_compact_dex,
                          args->use_jitzygote_image,
                          args->use_jitzygote,
                          args->compilation_reason);
        runner.Exec(/*exit_code=*/ 0);
    }
@@ -557,5 +559,22 @@ TEST_F(RunDex2OatTest, ExtraFlags) {
    VerifyExpectedFlags();
}

TEST_F(RunDex2OatTest, UseJitZygoteImage) {
    auto args = RunDex2OatArgs::MakeDefaultTestArgs();
    args->use_jitzygote = true;
    CallRunDex2Oat(std::move(args));

    SetExpectedFlagUsed("--force-jit-zygote", "");
    VerifyExpectedFlags();
}

TEST_F(RunDex2OatTest, BootImage) {
    setSystemProperty("dalvik.vm.boot-image", "foo.art:bar.art");
    CallRunDex2Oat(RunDex2OatArgs::MakeDefaultTestArgs());

    SetExpectedFlagUsed("--boot-image", "=foo.art:bar.art");
    VerifyExpectedFlags();
}

}  // namespace installd
}  // namespace android