Document when we can avoid read barriers.
Test: Rely on TreeHugger.
Bug: 119486698
Change-Id: I6d5e18709ff7d624eea7a083f39a56ed8f8ffa49
diff --git a/runtime/mirror/object-inl.h b/runtime/mirror/object-inl.h
index 005e272..814d86a 100644
--- a/runtime/mirror/object-inl.h
+++ b/runtime/mirror/object-inl.h
@@ -139,8 +139,9 @@
template<VerifyObjectFlags kVerifyFlags>
inline bool Object::IsClass() {
- // OK to look at from-space copies since java.lang.Class.class is not movable.
- // See b/114413743
+ // OK to look at from-space copies since java.lang.Class.class is non-moveable
+ // (even when running without boot image, see ClassLinker::InitWithoutImage())
+ // and we're reading constant references for comparison only. See ReadBarrierOption.
ObjPtr<Class> klass = GetClass<kVerifyFlags, kWithoutReadBarrier>();
ObjPtr<Class> java_lang_Class = klass->GetClass<kVerifyFlags, kWithoutReadBarrier>();
return klass == java_lang_Class;
@@ -194,8 +195,8 @@
template<VerifyObjectFlags kVerifyFlags, Primitive::Type kType>
ALWAYS_INLINE bool Object::IsSpecificPrimitiveArray() {
- // We do not need a read barrier here as the primitive type is constant,
- // both from-space and to-space component type classes shall yield the same result.
+ // We do not need a read barrier here as the primitive type is constant, both from-space
+ // and to-space component type classes shall yield the same result. See ReadBarrierOption.
ObjPtr<Class> klass = GetClass<kVerifyFlags, kWithoutReadBarrier>();
constexpr VerifyObjectFlags kNewFlags = RemoveThisFlags(kVerifyFlags);
ObjPtr<Class> const component_type = klass->GetComponentType<kNewFlags, kWithoutReadBarrier>();