Only visit app image classes in class loader

Only update dex cache arrays of added classes since the declaring
class is in image DCHECK fails for other classes in the class loader.

Also some cleanup to prevent app images leaving invalid state if
they get rejected.

Bug: 22858531
Bug: 27431418

(cherry picked from commit 6973100705716bffce3768a8a0908d7ca1d02ec1)

Change-Id: Ib05364c44f2b943e3341ef2b1dd43337833de143
diff --git a/runtime/class_table.cc b/runtime/class_table.cc
index afb0556..d815b1a 100644
--- a/runtime/class_table.cc
+++ b/runtime/class_table.cc
@@ -168,8 +168,12 @@
 
 size_t ClassTable::ReadFromMemory(uint8_t* ptr) {
   size_t read_count = 0;
-  classes_.insert(classes_.begin(), ClassSet(ptr, /*make copy*/false, &read_count));
+  AddClassSet(ClassSet(ptr, /*make copy*/false, &read_count));
   return read_count;
 }
 
+void ClassTable::AddClassSet(ClassSet&& set) {
+  classes_.insert(classes_.begin(), std::move(set));
+}
+
 }  // namespace art