summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Dmitrii Ishcheikin <ishcheikin@google.com> 2024-07-08 22:24:19 +0000
committer Dmitrii Ishcheikin <ishcheikin@google.com> 2024-07-09 13:54:51 +0000
commita8e94b7dda00ced868f6c5e91af5234eea332b00 (patch)
tree73b1f5c3585660d4751d7040390f5d630f32954b
parent801c4c9d8c55be2bd8ee9c3dcc6c20ab0cf4c5f7 (diff)
Revert "Add support for multiple dirty-image-objects files"
This reverts commit bfb7f772d13b28d4cde86692b92547dddd06c5d2. Reason for revert: b/351683797 unexpected change in dex2oat output Change-Id: I453ebd157f87878e6a91dbd4fee1c960585398ba
-rw-r--r--dex2oat/dex2oat.cc45
-rw-r--r--dex2oat/dex2oat_image_test.cc22
-rw-r--r--dex2oat/dex2oat_options.cc4
-rw-r--r--dex2oat/dex2oat_options.def4
-rw-r--r--odrefresh/odrefresh.cc28
-rw-r--r--odrefresh/odrefresh_test.cc57
6 files changed, 42 insertions, 118 deletions
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index f1d70fb7ff..076461c267 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -530,6 +530,8 @@ class Dex2Oat final {
image_base_(0U),
image_storage_mode_(ImageHeader::kStorageModeUncompressed),
passes_to_run_filename_(nullptr),
+ dirty_image_objects_filename_(nullptr),
+ dirty_image_objects_fd_(-1),
is_host_(false),
elf_writers_(),
oat_writers_(),
@@ -842,7 +844,7 @@ class Dex2Oat final {
}
}
- if (!dirty_image_objects_filenames_.empty() && !dirty_image_objects_fds_.empty()) {
+ if (dirty_image_objects_filename_ != nullptr && dirty_image_objects_fd_ != -1) {
Usage("--dirty-image-objects and --dirty-image-objects-fd should not be both specified");
}
@@ -1108,8 +1110,8 @@ class Dex2Oat final {
AssignIfExists(args, M::AppImageFileFd, &app_image_fd_);
AssignIfExists(args, M::NoInlineFrom, &no_inline_from_string_);
AssignIfExists(args, M::ClasspathDir, &classpath_dir_);
- AssignIfExists(args, M::DirtyImageObjects, &dirty_image_objects_filenames_);
- AssignIfExists(args, M::DirtyImageObjectsFd, &dirty_image_objects_fds_);
+ AssignIfExists(args, M::DirtyImageObjects, &dirty_image_objects_filename_);
+ AssignIfExists(args, M::DirtyImageObjectsFd, &dirty_image_objects_fd_);
AssignIfExists(args, M::ImageFormat, &image_storage_mode_);
AssignIfExists(args, M::CompilationReason, &compilation_reason_);
AssignTrueIfExists(args, M::CheckLinkageConditions, &check_linkage_conditions_);
@@ -2527,26 +2529,23 @@ class Dex2Oat final {
}
bool PrepareDirtyObjects() {
- if (!dirty_image_objects_fds_.empty()) {
- dirty_image_objects_ = std::make_unique<std::vector<std::string>>();
- for (int fd : dirty_image_objects_fds_) {
- if (!ReadCommentedInputFromFd(fd, nullptr, dirty_image_objects_.get())) {
- LOG(ERROR) << "Failed to create list of dirty objects from fd " << fd;
- return false;
- }
- }
+ if (dirty_image_objects_fd_ != -1) {
+ dirty_image_objects_ =
+ ReadCommentedInputFromFd<std::vector<std::string>>(dirty_image_objects_fd_, nullptr);
// Close since we won't need it again.
- for (int fd : dirty_image_objects_fds_) {
- close(fd);
+ close(dirty_image_objects_fd_);
+ dirty_image_objects_fd_ = -1;
+ if (dirty_image_objects_ == nullptr) {
+ LOG(ERROR) << "Failed to create list of dirty objects from fd " << dirty_image_objects_fd_;
+ return false;
}
- dirty_image_objects_fds_.clear();
- } else {
- dirty_image_objects_ = std::make_unique<std::vector<std::string>>();
- for (const std::string& file : preloaded_classes_files_) {
- if (!ReadCommentedInputFromFile(file.c_str(), nullptr, dirty_image_objects_.get())) {
- LOG(ERROR) << "Failed to create list of dirty objects from '" << file << "'";
- return false;
- }
+ } else if (dirty_image_objects_filename_ != nullptr) {
+ dirty_image_objects_ = ReadCommentedInputFromFile<std::vector<std::string>>(
+ dirty_image_objects_filename_, nullptr);
+ if (dirty_image_objects_ == nullptr) {
+ LOG(ERROR) << "Failed to create list of dirty objects from '"
+ << dirty_image_objects_filename_ << "'";
+ return false;
}
}
return true;
@@ -2948,8 +2947,8 @@ class Dex2Oat final {
uintptr_t image_base_;
ImageHeader::StorageMode image_storage_mode_;
const char* passes_to_run_filename_;
- std::vector<std::string> dirty_image_objects_filenames_;
- std::vector<int> dirty_image_objects_fds_;
+ const char* dirty_image_objects_filename_;
+ int dirty_image_objects_fd_;
std::unique_ptr<std::vector<std::string>> dirty_image_objects_;
std::unique_ptr<std::vector<std::string>> passes_to_run_;
bool is_host_;
diff --git a/dex2oat/dex2oat_image_test.cc b/dex2oat/dex2oat_image_test.cc
index 34ca3e4d84..b62dd832fc 100644
--- a/dex2oat/dex2oat_image_test.cc
+++ b/dex2oat/dex2oat_image_test.cc
@@ -246,28 +246,6 @@ TEST_F(Dex2oatImageTest, TestModesAndFilters) {
classes.Close();
std::cout << "Dirty image object sizes " << image_classes_sizes << std::endl;
}
- // Test multiple dirty image objects.
- {
- std::array<ScratchFile, 2> files;
- int idx = 0;
- VisitDexes(
- libcore_dexes_array,
- VoidFunctor(),
- [&](TypeReference ref) {
- WriteLine(files[idx].GetFile(), ref.dex_file->PrettyType(ref.TypeIndex()));
- idx = (idx + 1) % files.size();
- },
- /*method_frequency=*/1u,
- /*class_frequency=*/1u);
- ImageSizes image_classes_sizes =
- CompileImageAndGetSizes(dex_files,
- {"--dirty-image-objects=" + files[0].GetFilename(),
- "--dirty-image-objects=" + files[1].GetFilename()});
- for (ScratchFile& file : files) {
- file.Close();
- }
- std::cout << "Dirty image object sizes " << image_classes_sizes << std::endl;
- }
}
TEST_F(Dex2oatImageTest, TestExtension) {
diff --git a/dex2oat/dex2oat_options.cc b/dex2oat/dex2oat_options.cc
index 635961e5f8..34a72f084e 100644
--- a/dex2oat/dex2oat_options.cc
+++ b/dex2oat/dex2oat_options.cc
@@ -194,12 +194,12 @@ static void AddImageMappings(Builder& builder) {
"images.")
.IntoKey(M::MultiImage)
.Define("--dirty-image-objects=_")
- .WithType<std::vector<std::string>>().AppendValues()
+ .WithType<std::string>()
.WithHelp("list of known dirty objects in the image. The image writer will group them"
" together")
.IntoKey(M::DirtyImageObjects)
.Define("--dirty-image-objects-fd=_")
- .WithType<std::vector<int>>().AppendValues()
+ .WithType<int>()
.WithHelp("Specify a file descriptor for reading the list of known dirty objects in\n"
"the image. The image writer will group them together")
.IntoKey(M::DirtyImageObjectsFd)
diff --git a/dex2oat/dex2oat_options.def b/dex2oat/dex2oat_options.def
index 10c4eccfa0..7cf9d023b7 100644
--- a/dex2oat/dex2oat_options.def
+++ b/dex2oat/dex2oat_options.def
@@ -89,8 +89,8 @@ DEX2OAT_OPTIONS_KEY (std::string, InvocationFile)
DEX2OAT_OPTIONS_KEY (std::string, ClassLoaderContext)
DEX2OAT_OPTIONS_KEY (std::string, ClassLoaderContextFds)
DEX2OAT_OPTIONS_KEY (std::string, StoredClassLoaderContext)
-DEX2OAT_OPTIONS_KEY (std::vector<std::string>, DirtyImageObjects)
-DEX2OAT_OPTIONS_KEY (std::vector<int>, DirtyImageObjectsFd)
+DEX2OAT_OPTIONS_KEY (std::string, DirtyImageObjects)
+DEX2OAT_OPTIONS_KEY (int, DirtyImageObjectsFd)
DEX2OAT_OPTIONS_KEY (std::string, UpdatableBcpPackagesFile)
DEX2OAT_OPTIONS_KEY (int, UpdatableBcpPackagesFd)
DEX2OAT_OPTIONS_KEY (std::vector<std::string>, RuntimeOptions)
diff --git a/odrefresh/odrefresh.cc b/odrefresh/odrefresh.cc
index 733e22f99d..6a09a88a4e 100644
--- a/odrefresh/odrefresh.cc
+++ b/odrefresh/odrefresh.cc
@@ -1872,24 +1872,22 @@ OnDeviceRefresh::RunDex2oatForBootClasspath(const std::string& staging_dir,
args.Add(StringPrintf("--base=0x%08x", ART_BASE_ADDRESS));
- for (const std::string& prefix : {GetAndroidRoot(), GetArtRoot()}) {
- std::string dirty_image_objects_file = prefix + "/etc/dirty-image-objects";
- std::unique_ptr<File> file(OS::OpenFileForReading(dirty_image_objects_file.c_str()));
- if (file != nullptr) {
- args.Add("--dirty-image-objects-fd=%d", file->Fd());
- readonly_files_raii.push_back(std::move(file));
- } else if (errno == ENOENT) {
- LOG(WARNING) << ART_FORMAT("Missing dirty objects file '{}'", dirty_image_objects_file);
- } else {
- return CompilationResult::Error(OdrMetrics::Status::kIoError,
- ART_FORMAT("Failed to open dirty objects file '{}': {}",
- dirty_image_objects_file,
- strerror(errno)));
- }
+ std::string dirty_image_objects_file(GetAndroidRoot() + "/etc/dirty-image-objects");
+ std::unique_ptr<File> file(OS::OpenFileForReading(dirty_image_objects_file.c_str()));
+ if (file != nullptr) {
+ args.Add("--dirty-image-objects-fd=%d", file->Fd());
+ readonly_files_raii.push_back(std::move(file));
+ } else if (errno == ENOENT) {
+ LOG(WARNING) << ART_FORMAT("Missing dirty objects file '{}'", dirty_image_objects_file);
+ } else {
+ return CompilationResult::Error(OdrMetrics::Status::kIoError,
+ ART_FORMAT("Failed to open dirty objects file '{}': {}",
+ dirty_image_objects_file,
+ strerror(errno)));
}
std::string preloaded_classes_file(GetAndroidRoot() + "/etc/preloaded-classes");
- std::unique_ptr<File> file(OS::OpenFileForReading(preloaded_classes_file.c_str()));
+ file.reset(OS::OpenFileForReading(preloaded_classes_file.c_str()));
if (file != nullptr) {
args.Add("--preloaded-classes-fds=%d", file->Fd());
readonly_files_raii.push_back(std::move(file));
diff --git a/odrefresh/odrefresh_test.cc b/odrefresh/odrefresh_test.cc
index f44c3211c3..424b606ff8 100644
--- a/odrefresh/odrefresh_test.cc
+++ b/odrefresh/odrefresh_test.cc
@@ -177,9 +177,9 @@ class OdRefreshTest : public CommonArtTest {
CreateEmptyFile(dirty_image_objects_file_);
preloaded_classes_file_ = system_etc_dir + "/preloaded-classes";
CreateEmptyFile(preloaded_classes_file_);
- art_etc_dir_ = android_art_root_path + "/etc";
- ASSERT_TRUE(EnsureDirectoryExists(art_etc_dir_));
- art_profile_ = art_etc_dir_ + "/boot-image.prof";
+ std::string art_etc_dir = android_art_root_path + "/etc";
+ ASSERT_TRUE(EnsureDirectoryExists(art_etc_dir));
+ art_profile_ = art_etc_dir + "/boot-image.prof";
CreateEmptyFile(art_profile_);
framework_dir_ = android_root_path + "/framework";
@@ -267,7 +267,6 @@ class OdRefreshTest : public CommonArtTest {
std::string services_foo_jar_;
std::string services_bar_jar_;
std::string dalvik_cache_dir_;
- std::string art_etc_dir_;
std::string framework_dir_;
std::string framework_profile_;
std::string art_profile_;
@@ -1012,55 +1011,5 @@ TEST_F(OdRefreshTest, OnlyBootImages) {
ExitCode::kCompilationSuccess);
}
-TEST_F(OdRefreshTest, DirtyImageObjects) {
- // Primary.
- EXPECT_CALL(*mock_exec_utils_,
- DoExecAndReturnCode(AllOf(
- Contains(Flag("--dirty-image-objects-fd=", FdOf(dirty_image_objects_file_))),
- Contains(Flag("--dex-file=", core_oj_jar_)))))
- .WillOnce(Return(0));
-
- // Mainline extension.
- EXPECT_CALL(*mock_exec_utils_,
- DoExecAndReturnCode(AllOf(Contains(Flag("--dex-file=", conscrypt_jar_)))))
- .WillOnce(Return(0));
-
- EXPECT_EQ(odrefresh_->Compile(
- *metrics_,
- CompilationOptions{
- .boot_images_to_generate_for_isas{
- {InstructionSet::kX86_64,
- {.primary_boot_image = true, .boot_image_mainline_extension = true}}},
- }),
- ExitCode::kCompilationSuccess);
-}
-
-TEST_F(OdRefreshTest, DirtyImageObjectsMultipleFiles) {
- std::string art_dirty_image_objects = art_etc_dir_ + "/dirty-image-objects";
- auto file = ScopedCreateEmptyFile(art_dirty_image_objects);
-
- // Primary.
- EXPECT_CALL(*mock_exec_utils_,
- DoExecAndReturnCode(AllOf(
- Contains(Flag("--dirty-image-objects-fd=", FdOf(dirty_image_objects_file_))),
- Contains(Flag("--dirty-image-objects-fd=", FdOf(art_dirty_image_objects))),
- Contains(Flag("--dex-file=", core_oj_jar_)))))
- .WillOnce(Return(0));
-
- // Mainline extension.
- EXPECT_CALL(*mock_exec_utils_,
- DoExecAndReturnCode(AllOf(Contains(Flag("--dex-file=", conscrypt_jar_)))))
- .WillOnce(Return(0));
-
- EXPECT_EQ(odrefresh_->Compile(
- *metrics_,
- CompilationOptions{
- .boot_images_to_generate_for_isas{
- {InstructionSet::kX86_64,
- {.primary_boot_image = true, .boot_image_mainline_extension = true}}},
- }),
- ExitCode::kCompilationSuccess);
-}
-
} // namespace odrefresh
} // namespace art