diff options
| -rw-r--r-- | runtime/mirror/dex_cache-inl.h | 10 | ||||
| -rw-r--r-- | runtime/mirror/dex_cache.h | 9 |
2 files changed, 12 insertions, 7 deletions
diff --git a/runtime/mirror/dex_cache-inl.h b/runtime/mirror/dex_cache-inl.h index 0fa6d6bb21..b388f65d82 100644 --- a/runtime/mirror/dex_cache-inl.h +++ b/runtime/mirror/dex_cache-inl.h @@ -44,10 +44,7 @@ inline mirror::String* DexCache::GetResolvedString(uint32_t string_idx) { } inline void DexCache::SetResolvedString(uint32_t string_idx, mirror::String* resolved) { - DCHECK_LT(string_idx % NumStrings(), NumStrings()); - GetStrings()[string_idx % NumStrings()].store( - StringDexCachePair(resolved, string_idx), - std::memory_order_relaxed); + StringDexCachePair::Assign(GetStrings(), string_idx, resolved, NumStrings()); Runtime* const runtime = Runtime::Current(); if (UNLIKELY(runtime->IsActiveTransaction())) { DCHECK(runtime->IsAotCompiler()); @@ -94,9 +91,8 @@ inline void DexCache::SetResolvedMethodType(uint32_t proto_idx, MethodType* reso DCHECK(Runtime::Current()->IsMethodHandlesEnabled()); DCHECK_LT(proto_idx, GetDexFile()->NumProtoIds()); - GetResolvedMethodTypes()[proto_idx % NumResolvedMethodTypes()].store( - MethodTypeDexCachePair(resolved, proto_idx), std::memory_order_relaxed); - + MethodTypeDexCachePair::Assign(GetResolvedMethodTypes(), proto_idx, resolved, + NumResolvedMethodTypes()); // TODO: Fine-grained marking, so that we don't need to go through all arrays in full. Runtime::Current()->GetHeap()->WriteBarrierEveryFieldOf(this); } diff --git a/runtime/mirror/dex_cache.h b/runtime/mirror/dex_cache.h index 92d9c1de21..2fcabb5076 100644 --- a/runtime/mirror/dex_cache.h +++ b/runtime/mirror/dex_cache.h @@ -83,6 +83,15 @@ template <typename T> struct PACKED(8) DexCachePair { return element.object; } + static void Assign(std::atomic<DexCachePair<T>>* dex_cache, + uint32_t idx, + T* object, + uint32_t cache_size) { + DCHECK_LT(idx % cache_size, cache_size); + dex_cache[idx % cache_size].store( + DexCachePair<T>(object, idx), std::memory_order_relaxed); + } + static uint32_t InvalidIndexForSlot(uint32_t slot) { // Since the cache size is a power of two, 0 will always map to slot 0. // Use 1 for slot 0 and 0 for all other slots. |