Change class set search order in `ClassTable`.
Insert image class tables before the last, unfrozen, table
and search the tables from the back. Image tables are still
searched in the same order as before (namely in reverse
insertion order) but the unfrozen table is searched first
(instead of last) and the frozen zygote table is searched
between app image tables and boot image tables (instead of
second last).
This implements the same search order for `ClassTable` as
was implemented for `InternTable` by two changes:
https://android-review.googlesource.com/2054005 ,
https://android-review.googlesource.com/2059788 .
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 181943478
Change-Id: I8af3860fc5d6d19e85eb5d8df845ca5b9ddf11b6
diff --git a/runtime/class_table.cc b/runtime/class_table.cc
index 4bc2fe6..a4bc1fb 100644
--- a/runtime/class_table.cc
+++ b/runtime/class_table.cc
@@ -135,7 +135,7 @@
ObjPtr<mirror::Class> ClassTable::Lookup(const char* descriptor, size_t hash) {
DescriptorHashPair pair(descriptor, hash);
ReaderMutexLock mu(Thread::Current(), lock_);
- for (ClassSet& class_set : classes_) {
+ for (ClassSet& class_set : ReverseRange(classes_)) {
auto it = class_set.FindWithHash(pair, hash);
if (it != class_set.end()) {
return it->Read();
@@ -196,7 +196,12 @@
void ClassTable::AddClassSet(ClassSet&& set) {
WriterMutexLock mu(Thread::Current(), lock_);
- classes_.insert(classes_.begin(), std::move(set));
+ // Insert before the last (unfrozen) table since we add new classes into the back.
+ // Keep the order of previous frozen tables unchanged, so that we can can remember
+ // the number of searched frozen tables and not search them again.
+ // TODO: Make use of this in `ClassLinker::FindClass()`.
+ DCHECK(!classes_.empty());
+ classes_.insert(classes_.end() - 1, std::move(set));
}
void ClassTable::ClearStrongRoots() {