Fix unexpected circular dependency check

The PruneObjectReferenceVisitor, responsible for traversal instances of
a class, to avoid circular dependenceis which makes infinite recursion,
should only record an object received if it's not a ClassClass, because
the processing of ClassClass objects will be forwarded to
PruneAppImageClassInternal, which will first check circular
dependencies.

Test: make test-art-host -j64
Change-Id: Ib056d3fcd02135992b09f7d28176da3a1173d42e
diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc
index fc7cd01..f4e8a89 100644
--- a/compiler/image_writer.cc
+++ b/compiler/image_writer.cc
@@ -770,18 +770,18 @@
       *result_ = true;
     }
 
-    // Record the object visited in case of circular reference.
-    visited_->emplace(ref);
     if (ref->IsClass()) {
       *result_ = *result_ ||
           image_writer_->PruneAppImageClassInternal(ref->AsClass(), early_exit_, visited_);
     } else {
+      // Record the object visited in case of circular reference.
+      visited_->emplace(ref);
       *result_ = *result_ ||
           image_writer_->PruneAppImageClassInternal(klass, early_exit_, visited_);
       ref->VisitReferences(*this, *this);
+      // Clean up before exit for next call of this function.
+      visited_->erase(ref);
     }
-    // Clean up before exit for next call of this function.
-    visited_->erase(ref);
   }
 
   ALWAYS_INLINE void operator() (ObjPtr<mirror::Class> klass ATTRIBUTE_UNUSED,