diff options
author | 2022-03-17 07:11:11 +0000 | |
---|---|---|
committer | 2022-03-21 10:31:08 +0000 | |
commit | 3ab2474fa0b3bc8a09279d3aa33f0651522a420d (patch) | |
tree | e8ebf2361e20f77abd2e3e8ea71cfde97fd0d750 | |
parent | 14d3c2c0a0ca3733f63430066ce14b1f9ba5d90d (diff) |
Use correct min/max load factor in intern/class table.
Propagate the min/max load factor that was initially set
based on low memory mode flag to new internal sets.
And clean up some dead code related to image writing.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Change-Id: Id13c8a4833e93458a3f5eed22dc69431311211b7
-rw-r--r-- | runtime/class_table.cc | 6 | ||||
-rw-r--r-- | runtime/intern_table.cc | 32 | ||||
-rw-r--r-- | runtime/intern_table.h | 10 |
3 files changed, 17 insertions, 31 deletions
diff --git a/runtime/class_table.cc b/runtime/class_table.cc index 03921a132a..bd5d38f80d 100644 --- a/runtime/class_table.cc +++ b/runtime/class_table.cc @@ -30,7 +30,11 @@ ClassTable::ClassTable() : lock_("Class loader classes", kClassLoaderClassesLock void ClassTable::FreezeSnapshot() { WriterMutexLock mu(Thread::Current(), lock_); - classes_.push_back(ClassSet()); + // Propagate the min/max load factor from the old active set. + DCHECK(!classes_.empty()); + const ClassSet& last_set = classes_.back(); + ClassSet new_set(last_set.GetMinLoadFactor(), last_set.GetMaxLoadFactor()); + classes_.push_back(std::move(new_set)); } ObjPtr<mirror::Class> ClassTable::UpdateClass(const char* descriptor, diff --git a/runtime/intern_table.cc b/runtime/intern_table.cc index c36bc8a811..e5d4e33baa 100644 --- a/runtime/intern_table.cc +++ b/runtime/intern_table.cc @@ -195,26 +195,17 @@ void InternTable::WaitUntilAccessible(Thread* self) { Locks::intern_table_lock_->ExclusiveLock(self); } -ObjPtr<mirror::String> InternTable::Insert(ObjPtr<mirror::String> s, - bool is_strong, - bool holding_locks) { +ObjPtr<mirror::String> InternTable::Insert(ObjPtr<mirror::String> s, bool is_strong) { if (s == nullptr) { return nullptr; } Thread* const self = Thread::Current(); MutexLock mu(self, *Locks::intern_table_lock_); - if (kDebugLocking && !holding_locks) { + if (kDebugLocking) { Locks::mutator_lock_->AssertSharedHeld(self); CHECK_EQ(2u, self->NumberOfHeldMutexes()) << "may only safely hold the mutator lock"; } while (true) { - if (holding_locks) { - if (!kUseReadBarrier) { - CHECK_EQ(weak_root_state_, gc::kWeakRootStateNormal); - } else { - CHECK(self->GetWeakRefAccessEnabled()); - } - } // Check the strong table for a match. ObjPtr<mirror::String> strong = LookupStrongLocked(s); if (strong != nullptr) { @@ -227,7 +218,6 @@ ObjPtr<mirror::String> InternTable::Insert(ObjPtr<mirror::String> s, // weak_root_state_ is set to gc::kWeakRootStateNoReadsOrWrites in the GC pause but is only // cleared after SweepSystemWeaks has completed. This is why we need to wait until it is // cleared. - CHECK(!holding_locks); StackHandleScope<1> hs(self); auto h = hs.NewHandleWrapper(&s); WaitUntilAccessible(self); @@ -278,7 +268,7 @@ ObjPtr<mirror::String> InternTable::InternStrong(uint32_t utf16_length, const ch } else { s->SetHashCode(hash); } - return InternStrong(s); + return Insert(s, /*is_strong=*/ true); } ObjPtr<mirror::String> InternTable::InternStrong(const char* utf8_data) { @@ -286,13 +276,8 @@ ObjPtr<mirror::String> InternTable::InternStrong(const char* utf8_data) { return InternStrong(mirror::String::AllocFromModifiedUtf8(Thread::Current(), utf8_data)); } -ObjPtr<mirror::String> InternTable::InternStrongImageString(ObjPtr<mirror::String> s) { - // May be holding the heap bitmap lock. - return Insert(s, true, true); -} - ObjPtr<mirror::String> InternTable::InternStrong(ObjPtr<mirror::String> s) { - return Insert(s, true, false); + return Insert(s, /*is_strong=*/ true); } ObjPtr<mirror::String> InternTable::InternWeak(const char* utf8_data) { @@ -301,7 +286,7 @@ ObjPtr<mirror::String> InternTable::InternWeak(const char* utf8_data) { } ObjPtr<mirror::String> InternTable::InternWeak(ObjPtr<mirror::String> s) { - return Insert(s, false, false); + return Insert(s, /*is_strong=*/ false); } bool InternTable::ContainsWeak(ObjPtr<mirror::String> s) { @@ -347,7 +332,12 @@ ObjPtr<mirror::String> InternTable::Table::Find(const Utf8String& string) { } void InternTable::Table::AddNewTable() { - tables_.push_back(InternalTable()); + // Propagate the min/max load factor from the old active set. + DCHECK(!tables_.empty()); + const UnorderedSet& last_set = tables_.back().set_; + InternalTable new_table; + new_table.set_.SetLoadFactor(last_set.GetMinLoadFactor(), last_set.GetMaxLoadFactor()); + tables_.push_back(std::move(new_table)); } void InternTable::Table::Insert(ObjPtr<mirror::String> s) { diff --git a/runtime/intern_table.h b/runtime/intern_table.h index ba039cc22d..ad1b68ef5e 100644 --- a/runtime/intern_table.h +++ b/runtime/intern_table.h @@ -117,12 +117,6 @@ class InternTable { ObjPtr<mirror::String> InternStrong(uint32_t utf16_length, const char* utf8_data) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_); - // Only used by image writer. Special version that may not cause thread suspension since the GC - // cannot be running while we are doing image writing. Maybe be called while holding a - // lock since there will not be thread suspension. - ObjPtr<mirror::String> InternStrongImageString(ObjPtr<mirror::String> s) - REQUIRES_SHARED(Locks::mutator_lock_); - // Interns a potentially new string in the 'strong' table. May cause thread suspension. ObjPtr<mirror::String> InternStrong(const char* utf8_data) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_); @@ -282,9 +276,7 @@ class InternTable { }; // Insert if non null, otherwise return null. Must be called holding the mutator lock. - // If holding_locks is true, then we may also hold other locks. If holding_locks is true, then we - // require GC is not running since it is not safe to wait while holding locks. - ObjPtr<mirror::String> Insert(ObjPtr<mirror::String> s, bool is_strong, bool holding_locks) + ObjPtr<mirror::String> Insert(ObjPtr<mirror::String> s, bool is_strong) REQUIRES(!Locks::intern_table_lock_) REQUIRES_SHARED(Locks::mutator_lock_); // Add a table from memory to the strong interns. |