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

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

Issue 2783873002: [heap] Reland: Make SlotSet allocation thread-safe and refactor code. (Closed)
Patch Set: comment Created 3 years, 8 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') | src/heap/spaces-inl.h » ('j') | 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 <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
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->young_generation_bitmap_ = nullptr; 541 chunk->young_generation_bitmap_ = nullptr;
542 chunk->set_next_chunk(nullptr); 542 chunk->set_next_chunk(nullptr);
543 chunk->set_prev_chunk(nullptr); 543 chunk->set_prev_chunk(nullptr);
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 1109
1110 void MemoryChunk::ReleaseAllocatedMemory() { 1110 void MemoryChunk::ReleaseAllocatedMemory() {
1111 if (skip_list_ != nullptr) { 1111 if (skip_list_ != nullptr) {
1112 delete skip_list_; 1112 delete skip_list_;
1113 skip_list_ = nullptr; 1113 skip_list_ = nullptr;
1114 } 1114 }
1115 if (mutex_ != nullptr) { 1115 if (mutex_ != nullptr) {
1116 delete mutex_; 1116 delete mutex_;
1117 mutex_ = nullptr; 1117 mutex_ = nullptr;
1118 } 1118 }
1119 if (old_to_new_slots_.Value() != nullptr) ReleaseOldToNewSlots(); 1119 ReleaseSlotSet<OLD_TO_NEW>();
1120 if (old_to_old_slots_ != nullptr) ReleaseOldToOldSlots(); 1120 ReleaseSlotSet<OLD_TO_OLD>();
1121 if (typed_old_to_new_slots_.Value() != nullptr) ReleaseTypedOldToNewSlots(); 1121 ReleaseTypedSlotSet<OLD_TO_NEW>();
1122 if (typed_old_to_old_slots_ != nullptr) ReleaseTypedOldToOldSlots(); 1122 ReleaseTypedSlotSet<OLD_TO_OLD>();
1123 if (local_tracker_ != nullptr) ReleaseLocalTracker(); 1123 if (local_tracker_ != nullptr) ReleaseLocalTracker();
1124 if (young_generation_bitmap_ != nullptr) ReleaseYoungGenerationBitmap(); 1124 if (young_generation_bitmap_ != nullptr) ReleaseYoungGenerationBitmap();
1125 } 1125 }
1126 1126
1127 static SlotSet* AllocateSlotSet(size_t size, Address page_start) { 1127 static SlotSet* AllocateAndInitializeSlotSet(size_t size, Address page_start) {
1128 size_t pages = (size + Page::kPageSize - 1) / Page::kPageSize; 1128 size_t pages = (size + Page::kPageSize - 1) / Page::kPageSize;
1129 DCHECK(pages > 0); 1129 DCHECK(pages > 0);
1130 SlotSet* slot_set = new SlotSet[pages]; 1130 SlotSet* slot_set = new SlotSet[pages];
1131 for (size_t i = 0; i < pages; i++) { 1131 for (size_t i = 0; i < pages; i++) {
1132 slot_set[i].SetPageStart(page_start + i * Page::kPageSize); 1132 slot_set[i].SetPageStart(page_start + i * Page::kPageSize);
1133 } 1133 }
1134 return slot_set; 1134 return slot_set;
1135 } 1135 }
1136 1136
1137 void MemoryChunk::AllocateOldToNewSlots() { 1137 template SlotSet* MemoryChunk::AllocateSlotSet<OLD_TO_NEW>();
1138 DCHECK(nullptr == old_to_new_slots_.Value()); 1138 template SlotSet* MemoryChunk::AllocateSlotSet<OLD_TO_OLD>();
1139 old_to_new_slots_.SetValue(AllocateSlotSet(size_, address())); 1139
1140 template <RememberedSetType type>
1141 SlotSet* MemoryChunk::AllocateSlotSet() {
1142 SlotSet* slot_set = AllocateAndInitializeSlotSet(size_, address());
1143 if (!slot_set_[type].TrySetValue(nullptr, slot_set)) {
1144 delete[] slot_set;
1145 slot_set = slot_set_[type].Value();
1146 DCHECK(slot_set);
1147 return slot_set;
1148 }
1149 return slot_set;
1140 } 1150 }
1141 1151
1142 void MemoryChunk::ReleaseOldToNewSlots() { 1152 template void MemoryChunk::ReleaseSlotSet<OLD_TO_NEW>();
1143 SlotSet* old_to_new_slots = old_to_new_slots_.Value(); 1153 template void MemoryChunk::ReleaseSlotSet<OLD_TO_OLD>();
1144 delete[] old_to_new_slots; 1154
1145 old_to_new_slots_.SetValue(nullptr); 1155 template <RememberedSetType type>
1156 void MemoryChunk::ReleaseSlotSet() {
1157 SlotSet* slot_set = slot_set_[type].Value();
1158 if (slot_set) {
1159 delete[] slot_set;
1160 slot_set_[type].SetValue(nullptr);
1161 }
1146 } 1162 }
1147 1163
1148 void MemoryChunk::AllocateOldToOldSlots() { 1164 template TypedSlotSet* MemoryChunk::AllocateTypedSlotSet<OLD_TO_NEW>();
1149 DCHECK(nullptr == old_to_old_slots_); 1165 template TypedSlotSet* MemoryChunk::AllocateTypedSlotSet<OLD_TO_OLD>();
1150 old_to_old_slots_ = AllocateSlotSet(size_, address()); 1166
1167 template <RememberedSetType type>
1168 TypedSlotSet* MemoryChunk::AllocateTypedSlotSet() {
1169 TypedSlotSet* slot_set = new TypedSlotSet(address());
1170 if (!typed_slot_set_[type].TrySetValue(nullptr, slot_set)) {
1171 delete slot_set;
1172 slot_set = typed_slot_set_[type].Value();
1173 DCHECK(slot_set);
1174 return slot_set;
1175 }
1176 return slot_set;
1151 } 1177 }
1152 1178
1153 void MemoryChunk::ReleaseOldToOldSlots() { 1179 template void MemoryChunk::ReleaseTypedSlotSet<OLD_TO_NEW>();
1154 delete[] old_to_old_slots_; 1180 template void MemoryChunk::ReleaseTypedSlotSet<OLD_TO_OLD>();
1155 old_to_old_slots_ = nullptr;
1156 }
1157 1181
1158 void MemoryChunk::AllocateTypedOldToNewSlots() { 1182 template <RememberedSetType type>
1159 DCHECK(nullptr == typed_old_to_new_slots_.Value()); 1183 void MemoryChunk::ReleaseTypedSlotSet() {
1160 typed_old_to_new_slots_.SetValue(new TypedSlotSet(address())); 1184 TypedSlotSet* typed_slot_set = typed_slot_set_[type].Value();
1161 } 1185 if (typed_slot_set) {
1162 1186 delete typed_slot_set;
1163 void MemoryChunk::ReleaseTypedOldToNewSlots() { 1187 typed_slot_set_[type].SetValue(nullptr);
1164 TypedSlotSet* typed_old_to_new_slots = typed_old_to_new_slots_.Value(); 1188 }
1165 delete typed_old_to_new_slots;
1166 typed_old_to_new_slots_.SetValue(nullptr);
1167 }
1168
1169 void MemoryChunk::AllocateTypedOldToOldSlots() {
1170 DCHECK(nullptr == typed_old_to_old_slots_);
1171 typed_old_to_old_slots_ = new TypedSlotSet(address());
1172 }
1173
1174 void MemoryChunk::ReleaseTypedOldToOldSlots() {
1175 delete typed_old_to_old_slots_;
1176 typed_old_to_old_slots_ = nullptr;
1177 } 1189 }
1178 1190
1179 void MemoryChunk::AllocateLocalTracker() { 1191 void MemoryChunk::AllocateLocalTracker() {
1180 DCHECK_NULL(local_tracker_); 1192 DCHECK_NULL(local_tracker_);
1181 local_tracker_ = new LocalArrayBufferTracker(heap()); 1193 local_tracker_ = new LocalArrayBufferTracker(heap());
1182 } 1194 }
1183 1195
1184 void MemoryChunk::ReleaseLocalTracker() { 1196 void MemoryChunk::ReleaseLocalTracker() {
1185 DCHECK_NOT_NULL(local_tracker_); 1197 DCHECK_NOT_NULL(local_tracker_);
1186 delete local_tracker_; 1198 delete local_tracker_;
(...skipping 2095 matching lines...) Expand 10 before | Expand all | Expand 10 after
3282 PrintF("\n"); 3294 PrintF("\n");
3283 } 3295 }
3284 printf(" --------------------------------------\n"); 3296 printf(" --------------------------------------\n");
3285 printf(" Marked: %x, LiveCount: %" V8PRIdPTR "\n", mark_size, 3297 printf(" Marked: %x, LiveCount: %" V8PRIdPTR "\n", mark_size,
3286 MarkingState::Internal(this).live_bytes()); 3298 MarkingState::Internal(this).live_bytes());
3287 } 3299 }
3288 3300
3289 #endif // DEBUG 3301 #endif // DEBUG
3290 } // namespace internal 3302 } // namespace internal
3291 } // namespace v8 3303 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/spaces.h ('k') | src/heap/spaces-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698