DexCachePair : Add an Assign method.
This prevents the logic for determining a slot from the type ID from
being scattered all over the place.
Bug: 30550796
Test: make test-art-host
Change-Id: I4ad6db8b730dc617fa8474a71c3794963b58279b
diff --git a/runtime/mirror/dex_cache.h b/runtime/mirror/dex_cache.h
index 92d9c1d..2fcabb5 100644
--- a/runtime/mirror/dex_cache.h
+++ b/runtime/mirror/dex_cache.h
@@ -83,6 +83,15 @@
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.