ART: Ensure dex caches keep classloader live
Live dex caches must keep their associated classloader live. Otherwise
the classloader may get unloaded, attempting to free DexFiles which
cannot be unregistered.
Test: art/test/testrunner/testrunner.py -b --host
Test: m test-art-host-gtest
Change-Id: I0eed5b3b46ed681c739d6923a57d0878afbba1a7
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 73b8166..3919204 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -4025,6 +4025,8 @@
// Make sure to hold the dex cache live in the class table. This case happens for the boot class
// path dex caches without an image.
data.class_table->InsertStrongRoot(dex_cache);
+ // Make sure that the dex cache holds the classloader live.
+ dex_cache->SetClassLoader(class_loader);
if (class_loader != nullptr) {
// Since we added a strong root to the class table, do the write barrier as required for
// remembered sets and generational GCs.