Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: src/heap/spaces.cc

Issue 2516303006: [heap] Refactor heap object iteration (Closed)
Patch Set: Add comment Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/spaces.h ('k') | src/heap/spaces-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/heap/spaces.h" 5 #include "src/heap/spaces.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "src/base/bits.h" 9 #include "src/base/bits.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 11 matching lines...) Expand all
22 22
23 23
24 // ---------------------------------------------------------------------------- 24 // ----------------------------------------------------------------------------
25 // HeapObjectIterator 25 // HeapObjectIterator
26 26
27 HeapObjectIterator::HeapObjectIterator(PagedSpace* space) 27 HeapObjectIterator::HeapObjectIterator(PagedSpace* space)
28 : cur_addr_(nullptr), 28 : cur_addr_(nullptr),
29 cur_end_(nullptr), 29 cur_end_(nullptr),
30 space_(space), 30 space_(space),
31 page_range_(space->anchor()->next_page(), space->anchor()), 31 page_range_(space->anchor()->next_page(), space->anchor()),
32 current_page_(page_range_.begin()) {} 32 next_page_(page_range_.begin()) {}
33
34 HeapObjectIterator::HeapObjectIterator(NewSpace* space)
35 : cur_addr_(nullptr),
36 cur_end_(nullptr),
37 space_(space),
38 page_range_(space->bottom(), space->top()),
39 next_page_(page_range_.begin()) {}
33 40
34 HeapObjectIterator::HeapObjectIterator(Page* page) 41 HeapObjectIterator::HeapObjectIterator(Page* page)
35 : cur_addr_(nullptr), 42 : cur_addr_(nullptr),
36 cur_end_(nullptr), 43 cur_end_(nullptr),
37 space_(reinterpret_cast<PagedSpace*>(page->owner())), 44 space_(reinterpret_cast<SpaceWithInlineAllocationArea*>(page->owner())),
38 page_range_(page), 45 page_range_(page),
39 current_page_(page_range_.begin()) { 46 next_page_(page_range_.begin()) {
40 #ifdef DEBUG 47 #ifdef DEBUG
41 Space* owner = page->owner(); 48 Space* owner = page->owner();
42 DCHECK(owner == page->heap()->old_space() || 49 Heap* heap = page->heap();
43 owner == page->heap()->map_space() || 50 DCHECK(owner == heap->old_space() || owner == heap->map_space() ||
44 owner == page->heap()->code_space()); 51 owner == heap->code_space() || owner == heap->new_space());
45 #endif // DEBUG 52 #endif // DEBUG
46 } 53 }
47 54
48 // We have hit the end of the page and should advance to the next block of 55 // We have hit the end of the page and should advance to the next block of
49 // objects. This happens at the end of the page. 56 // objects. This happens at the end of the page.
50 bool HeapObjectIterator::AdvanceToNextPage() { 57 bool HeapObjectIterator::AdvanceToNextPage() {
51 DCHECK_EQ(cur_addr_, cur_end_); 58 DCHECK_EQ(cur_addr_, cur_end_);
52 if (current_page_ == page_range_.end()) return false; 59 if (next_page_ == page_range_.end()) return false;
53 Page* cur_page = *(current_page_++); 60 Page* cur_page = *(next_page_++);
54 space_->heap() 61 space_->heap()
55 ->mark_compact_collector() 62 ->mark_compact_collector()
56 ->sweeper() 63 ->sweeper()
57 .SweepOrWaitUntilSweepingCompleted(cur_page); 64 .SweepOrWaitUntilSweepingCompleted(cur_page);
58 cur_addr_ = cur_page->area_start(); 65 cur_addr_ = cur_page->area_start();
59 cur_end_ = cur_page->area_end(); 66 cur_end_ = cur_page->area_end();
60 DCHECK(cur_page->SweepingDone()); 67 DCHECK(cur_page->SweepingDone());
61 return true; 68 return true;
62 } 69 }
63 70
(...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 if (!allocation_observers_paused_) { 1180 if (!allocation_observers_paused_) {
1174 for (int i = 0; i < allocation_observers_->length(); ++i) { 1181 for (int i = 0; i < allocation_observers_->length(); ++i) {
1175 AllocationObserver* o = (*allocation_observers_)[i]; 1182 AllocationObserver* o = (*allocation_observers_)[i];
1176 o->AllocationStep(size, soon_object, size); 1183 o->AllocationStep(size, soon_object, size);
1177 } 1184 }
1178 } 1185 }
1179 } 1186 }
1180 1187
1181 PagedSpace::PagedSpace(Heap* heap, AllocationSpace space, 1188 PagedSpace::PagedSpace(Heap* heap, AllocationSpace space,
1182 Executability executable) 1189 Executability executable)
1183 : Space(heap, space, executable), anchor_(this), free_list_(this) { 1190 : SpaceWithInlineAllocationArea(heap, space, executable),
1191 anchor_(this),
1192 free_list_(this) {
1184 area_size_ = MemoryAllocator::PageAreaSize(space); 1193 area_size_ = MemoryAllocator::PageAreaSize(space);
1185 accounting_stats_.Clear(); 1194 accounting_stats_.Clear();
1186 1195
1187 allocation_info_.Reset(nullptr, nullptr); 1196 allocation_info_.Reset(nullptr, nullptr);
1188 } 1197 }
1189 1198
1190 1199
1191 bool PagedSpace::SetUp() { return true; } 1200 bool PagedSpace::SetUp() { return true; }
1192 1201
1193 1202
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after
2088 std::swap(from->current_page_, to->current_page_); 2097 std::swap(from->current_page_, to->current_page_);
2089 2098
2090 to->FixPagesFlags(saved_to_space_flags, Page::kCopyOnFlipFlagsMask); 2099 to->FixPagesFlags(saved_to_space_flags, Page::kCopyOnFlipFlagsMask);
2091 from->FixPagesFlags(0, 0); 2100 from->FixPagesFlags(0, 0);
2092 } 2101 }
2093 2102
2094 void SemiSpace::set_age_mark(Address mark) { 2103 void SemiSpace::set_age_mark(Address mark) {
2095 DCHECK_EQ(Page::FromAllocationAreaAddress(mark)->owner(), this); 2104 DCHECK_EQ(Page::FromAllocationAreaAddress(mark)->owner(), this);
2096 age_mark_ = mark; 2105 age_mark_ = mark;
2097 // Mark all pages up to the one containing mark. 2106 // Mark all pages up to the one containing mark.
2098 for (Page* p : NewSpacePageRange(space_start(), mark)) { 2107 for (Page* p : PageRange(space_start(), mark)) {
2099 p->SetFlag(MemoryChunk::NEW_SPACE_BELOW_AGE_MARK); 2108 p->SetFlag(MemoryChunk::NEW_SPACE_BELOW_AGE_MARK);
2100 } 2109 }
2101 } 2110 }
2102 2111
2103 std::unique_ptr<ObjectIterator> SemiSpace::GetObjectIterator() { 2112 std::unique_ptr<ObjectIterator> SemiSpace::GetObjectIterator() {
2104 // Use the NewSpace::NewObjectIterator to iterate the ToSpace. 2113 // Use the NewSpace::NewObjectIterator to iterate the ToSpace.
2105 UNREACHABLE(); 2114 UNREACHABLE();
2106 return std::unique_ptr<ObjectIterator>(); 2115 return std::unique_ptr<ObjectIterator>();
2107 } 2116 }
2108 2117
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after
3247 object->ShortPrint(); 3256 object->ShortPrint();
3248 PrintF("\n"); 3257 PrintF("\n");
3249 } 3258 }
3250 printf(" --------------------------------------\n"); 3259 printf(" --------------------------------------\n");
3251 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); 3260 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes());
3252 } 3261 }
3253 3262
3254 #endif // DEBUG 3263 #endif // DEBUG
3255 } // namespace internal 3264 } // namespace internal
3256 } // namespace v8 3265 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/spaces.h ('k') | src/heap/spaces-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698