Hold proxy classes live in class linker.

We currently assume that class loaders hold proxy classes live, but
this is not always the case (e.g. class loader gets freeed). This
was resulting in a bug where we were freeing a class when there
was still a live object referencing it.

Bug: 11141694
Change-Id: I318e9fee41c86b7790431d09ba5e83633fab547b
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 9248ee4..f072820 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -2661,7 +2661,6 @@
   mirror::Class* proxy_class = GetClassRoot(kJavaLangReflectProxy);
   klass->SetStatus(mirror::Class::kStatusIdx, self);
   // Instance fields are inherited, but we add a couple of static fields...
@@ -2772,6 +2771,9 @@
     CHECK_EQ(synth_proxy_class->GetInterfaces(), interfaces);
     CHECK_EQ(synth_proxy_class->GetThrows(), throws);
+  std::string descriptor(GetDescriptorForProxy(klass.get()));
+  mirror::Class* existing = InsertClass(descriptor.c_str(), klass.get(), Hash(descriptor.c_str()));
+  CHECK(existing == nullptr);
   return klass.get();