// Implement 16-byte atomic pair using the seq-lock synchronization algorithm. // This is currently only used for DexCache. // // This uses top 4-bytes of the key as version counter and lock bit, // which means the stored pair key can not use those bytes. // // This allows us to read the cache without exclusive access to the cache line. // // The 8-byte atomic pair uses the normal single-instruction implementation. // static constexpr uint64_t kSeqMask = (0xFFFFFFFFull << 32); static constexpr uint64_t kSeqLock = (0x80000000ull << 32); static constexpr uint64_t kSeqIncr = (0x00000001ull << 32); static constexpr uint kAtomicPairMaxSpins = 10'000u; static constexpr uint kAtomicPairSleepNanos = 100'000u;
// std::pair<> is not trivially copyable and as such it is unsuitable for atomic operations. template <typename IntType> struct PACKED(2 * sizeof(IntType)) AtomicPair {
static_assert(std::is_integral_v<IntType>);
ALWAYS_INLINE staticinlinevoid AtomicPairStoreRelease(AtomicPair<uint64_t>* pair,
AtomicPair<uint64_t> value) {
DCHECK((value.key & kSeqMask) == 0) << "Key=0x" << std::hex << value.key; auto* key_ptr = reinterpret_cast<std::atomic_uint64_t*>(&pair->key); auto* val_ptr = reinterpret_cast<std::atomic_uint64_t*>(&pair->val);
uint64_t key = key_ptr->load(std::memory_order_relaxed); for (uint i = 0;; ++i) {
key &= ~kSeqLock; // Ensure that the CAS below fails if the lock bit is already set. if (LIKELY(key_ptr->compare_exchange_weak(key, key | kSeqLock))) { break;
} if (UNLIKELY(i > kAtomicPairMaxSpins)) {
NanoSleep(kAtomicPairSleepNanos);
}
}
key = (((key & kSeqMask) + kSeqIncr) & ~kSeqLock) | (value.key & ~kSeqMask);
val_ptr->store(value.val, std::memory_order_release);
key_ptr->store(key, std::memory_order_release);
}
} // namespace art
#endif// ART_RUNTIME_BASE_ATOMIC_PAIR_H_
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.7Bemerkung:
(vorverarbeitet am 2026-09-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.