ART: Prune FindArrayClass cache in image writer

The ClassLinker cache speeds up FindArrayClass requests, but all
entries are roots. It is possible that an entry is a non-image
class when creating the boot image, artificially keeping the
class around.

Bug: 21596650

(cherry picked from commit 44905ce1c97613a5cb44046049843fe1029a64cf)

Change-Id: Ief9b439945d0e293a3cb5dcddfeb189b5e174f06
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 431ef27..31140a8 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -277,9 +277,9 @@
       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) {
@@ -5886,4 +5886,9 @@
   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