Add GC coverage test for moving GC
Adds testing coverage for collector transitions and homogeneous space
compaction.
Bug: 10808403
Change-Id: Ia79fecb47c33fc95d940243d6cb1068e9ee9dc9a
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index aec8d63..4bc44d3 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -1900,6 +1900,11 @@
CollectGarbageInternal(gc_plan_.back(), kGcCauseExplicit, clear_soft_references);
}
+bool Heap::SupportHomogeneousSpaceCompactAndCollectorTransitions() const {
+ return main_space_backup_.get() != nullptr && main_space_ != nullptr &&
+ foreground_collector_type_ == kCollectorTypeCMS;
+}
+
HomogeneousSpaceCompactResult Heap::PerformHomogeneousSpaceCompact() {
Thread* self = Thread::Current();
// Inc requested homogeneous space compaction.
@@ -1919,7 +1924,10 @@
// exit.
if (disable_moving_gc_count_ != 0 || IsMovingGc(collector_type_) ||
!main_space_->CanMoveObjects()) {
- return HomogeneousSpaceCompactResult::kErrorReject;
+ return kErrorReject;
+ }
+ if (!SupportHomogeneousSpaceCompactAndCollectorTransitions()) {
+ return kErrorUnsupported;
}
collector_type_running_ = kCollectorTypeHomogeneousSpaceCompact;
}