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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
977 skip_list_ = nullptr; | 979 skip_list_ = nullptr; |
978 } | 980 } |
979 if (mutex_ != nullptr) { | 981 if (mutex_ != nullptr) { |
980 delete mutex_; | 982 delete mutex_; |
981 mutex_ = nullptr; | 983 mutex_ = nullptr; |
982 } | 984 } |
983 if (old_to_new_slots_ != nullptr) ReleaseOldToNewSlots(); | 985 if (old_to_new_slots_ != nullptr) ReleaseOldToNewSlots(); |
984 if (old_to_old_slots_ != nullptr) ReleaseOldToOldSlots(); | 986 if (old_to_old_slots_ != nullptr) ReleaseOldToOldSlots(); |
985 if (typed_old_to_new_slots_ != nullptr) ReleaseTypedOldToNewSlots(); | 987 if (typed_old_to_new_slots_ != nullptr) ReleaseTypedOldToNewSlots(); |
986 if (typed_old_to_old_slots_ != nullptr) ReleaseTypedOldToOldSlots(); | 988 if (typed_old_to_old_slots_ != nullptr) ReleaseTypedOldToOldSlots(); |
989 if (local_tracker_ != nullptr) ReleaseLocalTracker(); | |
987 } | 990 } |
988 | 991 |
989 static SlotSet* AllocateSlotSet(size_t size, Address page_start) { | 992 static SlotSet* AllocateSlotSet(size_t size, Address page_start) { |
990 size_t pages = (size + Page::kPageSize - 1) / Page::kPageSize; | 993 size_t pages = (size + Page::kPageSize - 1) / Page::kPageSize; |
991 DCHECK(pages > 0); | 994 DCHECK(pages > 0); |
992 SlotSet* slot_set = new SlotSet[pages]; | 995 SlotSet* slot_set = new SlotSet[pages]; |
993 for (size_t i = 0; i < pages; i++) { | 996 for (size_t i = 0; i < pages; i++) { |
994 slot_set[i].SetPageStart(page_start + i * Page::kPageSize); | 997 slot_set[i].SetPageStart(page_start + i * Page::kPageSize); |
995 } | 998 } |
996 return slot_set; | 999 return slot_set; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1028 | 1031 |
1029 void MemoryChunk::AllocateTypedOldToOldSlots() { | 1032 void MemoryChunk::AllocateTypedOldToOldSlots() { |
1030 DCHECK(nullptr == typed_old_to_old_slots_); | 1033 DCHECK(nullptr == typed_old_to_old_slots_); |
1031 typed_old_to_old_slots_ = new TypedSlotSet(address()); | 1034 typed_old_to_old_slots_ = new TypedSlotSet(address()); |
1032 } | 1035 } |
1033 | 1036 |
1034 void MemoryChunk::ReleaseTypedOldToOldSlots() { | 1037 void MemoryChunk::ReleaseTypedOldToOldSlots() { |
1035 delete typed_old_to_old_slots_; | 1038 delete typed_old_to_old_slots_; |
1036 typed_old_to_old_slots_ = nullptr; | 1039 typed_old_to_old_slots_ = nullptr; |
1037 } | 1040 } |
1041 | |
1042 void MemoryChunk::AllocateLocalTracker() { | |
1043 DCHECK_NULL(local_tracker_); | |
1044 local_tracker_ = new LocalArrayBufferTracker(heap()); | |
1045 } | |
1046 | |
1047 void MemoryChunk::ReleaseLocalTracker() { | |
1048 DCHECK_NOT_NULL(local_tracker_); | |
1049 delete local_tracker_; | |
1050 local_tracker_ = nullptr; | |
1051 } | |
1052 | |
1038 // ----------------------------------------------------------------------------- | 1053 // ----------------------------------------------------------------------------- |
1039 // PagedSpace implementation | 1054 // PagedSpace implementation |
1040 | 1055 |
1041 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::NEW_SPACE) == | 1056 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::NEW_SPACE) == |
1042 ObjectSpace::kObjectSpaceNewSpace); | 1057 ObjectSpace::kObjectSpaceNewSpace); |
1043 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::OLD_SPACE) == | 1058 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::OLD_SPACE) == |
1044 ObjectSpace::kObjectSpaceOldSpace); | 1059 ObjectSpace::kObjectSpaceOldSpace); |
1045 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::CODE_SPACE) == | 1060 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::CODE_SPACE) == |
1046 ObjectSpace::kObjectSpaceCodeSpace); | 1061 ObjectSpace::kObjectSpaceCodeSpace); |
1047 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::MAP_SPACE) == | 1062 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::MAP_SPACE) == |
(...skipping 18 matching lines...) Expand all Loading... | |
1066 } | 1081 } |
1067 | 1082 |
1068 | 1083 |
1069 bool PagedSpace::SetUp() { return true; } | 1084 bool PagedSpace::SetUp() { return true; } |
1070 | 1085 |
1071 | 1086 |
1072 bool PagedSpace::HasBeenSetUp() { return true; } | 1087 bool PagedSpace::HasBeenSetUp() { return true; } |
1073 | 1088 |
1074 | 1089 |
1075 void PagedSpace::TearDown() { | 1090 void PagedSpace::TearDown() { |
1076 PageIterator iterator(this); | 1091 PageIterator iterator(this); |
Hannes Payer (out of office)
2016/06/03 07:43:15
Factor that out into a function.
Michael Lippautz
2016/06/03 08:07:36
Done.
| |
1077 while (iterator.has_next()) { | 1092 while (iterator.has_next()) { |
1078 heap()->memory_allocator()->Free<MemoryAllocator::kFull>(iterator.next()); | 1093 Page* page = iterator.next(); |
1094 Bitmap::Clear(page); | |
1095 { | |
1096 // Lock is required for FreeDead. | |
1097 base::LockGuard<base::Mutex> guard(page->mutex()); | |
1098 ArrayBufferTracker::FreeDead(page); | |
1099 } | |
1100 heap()->memory_allocator()->Free<MemoryAllocator::kFull>(page); | |
1079 } | 1101 } |
1080 anchor_.set_next_page(&anchor_); | 1102 anchor_.set_next_page(&anchor_); |
1081 anchor_.set_prev_page(&anchor_); | 1103 anchor_.set_prev_page(&anchor_); |
1082 accounting_stats_.Clear(); | 1104 accounting_stats_.Clear(); |
1083 } | 1105 } |
1084 | 1106 |
1085 void PagedSpace::RefillFreeList() { | 1107 void PagedSpace::RefillFreeList() { |
1086 // Any PagedSpace might invoke RefillFreeList. We filter all but our old | 1108 // Any PagedSpace might invoke RefillFreeList. We filter all but our old |
1087 // generation spaces out. | 1109 // generation spaces out. |
1088 if (identity() != OLD_SPACE && identity() != CODE_SPACE && | 1110 if (identity() != OLD_SPACE && identity() != CODE_SPACE && |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1686 DCHECK_GE(maximum_capacity, Page::kPageSize); | 1708 DCHECK_GE(maximum_capacity, Page::kPageSize); |
1687 minimum_capacity_ = RoundDown(initial_capacity, Page::kPageSize); | 1709 minimum_capacity_ = RoundDown(initial_capacity, Page::kPageSize); |
1688 current_capacity_ = minimum_capacity_; | 1710 current_capacity_ = minimum_capacity_; |
1689 maximum_capacity_ = RoundDown(maximum_capacity, Page::kPageSize); | 1711 maximum_capacity_ = RoundDown(maximum_capacity, Page::kPageSize); |
1690 committed_ = false; | 1712 committed_ = false; |
1691 } | 1713 } |
1692 | 1714 |
1693 | 1715 |
1694 void SemiSpace::TearDown() { | 1716 void SemiSpace::TearDown() { |
1695 // Properly uncommit memory to keep the allocator counters in sync. | 1717 // Properly uncommit memory to keep the allocator counters in sync. |
1696 if (is_committed()) Uncommit(); | 1718 if (is_committed()) { |
1719 NewSpacePageIterator it(this); | |
Hannes Payer (out of office)
2016/06/03 07:43:15
Factor that out into a function. It should reuse t
Michael Lippautz
2016/06/03 08:07:36
Done.
| |
1720 while (it.has_next()) { | |
1721 Page* page = it.next(); | |
1722 Bitmap::Clear(page); | |
1723 { | |
1724 // Lock is required for FreeDead. | |
1725 base::LockGuard<base::Mutex> guard(page->mutex()); | |
1726 ArrayBufferTracker::FreeDead(page); | |
1727 } | |
1728 } | |
1729 Uncommit(); | |
1730 } | |
1697 current_capacity_ = maximum_capacity_ = 0; | 1731 current_capacity_ = maximum_capacity_ = 0; |
1698 } | 1732 } |
1699 | 1733 |
1700 | 1734 |
1701 bool SemiSpace::Commit() { | 1735 bool SemiSpace::Commit() { |
1702 DCHECK(!is_committed()); | 1736 DCHECK(!is_committed()); |
1703 Page* current = anchor(); | 1737 Page* current = anchor(); |
1704 const int num_pages = current_capacity_ / Page::kPageSize; | 1738 const int num_pages = current_capacity_ / Page::kPageSize; |
1705 for (int pages_added = 0; pages_added < num_pages; pages_added++) { | 1739 for (int pages_added = 0; pages_added < num_pages; pages_added++) { |
1706 Page* new_page = | 1740 Page* new_page = |
(...skipping 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3198 object->ShortPrint(); | 3232 object->ShortPrint(); |
3199 PrintF("\n"); | 3233 PrintF("\n"); |
3200 } | 3234 } |
3201 printf(" --------------------------------------\n"); | 3235 printf(" --------------------------------------\n"); |
3202 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3236 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3203 } | 3237 } |
3204 | 3238 |
3205 #endif // DEBUG | 3239 #endif // DEBUG |
3206 } // namespace internal | 3240 } // namespace internal |
3207 } // namespace v8 | 3241 } // namespace v8 |
OLD | NEW |