From 1f9c184392020cb5c4bdf453f4c8847ca389614b Mon Sep 17 00:00:00 2001 From: Nicolas Geoffray Date: Fri, 25 Oct 2024 17:34:49 +0100 Subject: Always use an array in the DexCache for ArtField and ArtMethod. The lookup success rate is too low (<1%) during app startup where the cache is most stressed. So always use an array for them. To avoid memory regression, madvise away the arrays at every GC. go/art-benchmark-service reports ~3% improvement in app startup with no statistically significant memory regression. Test: test.py Change-Id: Id13612054943ed7770c9e96756f391eed2352d79 --- runtime/class_linker.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'runtime/class_linker.cc') diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 090ee42a08..5d76f802ee 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -10977,8 +10977,24 @@ void ClassLinker::InsertDexFileInToClassLoader(ObjPtr dex_file, } } +class ReclaimMemoryDexCacheVisitor : public DexCacheVisitor { + public: + ReclaimMemoryDexCacheVisitor() {} + + void Visit(ObjPtr dex_cache) + REQUIRES_SHARED(Locks::dex_lock_, Locks::mutator_lock_) override { + dex_cache->ReclaimMemory(); + } +}; + void ClassLinker::CleanupClassLoaders() { Thread* const self = Thread::Current(); + // We clear dex cache arrays for every GC. + { + ReaderMutexLock mu(self, *Locks::dex_lock_); + ReclaimMemoryDexCacheVisitor visitor; + VisitDexCaches(&visitor); + } std::list to_delete; // Do the delete outside the lock to avoid lock violation in jit code cache. { -- cgit v1.2.3-59-g8ed1b