diff options
author | 2022-01-28 12:30:31 -0800 | |
---|---|---|
committer | 2022-08-10 18:06:05 +0000 | |
commit | b7607c2fd67e12e998aebd71db38414ffc65621b (patch) | |
tree | 0b816edc36dc3a696c366e1e5922018accbde5b7 /runtime/class_table-inl.h | |
parent | 5d73d6b3e4de8e7a1cb1aa6c8683a6afac7725be (diff) |
Update native gc-roots separately in compaction pause
The concurrent compaction algorithm requires all GC roots to be updated
to post-compact addresses before resuming mutators for concurrent
compaction. Therefore, unlike CC, we cannot update native roots in
classes/dex-caches/class-loaders while visiting references
(VisitReferences) on heap objects.
This CL separates the two and updates all the gc-roots in the compaction
pause.
Bug: 160737021
Test: art/test/testrunner/testrunner.py
Change-Id: I8a57472ba49b9dc30bc0f41a7db3f5efa7eafd9a
Diffstat (limited to 'runtime/class_table-inl.h')
-rw-r--r-- | runtime/class_table-inl.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/runtime/class_table-inl.h b/runtime/class_table-inl.h index 071376cd77..67eeb553a4 100644 --- a/runtime/class_table-inl.h +++ b/runtime/class_table-inl.h @@ -104,6 +104,43 @@ void ClassTable::VisitRoots(const Visitor& visitor) { } } +template <typename Visitor> +class ClassTable::TableSlot::ClassAndRootVisitor { + public: + explicit ClassAndRootVisitor(Visitor& visitor) : visitor_(visitor) {} + + void VisitRoot(mirror::CompressedReference<mirror::Object>* klass) const + REQUIRES_SHARED(Locks::mutator_lock_) { + DCHECK(!klass->IsNull()); + // Visit roots in the klass object + visitor_(klass->AsMirrorPtr()); + // Visit the GC-root holding klass' reference + visitor_.VisitRoot(klass); + } + + private: + Visitor& visitor_; +}; + +template <typename Visitor> +void ClassTable::VisitClassesAndRoots(Visitor& visitor) { + TableSlot::ClassAndRootVisitor class_visitor(visitor); + ReaderMutexLock mu(Thread::Current(), lock_); + for (ClassSet& class_set : classes_) { + for (TableSlot& table_slot : class_set) { + table_slot.VisitRoot(class_visitor); + } + } + for (GcRoot<mirror::Object>& root : strong_roots_) { + visitor.VisitRoot(root.AddressWithoutBarrier()); + } + for (const OatFile* oat_file : oat_files_) { + for (GcRoot<mirror::Object>& root : oat_file->GetBssGcRoots()) { + visitor.VisitRootIfNonNull(root.AddressWithoutBarrier()); + } + } +} + template <ReadBarrierOption kReadBarrierOption, typename Visitor> bool ClassTable::Visit(Visitor& visitor) { ReaderMutexLock mu(Thread::Current(), lock_); |