Address some intern table comments

Change-Id: I7ffaa463272015c2924ba03e006041daee498ad4
diff --git a/runtime/intern_table.cc b/runtime/intern_table.cc
index 68d7ebd..015bf98 100644
--- a/runtime/intern_table.cc
+++ b/runtime/intern_table.cc
@@ -151,29 +151,30 @@
   RemoveWeak(s);
 }
 
-void InternTable::AddImageStringsToTable(gc::space::ImageSpace* image_space) {
-  CHECK(image_space != nullptr);
+void InternTable::AddImagesStringsToTable(const std::vector<gc::space::ImageSpace*>& image_spaces) {
   MutexLock mu(Thread::Current(), *Locks::intern_table_lock_);
-  const ImageHeader* const header = &image_space->GetImageHeader();
-  // Check if we have the interned strings section.
-  const ImageSection& section = header->GetImageSection(ImageHeader::kSectionInternedStrings);
-  if (section.Size() > 0) {
-    AddTableFromMemoryLocked(image_space->Begin() + section.Offset());
-  } else {
-    // TODO: Delete this logic?
-    mirror::Object* root = header->GetImageRoot(ImageHeader::kDexCaches);
-    mirror::ObjectArray<mirror::DexCache>* dex_caches = root->AsObjectArray<mirror::DexCache>();
-    for (int32_t i = 0; i < dex_caches->GetLength(); ++i) {
-      mirror::DexCache* dex_cache = dex_caches->Get(i);
-      const size_t num_strings = dex_cache->NumStrings();
-      for (size_t j = 0; j < num_strings; ++j) {
-        mirror::String* image_string = dex_cache->GetResolvedString(j);
-        if (image_string != nullptr) {
-          mirror::String* found = LookupStrong(image_string);
-          if (found == nullptr) {
-            InsertStrong(image_string);
-          } else {
-            DCHECK_EQ(found, image_string);
+  for (gc::space::ImageSpace* image_space : image_spaces) {
+    const ImageHeader* const header = &image_space->GetImageHeader();
+    // Check if we have the interned strings section.
+    const ImageSection& section = header->GetImageSection(ImageHeader::kSectionInternedStrings);
+    if (section.Size() > 0) {
+      AddTableFromMemoryLocked(image_space->Begin() + section.Offset());
+    } else {
+      // TODO: Delete this logic?
+      mirror::Object* root = header->GetImageRoot(ImageHeader::kDexCaches);
+      mirror::ObjectArray<mirror::DexCache>* dex_caches = root->AsObjectArray<mirror::DexCache>();
+      for (int32_t i = 0; i < dex_caches->GetLength(); ++i) {
+        mirror::DexCache* dex_cache = dex_caches->Get(i);
+        const size_t num_strings = dex_cache->NumStrings();
+        for (size_t j = 0; j < num_strings; ++j) {
+          mirror::String* image_string = dex_cache->GetResolvedString(j);
+          if (image_string != nullptr) {
+            mirror::String* found = LookupStrong(image_string);
+            if (found == nullptr) {
+              InsertStrong(image_string);
+            } else {
+              DCHECK_EQ(found, image_string);
+            }
           }
         }
       }
@@ -183,6 +184,7 @@
 }
 
 mirror::String* InternTable::LookupStringFromImage(mirror::String* s) {
+  DCHECK(!images_added_to_intern_table_);
   const std::vector<gc::space::ImageSpace*>& image_spaces =
       Runtime::Current()->GetHeap()->GetBootImageSpaces();
   if (image_spaces.empty()) {
@@ -453,7 +455,7 @@
 size_t InternTable::Table::Size() const {
   return std::accumulate(tables_.begin(),
                          tables_.end(),
-                         size_t(0),
+                         0U,
                          [](size_t sum, const UnorderedSet& set) {
                            return sum + set.Size();
                          });
diff --git a/runtime/intern_table.h b/runtime/intern_table.h
index ec0f1e2..8f715a3 100644
--- a/runtime/intern_table.h
+++ b/runtime/intern_table.h
@@ -98,11 +98,10 @@
 
   void BroadcastForNewInterns() SHARED_REQUIRES(Locks::mutator_lock_);
 
-  // Adds all of the resolved image strings from the image space into the intern table. The
+  // Adds all of the resolved image strings from the image spaces into the intern table. The
   // advantage of doing this is preventing expensive DexFile::FindStringId calls. Sets
-  // images_added_to_intern_table_ to true, AddImageStringsToTable must be called on either all
-  // images or none.
-  void AddImageStringsToTable(gc::space::ImageSpace* image_space)
+  // images_added_to_intern_table_ to true.
+  void AddImagesStringsToTable(const std::vector<gc::space::ImageSpace*>& image_spaces)
       SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Locks::intern_table_lock_);
 
   // Add a new intern table for inserting to, previous intern tables are still there but no
@@ -164,8 +163,8 @@
     // debug builds. Returns how many bytes were read.
     size_t AddTableFromMemory(const uint8_t* ptr)
         REQUIRES(Locks::intern_table_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
-    // Write the intern tables to ptr, if there are multiple tables they are combined into a single one.
-    // Returns how many bytes were written.
+    // Write the intern tables to ptr, if there are multiple tables they are combined into a single
+    // one. Returns how many bytes were written.
     size_t WriteToMemory(uint8_t* ptr)
         REQUIRES(Locks::intern_table_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
 
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 01f3bbd..9eadee2 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -543,11 +543,9 @@
   // Use !IsAotCompiler so that we get test coverage, tests are never the zygote.
   if (!IsAotCompiler()) {
     ScopedObjectAccess soa(self);
-    for (gc::space::ImageSpace* image_space : heap_->GetBootImageSpaces()) {
-      ATRACE_BEGIN("AddImageStringsToTable");
-      GetInternTable()->AddImageStringsToTable(image_space);
-      ATRACE_END();
-    }
+    ATRACE_BEGIN("AddImageStringsToTable");
+    GetInternTable()->AddImagesStringsToTable(heap_->GetBootImageSpaces());
+    ATRACE_END();
     ATRACE_BEGIN("MoveImageClassesToClassTable");
     GetClassLinker()->AddBootImageClassesToClassTable();
     ATRACE_END();