diff options
| -rw-r--r-- | runtime/gc/heap.cc | 5 | ||||
| -rw-r--r-- | runtime/gc/space/region_space.cc | 17 | ||||
| -rw-r--r-- | runtime/gc/space/region_space.h | 9 |
3 files changed, 30 insertions, 1 deletions
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index cf5bd4aed2..84671c34b5 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -3525,6 +3525,11 @@ void Heap::ClampGrowthLimit() { malloc_space->ClampGrowthLimit(); } } + if (collector_type_ == kCollectorTypeCC) { + DCHECK(region_space_ != nullptr); + // Twice the capacity as CC needs extra space for evacuating objects. + region_space_->ClampGrowthLimit(2 * capacity_); + } // This space isn't added for performance reasons. if (main_space_backup_.get() != nullptr) { main_space_backup_->ClampGrowthLimit(); diff --git a/runtime/gc/space/region_space.cc b/runtime/gc/space/region_space.cc index 45cfff90cc..a505f32c49 100644 --- a/runtime/gc/space/region_space.cc +++ b/runtime/gc/space/region_space.cc @@ -413,6 +413,23 @@ void RegionSpace::Clear() { evac_region_ = &full_region_; } +void RegionSpace::ClampGrowthLimit(size_t new_capacity) { + MutexLock mu(Thread::Current(), region_lock_); + CHECK_LE(new_capacity, NonGrowthLimitCapacity()); + size_t new_num_regions = new_capacity / kRegionSize; + if (non_free_region_index_limit_ > new_num_regions) { + LOG(WARNING) << "Couldn't clamp region space as there are regions in use beyond growth limit."; + return; + } + num_regions_ = new_num_regions; + SetLimit(Begin() + new_capacity); + if (Size() > new_capacity) { + SetEnd(Limit()); + } + GetMarkBitmap()->SetHeapSize(new_capacity); + GetMemMap()->SetSize(new_capacity); +} + void RegionSpace::Dump(std::ostream& os) const { os << GetName() << " " << reinterpret_cast<void*>(Begin()) << "-" << reinterpret_cast<void*>(Limit()); diff --git a/runtime/gc/space/region_space.h b/runtime/gc/space/region_space.h index ef8aa52a03..55c2772129 100644 --- a/runtime/gc/space/region_space.h +++ b/runtime/gc/space/region_space.h @@ -92,6 +92,13 @@ class RegionSpace FINAL : public ContinuousMemMapAllocSpace { void Clear() OVERRIDE REQUIRES(!region_lock_); + // Change the non growth limit capacity to new capacity by shrinking or expanding the map. + // Currently, only shrinking is supported. + // Unlike implementations of this function in other spaces, we need to pass + // new capacity as argument here as region space doesn't have any notion of + // growth limit. + void ClampGrowthLimit(size_t new_capacity) REQUIRES(!region_lock_); + void Dump(std::ostream& os) const; void DumpRegions(std::ostream& os) REQUIRES(!region_lock_); void DumpNonFreeRegions(std::ostream& os) REQUIRES(!region_lock_); @@ -530,7 +537,7 @@ class RegionSpace FINAL : public ContinuousMemMapAllocSpace { Mutex region_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; uint32_t time_; // The time as the number of collections since the startup. - const size_t num_regions_; // The number of regions in this space. + size_t num_regions_; // The number of regions in this space. // The number of non-free regions in this space. size_t num_non_free_regions_ GUARDED_BY(region_lock_); |