summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSantiago Aboy Solanes <solanes@google.com>2024-04-17 14:33:28 +0100
committerSantiago Aboy Solanes <solanes@google.com>2024-04-18 12:58:45 +0000
commitf3cb22e82075a89171e1f471d6b4ff8b680eac20 (patch)
tree13e3b05c302ca85bccee78b07c6191b575d54131
parentafc444479386645f5f876f10bb1cb0971dd15ad5 (diff)
downloadart-f3cb22e82075a89171e1f471d6b4ff8b680eac20.tar.gz
Add BCP dex file's BSS mappings to boot image extension compiles
Boot image extension BCP contains the dex files too. To have unique entries, we will only add the BCP dex files which are not included already in the dex file list. This allows for speed compiles of boot image extension. Bug: 327361582 Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b with speed compile of boot image extension Test: odrefresh gtests with speed compile of boot image extension Test: Presubmit with speed compile of boot image extension Change-Id: I4a2686fc6ec090b318fd9cf64efcd5fd5e6e3ed9
-rw-r--r--dex2oat/linker/oat_writer.cc31
-rw-r--r--dex2oat/linker/oat_writer.h3
-rw-r--r--runtime/oat/oat.h4
3 files changed, 31 insertions, 7 deletions
diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc
index f1b44a8263..0dbb4bb05b 100644
--- a/dex2oat/linker/oat_writer.cc
+++ b/dex2oat/linker/oat_writer.cc
@@ -2089,13 +2089,24 @@ size_t OatWriter::InitIndexBssMappings(size_t offset) {
oat_dex_files_[i].method_type_bss_mapping_offset_);
}
- if (!(compiler_options_.IsBootImage() || compiler_options_.IsBootImageExtension())) {
+ if (!compiler_options_.IsBootImage()) {
ArrayRef<const DexFile* const> boot_class_path(
Runtime::Current()->GetClassLinker()->GetBootClassPath());
- // We initialize bcp_bss_info for single image and purposively leave it empty for the multi
- // image case.
+ // We initialize bcp_bss_info except for the boot image case.
// Note that we have an early break at the beginning of the method, so `bcp_bss_info_` will also
// be empty in the case of having no mappings at all.
+
+ if (compiler_options_.IsBootImageExtension()) {
+ // For boot image extension, the boot_class_path ends with the compiled dex files. In multi
+ // image, we might have several oat writers so we have to get all of the compiled dex files
+ // and not just the one we are compiling right now. Remove them to have the correct number of
+ // references.
+ ArrayRef<const DexFile* const> to_exclude(compiler_options_.GetDexFilesForOatFile());
+ DCHECK_GE(boot_class_path.size(), to_exclude.size());
+ DCHECK(std::equal(to_exclude.rbegin(), to_exclude.rend(), boot_class_path.rbegin()));
+ boot_class_path = boot_class_path.SubArray(0, boot_class_path.size() - to_exclude.size());
+ }
+
DCHECK(bcp_bss_info_.empty());
bcp_bss_info_.resize(boot_class_path.size());
for (size_t i = 0, size = bcp_bss_info_.size(); i != size; ++i) {
@@ -3010,9 +3021,21 @@ size_t OatWriter::WriteIndexBssMappings(OutputStream* out,
}
}
- if (!(compiler_options_.IsBootImage() || compiler_options_.IsBootImageExtension())) {
+ if (!compiler_options_.IsBootImage()) {
ArrayRef<const DexFile* const> boot_class_path(
Runtime::Current()->GetClassLinker()->GetBootClassPath());
+
+ if (compiler_options_.IsBootImageExtension()) {
+ // For boot image extension, the boot_class_path ends with the compiled dex files. In multi
+ // image, we might have several oat writers so we have to get all of the compiled dex files
+ // and not just the one we are compiling right now. Remove them to have the correct number of
+ // references.
+ ArrayRef<const DexFile* const> to_exclude(compiler_options_.GetDexFilesForOatFile());
+ DCHECK_GE(boot_class_path.size(), to_exclude.size());
+ DCHECK(std::equal(to_exclude.rbegin(), to_exclude.rend(), boot_class_path.rbegin()));
+ boot_class_path = boot_class_path.SubArray(0, boot_class_path.size() - to_exclude.size());
+ }
+
for (size_t i = 0, size = bcp_bss_info_.size(); i != size; ++i) {
const DexFile* dex_file = boot_class_path[i];
DCHECK(!ContainsElement(*dex_files_, dex_file));
diff --git a/dex2oat/linker/oat_writer.h b/dex2oat/linker/oat_writer.h
index d2e761acae..4e2332e3cc 100644
--- a/dex2oat/linker/oat_writer.h
+++ b/dex2oat/linker/oat_writer.h
@@ -431,7 +431,8 @@ class OatWriter {
// The offset of the GC roots in .bss section.
size_t bss_roots_offset_;
- // OatFile's information regarding the bss metadata for BCP DexFiles. Empty for multi-image.
+ // OatFile's information regarding the bss metadata for BCP DexFiles. Empty for boot image
+ // compiles.
std::vector<BssMappingInfo> bcp_bss_info_;
// Map for allocating boot image .data.img.rel.ro entries. Indexed by the boot image offset
diff --git a/runtime/oat/oat.h b/runtime/oat/oat.h
index 99ac12f9ec..84c169a365 100644
--- a/runtime/oat/oat.h
+++ b/runtime/oat/oat.h
@@ -44,8 +44,8 @@ std::ostream& operator<<(std::ostream& stream, StubType stub_type);
class EXPORT PACKED(4) OatHeader {
public:
static constexpr std::array<uint8_t, 4> kOatMagic { { 'o', 'a', 't', '\n' } };
- // Last oat version changed reason: Rename `.data.bimg.rel.ro` to `.data.img.rel.ro`.
- static constexpr std::array<uint8_t, 4> kOatVersion{{'2', '4', '2', '\0'}};
+ // Last oat version changed reason: BSS mappings for boot image extension.
+ static constexpr std::array<uint8_t, 4> kOatVersion{{'2', '4', '3', '\0'}};
static constexpr const char* kDex2OatCmdLineKey = "dex2oat-cmdline";
static constexpr const char* kDebuggableKey = "debuggable";