Add fast path to GetWeakRefAccessEnabled
If it is already visibly enabled then relaxed load is sufficient.
This is what compiled code already does.
Test: test.py -b -r --host
Change-Id: I962d7668a7ffb18e3d22f582b3d0723b51468d1d
diff --git a/runtime/thread-inl.h b/runtime/thread-inl.h
index c0dcf88..324cd37 100644
--- a/runtime/thread-inl.h
+++ b/runtime/thread-inl.h
@@ -375,7 +375,11 @@
inline bool Thread::GetWeakRefAccessEnabled() const {
CHECK(kUseReadBarrier);
DCHECK(this == Thread::Current());
- WeakRefAccessState s = tls32_.weak_ref_access_enabled.load(std::memory_order_acquire);
+ WeakRefAccessState s = tls32_.weak_ref_access_enabled.load(std::memory_order_relaxed);
+ if (LIKELY(s == WeakRefAccessState::kVisiblyEnabled)) {
+ return true;
+ }
+ s = tls32_.weak_ref_access_enabled.load(std::memory_order_acquire);
if (s == WeakRefAccessState::kVisiblyEnabled) {
return true;
} else if (s == WeakRefAccessState::kDisabled) {