From a1227a185a5d6e2af83c532379b2f9b4600f6e16 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Tue, 5 Aug 2014 15:59:43 -0700 Subject: [PATCH] Fix byte_cas to use uintptr_t Atomic. Previously we used int32_t Atomic with a uintptr_t bit shift. This was a mismatch on 64 bit and resulted in occasionally having the cas return without having succeeded. Bug: 16819816 (cherry picked from commit aa3c3e5ee83c061e7f387c75b1b29c9f248ac39c) Change-Id: Ib97bf5880153ddfacf52409be3e9e821657bac59 --- runtime/gc/accounting/card_table-inl.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/runtime/gc/accounting/card_table-inl.h b/runtime/gc/accounting/card_table-inl.h index 46b9363b9..217360f21 100644 --- a/runtime/gc/accounting/card_table-inl.h +++ b/runtime/gc/accounting/card_table-inl.h @@ -37,12 +37,13 @@ static inline bool byte_cas(byte old_value, byte new_value, byte* address) { // Align the address down. address -= shift_in_bytes; const size_t shift_in_bits = shift_in_bytes * kBitsPerByte; - AtomicInteger* word_atomic = reinterpret_cast(address); + Atomic* word_atomic = reinterpret_cast*>(address); // Word with the byte we are trying to cas cleared. - const int32_t cur_word = word_atomic->LoadRelaxed() & ~(0xFF << shift_in_bits); - const int32_t old_word = cur_word | (static_cast(old_value) << shift_in_bits); - const int32_t new_word = cur_word | (static_cast(new_value) << shift_in_bits); + const uintptr_t cur_word = word_atomic->LoadRelaxed() & + ~(static_cast(0xFF) << shift_in_bits); + const uintptr_t old_word = cur_word | (static_cast(old_value) << shift_in_bits); + const uintptr_t new_word = cur_word | (static_cast(new_value) << shift_in_bits); return word_atomic->CompareExchangeWeakRelaxed(old_word, new_word); #endif } -- 2.11.0