summaryrefslogtreecommitdiff
path: root/runtime/mirror/dex_cache-inl.h
diff options
context:
space:
mode:
author Nicolas Geoffray <ngeoffray@google.com> 2022-10-19 10:11:48 +0100
committer Nicolas Geoffray <ngeoffray@google.com> 2022-10-24 12:57:49 +0000
commita25aeadee55630760b521176d0813d12eebae8c8 (patch)
tree8779544f31bf80d5b9c68d6eaa2bd4dbf737397e /runtime/mirror/dex_cache-inl.h
parentd9e355921fb2f039c3a19a8cf23d78ab87c1f390 (diff)
Allocate dex cache arrays at startup.
And deallocate them post startup. Local measurements for app startup average of 1000 runs on Pixel 5 and master: - youtube: 1035 -> 985 - maps: 1142 -> 877 Test: test.py Change-Id: I4fb6e7e2cecdea8bf977ef3b59d47efd0b8b9b74
Diffstat (limited to 'runtime/mirror/dex_cache-inl.h')
-rw-r--r--runtime/mirror/dex_cache-inl.h12
1 files changed, 9 insertions, 3 deletions
diff --git a/runtime/mirror/dex_cache-inl.h b/runtime/mirror/dex_cache-inl.h
index 0b6bb1433b..5a44fff665 100644
--- a/runtime/mirror/dex_cache-inl.h
+++ b/runtime/mirror/dex_cache-inl.h
@@ -54,7 +54,7 @@ static void InitializeArray(T*) {
}
template<typename T>
-T* DexCache::AllocArray(MemberOffset obj_offset, size_t num, LinearAllocKind kind) {
+T* DexCache::AllocArray(MemberOffset obj_offset, size_t num, LinearAllocKind kind, bool startup) {
Thread* self = Thread::Current();
mirror::DexCache* dex_cache = this;
if (gUseReadBarrier && self->GetIsGcMarking()) {
@@ -63,8 +63,14 @@ T* DexCache::AllocArray(MemberOffset obj_offset, size_t num, LinearAllocKind kin
dex_cache = reinterpret_cast<DexCache*>(ReadBarrier::Mark(this));
}
// DON'T USE 'this' from now on.
- ClassLinker* linker = Runtime::Current()->GetClassLinker();
- LinearAlloc* alloc = linker->GetOrCreateAllocatorForClassLoader(GetClassLoader());
+ Runtime* runtime = Runtime::Current();
+ // Note: in the 1002-notify-startup test, the startup linear alloc can become null
+ // concurrently, even if the runtime is marked at startup. Therefore we should only
+ // fetch it once here.
+ LinearAlloc* startup_linear_alloc = runtime->GetStartupLinearAlloc();
+ LinearAlloc* alloc = (startup && startup_linear_alloc != nullptr)
+ ? startup_linear_alloc
+ : runtime->GetClassLinker()->GetOrCreateAllocatorForClassLoader(GetClassLoader());
MutexLock mu(self, *Locks::dex_cache_lock_); // Avoid allocation by multiple threads.
T* array = dex_cache->GetFieldPtr64<T*>(obj_offset);
if (array != nullptr) {