Home | History | Annotate | Download | only in gc

Lines Matching refs:space

51 #include "gc/space/bump_pointer_space.h"
52 #include "gc/space/dlmalloc_space-inl.h"
53 #include "gc/space/image_space.h"
54 #include "gc/space/large_object_space.h"
55 #include "gc/space/region_space.h"
56 #include "gc/space/rosalloc_space-inl.h"
57 #include "gc/space/space-inl.h"
58 #include "gc/space/zygote_space.h"
98 // Define space name.
99 static const char* kDlMallocSpaceName[2] = {"main dlmalloc space", "main dlmalloc space 1"};
100 static const char* kRosAllocSpaceName[2] = {"main rosalloc space", "main rosalloc space 1"};
101 static const char* kMemMapSpaceName[2] = {"main space", "main space 1"};
102 static const char* kNonMovingSpaceName = "non moving space";
103 static const char* kZygoteSpaceName = "zygote space";
123 space::LargeObjectSpaceType large_object_space_type, size_t large_object_threshold,
236 // Requested begin for the alloc space, to follow the mapped image and oat files
240 // 2 * Xmx space when there's no image (dex2oat for target).
247 auto* image_space = space::ImageSpace::Create(image_file_name.c_str(), image_instruction_set,
252 // Oat files referenced by image files immediately follow them in memory, ensure alloc space
258 LOG(ERROR) << "Could not create image space with image file '" << image_file_name << "'. "
264 +- nonmoving space (non_moving_space_capacity)+-
268 +-main alloc space / bump space 1 (capacity_) +-
272 +-main alloc space2 / bump space 2 (capacity_)+-
283 // We may use the same space the main space for the non moving space if we don't need to compact
284 // from the main space.
303 // If we are the zygote, the non moving space becomes the zygote space when we run
304 // PreZygoteFork the first time. In this case, call the map "zygote space" since we can't
314 // Try to reserve virtual memory at a lower address if we have a separate non moving space.
323 // If no separate non-moving space, the main space must come
324 // right after the image space to avoid a gap.
340 // Create the non moving space first so that bitmaps don't take up the address range.
342 // Non moving space is always dlmalloc since we currently don't have support for multiple
345 non_moving_space_ = space::DlMallocSpace::CreateFromMemMap(
346 non_moving_space_mem_map.release(), "zygote / non moving space", kDefaultStartingSize,
349 CHECK(non_moving_space_ != nullptr) << "Failed creating non moving space "
355 region_space_ = space::RegionSpace::Create("Region space", capacity_ * 2, request_begin);
362 bump_pointer_space_ = space::BumpPointerSpace::CreateFromMemMap("Bump pointer space 1",
364 CHECK(bump_pointer_space_ != nullptr) << "Failed to create bump pointer space";
366 temp_space_ = space::BumpPointerSpace::CreateFromMemMap("Bump pointer space 2",
368 CHECK(temp_space_ != nullptr) << "Failed to create bump pointer space";
381 // Create bump pointer spaces instead of a backup space.
383 bump_pointer_space_ = space::BumpPointerSpace::Create("Bump pointer space 1",
387 temp_space_ = space::BumpPointerSpace::Create("Bump pointer space 2",
396 // Add the space so its accounted for in the heap_begin and heap_end.
402 // Allocate the large object space.
403 if (large_object_space_type == space::LargeObjectSpaceType::kFreeList) {
404 large_object_space_ = space::FreeListSpace::Create("free list large object space", nullptr,
406 CHECK(large_object_space_ != nullptr) << "Failed to create large object space";
407 } else if (large_object_space_type == space::LargeObjectSpaceType::kMap) {
408 large_object_space_ = space::LargeObjectMapSpace::Create("mem map large object space");
409 CHECK(large_object_space_ != nullptr) << "Failed to create large object space";
411 // Disable the large object space by making the cutoff excessively large.
424 // Remove the main backup space since it slows down the GC to have unused extra spaces.
449 new accounting::RememberedSet("Non-moving space remembered set", this, non_moving_space_);
450 CHECK(non_moving_space_rem_set != nullptr) << "Failed to create non-moving space remembered set";
453 // TODO: Count objects in the image space here?
506 // Check that there's no gap between the image space and the non moving space so that the
514 LOG(FATAL) << "There's a gap between the image space and the non-moving space";
546 space::MallocSpace* Heap::CreateMallocSpaceFromMemMap(MemMap* mem_map, size_t initial_size,
549 space::MallocSpace* malloc_space = nullptr;
551 // Create rosalloc space.
552 malloc_space = space::RosAllocSpace::CreateFromMemMap(mem_map, name, kDefaultStartingSize,
556 malloc_space = space::DlMallocSpace::CreateFromMemMap(mem_map, name, kDefaultStartingSize,
563 CHECK(rem_set != nullptr) << "Failed to create main space remembered set";
576 // If we are the zygote and don't yet have a zygote space, it means that the zygote fork will
578 // from the main space to the zygote space. If background compaction is enabled, always pass in
583 // We never have homogeneous compaction with GSS and don't need a space with movable objects.
593 VLOG(heap) << "Created main space " << main_space_;
624 // can't only handle marking allocation stack objects of one non moving space and one main
625 // space.
687 space::Space* space = nullptr;
688 // Don't use find space since it only finds spaces which actually contain objects instead of
692 space = cur_space;
701 if (space != nullptr) {
702 stream << " in space " << *space;
718 for (const auto& space : continuous_spaces_) {
719 if (space->IsImageSpace() || space->IsZygoteSpace()) {
727 for (const auto& space : continuous_spaces_) {
728 if (space->IsImageSpace()) {
768 // special handling which does a homogenous space compaction once but then doesn't transition
794 // (both the region space and the non-moving space) or which
795 // copies of objects to visit, and the to-space invariant could be
830 // Exclude the pre-zygote fork time where the semi-space collector
843 // Visit objects in bump pointer space.
863 space::ContinuousSpace* space1 = main_space_ != nullptr ? main_space_ : non_moving_space_;
864 space::ContinuousSpace* space2 = non_moving_space_;
877 void Heap::AddSpace(space::Space* space) {
878 CHECK(space != nullptr);
880 if (space->IsContinuousSpace()) {
881 DCHECK(!space->IsDiscontinuousSpace());
882 space::ContinuousSpace* continuous_space = space->AsContinuousSpace();
894 [](const space::ContinuousSpace* a, const space::ContinuousSpace* b) {
898 CHECK(space->IsDiscontinuousSpace());
899 space::DiscontinuousSpace* discontinuous_space = space->AsDiscontinuousSpace();
904 if (space->IsAllocSpace()) {
905 alloc_spaces_.push_back(space->AsAllocSpace());
909 void Heap::SetSpaceAsDefault(space::ContinuousSpace* continuous_space) {
918 void Heap::RemoveSpace(space::Space* space) {
919 DCHECK(space != nullptr);
921 if (space->IsContinuousSpace()) {
922 DCHECK(!space->IsDiscontinuousSpace());
923 space::ContinuousSpace* continuous_space = space->AsContinuousSpace();
936 DCHECK(space->IsDiscontinuousSpace());
937 space::DiscontinuousSpace* discontinuous_space = space->AsDiscontinuousSpace();
945 if (space->IsAllocSpace()) {
946 auto it = std::find(alloc_spaces_.begin(), alloc_spaces_.end(), space->AsAllocSpace());
988 os << "Zygote space size " << PrettySize(zygote_space_->Size()) << "\n";
1095 space::ContinuousSpace* Heap::FindContinuousSpaceFromObject(const mirror::Object* obj,
1097 for (const auto& space : continuous_spaces_) {
1098 if (space->Contains(obj)) {
1099 return space;
1108 space::DiscontinuousSpace* Heap::FindDiscontinuousSpaceFromObject(const mirror::Object* obj,
1110 for (const auto& space : discontinuous_spaces_) {
1111 if (space->Contains(obj)) {
1112 return space;
1121 space::Space* Heap::FindSpaceFromObject(const mirror::Object* obj, bool fail_ok) const {
1122 space::Space* result = FindContinuousSpaceFromObject(obj, true);
1129 space::ImageSpace* Heap::GetImageSpace() const {
1130 for (const auto& space : continuous_spaces_) {
1131 if (space->IsImageSpace()) {
1132 return space->AsImageSpace();
1145 space::AllocSpace* space = nullptr;
1147 space = non_moving_space_;
1150 space = main_space_;
1153 space = bump_pointer_space_;
1156 space = region_space_;
1158 if (space != nullptr) {
1159 space->LogFragmentationAllocFailure(oss, byte_count);
1167 // Launch homogeneous space compaction if it is desired.
1238 // Pretend we are doing a GC to prevent background compaction from deleting the space we are
1251 for (const auto& space : continuous_spaces_) {
1252 if (space->IsMallocSpace()) {
1253 gc::space::MallocSpace* malloc_space = space->AsMallocSpace();
1255 // Don't trim dlmalloc spaces if we care about pauses since this can hold the space lock
1319 for (const auto& space : continuous_spaces_) {
1320 if (space->HasAddress(obj)) {
1340 // If we are in the allocated region of the temp space, then we are probably live (e.g. during
1347 space::ContinuousSpace* c_space = FindContinuousSpaceFromObject(obj, true);
1348 space::DiscontinuousSpace* d_space = nullptr;
1408 for (const auto& space : continuous_spaces_) {
1409 accounting::ContinuousSpaceBitmap* live_bitmap = space->GetLiveBitmap();
1410 accounting::ContinuousSpaceBitmap* mark_bitmap = space->GetMarkBitmap();
1411 stream << space << " " << *space << "\n";
1419 for (const auto& space : discontinuous_spaces_) {
1420 stream << space << " " << *space << "\n";
1456 // transitions occurs. This is caused by the moving objects from a bump pointer space to a
1457 // free list backed space typically increasing memory footprint due to padding and binning.
1485 space::RosAllocSpace* Heap::GetRosAllocSpace(gc::allocator::RosAlloc* rosalloc) const {
1486 for (const auto& space : continuous_spaces_) {
1487 if (space->AsContinuousSpace()->IsRosAllocSpace()) {
1488 if (space->AsContinuousSpace()->AsRosAllocSpace()->GetRosAlloc() == rosalloc) {
1489 return space->AsContinuousSpace()->AsRosAllocSpace();
1608 UNIMPLEMENTED(FATAL) << "homogeneous space compaction result: "
1613 // Always print that we ran homogeneous space compation since this can cause jank.
1614 VLOG(heap) << "Ran heap homogeneous space compaction, "
1619 << " ignored homogeneous space compaction "
1627 // Try to transition the heap if the allocation failure was due to the space being full.
1629 // If we aren't out of memory then the OOM was probably from the non moving space being
1630 // full. Attempt to disable compaction and turn the main space into a non moving space.
1639 LOG(WARNING) << "Disabled moving GC due to the non moving space being full";
1673 for (space::AllocSpace* space : alloc_spaces_) {
1674 total += space->GetObjectsAllocated();
1810 // Inc requested homogeneous space compaction.
1812 // Store performed homogeneous space compaction at a new request arrival.
1821 // Homogeneous space compaction is a copying transition, can't run it if the moving GC disable count
1823 // If the collector type changed to something which doesn't benefit from homogeneous space compaction,
1841 space::MallocSpace* to_space = main_space_backup_.release();
1842 space::MallocSpace* from_space = main_space_;
1854 SetSpaceAsDefault(main_space_); // Set as default to reset the proper dlmalloc space.
1855 // Update performed homogeneous space compaction count.
1859 VLOG(heap) << "Heap homogeneous space compaction took " << PrettyDuration(duration) << " size: "
1906 // TODO: Not hard code in semi-space collector?
1924 // Create the bump pointer space from the backup space.
1928 // pointer space last transition it will be protected.
1931 bump_pointer_space_ = space::BumpPointerSpace::CreateFromMemMap("Bump pointer space",
1935 // Use the now empty main space mem map for the bump pointer temp space.
1943 // Remove the main space so that we don't try to trim it, this doens't work for debug
1947 delete main_space_; // Delete the space since it has been removed.
1950 main_space_backup_.reset(nullptr); // Deletes the space.
1951 temp_space_ = space::BumpPointerSpace::CreateFromMemMap("Bump pointer space 2",
1969 // Compact to the main space from the bump pointer space, don't need to swap semispaces.
2075 // Special compacting collector which uses sub-optimal bin packing to reduce zygote space size.
2082 void BuildBins(space::ContinuousSpace* space) {
2083 bin_live_bitmap_ = space->GetLiveBitmap();
2084 bin_mark_bitmap_ = space->GetMarkBitmap();
2086 context.prev_ = reinterpret_cast<uintptr_t>(space->Begin());
2089 // Note: This requires traversing the space in increasing order of object addresses.
2091 // Add the last bin which spans after the last object to the end of the space.
2092 AddBin(reinterpret_cast<uintptr_t>(space->End()) - context.prev_, context.prev_);
2102 // Live bitmap of the space which contains the bins.
2104 // Mark bitmap of the space which contains the bins.
2125 virtual bool ShouldSweepSpace(space::ContinuousSpace* space) const {
2128 UNUSED(space);
2140 // No available space in the bins, place it in the target space instead (grows the zygote
2141 // space).
2159 // Add a new bin with the remaining space.
2178 for (const auto& space : GetContinuousSpaces()) {
2179 if (space->IsContinuousMemMapAllocSpace()) {
2180 space::ContinuousMemMapAllocSpace* alloc_space = space->AsContinuousMemMapAllocSpace();
2191 // suboptimal bin packing when we compact the zygote space.
2203 // Trim the pages at the end of the non moving space.
2205 // The end of the non-moving space may be protected, unprotect it so that we can copy the zygote
2215 // Create a new bump pointer space which we will compact into.
2216 space::BumpPointerSpace target_space("zygote bump space", non_moving_space_->End(),
2218 // Compact the bump pointer space to a new zygote bump pointer space.
2229 << "Does not make sense to compact within the same space";
2230 // Copy from the main space.
2242 space::Space* old_main_space = main_space_;
2262 VLOG(heap) << "Create zygote space with size=" << non_moving_space_->Size() << " bytes";
2266 // Save the old space so that we can remove it after we complete creating the zygote space.
2267 space::MallocSpace* old_alloc_space = non_moving_space_;
2268 // Turn the current alloc space into a zygote space and obtain the new alloc space composed of
2269 // the remaining available space.
2270 // Remove the old space before creating the zygote space since creating the zygote space sets
2271 // the old alloc space's bitmaps to null.
2276 // Remove the remembered set for the now zygote space (the old
2277 // non-moving space). Note now that we have compacted objects into
2278 // the zygote space, the data in the remembered set is no longer
2279 // needed. The zygote space will instead have a mod-union table
2283 // Remaining space becomes the new non moving space.
2292 CHECK(HasZygoteSpace()) << "Failed creating zygote space";
2296 // Create the zygote space mod union table.
2298 new accounting::ModUnionTableCardCache("zygote space mod-union table", this,
2300 CHECK(mod_union_table != nullptr) << "Failed to create zygote space mod-union table";
2307 // Add a new remembered set for the post-zygote non-moving space.
2309 new accounting::RememberedSet("Post-zygote non-moving space remembered set", this,
2312 << "Failed to create post-zygote non-moving space remembered set";
2350 collector::GarbageCollector* Heap::Compact(space::ContinuousMemMapAllocSpace* target_space,
2351 space::ContinuousMemMapAllocSpace* source_space,
2355 // Don't swap spaces since this isn't a typical semi space collection.
2391 // space to run the GC.
2661 space::ContinuousSpace* ref_space = heap_->FindContinuousSpaceFromObject(ref, true);
2663 space::MallocSpace* space = ref_space->AsMallocSpace();
2664 mirror::Class* ref_class = space->FindRecentFreedObject(ref);
2997 accounting::ModUnionTable* Heap::FindModUnionTableFromSpace(space::Spacespace) {
2998 auto it = mod_union_tables_.find(space);
3005 accounting::RememberedSet* Heap::FindRememberedSetFromSpace(space::Space* space) {
3006 auto it = remembered_sets_.find(space);
3017 for (const auto& space : continuous_spaces_) {
3018 accounting::ModUnionTable* table = FindModUnionTableFromSpace(space);
3019 accounting::RememberedSet* rem_set = FindRememberedSetFromSpace(space);
3021 const char* name = space->IsZygoteSpace() ? "ZygoteModUnionClearCards" :
3033 card_table_->ClearCardRange(space->Begin(), space->End());
3042 card_table_->ModifyCardsAtomic(space->Begin(), space->End(), AgeCardVisitor(),
3163 for (const auto& space : continuous_spaces_) {
3164 if (space->IsRosAllocSpace()) {
3165 VLOG(heap) << name << " : " << space->GetName();
3166 space->AsRosAllocSpace()->Verify();
3232 space::Space* space = FindContinuousSpaceFromObject(obj, true);
3233 if (space != nullptr) {
3235 return space->CanMoveObjects();
3355 for (const auto& space : continuous_spaces_) {
3356 if (space->IsMallocSpace()) {
3357 gc::space::MallocSpace* malloc_space = space->AsMallocSpace();
3361 // This space isn't added for performance reasons.
3369 for (const auto& space : continuous_spaces_) {
3370 if (space->IsMallocSpace()) {
3371 gc::spacespace->AsMallocSpace();
3376 // This space isn't added for performance reasons.
3514 // a space it will hold its lock and can become a cause of jank.
3515 // Note, the large object space self trims and the Zygote space was trimmed and unchanging since
3519 // because that only marks object heads, so a large array looks like lots of empty space. We
3665 space::Space* space = remembered_set->GetSpace();
3666 CHECK(space != nullptr);
3667 CHECK(remembered_sets_.find(space) == remembered_sets_.end()) << space;
3668 remembered_sets_.Put(space, remembered_set);
3669 CHECK(remembered_sets_.find(space) != remembered_sets_.end()) << space;
3672 void Heap::RemoveRememberedSet(space::Space* space) {
3673 CHECK(space != nullptr);
3674 auto it = remembered_sets_.find(space);
3678 CHECK(remembered_sets_.find(space) == remembered_sets_.end());
3683 for (const auto& space : GetContinuousSpaces()) {
3684 accounting::ContinuousSpaceBitmap* mark_bitmap = space->GetMarkBitmap();
3685 if (space->GetLiveBitmap() != mark_bitmap) {
3689 // Clear the marked objects in the discontinous space object sets.
3690 for (const auto& space : GetDiscontinuousSpaces()) {
3691 space->GetMarkBitmap()->Clear();