Add a dex2oat flag to optimize apps for JIT Zygote environment.
This change allows us to control the boot image to use within the ART
module.
It is a no-op change for now as the behavior of the new flag mirrors the
current behavior of installd.
Also: allow missing primary boot image for app compilation.
Bug: 203492478
Test: atest art_standalone_dex2oat_tests
Test: manual -
1. Build a system image and flash it into a device.
2. adb shell setprop dalvik.vm.profilebootclasspath true
3. adb shell pm compile -m speed -f com.android.htmlviewer
4. See dex2oat running with the primary boot image only
(http://gpaste/5031926999023616)
Change-Id: I760808302d4760330befc271c9312018ed1671ef
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 16e71e5..0a7cd8b 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -1174,6 +1174,13 @@
LOG(WARNING) << "Option --updatable-bcp-packages-fd is deprecated and no longer takes effect";
}
+ if (args.Exists(M::ForceJitZygote)) {
+ if (!parser_options->boot_image_filename.empty()) {
+ Usage("Option --boot-image and --force-jit-zygote cannot be specified together");
+ }
+ parser_options->boot_image_filename = "boot.art:/nonx/boot-framework.art";
+ }
+
// If we have a profile, change the default compiler filter to speed-profile
// before reading compiler options.
static_assert(CompilerFilter::kDefaultCompilerFilter == CompilerFilter::kSpeed);
@@ -1556,12 +1563,6 @@
LOG(ERROR) << "Missing required boot image(s) for boot image extension.";
return dex2oat::ReturnCode::kOther;
}
- } else {
- // Check that we loaded at least the primary boot image for app compilation.
- if (runtime_->GetHeap()->GetBootImageSpaces().empty()) {
- LOG(ERROR) << "Missing primary boot image for app compilation.";
- return dex2oat::ReturnCode::kOther;
- }
}
if (!compilation_reason_.empty()) {
diff --git a/dex2oat/dex2oat_options.cc b/dex2oat/dex2oat_options.cc
index 8d5296b..2e5caf3 100644
--- a/dex2oat/dex2oat_options.cc
+++ b/dex2oat/dex2oat_options.cc
@@ -430,7 +430,10 @@
.Define("--apex-versions=_")
.WithType<std::string>()
.WithHelp("Versions of apexes in the boot classpath, separated by '/'")
- .IntoKey(M::ApexVersions);
+ .IntoKey(M::ApexVersions)
+ .Define("--force-jit-zygote")
+ .WithHelp("Optimizes the app to be executed in an environment that uses JIT Zygote.")
+ .IntoKey(M::ForceJitZygote);
AddCompilerOptionsArgumentParserOptions<Dex2oatArgumentMap>(*parser_builder);
diff --git a/dex2oat/dex2oat_options.def b/dex2oat/dex2oat_options.def
index f153ddf..d878088 100644
--- a/dex2oat/dex2oat_options.def
+++ b/dex2oat/dex2oat_options.def
@@ -61,6 +61,7 @@
DEX2OAT_OPTIONS_KEY (std::string, Passes)
DEX2OAT_OPTIONS_KEY (std::string, Base) // TODO: Hex string parsing.
DEX2OAT_OPTIONS_KEY (std::string, BootImage)
+DEX2OAT_OPTIONS_KEY (Unit, ForceJitZygote)
DEX2OAT_OPTIONS_KEY (std::string, AndroidRoot)
DEX2OAT_OPTIONS_KEY (InstructionSet, TargetInstructionSet)
DEX2OAT_OPTIONS_KEY (std::string, TargetInstructionSetVariant)
diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc
index ab5f8c6..083e1c9 100644
--- a/dex2oat/dex2oat_test.cc
+++ b/dex2oat/dex2oat_test.cc
@@ -1501,17 +1501,13 @@
TEST_F(Dex2oatTest, MissingBootImageTest) {
std::string out_dir = GetScratchDir();
const std::string base_oat_name = out_dir + "/base.oat";
- std::string error_msg;
- int status = GenerateOdexForTestWithStatus(
- { GetTestDexFileName("MainUncompressedAligned") },
+ // The compilation should succeed even without the boot image.
+ ASSERT_TRUE(GenerateOdexForTest(
+ {GetTestDexFileName("MainUncompressedAligned")},
base_oat_name,
CompilerFilter::Filter::kVerify,
- &error_msg,
// Note: Extra options go last and the second `--boot-image` option overrides the first.
- { "--boot-image=/nonx/boot.art" });
- // Expect to fail with code 1 and not SIGSEGV or SIGABRT.
- ASSERT_TRUE(WIFEXITED(status));
- ASSERT_EQ(WEXITSTATUS(status), 1) << error_msg;
+ {"--boot-image=/nonx/boot.art"}));
}
TEST_F(Dex2oatTest, EmptyUncompressedDexTest) {