From d0600629cfab3133eb1cb4d6826799e1c777562e Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Tue, 12 Apr 2022 11:55:36 +0100 Subject: 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 --- runtime/class_table.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'runtime/class_table.cc') diff --git a/runtime/class_table.cc b/runtime/class_table.cc index 4bc2fe6833..a4bc1fbc00 100644 --- a/runtime/class_table.cc +++ b/runtime/class_table.cc @@ -135,7 +135,7 @@ size_t ClassTable::NumReferencedNonZygoteClasses() const { ObjPtr 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 @@ size_t ClassTable::ReadFromMemory(uint8_t* ptr) { 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() { -- cgit v1.2.3-59-g8ed1b