summaryrefslogtreecommitdiff
path: root/runtime/class_table.cc
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2022-04-12 11:55:36 +0100
committer Vladimir Marko <vmarko@google.com> 2022-04-12 16:05:22 +0000
commitd0600629cfab3133eb1cb4d6826799e1c777562e (patch)
treea35279f774f8ba934c14a3b30ba128cf8e54f530 /runtime/class_table.cc
parentebf0dac3fae9919f78a5c2336a1fcc2890396597 (diff)
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
Diffstat (limited to 'runtime/class_table.cc')
-rw-r--r--runtime/class_table.cc9
1 files changed, 7 insertions, 2 deletions
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<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 @@ 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() {