Fix incorrect initial dex cache size.

We were previously setting it to be sizeof(DexCacheClass) instead
of sizeof(DexCache). This was causing some problems with
compaction when I relied on the object sizes being accurate to
visit objects in the bump pointer space.

Bug: 8981901
Change-Id: Iede04763aced041986b1b239368fc867143ad70d
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index aa5f2bf..663e8b7 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -283,7 +283,7 @@
   SirtRef<mirror::Class>
       java_lang_DexCache(self, AllocClass(self, java_lang_Class.get(), sizeof(mirror::DexCacheClass)));
   SetClassRoot(kJavaLangDexCache, java_lang_DexCache.get());
-  java_lang_DexCache->SetObjectSize(sizeof(mirror::DexCacheClass));
+  java_lang_DexCache->SetObjectSize(sizeof(mirror::DexCache));
   java_lang_DexCache->SetStatus(mirror::Class::kStatusResolved, self);
 
   // Constructor, Field, Method, and AbstractMethod are necessary so that FindClass can link members.
@@ -3911,6 +3911,11 @@
     klass->SetNumReferenceInstanceFields(num_reference_fields);
     if (!klass->IsVariableSize()) {
       DCHECK_GE(size, sizeof(mirror::Object)) << ClassHelper(klass.get(), this).GetDescriptor();
+      size_t previous_size = klass->GetObjectSize();
+      if (previous_size != 0) {
+        // Make sure that we didn't originally have an incorrect size.
+        CHECK_EQ(previous_size, size);
+      }
       klass->SetObjectSize(size);
     }
   }
diff --git a/runtime/mirror/class-inl.h b/runtime/mirror/class-inl.h
index 88cffb7..cd5e865 100644
--- a/runtime/mirror/class-inl.h
+++ b/runtime/mirror/class-inl.h
@@ -35,9 +35,7 @@
 inline size_t Class::GetObjectSize() const {
   DCHECK(!IsVariableSize()) << " class=" << PrettyTypeOf(this);
   DCHECK_EQ(sizeof(size_t), sizeof(int32_t));
-  size_t result = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), false);
-  DCHECK_GE(result, sizeof(Object)) << " class=" << PrettyTypeOf(this);
-  return result;
+  return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), false);
 }
 
 inline Class* Class::GetSuperClass() const {
diff --git a/runtime/mirror/object-inl.h b/runtime/mirror/object-inl.h
index e659108..e460a8d 100644
--- a/runtime/mirror/object-inl.h
+++ b/runtime/mirror/object-inl.h
@@ -247,6 +247,7 @@
   } else {
     result = GetClass()->GetObjectSize();
   }
+  DCHECK_GE(result, sizeof(Object)) << " class=" << PrettyTypeOf(GetClass());
   DCHECK(!IsArtField()  || result == sizeof(ArtField));
   DCHECK(!IsArtMethod() || result == sizeof(ArtMethod));
   return result;