Do GC for alloc for unstarted runtimes
Currently, concurrent GC requests are ignored for unstarted runtimes.
The new logic is to do a GC for alloc in RequestConcurrentGC if the
runtime is not started. This reduces the java heap size in dex2oat.
Change-Id: I8d4364a4e3537013b27390bb22a6f64aab58c924
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 419d555..452980c 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.
}
}