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

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

Issue 1380723002: [heap] Remove unswept bytes counter (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added CHECK Created 5 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
« no previous file with comments | « 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 "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/full-codegen/full-codegen.h" 9 #include "src/full-codegen/full-codegen.h"
10 #include "src/heap/slots-buffer.h" 10 #include "src/heap/slots-buffer.h"
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 return false; 917 return false;
918 } 918 }
919 919
920 920
921 // ----------------------------------------------------------------------------- 921 // -----------------------------------------------------------------------------
922 // MemoryChunk implementation 922 // MemoryChunk implementation
923 923
924 void MemoryChunk::IncrementLiveBytesFromMutator(HeapObject* object, int by) { 924 void MemoryChunk::IncrementLiveBytesFromMutator(HeapObject* object, int by) {
925 MemoryChunk* chunk = MemoryChunk::FromAddress(object->address()); 925 MemoryChunk* chunk = MemoryChunk::FromAddress(object->address());
926 if (!chunk->InNewSpace() && !static_cast<Page*>(chunk)->WasSwept()) { 926 if (!chunk->InNewSpace() && !static_cast<Page*>(chunk)->WasSwept()) {
927 static_cast<PagedSpace*>(chunk->owner())->IncrementUnsweptFreeBytes(-by); 927 static_cast<PagedSpace*>(chunk->owner())->Allocate(by);
928 } 928 }
929 chunk->IncrementLiveBytes(by); 929 chunk->IncrementLiveBytes(by);
930 } 930 }
931 931
932 932
933 void MemoryChunk::ReleaseAllocatedMemory() { 933 void MemoryChunk::ReleaseAllocatedMemory() {
934 delete slots_buffer_; 934 delete slots_buffer_;
935 delete skip_list_; 935 delete skip_list_;
936 delete mutex_; 936 delete mutex_;
937 } 937 }
938 938
939 939
940 // ----------------------------------------------------------------------------- 940 // -----------------------------------------------------------------------------
941 // PagedSpace implementation 941 // PagedSpace implementation
942 942
943 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::NEW_SPACE) == 943 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::NEW_SPACE) ==
944 ObjectSpace::kObjectSpaceNewSpace); 944 ObjectSpace::kObjectSpaceNewSpace);
945 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::OLD_SPACE) == 945 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::OLD_SPACE) ==
946 ObjectSpace::kObjectSpaceOldSpace); 946 ObjectSpace::kObjectSpaceOldSpace);
947 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::CODE_SPACE) == 947 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::CODE_SPACE) ==
948 ObjectSpace::kObjectSpaceCodeSpace); 948 ObjectSpace::kObjectSpaceCodeSpace);
949 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::MAP_SPACE) == 949 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::MAP_SPACE) ==
950 ObjectSpace::kObjectSpaceMapSpace); 950 ObjectSpace::kObjectSpaceMapSpace);
951 951
952 952
953 PagedSpace::PagedSpace(Heap* heap, AllocationSpace space, 953 PagedSpace::PagedSpace(Heap* heap, AllocationSpace space,
954 Executability executable) 954 Executability executable)
955 : Space(heap, space, executable), 955 : Space(heap, space, executable),
956 free_list_(this), 956 free_list_(this),
957 unswept_free_bytes_(0),
958 end_of_unswept_pages_(NULL) { 957 end_of_unswept_pages_(NULL) {
959 area_size_ = MemoryAllocator::PageAreaSize(space); 958 area_size_ = MemoryAllocator::PageAreaSize(space);
960 accounting_stats_.Clear(); 959 accounting_stats_.Clear();
961 960
962 allocation_info_.set_top(NULL); 961 allocation_info_.set_top(NULL);
963 allocation_info_.set_limit(NULL); 962 allocation_info_.set_limit(NULL);
964 963
965 anchor_.InitializeAsAnchor(this); 964 anchor_.InitializeAsAnchor(this);
966 } 965 }
967 966
(...skipping 17 matching lines...) Expand all
985 984
986 void PagedSpace::MoveOverFreeMemory(PagedSpace* other) { 985 void PagedSpace::MoveOverFreeMemory(PagedSpace* other) {
987 DCHECK(identity() == other->identity()); 986 DCHECK(identity() == other->identity());
988 // Destroy the linear allocation space of {other}. This is needed to 987 // Destroy the linear allocation space of {other}. This is needed to
989 // (a) not waste the memory and 988 // (a) not waste the memory and
990 // (b) keep the rest of the chunk in an iterable state (filler is needed). 989 // (b) keep the rest of the chunk in an iterable state (filler is needed).
991 other->EmptyAllocationInfo(); 990 other->EmptyAllocationInfo();
992 991
993 // Move over the free list. Concatenate makes sure that the source free list 992 // Move over the free list. Concatenate makes sure that the source free list
994 // gets properly reset after moving over all nodes. 993 // gets properly reset after moving over all nodes.
995 intptr_t freed_bytes = free_list_.Concatenate(other->free_list()); 994 intptr_t added = free_list_.Concatenate(other->free_list());
996 995
997 // Moved memory is not recorded as allocated memory, but rather increases and 996 // Moved memory is not recorded as allocated memory, but rather increases and
998 // decreases capacity of the corresponding spaces. Used size and waste size 997 // decreases capacity of the corresponding spaces. Used size and waste size
999 // are maintained by the receiving space upon allocating and freeing blocks. 998 // are maintained by the receiving space upon allocating and freeing blocks.
1000 other->accounting_stats_.DecreaseCapacity(freed_bytes); 999 other->accounting_stats_.DecreaseCapacity(added);
1001 accounting_stats_.IncreaseCapacity(freed_bytes); 1000 accounting_stats_.IncreaseCapacity(added);
1002 } 1001 }
1003 1002
1004 1003
1005 void PagedSpace::MergeCompactionSpace(CompactionSpace* other) { 1004 void PagedSpace::MergeCompactionSpace(CompactionSpace* other) {
1006 // Unmerged fields: 1005 // Unmerged fields:
1007 // area_size_ 1006 // area_size_
1008 // allocation_info_ 1007 // allocation_info_
1009 // end_of_unswept_pages_ 1008 // end_of_unswept_pages_
1010 // unswept_free_bytes_ 1009 // unswept_free_bytes_
1011 // anchor_ 1010 // anchor_
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 1134
1136 1135
1137 void PagedSpace::ReleasePage(Page* page) { 1136 void PagedSpace::ReleasePage(Page* page) {
1138 DCHECK(page->LiveBytes() == 0); 1137 DCHECK(page->LiveBytes() == 0);
1139 DCHECK(AreaSize() == page->area_size()); 1138 DCHECK(AreaSize() == page->area_size());
1140 1139
1141 if (page->WasSwept()) { 1140 if (page->WasSwept()) {
1142 intptr_t size = free_list_.EvictFreeListItems(page); 1141 intptr_t size = free_list_.EvictFreeListItems(page);
1143 accounting_stats_.AllocateBytes(size); 1142 accounting_stats_.AllocateBytes(size);
1144 DCHECK_EQ(AreaSize(), static_cast<int>(size)); 1143 DCHECK_EQ(AreaSize(), static_cast<int>(size));
1145 } else {
1146 DecreaseUnsweptFreeBytes(page);
1147 } 1144 }
1148 1145
1149 if (page->IsFlagSet(MemoryChunk::SCAN_ON_SCAVENGE)) { 1146 if (page->IsFlagSet(MemoryChunk::SCAN_ON_SCAVENGE)) {
1150 heap()->decrement_scan_on_scavenge_pages(); 1147 heap()->decrement_scan_on_scavenge_pages();
1151 page->ClearFlag(MemoryChunk::SCAN_ON_SCAVENGE); 1148 page->ClearFlag(MemoryChunk::SCAN_ON_SCAVENGE);
1152 } 1149 }
1153 1150
1154 DCHECK(!free_list_.ContainsPageFreeListItems(page)); 1151 DCHECK(!free_list_.ContainsPageFreeListItems(page));
1155 1152
1156 if (Page::FromAllocationTop(allocation_info_.top()) == page) { 1153 if (Page::FromAllocationTop(allocation_info_.top()) == page) {
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after
2244 wasted_bytes_(0), 2241 wasted_bytes_(0),
2245 small_list_(this, kSmall), 2242 small_list_(this, kSmall),
2246 medium_list_(this, kMedium), 2243 medium_list_(this, kMedium),
2247 large_list_(this, kLarge), 2244 large_list_(this, kLarge),
2248 huge_list_(this, kHuge) { 2245 huge_list_(this, kHuge) {
2249 Reset(); 2246 Reset();
2250 } 2247 }
2251 2248
2252 2249
2253 intptr_t FreeList::Concatenate(FreeList* other) { 2250 intptr_t FreeList::Concatenate(FreeList* other) {
2254 intptr_t free_bytes = 0; 2251 intptr_t usable_bytes = 0;
2252 intptr_t wasted_bytes = 0;
2255 2253
2256 // This is safe (not going to deadlock) since Concatenate operations 2254 // This is safe (not going to deadlock) since Concatenate operations
2257 // are never performed on the same free lists at the same time in 2255 // are never performed on the same free lists at the same time in
2258 // reverse order. Furthermore, we only lock if the PagedSpace containing 2256 // reverse order. Furthermore, we only lock if the PagedSpace containing
2259 // the free list is know to be globally available, i.e., not local. 2257 // the free list is know to be globally available, i.e., not local.
2260 if (!owner()->is_local()) mutex_.Lock(); 2258 if (!owner()->is_local()) mutex_.Lock();
2261 if (!other->owner()->is_local()) other->mutex()->Lock(); 2259 if (!other->owner()->is_local()) other->mutex()->Lock();
2262 2260
2263 wasted_bytes_ += other->wasted_bytes_; 2261 wasted_bytes = other->wasted_bytes_;
2262 wasted_bytes_ += wasted_bytes;
2264 other->wasted_bytes_ = 0; 2263 other->wasted_bytes_ = 0;
2265 2264
2266 free_bytes += small_list_.Concatenate(other->small_list()); 2265 usable_bytes += small_list_.Concatenate(other->small_list());
2267 free_bytes += medium_list_.Concatenate(other->medium_list()); 2266 usable_bytes += medium_list_.Concatenate(other->medium_list());
2268 free_bytes += large_list_.Concatenate(other->large_list()); 2267 usable_bytes += large_list_.Concatenate(other->large_list());
2269 free_bytes += huge_list_.Concatenate(other->huge_list()); 2268 usable_bytes += huge_list_.Concatenate(other->huge_list());
2270 2269
2271 if (!other->owner()->is_local()) other->mutex()->Unlock(); 2270 if (!other->owner()->is_local()) other->mutex()->Unlock();
2272 if (!owner()->is_local()) mutex_.Unlock(); 2271 if (!owner()->is_local()) mutex_.Unlock();
2273 return free_bytes; 2272 return usable_bytes + wasted_bytes;
2274 } 2273 }
2275 2274
2276 2275
2277 void FreeList::Reset() { 2276 void FreeList::Reset() {
2278 small_list_.Reset(); 2277 small_list_.Reset();
2279 medium_list_.Reset(); 2278 medium_list_.Reset();
2280 large_list_.Reset(); 2279 large_list_.Reset();
2281 huge_list_.Reset(); 2280 huge_list_.Reset();
2282 ResetStats(); 2281 ResetStats();
2283 } 2282 }
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
2548 2547
2549 2548
2550 // ----------------------------------------------------------------------------- 2549 // -----------------------------------------------------------------------------
2551 // OldSpace implementation 2550 // OldSpace implementation
2552 2551
2553 void PagedSpace::PrepareForMarkCompact() { 2552 void PagedSpace::PrepareForMarkCompact() {
2554 // We don't have a linear allocation area while sweeping. It will be restored 2553 // We don't have a linear allocation area while sweeping. It will be restored
2555 // on the first allocation after the sweep. 2554 // on the first allocation after the sweep.
2556 EmptyAllocationInfo(); 2555 EmptyAllocationInfo();
2557 2556
2558 // This counter will be increased for pages which will be swept by the
2559 // sweeper threads.
2560 unswept_free_bytes_ = 0;
2561
2562 // Clear the free list before a full GC---it will be rebuilt afterward. 2557 // Clear the free list before a full GC---it will be rebuilt afterward.
2563 free_list_.Reset(); 2558 free_list_.Reset();
2564 } 2559 }
2565 2560
2566 2561
2567 intptr_t PagedSpace::SizeOfObjects() { 2562 intptr_t PagedSpace::SizeOfObjects() {
2568 DCHECK(!FLAG_concurrent_sweeping || 2563 const intptr_t size = Size() - (limit() - top());
2569 heap()->mark_compact_collector()->sweeping_in_progress() ||
2570 (unswept_free_bytes_ == 0));
2571 const intptr_t size = Size() - unswept_free_bytes_ - (limit() - top());
2572 DCHECK_GE(size, 0); 2564 DCHECK_GE(size, 0);
2573 USE(size); 2565 USE(size);
2574 return size; 2566 return size;
2575 } 2567 }
2576 2568
2577 2569
2578 // After we have booted, we have created a map which represents free space 2570 // After we have booted, we have created a map which represents free space
2579 // on the heap. If there was already a free list then the elements on it 2571 // on the heap. If there was already a free list then the elements on it
2580 // were created with the wrong FreeSpaceMap (normally NULL), so we need to 2572 // were created with the wrong FreeSpaceMap (normally NULL), so we need to
2581 // fix them. 2573 // fix them.
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
3164 object->ShortPrint(); 3156 object->ShortPrint();
3165 PrintF("\n"); 3157 PrintF("\n");
3166 } 3158 }
3167 printf(" --------------------------------------\n"); 3159 printf(" --------------------------------------\n");
3168 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); 3160 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes());
3169 } 3161 }
3170 3162
3171 #endif // DEBUG 3163 #endif // DEBUG
3172 } // namespace internal 3164 } // namespace internal
3173 } // namespace v8 3165 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/spaces.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698