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

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

Issue 2094753002: [heap] Use PageIterator in HeapObjectIterator (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 months 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
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 "src/base/bits.h" 7 #include "src/base/bits.h"
8 #include "src/base/platform/platform.h" 8 #include "src/base/platform/platform.h"
9 #include "src/base/platform/semaphore.h" 9 #include "src/base/platform/semaphore.h"
10 #include "src/full-codegen/full-codegen.h" 10 #include "src/full-codegen/full-codegen.h"
11 #include "src/heap/array-buffer-tracker.h" 11 #include "src/heap/array-buffer-tracker.h"
12 #include "src/heap/slot-set.h" 12 #include "src/heap/slot-set.h"
13 #include "src/macro-assembler.h" 13 #include "src/macro-assembler.h"
14 #include "src/msan.h" 14 #include "src/msan.h"
15 #include "src/snapshot/snapshot.h" 15 #include "src/snapshot/snapshot.h"
16 #include "src/v8.h" 16 #include "src/v8.h"
17 17
18 namespace v8 { 18 namespace v8 {
19 namespace internal { 19 namespace internal {
20 20
21 21
22 // ---------------------------------------------------------------------------- 22 // ----------------------------------------------------------------------------
23 // HeapObjectIterator 23 // HeapObjectIterator
24 24
25 HeapObjectIterator::HeapObjectIterator(PagedSpace* space) { 25 HeapObjectIterator::HeapObjectIterator(PagedSpace* space)
26 // You can't actually iterate over the anchor page. It is not a real page, 26 : cur_addr_(nullptr),
27 // just an anchor for the double linked page list. Initialize as if we have 27 cur_end_(nullptr),
28 // reached the end of the anchor page, then the first iteration will move on 28 space_(space),
29 // to the first page. 29 page_range_(space->anchor()->next_page(), space->anchor()),
30 Initialize(space, NULL, NULL, kAllPagesInSpace); 30 current_page_(page_range_.begin()) {}
31 }
32 31
33 32 HeapObjectIterator::HeapObjectIterator(Page* page)
34 HeapObjectIterator::HeapObjectIterator(Page* page) { 33 : cur_addr_(nullptr),
34 cur_end_(nullptr),
35 space_(reinterpret_cast<PagedSpace*>(page->owner())),
36 page_range_(page),
37 current_page_(page_range_.begin()) {
38 #ifdef DEBUG
35 Space* owner = page->owner(); 39 Space* owner = page->owner();
36 DCHECK(owner == page->heap()->old_space() || 40 DCHECK(owner == page->heap()->old_space() ||
37 owner == page->heap()->map_space() || 41 owner == page->heap()->map_space() ||
38 owner == page->heap()->code_space()); 42 owner == page->heap()->code_space());
39 Initialize(reinterpret_cast<PagedSpace*>(owner), page->area_start(), 43 #endif // DEBUG
40 page->area_end(), kOnePageOnly);
41 DCHECK(page->SweepingDone());
42 } 44 }
43 45
44
45 void HeapObjectIterator::Initialize(PagedSpace* space, Address cur, Address end,
46 HeapObjectIterator::PageMode mode) {
47 space_ = space;
48 cur_addr_ = cur;
49 cur_end_ = end;
50 page_mode_ = mode;
51 }
52
53
54 // We have hit the end of the page and should advance to the next block of 46 // We have hit the end of the page and should advance to the next block of
55 // objects. This happens at the end of the page. 47 // objects. This happens at the end of the page.
56 bool HeapObjectIterator::AdvanceToNextPage() { 48 bool HeapObjectIterator::AdvanceToNextPage() {
57 DCHECK(cur_addr_ == cur_end_); 49 DCHECK_EQ(cur_addr_, cur_end_);
58 if (page_mode_ == kOnePageOnly) return false; 50 if (current_page_ == page_range_.end()) return false;
59 Page* cur_page; 51 Page* cur_page = *(current_page_++);
60 if (cur_addr_ == NULL) { 52 space_->heap()
61 cur_page = space_->anchor();
62 } else {
63 cur_page = Page::FromAddress(cur_addr_ - 1);
64 DCHECK(cur_addr_ == cur_page->area_end());
65 }
66 cur_page = cur_page->next_page();
67 if (cur_page == space_->anchor()) return false;
68 cur_page->heap()
69 ->mark_compact_collector() 53 ->mark_compact_collector()
70 ->sweeper() 54 ->sweeper()
71 .SweepOrWaitUntilSweepingCompleted(cur_page); 55 .SweepOrWaitUntilSweepingCompleted(cur_page);
72 cur_addr_ = cur_page->area_start(); 56 cur_addr_ = cur_page->area_start();
73 cur_end_ = cur_page->area_end(); 57 cur_end_ = cur_page->area_end();
74 DCHECK(cur_page->SweepingDone()); 58 DCHECK(cur_page->SweepingDone());
75 return true; 59 return true;
76 } 60 }
77 61
78 PauseAllocationObserversScope::PauseAllocationObserversScope(Heap* heap) 62 PauseAllocationObserversScope::PauseAllocationObserversScope(Heap* heap)
(...skipping 3157 matching lines...) Expand 10 before | Expand all | Expand 10 after
3236 object->ShortPrint(); 3220 object->ShortPrint();
3237 PrintF("\n"); 3221 PrintF("\n");
3238 } 3222 }
3239 printf(" --------------------------------------\n"); 3223 printf(" --------------------------------------\n");
3240 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); 3224 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes());
3241 } 3225 }
3242 3226
3243 #endif // DEBUG 3227 #endif // DEBUG
3244 } // namespace internal 3228 } // namespace internal
3245 } // namespace v8 3229 } // namespace v8
OLDNEW
« src/heap/spaces.h ('K') | « 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