Simplify access_flags_ updates
Simplify the code. Probably also results in trivial performance
improvements.
Use memory_order_relaxed consistently. Updates used stronger ordering,
but readers didn't, which made little sense.
Test: Build AOSP and boot.
Change-Id: I87fe8537b497dd79b8e674b10263ae6b017c9236
diff --git a/runtime/art_method.h b/runtime/art_method.h
index ff61065..f769f52 100644
--- a/runtime/art_method.h
+++ b/runtime/art_method.h
@@ -894,26 +894,15 @@
// This setter guarantees atomicity.
void AddAccessFlags(uint32_t flag) REQUIRES_SHARED(Locks::mutator_lock_) {
- DCHECK(!IsIntrinsic() ||
- !OverlapsIntrinsicBits(flag) ||
- IsValidIntrinsicUpdate(flag));
- uint32_t old_access_flags;
- uint32_t new_access_flags;
- do {
- old_access_flags = access_flags_.load(std::memory_order_relaxed);
- new_access_flags = old_access_flags | flag;
- } while (!access_flags_.compare_exchange_weak(old_access_flags, new_access_flags));
+ DCHECK(!IsIntrinsic() || !OverlapsIntrinsicBits(flag) || IsValidIntrinsicUpdate(flag));
+ // None of the readers rely ordering.
+ access_flags_.fetch_or(flag, std::memory_order_relaxed);
}
// This setter guarantees atomicity.
void ClearAccessFlags(uint32_t flag) REQUIRES_SHARED(Locks::mutator_lock_) {
DCHECK(!IsIntrinsic() || !OverlapsIntrinsicBits(flag) || IsValidIntrinsicUpdate(flag));
- uint32_t old_access_flags;
- uint32_t new_access_flags;
- do {
- old_access_flags = access_flags_.load(std::memory_order_relaxed);
- new_access_flags = old_access_flags & ~flag;
- } while (!access_flags_.compare_exchange_weak(old_access_flags, new_access_flags));
+ access_flags_.fetch_and(~flag, std::memory_order_relaxed);
}
// Used by GetName and GetNameView to share common code.