Merge "Do GC for alloc for unstarted runtimes"
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 419d555..452980cf 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -3154,8 +3154,12 @@
 }
 
 void Heap::RequestConcurrentGC(Thread* self) {
-  if (CanAddHeapTask(self) &&
-      concurrent_gc_pending_.CompareExchangeStrongSequentiallyConsistent(false, true)) {
+  // If we don't have a started runtime, then we don't have a thread which is running the heap
+  // tasks. In this case, do the GC in the allocating thread to ensure that memory gets freed.
+  if (!Runtime::Current()->IsFinishedStarting()) {
+    CollectGarbageInternal(collector::kGcTypeFull, kGcCauseForAlloc, false);
+  } else if (CanAddHeapTask(self) &&
+    concurrent_gc_pending_.CompareExchangeStrongSequentiallyConsistent(false, true)) {
     task_processor_->AddTask(self, new ConcurrentGCTask(NanoTime()));  // Start straight away.
   }
 }