diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/class_table-inl.h | 5 | ||||
-rw-r--r-- | runtime/class_table.cc | 10 | ||||
-rw-r--r-- | runtime/class_table.h | 10 | ||||
-rw-r--r-- | runtime/class_table_test.cc | 12 | ||||
-rw-r--r-- | runtime/gc/space/image_space.cc | 14 |
5 files changed, 28 insertions, 23 deletions
diff --git a/runtime/class_table-inl.h b/runtime/class_table-inl.h index d07ad33d21..d043af36fe 100644 --- a/runtime/class_table-inl.h +++ b/runtime/class_table-inl.h @@ -23,6 +23,7 @@ #include "gc_root-inl.h" #include "mirror/class.h" #include "oat_file.h" +#include "obj_ptr-inl.h" namespace art { @@ -93,7 +94,7 @@ inline bool ClassTable::TableSlot::IsNull() const { } template<ReadBarrierOption kReadBarrierOption> -inline mirror::Class* ClassTable::TableSlot::Read() const { +inline ObjPtr<mirror::Class> ClassTable::TableSlot::Read() const { const uint32_t before = data_.load(std::memory_order_relaxed); const ObjPtr<mirror::Class> before_ptr(ExtractPtr(before)); const ObjPtr<mirror::Class> after_ptr( @@ -103,7 +104,7 @@ inline mirror::Class* ClassTable::TableSlot::Read() const { // one. data_.CompareAndSetStrongRelease(before, Encode(after_ptr, MaskHash(before))); } - return after_ptr.Ptr(); + return after_ptr; } template<typename Visitor> diff --git a/runtime/class_table.cc b/runtime/class_table.cc index 58f3674804..b7d37e2e37 100644 --- a/runtime/class_table.cc +++ b/runtime/class_table.cc @@ -37,7 +37,7 @@ bool ClassTable::Contains(ObjPtr<mirror::Class> klass) { return LookupByDescriptor(klass) == klass; } -mirror::Class* ClassTable::LookupByDescriptor(ObjPtr<mirror::Class> klass) { +ObjPtr<mirror::Class> ClassTable::LookupByDescriptor(ObjPtr<mirror::Class> klass) { ReaderMutexLock mu(Thread::Current(), lock_); TableSlot slot(klass); for (ClassSet& class_set : classes_) { @@ -49,7 +49,9 @@ mirror::Class* ClassTable::LookupByDescriptor(ObjPtr<mirror::Class> klass) { return nullptr; } -mirror::Class* ClassTable::UpdateClass(const char* descriptor, mirror::Class* klass, size_t hash) { +ObjPtr<mirror::Class> ClassTable::UpdateClass(const char* descriptor, + ObjPtr<mirror::Class> klass, + size_t hash) { WriterMutexLock mu(Thread::Current(), lock_); // Should only be updating latest table. DescriptorHashPair pair(descriptor, hash); @@ -62,7 +64,7 @@ mirror::Class* ClassTable::UpdateClass(const char* descriptor, mirror::Class* kl } LOG(FATAL) << "Updating class not found " << descriptor; } - mirror::Class* const existing = existing_it->Read(); + const ObjPtr<mirror::Class> existing = existing_it->Read(); CHECK_NE(existing, klass) << descriptor; CHECK(!existing->IsResolved()) << descriptor; CHECK_EQ(klass->GetStatus(), ClassStatus::kResolving) << descriptor; @@ -113,7 +115,7 @@ size_t ClassTable::NumReferencedNonZygoteClasses() const { return classes_.back().size(); } -mirror::Class* ClassTable::Lookup(const char* descriptor, size_t hash) { +ObjPtr<mirror::Class> ClassTable::Lookup(const char* descriptor, size_t hash) { DescriptorHashPair pair(descriptor, hash); ReaderMutexLock mu(Thread::Current(), lock_); for (ClassSet& class_set : classes_) { diff --git a/runtime/class_table.h b/runtime/class_table.h index 26cd3ec249..810c09c3ec 100644 --- a/runtime/class_table.h +++ b/runtime/class_table.h @@ -82,7 +82,7 @@ class ClassTable { REQUIRES_SHARED(Locks::mutator_lock_); template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier> - mirror::Class* Read() const REQUIRES_SHARED(Locks::mutator_lock_); + ObjPtr<mirror::Class> Read() const REQUIRES_SHARED(Locks::mutator_lock_); // NO_THREAD_SAFETY_ANALYSIS since the visitor may require heap bitmap lock. template<typename Visitor> @@ -170,7 +170,9 @@ class ClassTable { REQUIRES_SHARED(Locks::mutator_lock_); // Update a class in the table with the new class. Returns the existing class which was replaced. - mirror::Class* UpdateClass(const char* descriptor, mirror::Class* new_klass, size_t hash) + ObjPtr<mirror::Class> UpdateClass(const char* descriptor, + ObjPtr<mirror::Class> new_klass, + size_t hash) REQUIRES(!lock_) REQUIRES_SHARED(Locks::mutator_lock_); @@ -198,12 +200,12 @@ class ClassTable { REQUIRES_SHARED(Locks::mutator_lock_); // Return the first class that matches the descriptor. Returns null if there are none. - mirror::Class* Lookup(const char* descriptor, size_t hash) + ObjPtr<mirror::Class> Lookup(const char* descriptor, size_t hash) REQUIRES(!lock_) REQUIRES_SHARED(Locks::mutator_lock_); // Return the first class that matches the descriptor of klass. Returns null if there are none. - mirror::Class* LookupByDescriptor(ObjPtr<mirror::Class> klass) + ObjPtr<mirror::Class> LookupByDescriptor(ObjPtr<mirror::Class> klass) REQUIRES(!lock_) REQUIRES_SHARED(Locks::mutator_lock_); diff --git a/runtime/class_table_test.cc b/runtime/class_table_test.cc index 2270662260..5275c7ea95 100644 --- a/runtime/class_table_test.cc +++ b/runtime/class_table_test.cc @@ -87,9 +87,9 @@ TEST_F(ClassTableTest, ClassTable) { // Add h_X to the class table. table.Insert(h_X.Get()); - EXPECT_EQ(table.LookupByDescriptor(h_X.Get()), h_X.Get()); - EXPECT_EQ(table.Lookup(descriptor_x, ComputeModifiedUtf8Hash(descriptor_x)), h_X.Get()); - EXPECT_EQ(table.Lookup("NOT_THERE", ComputeModifiedUtf8Hash("NOT_THERE")), nullptr); + EXPECT_OBJ_PTR_EQ(table.LookupByDescriptor(h_X.Get()), h_X.Get()); + EXPECT_OBJ_PTR_EQ(table.Lookup(descriptor_x, ComputeModifiedUtf8Hash(descriptor_x)), h_X.Get()); + EXPECT_TRUE(table.Lookup("NOT_THERE", ComputeModifiedUtf8Hash("NOT_THERE")) == nullptr); EXPECT_EQ(table.NumZygoteClasses(class_loader.Get()), 0u); EXPECT_EQ(table.NumNonZygoteClasses(class_loader.Get()), 1u); @@ -99,11 +99,11 @@ TEST_F(ClassTableTest, ClassTable) { EXPECT_EQ(table.NumNonZygoteClasses(class_loader.Get()), 0u); // Test inserting and related lookup functions. - EXPECT_EQ(table.LookupByDescriptor(h_Y.Get()), nullptr); + EXPECT_TRUE(table.LookupByDescriptor(h_Y.Get()) == nullptr); EXPECT_FALSE(table.Contains(h_Y.Get())); table.Insert(h_Y.Get()); - EXPECT_EQ(table.LookupByDescriptor(h_X.Get()), h_X.Get()); - EXPECT_EQ(table.LookupByDescriptor(h_Y.Get()), h_Y.Get()); + EXPECT_OBJ_PTR_EQ(table.LookupByDescriptor(h_X.Get()), h_X.Get()); + EXPECT_OBJ_PTR_EQ(table.LookupByDescriptor(h_Y.Get()), h_Y.Get()); EXPECT_TRUE(table.Contains(h_X.Get())); EXPECT_TRUE(table.Contains(h_Y.Get())); diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc index 985fad4a01..346b81134e 100644 --- a/runtime/gc/space/image_space.cc +++ b/runtime/gc/space/image_space.cc @@ -1213,13 +1213,13 @@ class ImageSpace::Loader { ClassTable::ClassSet temp_set(data, /*make_copy_of_data=*/ false, &read_count); for (ClassTable::TableSlot& slot : temp_set) { slot.VisitRoot(class_table_visitor); - mirror::Class* klass = slot.Read<kWithoutReadBarrier>(); - if (!app_image_objects.InDest(klass)) { + ObjPtr<mirror::Class> klass = slot.Read<kWithoutReadBarrier>(); + if (!app_image_objects.InDest(klass.Ptr())) { continue; } - const bool already_marked = visited_bitmap->Set(klass); + const bool already_marked = visited_bitmap->Set(klass.Ptr()); CHECK(!already_marked) << "App image class already visited"; - patch_object_visitor.VisitClass(klass); + patch_object_visitor.VisitClass(klass.Ptr()); // Then patch the non-embedded vtable and iftable. ObjPtr<mirror::PointerArray> vtable = klass->GetVTable<kVerifyNone, kWithoutReadBarrier>(); @@ -1609,10 +1609,10 @@ class ImageSpace::BootImageLoader { ClassTableVisitor class_table_visitor(relocate_visitor); for (ClassTable::TableSlot& slot : temp_set) { slot.VisitRoot(class_table_visitor); - mirror::Class* klass = slot.Read<kWithoutReadBarrier>(); + ObjPtr<mirror::Class> klass = slot.Read<kWithoutReadBarrier>(); DCHECK(klass != nullptr); - patched_objects->Set(klass); - patch_object_visitor.VisitClass(klass); + patched_objects->Set(klass.Ptr()); + patch_object_visitor.VisitClass(klass.Ptr()); if (kIsDebugBuild) { mirror::Class* class_class = klass->GetClass<kVerifyNone, kWithoutReadBarrier>(); if (dcheck_class_class == nullptr) { |