summaryrefslogtreecommitdiff
path: root/runtime/class_linker.cc
diff options
context:
space:
mode:
author Nicolas Geoffray <ngeoffray@google.com> 2024-04-09 15:47:59 +0100
committer Nicolas Geoffray <ngeoffray@google.com> 2024-04-11 10:00:38 +0000
commita7bc7cbf3182cb5c66f7cf36611c0389e7b7cc0f (patch)
tree9d733f328aacddd79b1c1329cc4f53f6df0986e8 /runtime/class_linker.cc
parent98556fe15d5124564de8d85589c7c9f3f66621a8 (diff)
Fetch class loaders and wait for GC in JitCodeCache::GetProfiledMethods.
Otherwise, we could be looking at ArtMethods whose class loader is being deleted. Test: test.py Bug: 331427447 Change-Id: I3a1d052216c7691d98576ab912e8af96de65a77b
Diffstat (limited to 'runtime/class_linker.cc')
-rw-r--r--runtime/class_linker.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index ce75c2dd35..ac9dda637a 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -11164,6 +11164,28 @@ void ClassLinker::RemoveDexFromCaches(const DexFile& dex_file) {
}
}
+// GetClassLoadersVisitor collects visited class loaders.
+class GetClassLoadersVisitor : public ClassLoaderVisitor {
+ public:
+ explicit GetClassLoadersVisitor(VariableSizedHandleScope* class_loaders)
+ : class_loaders_(class_loaders) {}
+
+ void Visit(ObjPtr<mirror::ClassLoader> class_loader)
+ REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_) override {
+ DCHECK(class_loader != nullptr);
+ class_loaders_->NewHandle(class_loader);
+ }
+
+ private:
+ VariableSizedHandleScope* const class_loaders_;
+};
+
+void ClassLinker::GetClassLoaders(Thread* self, VariableSizedHandleScope* handles) {
+ GetClassLoadersVisitor class_loader_visitor(handles);
+ ReaderMutexLock mu(self, *Locks::classlinker_classes_lock_);
+ VisitClassLoaders(&class_loader_visitor);
+}
+
// Instantiate ClassLinker::AllocClass.
template ObjPtr<mirror::Class> ClassLinker::AllocClass</* kMovable= */ true>(
Thread* self,