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

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

Issue 2377513007: [heap] Decouple SpaceIterator from ObjectIterator. (Closed)
Patch Set: Created 4 years, 2 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
« src/heap/spaces.h ('K') | « src/heap/spaces.h ('k') | no next file » | 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 1412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 if (page->next_chunk() != NULL) { 1423 if (page->next_chunk() != NULL) {
1424 DCHECK(page->prev_chunk() != NULL); 1424 DCHECK(page->prev_chunk() != NULL);
1425 page->Unlink(); 1425 page->Unlink();
1426 } 1426 }
1427 1427
1428 AccountUncommitted(static_cast<intptr_t>(page->size())); 1428 AccountUncommitted(static_cast<intptr_t>(page->size()));
1429 accounting_stats_.ShrinkSpace(page->area_size()); 1429 accounting_stats_.ShrinkSpace(page->area_size());
1430 heap()->memory_allocator()->Free<MemoryAllocator::kPreFreeAndQueue>(page); 1430 heap()->memory_allocator()->Free<MemoryAllocator::kPreFreeAndQueue>(page);
1431 } 1431 }
1432 1432
1433 std::unique_ptr<ObjectIterator> PagedSpace::GetObjectIterator() {
1434 return std::unique_ptr<ObjectIterator>(new HeapObjectIterator(this));
1435 }
1436
1433 #ifdef DEBUG 1437 #ifdef DEBUG
1434 void PagedSpace::Print() {} 1438 void PagedSpace::Print() {}
1435 #endif 1439 #endif
1436 1440
1437 #ifdef VERIFY_HEAP 1441 #ifdef VERIFY_HEAP
1438 void PagedSpace::Verify(ObjectVisitor* visitor) { 1442 void PagedSpace::Verify(ObjectVisitor* visitor) {
1439 bool allocation_pointer_found_in_space = 1443 bool allocation_pointer_found_in_space =
1440 (allocation_info_.top() == allocation_info_.limit()); 1444 (allocation_info_.top() == allocation_info_.limit());
1441 for (Page* page : *this) { 1445 for (Page* page : *this) {
1442 CHECK(page->owner() == this); 1446 CHECK(page->owner() == this);
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1809 if (top_on_previous_step_) { 1813 if (top_on_previous_step_) {
1810 int bytes_allocated = static_cast<int>(top - top_on_previous_step_); 1814 int bytes_allocated = static_cast<int>(top - top_on_previous_step_);
1811 for (int i = 0; i < allocation_observers_->length(); ++i) { 1815 for (int i = 0; i < allocation_observers_->length(); ++i) {
1812 (*allocation_observers_)[i]->AllocationStep(bytes_allocated, soon_object, 1816 (*allocation_observers_)[i]->AllocationStep(bytes_allocated, soon_object,
1813 size); 1817 size);
1814 } 1818 }
1815 top_on_previous_step_ = new_top; 1819 top_on_previous_step_ = new_top;
1816 } 1820 }
1817 } 1821 }
1818 1822
1823 std::unique_ptr<ObjectIterator> NewSpace::GetObjectIterator() {
1824 return std::unique_ptr<ObjectIterator>(new SemiSpaceIterator(this));
1825 }
1826
1819 #ifdef VERIFY_HEAP 1827 #ifdef VERIFY_HEAP
1820 // We do not use the SemiSpaceIterator because verification doesn't assume 1828 // We do not use the SemiSpaceIterator because verification doesn't assume
1821 // that it works (it depends on the invariants we are checking). 1829 // that it works (it depends on the invariants we are checking).
1822 void NewSpace::Verify() { 1830 void NewSpace::Verify() {
1823 // The allocation pointer should be in the space or at the very end. 1831 // The allocation pointer should be in the space or at the very end.
1824 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); 1832 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_);
1825 1833
1826 // There should be objects packed in from the low address up to the 1834 // There should be objects packed in from the low address up to the
1827 // allocation pointer. 1835 // allocation pointer.
1828 Address current = to_space_.first_page()->area_start(); 1836 Address current = to_space_.first_page()->area_start();
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
2082 2090
2083 void SemiSpace::set_age_mark(Address mark) { 2091 void SemiSpace::set_age_mark(Address mark) {
2084 DCHECK_EQ(Page::FromAllocationAreaAddress(mark)->owner(), this); 2092 DCHECK_EQ(Page::FromAllocationAreaAddress(mark)->owner(), this);
2085 age_mark_ = mark; 2093 age_mark_ = mark;
2086 // Mark all pages up to the one containing mark. 2094 // Mark all pages up to the one containing mark.
2087 for (Page* p : NewSpacePageRange(space_start(), mark)) { 2095 for (Page* p : NewSpacePageRange(space_start(), mark)) {
2088 p->SetFlag(MemoryChunk::NEW_SPACE_BELOW_AGE_MARK); 2096 p->SetFlag(MemoryChunk::NEW_SPACE_BELOW_AGE_MARK);
2089 } 2097 }
2090 } 2098 }
2091 2099
2100 std::unique_ptr<ObjectIterator> SemiSpace::GetObjectIterator() {
2101 // Use the NewSpace::NewObjectIterator to iterate the ToSpace.
2102 UNREACHABLE();
2103 return std::unique_ptr<ObjectIterator>();
2104 }
2092 2105
2093 #ifdef DEBUG 2106 #ifdef DEBUG
2094 void SemiSpace::Print() {} 2107 void SemiSpace::Print() {}
2095 #endif 2108 #endif
2096 2109
2097 #ifdef VERIFY_HEAP 2110 #ifdef VERIFY_HEAP
2098 void SemiSpace::Verify() { 2111 void SemiSpace::Verify() {
2099 bool is_from_space = (id_ == kFromSpace); 2112 bool is_from_space = (id_ == kFromSpace);
2100 Page* page = anchor_.next_page(); 2113 Page* page = anchor_.next_page();
2101 CHECK(anchor_.owner() == this); 2114 CHECK(anchor_.owner() == this);
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after
3134 Address address = object->address(); 3147 Address address = object->address();
3135 MemoryChunk* chunk = MemoryChunk::FromAddress(address); 3148 MemoryChunk* chunk = MemoryChunk::FromAddress(address);
3136 3149
3137 bool owned = (chunk->owner() == this); 3150 bool owned = (chunk->owner() == this);
3138 3151
3139 SLOW_DCHECK(!owned || FindObject(address)->IsHeapObject()); 3152 SLOW_DCHECK(!owned || FindObject(address)->IsHeapObject());
3140 3153
3141 return owned; 3154 return owned;
3142 } 3155 }
3143 3156
3157 std::unique_ptr<ObjectIterator> LargeObjectSpace::GetObjectIterator() {
3158 return std::unique_ptr<ObjectIterator>(new LargeObjectIterator(this));
3159 }
3144 3160
3145 #ifdef VERIFY_HEAP 3161 #ifdef VERIFY_HEAP
3146 // We do not assume that the large object iterator works, because it depends 3162 // We do not assume that the large object iterator works, because it depends
3147 // on the invariants we are checking during verification. 3163 // on the invariants we are checking during verification.
3148 void LargeObjectSpace::Verify() { 3164 void LargeObjectSpace::Verify() {
3149 for (LargePage* chunk = first_page_; chunk != NULL; 3165 for (LargePage* chunk = first_page_; chunk != NULL;
3150 chunk = chunk->next_page()) { 3166 chunk = chunk->next_page()) {
3151 // Each chunk contains an object that starts at the large object page's 3167 // Each chunk contains an object that starts at the large object page's
3152 // object area start. 3168 // object area start.
3153 HeapObject* object = chunk->GetObject(); 3169 HeapObject* object = chunk->GetObject();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
3235 object->ShortPrint(); 3251 object->ShortPrint();
3236 PrintF("\n"); 3252 PrintF("\n");
3237 } 3253 }
3238 printf(" --------------------------------------\n"); 3254 printf(" --------------------------------------\n");
3239 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); 3255 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes());
3240 } 3256 }
3241 3257
3242 #endif // DEBUG 3258 #endif // DEBUG
3243 } // namespace internal 3259 } // namespace internal
3244 } // namespace v8 3260 } // namespace v8
OLDNEW
« src/heap/spaces.h ('K') | « src/heap/spaces.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698