Remove CHA dependencies for class unloading when JIT is disabled

When a linear alloc is unloaded, remove the corresponding CHA
dependencies to prevent any dangling pointers to ArtMethods.

Bug: 63905544
Bug: 63467744
Test: test-art-host
Change-Id: I6f54c6e774daef1a64c6a02a17eb5f5ab98841fd
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index c5e11f1..74c04d1 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -2315,11 +2315,16 @@
   JavaVMExt* const vm = runtime->GetJavaVM();
   vm->DeleteWeakGlobalRef(self, data.weak_root);
   // Notify the JIT that we need to remove the methods and/or profiling info.
+  ClassHierarchyAnalysis* const cha = runtime->GetClassHierarchyAnalysis();
   if (runtime->GetJit() != nullptr) {
     jit::JitCodeCache* code_cache = runtime->GetJit()->GetCodeCache();
     if (code_cache != nullptr) {
+      // For the JIT case, RemoveMethodsIn removes the CHA dependencies.
       code_cache->RemoveMethodsIn(self, *data.allocator);
     }
+  } else {
+    // If we don't have a JIT, we need to manually remove the CHA dependencies manually.
+    cha->RemoveDependenciesForLinearAlloc(data.allocator);
   }
   delete data.allocator;
   delete data.class_table;