Release app image metadata when startup is completed

The app image startup cache is only required for startup. Release
it after startup is completed.

Note that the cache handles being zeroed out at any time.

Bug: 123377072
Test: test-art-host

Change-Id: Iaa1c800bd0de7290b44d814a21bda20298a10d5f
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 4565939..3e8b7c8 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -2788,6 +2788,33 @@
   }
   VLOG(startup) << "Startup completed notified";
 
+  {
+    ScopedTrace trace("Releasing app image spaces metadata");
+    ScopedObjectAccess soa(Thread::Current());
+    for (gc::space::ContinuousSpace* space : GetHeap()->GetContinuousSpaces()) {
+      if (space->IsImageSpace()) {
+        gc::space::ImageSpace* image_space = space->AsImageSpace();
+        if (image_space->GetImageHeader().IsAppImage()) {
+          image_space->DisablePreResolvedStrings();
+        }
+      }
+    }
+    // Request empty checkpoint to make sure no threads are accessing the section when we madvise
+    // it.
+    {
+      ScopedThreadStateChange tsc(Thread::Current(), kSuspended);
+      GetThreadList()->RunEmptyCheckpoint();
+    }
+    for (gc::space::ContinuousSpace* space : GetHeap()->GetContinuousSpaces()) {
+      if (space->IsImageSpace()) {
+        gc::space::ImageSpace* image_space = space->AsImageSpace();
+        if (image_space->GetImageHeader().IsAppImage()) {
+          image_space->ReleaseMetadata();
+        }
+      }
+    }
+  }
+
   // Notify the profiler saver that startup is now completed.
   ProfileSaver::NotifyStartupCompleted();