Remove unresolved classes from image classes.

This allows compiling partial boot image, without conscrypt,
while using the current image classes in preloaded-classes.
Excluding the conscrypt makes the class
  android.security.net.config.TrustedCertificateStoreAdapter
unresolved because it extends the class
  com.android.org.conscrypt.TrustedCertificateStore .
Without pruning, we hit a DCHECK() in ImageWriter, checking
that image classes are not erroneous. And we clearly do not
want to put erroneous classes in the partial boot image.

Test: Build partial boot image without conscrypt.
Bug: 119868597
Change-Id: I6017462366a4b9e69abe1fb3d22461cab35f84c5
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index 0039be0..f52c566 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -1231,8 +1231,15 @@
     bool operator()(ObjPtr<mirror::Class> klass) override REQUIRES_SHARED(Locks::mutator_lock_) {
       std::string temp;
       StringPiece name(klass->GetDescriptor(&temp));
-      if (data_->image_class_descriptors_->find(name) != data_->image_class_descriptors_->end()) {
-        data_->image_classes_.push_back(hs_.NewHandle(klass));
+      auto it = data_->image_class_descriptors_->find(name);
+      if (it != data_->image_class_descriptors_->end()) {
+        if (LIKELY(klass->IsResolved())) {
+          data_->image_classes_.push_back(hs_.NewHandle(klass));
+        } else {
+          DCHECK(klass->IsErroneousUnresolved());
+          VLOG(compiler) << "Removing unresolved class from image classes: " << name;
+          data_->image_class_descriptors_->erase(it);
+        }
       } else {
         // Check whether it is initialized and has a clinit. They must be kept, too.
         if (klass->IsInitialized() && klass->FindClassInitializer(