Remove lock from ClassExt installation procedure.
We were using a lock on the class to ensure that we avoid races in
setting the ext_data_ field of a class object. We replace this with a
CAS of the field in order to prevent deadlocks.
Test: mma test-art-host
Change-Id: Ie436ff9526f2c3b38a9af49c5606a7cee6d718f1
diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h
index 23c70ff..711914d 100644
--- a/runtime/mirror/class.h
+++ b/runtime/mirror/class.h
@@ -1133,6 +1133,12 @@
ClassExt* GetExtData() REQUIRES_SHARED(Locks::mutator_lock_);
+ // Returns the ExtData for this class, allocating one if necessary. This should be the only way
+ // to force ext_data_ to be set. No functions are available for changing an already set ext_data_
+ // since doing so is not allowed.
+ ClassExt* EnsureExtDataPresent(Thread* self)
+ REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
+
uint16_t GetDexClassDefIndex() REQUIRES_SHARED(Locks::mutator_lock_) {
return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_));
}
@@ -1320,9 +1326,6 @@
ALWAYS_INLINE void SetMethodsPtrInternal(LengthPrefixedArray<ArtMethod>* new_methods)
REQUIRES_SHARED(Locks::mutator_lock_);
- // Set the extData field. This should be done while the 'this' is locked to prevent races.
- void SetExtData(ObjPtr<ClassExt> ext) REQUIRES_SHARED(Locks::mutator_lock_);
-
template <bool throw_on_failure, bool use_referrers_cache>
bool ResolvedFieldAccessTest(ObjPtr<Class> access_to,
ArtField* field,