| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 | 1131 |
| 1133 void PagedSpace::ReleasePage(Page* page) { | 1132 void PagedSpace::ReleasePage(Page* page) { |
| 1134 DCHECK(page->LiveBytes() == 0); | 1133 DCHECK(page->LiveBytes() == 0); |
| 1135 DCHECK(AreaSize() == page->area_size()); | 1134 DCHECK(AreaSize() == page->area_size()); |
| 1136 | 1135 |
| 1137 if (page->WasSwept()) { | 1136 if (page->WasSwept()) { |
| 1138 intptr_t size = free_list_.EvictFreeListItems(page); | 1137 intptr_t size = free_list_.EvictFreeListItems(page); |
| 1139 accounting_stats_.AllocateBytes(size); | 1138 accounting_stats_.AllocateBytes(size); |
| 1140 DCHECK_EQ(AreaSize(), static_cast<int>(size)); | 1139 DCHECK_EQ(AreaSize(), static_cast<int>(size)); |
| 1141 } else { | 1140 } else { |
| 1142 DecreaseUnsweptFreeBytes(page); | 1141 accounting_stats_.DeallocateBytes(page->area_size()); |
| 1143 } | 1142 } |
| 1144 | 1143 |
| 1145 if (page->IsFlagSet(MemoryChunk::SCAN_ON_SCAVENGE)) { | 1144 if (page->IsFlagSet(MemoryChunk::SCAN_ON_SCAVENGE)) { |
| 1146 heap()->decrement_scan_on_scavenge_pages(); | 1145 heap()->decrement_scan_on_scavenge_pages(); |
| 1147 page->ClearFlag(MemoryChunk::SCAN_ON_SCAVENGE); | 1146 page->ClearFlag(MemoryChunk::SCAN_ON_SCAVENGE); |
| 1148 } | 1147 } |
| 1149 | 1148 |
| 1150 DCHECK(!free_list_.ContainsPageFreeListItems(page)); | 1149 DCHECK(!free_list_.ContainsPageFreeListItems(page)); |
| 1151 | 1150 |
| 1152 if (Page::FromAllocationTop(allocation_info_.top()) == page) { | 1151 if (Page::FromAllocationTop(allocation_info_.top()) == page) { |
| (...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2190 wasted_bytes_(0), | 2189 wasted_bytes_(0), |
| 2191 small_list_(this), | 2190 small_list_(this), |
| 2192 medium_list_(this), | 2191 medium_list_(this), |
| 2193 large_list_(this), | 2192 large_list_(this), |
| 2194 huge_list_(this) { | 2193 huge_list_(this) { |
| 2195 Reset(); | 2194 Reset(); |
| 2196 } | 2195 } |
| 2197 | 2196 |
| 2198 | 2197 |
| 2199 intptr_t FreeList::Concatenate(FreeList* other) { | 2198 intptr_t FreeList::Concatenate(FreeList* other) { |
| 2200 intptr_t free_bytes = 0; | 2199 intptr_t usable_bytes = 0; |
| 2200 intptr_t wasted_bytes = 0; |
| 2201 | 2201 |
| 2202 // This is safe (not going to deadlock) since Concatenate operations | 2202 // This is safe (not going to deadlock) since Concatenate operations |
| 2203 // are never performed on the same free lists at the same time in | 2203 // are never performed on the same free lists at the same time in |
| 2204 // reverse order. Furthermore, we only lock if the PagedSpace containing | 2204 // reverse order. Furthermore, we only lock if the PagedSpace containing |
| 2205 // the free list is know to be globally available, i.e., not local. | 2205 // the free list is know to be globally available, i.e., not local. |
| 2206 if (!owner()->is_local()) mutex_.Lock(); | 2206 if (!owner()->is_local()) mutex_.Lock(); |
| 2207 if (!other->owner()->is_local()) other->mutex()->Lock(); | 2207 if (!other->owner()->is_local()) other->mutex()->Lock(); |
| 2208 | 2208 |
| 2209 wasted_bytes_ += other->wasted_bytes_; | 2209 wasted_bytes = other->wasted_bytes_; |
| 2210 wasted_bytes_ += wasted_bytes; |
| 2210 other->wasted_bytes_ = 0; | 2211 other->wasted_bytes_ = 0; |
| 2211 | 2212 |
| 2212 free_bytes += small_list_.Concatenate(other->small_list()); | 2213 usable_bytes += small_list_.Concatenate(other->small_list()); |
| 2213 free_bytes += medium_list_.Concatenate(other->medium_list()); | 2214 usable_bytes += medium_list_.Concatenate(other->medium_list()); |
| 2214 free_bytes += large_list_.Concatenate(other->large_list()); | 2215 usable_bytes += large_list_.Concatenate(other->large_list()); |
| 2215 free_bytes += huge_list_.Concatenate(other->huge_list()); | 2216 usable_bytes += huge_list_.Concatenate(other->huge_list()); |
| 2216 | 2217 |
| 2217 if (!other->owner()->is_local()) other->mutex()->Unlock(); | 2218 if (!other->owner()->is_local()) other->mutex()->Unlock(); |
| 2218 if (!owner()->is_local()) mutex_.Unlock(); | 2219 if (!owner()->is_local()) mutex_.Unlock(); |
| 2219 return free_bytes; | 2220 return usable_bytes + wasted_bytes; |
| 2220 } | 2221 } |
| 2221 | 2222 |
| 2222 | 2223 |
| 2223 void FreeList::Reset() { | 2224 void FreeList::Reset() { |
| 2224 small_list_.Reset(); | 2225 small_list_.Reset(); |
| 2225 medium_list_.Reset(); | 2226 medium_list_.Reset(); |
| 2226 large_list_.Reset(); | 2227 large_list_.Reset(); |
| 2227 huge_list_.Reset(); | 2228 huge_list_.Reset(); |
| 2228 ResetStats(); | 2229 ResetStats(); |
| 2229 } | 2230 } |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2531 | 2532 |
| 2532 | 2533 |
| 2533 // ----------------------------------------------------------------------------- | 2534 // ----------------------------------------------------------------------------- |
| 2534 // OldSpace implementation | 2535 // OldSpace implementation |
| 2535 | 2536 |
| 2536 void PagedSpace::PrepareForMarkCompact() { | 2537 void PagedSpace::PrepareForMarkCompact() { |
| 2537 // We don't have a linear allocation area while sweeping. It will be restored | 2538 // We don't have a linear allocation area while sweeping. It will be restored |
| 2538 // on the first allocation after the sweep. | 2539 // on the first allocation after the sweep. |
| 2539 EmptyAllocationInfo(); | 2540 EmptyAllocationInfo(); |
| 2540 | 2541 |
| 2541 // This counter will be increased for pages which will be swept by the | |
| 2542 // sweeper threads. | |
| 2543 unswept_free_bytes_ = 0; | |
| 2544 | |
| 2545 // Clear the free list before a full GC---it will be rebuilt afterward. | 2542 // Clear the free list before a full GC---it will be rebuilt afterward. |
| 2546 free_list_.Reset(); | 2543 free_list_.Reset(); |
| 2547 } | 2544 } |
| 2548 | 2545 |
| 2549 | 2546 |
| 2550 intptr_t PagedSpace::SizeOfObjects() { | 2547 intptr_t PagedSpace::SizeOfObjects() { |
| 2551 DCHECK(!FLAG_concurrent_sweeping || | 2548 const intptr_t size = Size() - (limit() - top()); |
| 2552 heap()->mark_compact_collector()->sweeping_in_progress() || | |
| 2553 (unswept_free_bytes_ == 0)); | |
| 2554 const intptr_t size = Size() - unswept_free_bytes_ - (limit() - top()); | |
| 2555 DCHECK_GE(size, 0); | 2549 DCHECK_GE(size, 0); |
| 2556 USE(size); | 2550 USE(size); |
| 2557 return size; | 2551 return size; |
| 2558 } | 2552 } |
| 2559 | 2553 |
| 2560 | 2554 |
| 2561 // After we have booted, we have created a map which represents free space | 2555 // After we have booted, we have created a map which represents free space |
| 2562 // on the heap. If there was already a free list then the elements on it | 2556 // on the heap. If there was already a free list then the elements on it |
| 2563 // were created with the wrong FreeSpaceMap (normally NULL), so we need to | 2557 // were created with the wrong FreeSpaceMap (normally NULL), so we need to |
| 2564 // fix them. | 2558 // fix them. |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3150 object->ShortPrint(); | 3144 object->ShortPrint(); |
| 3151 PrintF("\n"); | 3145 PrintF("\n"); |
| 3152 } | 3146 } |
| 3153 printf(" --------------------------------------\n"); | 3147 printf(" --------------------------------------\n"); |
| 3154 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3148 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
| 3155 } | 3149 } |
| 3156 | 3150 |
| 3157 #endif // DEBUG | 3151 #endif // DEBUG |
| 3158 } // namespace internal | 3152 } // namespace internal |
| 3159 } // namespace v8 | 3153 } // namespace v8 |
| OLD | NEW |