| 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/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/slot-set.h" | 12 #include "src/heap/slot-set.h" |
| 12 #include "src/macro-assembler.h" | 13 #include "src/macro-assembler.h" |
| 13 #include "src/msan.h" | 14 #include "src/msan.h" |
| 14 #include "src/snapshot/snapshot.h" | 15 #include "src/snapshot/snapshot.h" |
| 15 #include "src/v8.h" | 16 #include "src/v8.h" |
| 16 | 17 |
| 17 namespace v8 { | 18 namespace v8 { |
| 18 namespace internal { | 19 namespace internal { |
| 19 | 20 |
| 20 | 21 |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 chunk->InitializeReservedMemory(); | 505 chunk->InitializeReservedMemory(); |
| 505 chunk->old_to_new_slots_ = nullptr; | 506 chunk->old_to_new_slots_ = nullptr; |
| 506 chunk->old_to_old_slots_ = nullptr; | 507 chunk->old_to_old_slots_ = nullptr; |
| 507 chunk->typed_old_to_new_slots_ = nullptr; | 508 chunk->typed_old_to_new_slots_ = nullptr; |
| 508 chunk->typed_old_to_old_slots_ = nullptr; | 509 chunk->typed_old_to_old_slots_ = nullptr; |
| 509 chunk->skip_list_ = nullptr; | 510 chunk->skip_list_ = nullptr; |
| 510 chunk->write_barrier_counter_ = kWriteBarrierCounterGranularity; | 511 chunk->write_barrier_counter_ = kWriteBarrierCounterGranularity; |
| 511 chunk->progress_bar_ = 0; | 512 chunk->progress_bar_ = 0; |
| 512 chunk->high_water_mark_.SetValue(static_cast<intptr_t>(area_start - base)); | 513 chunk->high_water_mark_.SetValue(static_cast<intptr_t>(area_start - base)); |
| 513 chunk->concurrent_sweeping_state().SetValue(kSweepingDone); | 514 chunk->concurrent_sweeping_state().SetValue(kSweepingDone); |
| 514 chunk->mutex_ = nullptr; | 515 chunk->mutex_ = new base::Mutex(); |
| 515 chunk->available_in_free_list_ = 0; | 516 chunk->available_in_free_list_ = 0; |
| 516 chunk->wasted_memory_ = 0; | 517 chunk->wasted_memory_ = 0; |
| 517 chunk->ResetLiveBytes(); | 518 chunk->ResetLiveBytes(); |
| 518 Bitmap::Clear(chunk); | 519 Bitmap::Clear(chunk); |
| 519 chunk->set_next_chunk(nullptr); | 520 chunk->set_next_chunk(nullptr); |
| 520 chunk->set_prev_chunk(nullptr); | 521 chunk->set_prev_chunk(nullptr); |
| 522 chunk->local_tracker_ = nullptr; |
| 521 | 523 |
| 522 DCHECK(OFFSET_OF(MemoryChunk, flags_) == kFlagsOffset); | 524 DCHECK(OFFSET_OF(MemoryChunk, flags_) == kFlagsOffset); |
| 523 DCHECK(OFFSET_OF(MemoryChunk, live_byte_count_) == kLiveBytesOffset); | 525 DCHECK(OFFSET_OF(MemoryChunk, live_byte_count_) == kLiveBytesOffset); |
| 524 | 526 |
| 525 if (executable == EXECUTABLE) { | 527 if (executable == EXECUTABLE) { |
| 526 chunk->SetFlag(IS_EXECUTABLE); | 528 chunk->SetFlag(IS_EXECUTABLE); |
| 527 } | 529 } |
| 528 | 530 |
| 529 if (reservation != nullptr) { | 531 if (reservation != nullptr) { |
| 530 chunk->reservation_.TakeControl(reservation); | 532 chunk->reservation_.TakeControl(reservation); |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 skip_list_ = nullptr; | 1005 skip_list_ = nullptr; |
| 1004 } | 1006 } |
| 1005 if (mutex_ != nullptr) { | 1007 if (mutex_ != nullptr) { |
| 1006 delete mutex_; | 1008 delete mutex_; |
| 1007 mutex_ = nullptr; | 1009 mutex_ = nullptr; |
| 1008 } | 1010 } |
| 1009 if (old_to_new_slots_ != nullptr) ReleaseOldToNewSlots(); | 1011 if (old_to_new_slots_ != nullptr) ReleaseOldToNewSlots(); |
| 1010 if (old_to_old_slots_ != nullptr) ReleaseOldToOldSlots(); | 1012 if (old_to_old_slots_ != nullptr) ReleaseOldToOldSlots(); |
| 1011 if (typed_old_to_new_slots_ != nullptr) ReleaseTypedOldToNewSlots(); | 1013 if (typed_old_to_new_slots_ != nullptr) ReleaseTypedOldToNewSlots(); |
| 1012 if (typed_old_to_old_slots_ != nullptr) ReleaseTypedOldToOldSlots(); | 1014 if (typed_old_to_old_slots_ != nullptr) ReleaseTypedOldToOldSlots(); |
| 1015 if (local_tracker_ != nullptr) ReleaseLocalTracker(); |
| 1013 } | 1016 } |
| 1014 | 1017 |
| 1015 static SlotSet* AllocateSlotSet(size_t size, Address page_start) { | 1018 static SlotSet* AllocateSlotSet(size_t size, Address page_start) { |
| 1016 size_t pages = (size + Page::kPageSize - 1) / Page::kPageSize; | 1019 size_t pages = (size + Page::kPageSize - 1) / Page::kPageSize; |
| 1017 DCHECK(pages > 0); | 1020 DCHECK(pages > 0); |
| 1018 SlotSet* slot_set = new SlotSet[pages]; | 1021 SlotSet* slot_set = new SlotSet[pages]; |
| 1019 for (size_t i = 0; i < pages; i++) { | 1022 for (size_t i = 0; i < pages; i++) { |
| 1020 slot_set[i].SetPageStart(page_start + i * Page::kPageSize); | 1023 slot_set[i].SetPageStart(page_start + i * Page::kPageSize); |
| 1021 } | 1024 } |
| 1022 return slot_set; | 1025 return slot_set; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 | 1057 |
| 1055 void MemoryChunk::AllocateTypedOldToOldSlots() { | 1058 void MemoryChunk::AllocateTypedOldToOldSlots() { |
| 1056 DCHECK(nullptr == typed_old_to_old_slots_); | 1059 DCHECK(nullptr == typed_old_to_old_slots_); |
| 1057 typed_old_to_old_slots_ = new TypedSlotSet(address()); | 1060 typed_old_to_old_slots_ = new TypedSlotSet(address()); |
| 1058 } | 1061 } |
| 1059 | 1062 |
| 1060 void MemoryChunk::ReleaseTypedOldToOldSlots() { | 1063 void MemoryChunk::ReleaseTypedOldToOldSlots() { |
| 1061 delete typed_old_to_old_slots_; | 1064 delete typed_old_to_old_slots_; |
| 1062 typed_old_to_old_slots_ = nullptr; | 1065 typed_old_to_old_slots_ = nullptr; |
| 1063 } | 1066 } |
| 1067 |
| 1068 void MemoryChunk::AllocateLocalTracker() { |
| 1069 DCHECK_NULL(local_tracker_); |
| 1070 local_tracker_ = new LocalArrayBufferTracker(heap()); |
| 1071 } |
| 1072 |
| 1073 void MemoryChunk::ReleaseLocalTracker() { |
| 1074 DCHECK_NOT_NULL(local_tracker_); |
| 1075 delete local_tracker_; |
| 1076 local_tracker_ = nullptr; |
| 1077 } |
| 1078 |
| 1064 // ----------------------------------------------------------------------------- | 1079 // ----------------------------------------------------------------------------- |
| 1065 // PagedSpace implementation | 1080 // PagedSpace implementation |
| 1066 | 1081 |
| 1067 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::NEW_SPACE) == | 1082 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::NEW_SPACE) == |
| 1068 ObjectSpace::kObjectSpaceNewSpace); | 1083 ObjectSpace::kObjectSpaceNewSpace); |
| 1069 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::OLD_SPACE) == | 1084 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::OLD_SPACE) == |
| 1070 ObjectSpace::kObjectSpaceOldSpace); | 1085 ObjectSpace::kObjectSpaceOldSpace); |
| 1071 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::CODE_SPACE) == | 1086 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::CODE_SPACE) == |
| 1072 ObjectSpace::kObjectSpaceCodeSpace); | 1087 ObjectSpace::kObjectSpaceCodeSpace); |
| 1073 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::MAP_SPACE) == | 1088 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::MAP_SPACE) == |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1094 | 1109 |
| 1095 bool PagedSpace::SetUp() { return true; } | 1110 bool PagedSpace::SetUp() { return true; } |
| 1096 | 1111 |
| 1097 | 1112 |
| 1098 bool PagedSpace::HasBeenSetUp() { return true; } | 1113 bool PagedSpace::HasBeenSetUp() { return true; } |
| 1099 | 1114 |
| 1100 | 1115 |
| 1101 void PagedSpace::TearDown() { | 1116 void PagedSpace::TearDown() { |
| 1102 PageIterator iterator(this); | 1117 PageIterator iterator(this); |
| 1103 while (iterator.has_next()) { | 1118 while (iterator.has_next()) { |
| 1104 heap()->memory_allocator()->Free<MemoryAllocator::kFull>(iterator.next()); | 1119 Page* page = iterator.next(); |
| 1120 ArrayBufferTracker::FreeAll(page); |
| 1121 heap()->memory_allocator()->Free<MemoryAllocator::kFull>(page); |
| 1105 } | 1122 } |
| 1106 anchor_.set_next_page(&anchor_); | 1123 anchor_.set_next_page(&anchor_); |
| 1107 anchor_.set_prev_page(&anchor_); | 1124 anchor_.set_prev_page(&anchor_); |
| 1108 accounting_stats_.Clear(); | 1125 accounting_stats_.Clear(); |
| 1109 } | 1126 } |
| 1110 | 1127 |
| 1111 void PagedSpace::RefillFreeList() { | 1128 void PagedSpace::RefillFreeList() { |
| 1112 // Any PagedSpace might invoke RefillFreeList. We filter all but our old | 1129 // Any PagedSpace might invoke RefillFreeList. We filter all but our old |
| 1113 // generation spaces out. | 1130 // generation spaces out. |
| 1114 if (identity() != OLD_SPACE && identity() != CODE_SPACE && | 1131 if (identity() != OLD_SPACE && identity() != CODE_SPACE && |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1712 DCHECK_GE(maximum_capacity, Page::kPageSize); | 1729 DCHECK_GE(maximum_capacity, Page::kPageSize); |
| 1713 minimum_capacity_ = RoundDown(initial_capacity, Page::kPageSize); | 1730 minimum_capacity_ = RoundDown(initial_capacity, Page::kPageSize); |
| 1714 current_capacity_ = minimum_capacity_; | 1731 current_capacity_ = minimum_capacity_; |
| 1715 maximum_capacity_ = RoundDown(maximum_capacity, Page::kPageSize); | 1732 maximum_capacity_ = RoundDown(maximum_capacity, Page::kPageSize); |
| 1716 committed_ = false; | 1733 committed_ = false; |
| 1717 } | 1734 } |
| 1718 | 1735 |
| 1719 | 1736 |
| 1720 void SemiSpace::TearDown() { | 1737 void SemiSpace::TearDown() { |
| 1721 // Properly uncommit memory to keep the allocator counters in sync. | 1738 // Properly uncommit memory to keep the allocator counters in sync. |
| 1722 if (is_committed()) Uncommit(); | 1739 if (is_committed()) { |
| 1740 NewSpacePageIterator it(this); |
| 1741 while (it.has_next()) { |
| 1742 Page* page = it.next(); |
| 1743 ArrayBufferTracker::FreeAll(page); |
| 1744 } |
| 1745 Uncommit(); |
| 1746 } |
| 1723 current_capacity_ = maximum_capacity_ = 0; | 1747 current_capacity_ = maximum_capacity_ = 0; |
| 1724 } | 1748 } |
| 1725 | 1749 |
| 1726 | 1750 |
| 1727 bool SemiSpace::Commit() { | 1751 bool SemiSpace::Commit() { |
| 1728 DCHECK(!is_committed()); | 1752 DCHECK(!is_committed()); |
| 1729 Page* current = anchor(); | 1753 Page* current = anchor(); |
| 1730 const int num_pages = current_capacity_ / Page::kPageSize; | 1754 const int num_pages = current_capacity_ / Page::kPageSize; |
| 1731 for (int pages_added = 0; pages_added < num_pages; pages_added++) { | 1755 for (int pages_added = 0; pages_added < num_pages; pages_added++) { |
| 1732 Page* new_page = | 1756 Page* new_page = |
| (...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3240 object->ShortPrint(); | 3264 object->ShortPrint(); |
| 3241 PrintF("\n"); | 3265 PrintF("\n"); |
| 3242 } | 3266 } |
| 3243 printf(" --------------------------------------\n"); | 3267 printf(" --------------------------------------\n"); |
| 3244 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3268 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
| 3245 } | 3269 } |
| 3246 | 3270 |
| 3247 #endif // DEBUG | 3271 #endif // DEBUG |
| 3248 } // namespace internal | 3272 } // namespace internal |
| 3249 } // namespace v8 | 3273 } // namespace v8 |
| OLD | NEW |