summaryrefslogtreecommitdiff
path: root/runtime/class_linker.cc
diff options
context:
space:
mode:
author Nicolas Geoffray <ngeoffray@google.com> 2024-10-25 17:34:49 +0100
committer Nicolas Geoffray <ngeoffray@google.com> 2024-10-28 18:19:29 +0000
commit1f9c184392020cb5c4bdf453f4c8847ca389614b (patch)
treea2c535a1ee4353f880215297a2ddb78a983968ee /runtime/class_linker.cc
parent323dfbf34ff435f673e83c86af6e957d7d4a2369 (diff)
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
Diffstat (limited to 'runtime/class_linker.cc')
-rw-r--r--runtime/class_linker.cc16
1 files changed, 16 insertions, 0 deletions
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<mirror::Object> dex_file,
}
}
+class ReclaimMemoryDexCacheVisitor : public DexCacheVisitor {
+ public:
+ ReclaimMemoryDexCacheVisitor() {}
+
+ void Visit(ObjPtr<mirror::DexCache> 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<ClassLoaderData> to_delete;
// Do the delete outside the lock to avoid lock violation in jit code cache.
{