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
diff --git a/runtime/class_table.cc b/runtime/class_table.cc
index 03921a1..bd5d38f 100644
--- a/runtime/class_table.cc
+++ b/runtime/class_table.cc
@@ -30,7 +30,11 @@
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 c36bc8a..e5d4e33 100644
--- a/runtime/intern_table.cc
+++ b/runtime/intern_table.cc
@@ -195,26 +195,17 @@
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 @@
// 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 @@
} 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 @@
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(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 @@
}
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 ba039cc..ad1b68e 100644
--- a/runtime/intern_table.h
+++ b/runtime/intern_table.h
@@ -117,12 +117,6 @@
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 @@
};
// 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.