Fix race conditions caused by StartGC.
Race1: Heap trimming could happen when we were transitioning the heap.
This caused the space to get deleted in the middle of the trim.
Race2: IncrementDisableCompactingGC needed to WaitForConcurrentGC if
we were running a moving GC or about to starting a moving GC.
Race3: The logic for whether or not we had a compacting GC was
calculated before StartGC in CollectGarbageInternal. This could cause
us to get blocked waiting for the GC to complete and come out of the
wait with a new collector_type_ due to a heap transition.
Change-Id: I07c36ae5df1820e9cca70cf239e46175c1eb9575
diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h
index fd7a614..606bbc6 100644
--- a/runtime/gc/heap.h
+++ b/runtime/gc/heap.h
@@ -537,7 +537,6 @@
void Compact(space::ContinuousMemMapAllocSpace* target_space,
space::ContinuousMemMapAllocSpace* source_space);
- bool StartGC(Thread* self, bool is_compacting) LOCKS_EXCLUDED(gc_complete_lock_);
void FinishGC(Thread* self, collector::GcType gc_type) LOCKS_EXCLUDED(gc_complete_lock_);
static ALWAYS_INLINE bool AllocatorHasAllocationStack(AllocatorType allocator_type) {
@@ -755,7 +754,7 @@
ReferenceQueue cleared_references_;
// True while the garbage collector is running.
- volatile bool is_gc_running_ GUARDED_BY(gc_complete_lock_);
+ volatile CollectorType collector_type_running_ GUARDED_BY(gc_complete_lock_);
// Last Gc type we ran. Used by WaitForConcurrentGc to know which Gc was waited on.
volatile collector::GcType last_gc_type_ GUARDED_BY(gc_complete_lock_);