Make it easier to change the location of the primary boot image.
This CL adds a function `art::GetPrebuiltPrimaryBootImageDir`, which
returns the location of the primary boot image. Other code should use
this function to find the primary boot image. In that way, changing the
location of the primary boot image only requires changing this function.
Also:
- Use the ART boot profile in art_common_test as a fallback when the
primary boot image cannot be used.
- Update the `-Xforcejitzygote` flag not to assume that the primary
boot image exists in the ART APEX.
Bug: 211973309
Test: All ART test suites.
Test: -
1. Change `art::GetPrebuiltPrimaryBootImageDir` to returning a path on
/system.
2. Make the corresponding change in the build system.
3. Run all ART test suites again.
Change-Id: Id34d7eec534733d932e520fa3b503488c0dc513a
diff --git a/libartbase/base/common_art_test.cc b/libartbase/base/common_art_test.cc
index 593ea25..b0f1c6c 100644
--- a/libartbase/base/common_art_test.cc
+++ b/libartbase/base/common_art_test.cc
@@ -559,15 +559,12 @@
}
std::string CommonArtTestImpl::GetImageDirectory() {
- std::string path;
if (IsHost()) {
const char* host_dir = getenv("ANDROID_HOST_OUT");
CHECK(host_dir != nullptr);
- path = std::string(host_dir) + "/apex/art_boot_images";
- } else {
- path = std::string(kAndroidArtApexDefaultPath);
+ return std::string(host_dir) + "/apex/art_boot_images/javalib";
}
- return path + "/javalib";
+ return GetPrebuiltPrimaryBootImageDir();
}
std::string CommonArtTestImpl::GetCoreFileLocation(const char* suffix) {
diff --git a/libartbase/base/file_utils.cc b/libartbase/base/file_utils.cc
index 07402a3..a62d6de 100644
--- a/libartbase/base/file_utils.cc
+++ b/libartbase/base/file_utils.cc
@@ -283,9 +283,12 @@
return GetAndroidDir(kArtApexDataEnvVar, kArtApexDataDefaultPath, /*must_exist=*/false);
}
+std::string GetPrebuiltPrimaryBootImageDir() {
+ return StringPrintf("%s/javalib", kAndroidArtApexDefaultPath);
+}
+
std::string GetDefaultBootImageLocation(const std::string& android_root,
bool deny_art_apex_data_files) {
- constexpr static const char* kJavalibBootArt = "javalib/boot.art";
constexpr static const char* kEtcBootImageProf = "etc/boot-image.prof";
// If an update for the ART module has been been installed, a single boot image for the entire
@@ -307,12 +310,12 @@
}
}
// Boot image consists of two parts:
- // - the primary boot image in the ART APEX (contains the Core Libraries)
- // - the boot image extensions (contains framework libraries) on the system partition
- // TODO(b/211973309): Update this once the primary boot image is moved.
- return StringPrintf("%s/%s:%s/framework/boot-framework.art!%s/%s",
+ // - the primary boot image (contains the Core Libraries)
+ // - the boot image extensions (contains framework libraries)
+ return StringPrintf("%s/boot.art!%s/%s:%s/framework/boot-framework.art!%s/%s",
+ GetPrebuiltPrimaryBootImageDir().c_str(),
kAndroidArtApexDefaultPath,
- kJavalibBootArt,
+ kEtcBootImageProf,
android_root.c_str(),
android_root.c_str(),
kEtcBootImageProf);
diff --git a/libartbase/base/file_utils.h b/libartbase/base/file_utils.h
index 97abc73..c1c45bc 100644
--- a/libartbase/base/file_utils.h
+++ b/libartbase/base/file_utils.h
@@ -69,6 +69,10 @@
// Find $ART_APEX_DATA, /data/misc/apexdata/com.android.art, or abort.
std::string GetArtApexData();
+// Returns the directory that contains the prebuilt version of the primary boot image (i.e., the one
+// generated at build time).
+std::string GetPrebuiltPrimaryBootImageDir();
+
// Returns the default boot image location (ANDROID_ROOT/framework/boot.art).
// Returns an empty string if ANDROID_ROOT is not set.
std::string GetDefaultBootImageLocation(std::string* error_msg);
diff --git a/odrefresh/odrefresh.cc b/odrefresh/odrefresh.cc
index 857e8ba..f573134 100644
--- a/odrefresh/odrefresh.cc
+++ b/odrefresh/odrefresh.cc
@@ -539,8 +539,6 @@
}
}
-std::string GetArtBootImageDir() { return GetArtRoot() + "/javalib"; }
-
std::string GetSystemBootImageDir() { return GetAndroidRoot() + "/framework"; }
} // namespace
@@ -726,9 +724,8 @@
std::string OnDeviceRefresh::GetBootImage(bool on_system) const {
if (on_system) {
- // Typically "/apex/com.android.art/javalib/boot.art".
- // TODO(b/211973309): Update this once the primary boot image is moved.
- return GetArtBootImageDir() + "/" + kFirstBootImageBasename;
+ // Typically "/system/framework/boot.art".
+ return GetPrebuiltPrimaryBootImageDir() + "/" + kFirstBootImageBasename;
} else {
// Typically "/data/misc/apexdata/com.android.art/dalvik-cache/boot.art".
return config_.GetArtifactDirectory() + "/" + kFirstBootImageBasename;
diff --git a/odrefresh/odrefresh_test.cc b/odrefresh/odrefresh_test.cc
index 370fd0d..60abcd5 100644
--- a/odrefresh/odrefresh_test.cc
+++ b/odrefresh/odrefresh_test.cc
@@ -516,17 +516,17 @@
auto file3 = ScopedCreateEmptyFile(artifacts.OatPath());
EXPECT_CALL(*mock_odr_dexopt,
- DoDexoptSystemServer(
- AllOf(Field(&DexoptSystemServerArgs::bootImage,
- Eq(android::base::StringPrintf("%s/boot.art:%s/boot-framework.art",
- art_javalib_dir_.c_str(),
- framework_dir_.c_str()))),
- Field(&DexoptSystemServerArgs::bootClasspathImageFds,
- Contains(FdOf(artifacts.ImagePath()))),
- Field(&DexoptSystemServerArgs::bootClasspathVdexFds,
- Contains(FdOf(artifacts.VdexPath()))),
- Field(&DexoptSystemServerArgs::bootClasspathOatFds,
- Contains(FdOf(artifacts.OatPath()))))))
+ DoDexoptSystemServer(AllOf(
+ Field(&DexoptSystemServerArgs::bootImage,
+ Eq(android::base::StringPrintf("%s/boot.art:%s/boot-framework.art",
+ GetPrebuiltPrimaryBootImageDir().c_str(),
+ framework_dir_.c_str()))),
+ Field(&DexoptSystemServerArgs::bootClasspathImageFds,
+ Contains(FdOf(artifacts.ImagePath()))),
+ Field(&DexoptSystemServerArgs::bootClasspathVdexFds,
+ Contains(FdOf(artifacts.VdexPath()))),
+ Field(&DexoptSystemServerArgs::bootClasspathOatFds,
+ Contains(FdOf(artifacts.OatPath()))))))
.Times(odrefresh->AllSystemServerJars().size())
.WillRepeatedly(Return(0));
EXPECT_EQ(
diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc
index f949759..c8cd151 100644
--- a/runtime/common_runtime_test.cc
+++ b/runtime/common_runtime_test.cc
@@ -99,7 +99,13 @@
options.push_back(std::make_pair(boot_class_path_string, nullptr));
options.push_back(std::make_pair(boot_class_path_locations_string, nullptr));
if (use_boot_image_) {
- options.emplace_back("-Ximage:" + GetImageLocation(), nullptr);
+ std::string image_location = GetImageLocation();
+ if (!IsHost()) {
+ // On target, the boot image can be outdated due to an ART update. In such case, the profile
+ // will be used for generating a boot image in memory.
+ image_location += "!/apex/com.android.art/etc/boot-image.prof";
+ }
+ options.emplace_back("-Ximage:" + image_location, nullptr);
}
options.push_back(std::make_pair("-Xcheck:jni", nullptr));
options.push_back(std::make_pair(min_heap_string, nullptr));
diff --git a/runtime/parsed_options.cc b/runtime/parsed_options.cc
index f8bad3f..4d24482 100644
--- a/runtime/parsed_options.cc
+++ b/runtime/parsed_options.cc
@@ -731,9 +731,10 @@
Usage("-Ximage and -Xforcejitzygote cannot be specified together\n");
Exit(0);
}
- args.Set(
- M::Image,
- ParseStringList<':'>{{"boot.art", "/nonx/boot-framework.art!/system/etc/boot-image.prof"}});
+ // If `boot.art` exists in the ART APEX, it will be used. Otherwise, Everything will be JITed.
+ args.Set(M::Image,
+ ParseStringList<':'>{{"boot.art!/apex/com.android.art/etc/boot-image.prof",
+ "/nonx/boot-framework.art!/system/etc/boot-image.prof"}});
}
if (!args.Exists(M::CompilerCallbacksPtr) && !args.Exists(M::Image)) {
diff --git a/test/dexpreopt/dexpreopt_test.cc b/test/dexpreopt/dexpreopt_test.cc
index 5315937..55593ea 100644
--- a/test/dexpreopt/dexpreopt_test.cc
+++ b/test/dexpreopt/dexpreopt_test.cc
@@ -106,8 +106,7 @@
const std::string& jar = jars[i];
std::string basename =
i == 0 ? "boot.oat" : "boot-" + ReplaceFileExtension(android::base::Basename(jar), "oat");
- // TODO(b/211973309): Update this once the primary boot image is moved.
- std::string dir = android::base::StartsWith(jar, art_root) ? art_root + "/javalib" :
+ std::string dir = android::base::StartsWith(jar, art_root) ? GetPrebuiltPrimaryBootImageDir() :
android_root + "/framework";
std::string oat_file = android::base::StringPrintf(
"%s/%s/%s", dir.c_str(), GetInstructionSetString(isa), basename.c_str());