summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--compiler/image_writer.cc3
-rw-r--r--runtime/class_linker.cc11
-rw-r--r--runtime/class_linker.h4
3 files changed, 15 insertions, 3 deletions
diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc
index dd62d94e0f..c846933249 100644
--- a/compiler/image_writer.cc
+++ b/compiler/image_writer.cc
@@ -718,6 +718,9 @@ void ImageWriter::PruneNonImageClasses() {
// contains data only valid during a real run.
dex_cache->SetFieldObject<false>(mirror::DexCache::DexOffset(), nullptr);
}
+
+ // Drop the array class cache in the ClassLinker, as these are roots holding those classes live.
+ class_linker->DropFindArrayClassCache();
}
bool ImageWriter::NonImageClassesVisitor(Class* klass, void* arg) {
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 84d10008ea..79c5a0803c 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -277,9 +277,9 @@ ClassLinker::ClassLinker(InternTable* intern_table)
quick_to_interpreter_bridge_trampoline_(nullptr),
image_pointer_size_(sizeof(void*)) {
CHECK(intern_table_ != nullptr);
- for (auto& root : find_array_class_cache_) {
- root = GcRoot<mirror::Class>(nullptr);
- }
+ static_assert(kFindArrayCacheSize == arraysize(find_array_class_cache_),
+ "Array cache size wrong.");
+ std::fill_n(find_array_class_cache_, kFindArrayCacheSize, GcRoot<mirror::Class>(nullptr));
}
void ClassLinker::InitWithoutImage(std::vector<std::unique_ptr<const DexFile>> boot_class_path) {
@@ -5877,4 +5877,9 @@ ArtMethod* ClassLinker::CreateRuntimeMethod() {
return method;
}
+void ClassLinker::DropFindArrayClassCache() {
+ std::fill_n(find_array_class_cache_, kFindArrayCacheSize, GcRoot<mirror::Class>(nullptr));
+ find_array_class_cache_next_victim_ = 0;
+}
+
} // namespace art
diff --git a/runtime/class_linker.h b/runtime/class_linker.h
index fa8b2e796b..d9935cbfda 100644
--- a/runtime/class_linker.h
+++ b/runtime/class_linker.h
@@ -480,6 +480,10 @@ class ClassLinker {
ArtMethod* CreateRuntimeMethod();
+ // Clear the ArrayClass cache. This is necessary when cleaning up for the image, as the cache
+ // entries are roots, but potentially not image classes.
+ void DropFindArrayClassCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+
private:
const OatFile::OatMethod FindOatMethodFor(ArtMethod* method, bool* found)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);