summaryrefslogtreecommitdiff
path: root/runtime/mirror/dex_cache-inl.h
diff options
context:
space:
mode:
author Nicolas Geoffray <ngeoffray@google.com> 2022-10-27 12:44:48 +0000
committer Nicolas Geoffray <ngeoffray@google.com> 2022-10-28 15:12:51 +0000
commit1316d3a632032f2898b12eb86bccf455693c2eb8 (patch)
treebf8aa0cf02e37a1f4f58d8b0a7f81f8294a54167 /runtime/mirror/dex_cache-inl.h
parentf3df7be92137facde077db49cbdfd48832d8f8af (diff)
Reland "Allocate dex cache arrays at startup."
This reverts commit cc97f11fe689c1344bb04ab85e8bdc7baaeb3fb1. Reason for revert: be more selective when using full arrays. Test: test.py Change-Id: If941e81849d9e3b2c4ddcc03e46fb8442a608c82
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) {