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 <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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 | 520 |
521 DCHECK(base == chunk->address()); | 521 DCHECK(base == chunk->address()); |
522 | 522 |
523 chunk->heap_ = heap; | 523 chunk->heap_ = heap; |
524 chunk->size_ = size; | 524 chunk->size_ = size; |
525 chunk->area_start_ = area_start; | 525 chunk->area_start_ = area_start; |
526 chunk->area_end_ = area_end; | 526 chunk->area_end_ = area_end; |
527 chunk->flags_ = Flags(NO_FLAGS); | 527 chunk->flags_ = Flags(NO_FLAGS); |
528 chunk->set_owner(owner); | 528 chunk->set_owner(owner); |
529 chunk->InitializeReservedMemory(); | 529 chunk->InitializeReservedMemory(); |
530 chunk->old_to_new_slots_.SetValue(nullptr); | 530 chunk->slot_set_[OLD_TO_NEW].SetValue(nullptr); |
531 chunk->old_to_old_slots_ = nullptr; | 531 chunk->slot_set_[OLD_TO_OLD].SetValue(nullptr); |
532 chunk->typed_old_to_new_slots_.SetValue(nullptr); | 532 chunk->typed_slot_set_[OLD_TO_NEW].SetValue(nullptr); |
533 chunk->typed_old_to_old_slots_ = nullptr; | 533 chunk->typed_slot_set_[OLD_TO_OLD].SetValue(nullptr); |
534 chunk->skip_list_ = nullptr; | 534 chunk->skip_list_ = nullptr; |
535 chunk->progress_bar_ = 0; | 535 chunk->progress_bar_ = 0; |
536 chunk->high_water_mark_.SetValue(static_cast<intptr_t>(area_start - base)); | 536 chunk->high_water_mark_.SetValue(static_cast<intptr_t>(area_start - base)); |
537 chunk->concurrent_sweeping_state().SetValue(kSweepingDone); | 537 chunk->concurrent_sweeping_state().SetValue(kSweepingDone); |
538 chunk->mutex_ = new base::Mutex(); | 538 chunk->mutex_ = new base::Mutex(); |
539 chunk->available_in_free_list_ = 0; | 539 chunk->available_in_free_list_ = 0; |
540 chunk->wasted_memory_ = 0; | 540 chunk->wasted_memory_ = 0; |
541 chunk->ResetLiveBytes(); | 541 chunk->ResetLiveBytes(); |
542 chunk->ClearLiveness(); | 542 chunk->ClearLiveness(); |
543 chunk->young_generation_bitmap_ = nullptr; | 543 chunk->young_generation_bitmap_ = nullptr; |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 | 1108 |
1109 void MemoryChunk::ReleaseAllocatedMemory() { | 1109 void MemoryChunk::ReleaseAllocatedMemory() { |
1110 if (skip_list_ != nullptr) { | 1110 if (skip_list_ != nullptr) { |
1111 delete skip_list_; | 1111 delete skip_list_; |
1112 skip_list_ = nullptr; | 1112 skip_list_ = nullptr; |
1113 } | 1113 } |
1114 if (mutex_ != nullptr) { | 1114 if (mutex_ != nullptr) { |
1115 delete mutex_; | 1115 delete mutex_; |
1116 mutex_ = nullptr; | 1116 mutex_ = nullptr; |
1117 } | 1117 } |
1118 if (old_to_new_slots_.Value() != nullptr) ReleaseOldToNewSlots(); | 1118 ReleaseSlotSet<OLD_TO_NEW>(); |
1119 if (old_to_old_slots_ != nullptr) ReleaseOldToOldSlots(); | 1119 ReleaseSlotSet<OLD_TO_OLD>(); |
1120 if (typed_old_to_new_slots_.Value() != nullptr) ReleaseTypedOldToNewSlots(); | 1120 ReleaseTypedSlotSet<OLD_TO_NEW>(); |
1121 if (typed_old_to_old_slots_ != nullptr) ReleaseTypedOldToOldSlots(); | 1121 ReleaseTypedSlotSet<OLD_TO_OLD>(); |
1122 if (local_tracker_ != nullptr) ReleaseLocalTracker(); | 1122 if (local_tracker_ != nullptr) ReleaseLocalTracker(); |
1123 if (young_generation_bitmap_ != nullptr) ReleaseExternalBitmap(); | 1123 if (young_generation_bitmap_ != nullptr) ReleaseExternalBitmap(); |
1124 } | 1124 } |
1125 | 1125 |
1126 static SlotSet* AllocateSlotSet(size_t size, Address page_start) { | 1126 static SlotSet* AllocateAndInitializeSlotSet(size_t size, Address page_start) { |
1127 size_t pages = (size + Page::kPageSize - 1) / Page::kPageSize; | 1127 size_t pages = (size + Page::kPageSize - 1) / Page::kPageSize; |
1128 DCHECK(pages > 0); | 1128 DCHECK(pages > 0); |
1129 SlotSet* slot_set = new SlotSet[pages]; | 1129 SlotSet* slot_set = new SlotSet[pages]; |
1130 for (size_t i = 0; i < pages; i++) { | 1130 for (size_t i = 0; i < pages; i++) { |
1131 slot_set[i].SetPageStart(page_start + i * Page::kPageSize); | 1131 slot_set[i].SetPageStart(page_start + i * Page::kPageSize); |
1132 } | 1132 } |
1133 return slot_set; | 1133 return slot_set; |
1134 } | 1134 } |
1135 | 1135 |
1136 void MemoryChunk::AllocateOldToNewSlots() { | 1136 template SlotSet* MemoryChunk::AllocateSlotSet<OLD_TO_NEW>(); |
1137 DCHECK(nullptr == old_to_new_slots_.Value()); | 1137 template SlotSet* MemoryChunk::AllocateSlotSet<OLD_TO_OLD>(); |
1138 old_to_new_slots_.SetValue(AllocateSlotSet(size_, address())); | 1138 |
| 1139 template <RememberedSetType type> |
| 1140 SlotSet* MemoryChunk::AllocateSlotSet() { |
| 1141 SlotSet* slot_set = AllocateAndInitializeSlotSet(size_, address()); |
| 1142 if (!slot_set_[type].TrySetValue(nullptr, slot_set)) { |
| 1143 delete[] slot_set; |
| 1144 slot_set = slot_set_[type].Value(); |
| 1145 DCHECK(slot_set); |
| 1146 return slot_set; |
| 1147 } |
| 1148 return slot_set; |
1139 } | 1149 } |
1140 | 1150 |
1141 void MemoryChunk::ReleaseOldToNewSlots() { | 1151 template void MemoryChunk::ReleaseSlotSet<OLD_TO_NEW>(); |
1142 SlotSet* old_to_new_slots = old_to_new_slots_.Value(); | 1152 template void MemoryChunk::ReleaseSlotSet<OLD_TO_OLD>(); |
1143 delete[] old_to_new_slots; | 1153 |
1144 old_to_new_slots_.SetValue(nullptr); | 1154 template <RememberedSetType type> |
| 1155 void MemoryChunk::ReleaseSlotSet() { |
| 1156 SlotSet* slot_set = slot_set_[type].Value(); |
| 1157 if (slot_set) { |
| 1158 delete[] slot_set; |
| 1159 slot_set_[type].SetValue(nullptr); |
| 1160 } |
1145 } | 1161 } |
1146 | 1162 |
1147 void MemoryChunk::AllocateOldToOldSlots() { | 1163 template TypedSlotSet* MemoryChunk::AllocateTypedSlotSet<OLD_TO_NEW>(); |
1148 DCHECK(nullptr == old_to_old_slots_); | 1164 template TypedSlotSet* MemoryChunk::AllocateTypedSlotSet<OLD_TO_OLD>(); |
1149 old_to_old_slots_ = AllocateSlotSet(size_, address()); | 1165 |
| 1166 template <RememberedSetType type> |
| 1167 TypedSlotSet* MemoryChunk::AllocateTypedSlotSet() { |
| 1168 TypedSlotSet* slot_set = new TypedSlotSet(address()); |
| 1169 if (!typed_slot_set_[type].TrySetValue(nullptr, slot_set)) { |
| 1170 delete slot_set; |
| 1171 slot_set = typed_slot_set_[type].Value(); |
| 1172 DCHECK(slot_set); |
| 1173 return slot_set; |
| 1174 } |
| 1175 return slot_set; |
1150 } | 1176 } |
1151 | 1177 |
1152 void MemoryChunk::ReleaseOldToOldSlots() { | 1178 template void MemoryChunk::ReleaseTypedSlotSet<OLD_TO_NEW>(); |
1153 delete[] old_to_old_slots_; | 1179 template void MemoryChunk::ReleaseTypedSlotSet<OLD_TO_OLD>(); |
1154 old_to_old_slots_ = nullptr; | |
1155 } | |
1156 | 1180 |
1157 void MemoryChunk::AllocateTypedOldToNewSlots() { | 1181 template <RememberedSetType type> |
1158 DCHECK(nullptr == typed_old_to_new_slots_.Value()); | 1182 void MemoryChunk::ReleaseTypedSlotSet() { |
1159 typed_old_to_new_slots_.SetValue(new TypedSlotSet(address())); | 1183 TypedSlotSet* typed_slot_set = typed_slot_set_[type].Value(); |
1160 } | 1184 if (typed_slot_set) { |
1161 | 1185 delete typed_slot_set; |
1162 void MemoryChunk::ReleaseTypedOldToNewSlots() { | 1186 typed_slot_set_[type].SetValue(nullptr); |
1163 TypedSlotSet* typed_old_to_new_slots = typed_old_to_new_slots_.Value(); | 1187 } |
1164 delete typed_old_to_new_slots; | |
1165 typed_old_to_new_slots_.SetValue(nullptr); | |
1166 } | |
1167 | |
1168 void MemoryChunk::AllocateTypedOldToOldSlots() { | |
1169 DCHECK(nullptr == typed_old_to_old_slots_); | |
1170 typed_old_to_old_slots_ = new TypedSlotSet(address()); | |
1171 } | |
1172 | |
1173 void MemoryChunk::ReleaseTypedOldToOldSlots() { | |
1174 delete typed_old_to_old_slots_; | |
1175 typed_old_to_old_slots_ = nullptr; | |
1176 } | 1188 } |
1177 | 1189 |
1178 void MemoryChunk::AllocateLocalTracker() { | 1190 void MemoryChunk::AllocateLocalTracker() { |
1179 DCHECK_NULL(local_tracker_); | 1191 DCHECK_NULL(local_tracker_); |
1180 local_tracker_ = new LocalArrayBufferTracker(heap()); | 1192 local_tracker_ = new LocalArrayBufferTracker(heap()); |
1181 } | 1193 } |
1182 | 1194 |
1183 void MemoryChunk::ReleaseLocalTracker() { | 1195 void MemoryChunk::ReleaseLocalTracker() { |
1184 DCHECK_NOT_NULL(local_tracker_); | 1196 DCHECK_NOT_NULL(local_tracker_); |
1185 delete local_tracker_; | 1197 delete local_tracker_; |
(...skipping 2096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3282 object->ShortPrint(); | 3294 object->ShortPrint(); |
3283 PrintF("\n"); | 3295 PrintF("\n"); |
3284 } | 3296 } |
3285 printf(" --------------------------------------\n"); | 3297 printf(" --------------------------------------\n"); |
3286 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3298 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3287 } | 3299 } |
3288 | 3300 |
3289 #endif // DEBUG | 3301 #endif // DEBUG |
3290 } // namespace internal | 3302 } // namespace internal |
3291 } // namespace v8 | 3303 } // namespace v8 |
OLD | NEW |