Avoid growing boot class path for --single-image compiled images
Calculation of the number of components in Runtime::Init did not
account for images compiled with --single-image where the number of
images does not equal the number of components.
Bug: 160683548
Test: Treehugger
Change-Id: I1db7a4bbbc8bb2f48d54f5048bd1b8407d19cf02
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index ac3c392..2012a04 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1594,10 +1594,13 @@
GetInternTable()->AddImageStringsToTable(image_space, VoidFunctor());
}
}
- if (heap_->GetBootImageSpaces().size() != GetBootClassPath().size()) {
+
+ const size_t total_components = gc::space::ImageSpace::GetNumberOfComponents(
+ ArrayRef<gc::space::ImageSpace* const>(heap_->GetBootImageSpaces()));
+ if (total_components != GetBootClassPath().size()) {
// The boot image did not contain all boot class path components. Load the rest.
- DCHECK_LT(heap_->GetBootImageSpaces().size(), GetBootClassPath().size());
- size_t start = heap_->GetBootImageSpaces().size();
+ CHECK_LT(total_components, GetBootClassPath().size());
+ size_t start = total_components;
DCHECK_LT(start, GetBootClassPath().size());
std::vector<std::unique_ptr<const DexFile>> extra_boot_class_path;
if (runtime_options.Exists(Opt::BootClassPathDexList)) {