From faff0f05fef90577c9744505555675185832aacd Mon Sep 17 00:00:00 2001 From: Mingyao Yang Date: Wed, 10 Sep 2014 12:03:22 -0700 Subject: Remove reference_static_offsets used for iterating through class static fields. Since static fields are contiguous in class object and there is no need to traverse super classes, it's not meaningful to use reference_static_offsets. Also especially with embedded vtable/imt, static field offset can't be encoded with an unsigned integer anyway. A corresponding change is made to Class.java to remove the member field. Bug: 16236588 Change-Id: I1fde3cd9efce884945876f0658c63d992164fd94 --- runtime/class_linker.cc | 23 +++++------------------ runtime/class_linker.h | 5 +---- runtime/class_linker_test.cc | 1 - runtime/mirror/class.cc | 12 ------------ runtime/mirror/class.h | 11 ----------- runtime/mirror/object-inl.h | 9 ++++----- 6 files changed, 10 insertions(+), 51 deletions(-) (limited to 'runtime') diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 563ee93..4ec4c1f 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -4433,7 +4433,6 @@ bool ClassLinker::LinkClass(Thread* self, const char* descriptor, ConstHandleGetStatus()); if (!klass->IsTemp() || (!init_done_ && klass->GetClassSize() == class_size)) { @@ -5166,20 +5165,13 @@ void ClassLinker::CreateReferenceInstanceOffsets(ConstHandle klas return; } } - CreateReferenceOffsets(klass, false, reference_offsets); + CreateReferenceOffsets(klass, reference_offsets); } -void ClassLinker::CreateReferenceStaticOffsets(ConstHandle klass) { - CreateReferenceOffsets(klass, true, 0); -} - -void ClassLinker::CreateReferenceOffsets(ConstHandle klass, bool is_static, +void ClassLinker::CreateReferenceOffsets(ConstHandle klass, uint32_t reference_offsets) { - size_t num_reference_fields = - is_static ? klass->NumReferenceStaticFieldsDuringLinking() - : klass->NumReferenceInstanceFieldsDuringLinking(); - mirror::ObjectArray* fields = - is_static ? klass->GetSFields() : klass->GetIFields(); + size_t num_reference_fields = klass->NumReferenceInstanceFieldsDuringLinking(); + mirror::ObjectArray* fields = klass->GetIFields(); // All of the fields that contain object references are guaranteed // to be at the beginning of the fields list. for (size_t i = 0; i < num_reference_fields; ++i) { @@ -5197,12 +5189,7 @@ void ClassLinker::CreateReferenceOffsets(ConstHandle klass, bool break; } } - // Update fields in klass - if (is_static) { - klass->SetReferenceStaticOffsets(reference_offsets); - } else { - klass->SetReferenceInstanceOffsets(reference_offsets); - } + klass->SetReferenceInstanceOffsets(reference_offsets); } mirror::String* ClassLinker::ResolveString(const DexFile& dex_file, uint32_t string_idx, diff --git a/runtime/class_linker.h b/runtime/class_linker.h index d1f5aa0..c8ccf6e 100644 --- a/runtime/class_linker.h +++ b/runtime/class_linker.h @@ -533,10 +533,7 @@ class ClassLinker { SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); void CreateReferenceInstanceOffsets(ConstHandle klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - void CreateReferenceStaticOffsets(ConstHandle klass) - SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - void CreateReferenceOffsets(ConstHandle klass, bool is_static, - uint32_t reference_offsets) + void CreateReferenceOffsets(ConstHandle klass, uint32_t reference_offsets) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // For use by ImageWriter to find DexCaches for its roots diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc index 69c281e..b250918 100644 --- a/runtime/class_linker_test.cc +++ b/runtime/class_linker_test.cc @@ -528,7 +528,6 @@ struct ClassOffsets : public CheckOffsets { offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::Class, object_size_), "objectSize")); offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::Class, primitive_type_), "primitiveType")); offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::Class, reference_instance_offsets_), "referenceInstanceOffsets")); - offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::Class, reference_static_offsets_), "referenceStaticOffsets")); offsets.push_back(CheckOffset(OFFSETOF_MEMBER(mirror::Class, status_), "status")); }; }; diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc index 760d54c..e7d8163 100644 --- a/runtime/mirror/class.cc +++ b/runtime/mirror/class.cc @@ -292,18 +292,6 @@ void Class::SetReferenceInstanceOffsets(uint32_t new_reference_offsets) { new_reference_offsets); } -void Class::SetReferenceStaticOffsets(uint32_t new_reference_offsets) { - if (new_reference_offsets != CLASS_WALK_SUPER) { - // Sanity check that the number of bits set in the reference offset bitmap - // agrees with the number of references - CHECK_EQ((size_t)POPCOUNT(new_reference_offsets), - NumReferenceStaticFieldsDuringLinking()); - } - // Not called within a transaction. - SetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_), - new_reference_offsets); -} - bool Class::IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2) { size_t i = 0; while (descriptor1[i] != '\0' && descriptor1[i] == descriptor2[i]) { diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h index 0d30bc6..cf9501a 100644 --- a/runtime/mirror/class.h +++ b/runtime/mirror/class.h @@ -871,14 +871,6 @@ class MANAGED Class FINAL : public Object { // TODO: uint16_t void SetStaticField(uint32_t i, ArtField* f) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - template - uint32_t GetReferenceStaticOffsets() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_)); - } - - void SetReferenceStaticOffsets(uint32_t new_reference_offsets) - SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - // Find a static or instance field using the JLS resolution order static ArtField* FindField(Thread* self, Handle klass, const StringPiece& name, const StringPiece& type) @@ -1150,9 +1142,6 @@ class MANAGED Class FINAL : public Object { // Bitmap of offsets of ifields. uint32_t reference_instance_offsets_; - // Bitmap of offsets of sfields. - uint32_t reference_static_offsets_; - // State of class initialization. Status status_; diff --git a/runtime/mirror/object-inl.h b/runtime/mirror/object-inl.h index 8c1dc7d..166ea9c 100644 --- a/runtime/mirror/object-inl.h +++ b/runtime/mirror/object-inl.h @@ -888,9 +888,9 @@ inline bool Object::CasFieldStrongSequentiallyConsistentObject(MemberOffset fiel template inline void Object::VisitFieldsReferences(uint32_t ref_offsets, const Visitor& visitor) { - if (LIKELY(ref_offsets != CLASS_WALK_SUPER)) { + if (!kIsStatic && LIKELY(ref_offsets != CLASS_WALK_SUPER)) { if (!kVisitClass) { - // Mask out the class from the reference offsets. + // Mask out the class from the reference offsets. ref_offsets ^= kWordHighBitMask; } DCHECK_EQ(ClassOffset().Uint32Value(), 0U); @@ -902,7 +902,7 @@ inline void Object::VisitFieldsReferences(uint32_t ref_offsets, const Visitor& v ref_offsets &= ~(CLASS_HIGH_BIT >> right_shift); } } else { - // There is no reference offset bitmap. In the non-static case, walk up the class + // There is no reference offset bitmap. In the non-static case, walk up the class // inheritance hierarchy and find reference offsets the hard way. In the static case, just // consider this class. for (mirror::Class* klass = kIsStatic ? AsClass() : GetClass(); klass != nullptr; @@ -930,8 +930,7 @@ inline void Object::VisitInstanceFieldsReferences(mirror::Class* klass, const Vi template inline void Object::VisitStaticFieldsReferences(mirror::Class* klass, const Visitor& visitor) { DCHECK(!klass->IsTemp()); - klass->VisitFieldsReferences( - klass->GetReferenceStaticOffsets(), visitor); + klass->VisitFieldsReferences(0, visitor); } template