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

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

Issue 2764473002: [heap] Make SlotSet allocation thread-safe and refactor code. (Closed)
Patch Set: Created 3 years, 9 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
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->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
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 if (slot_set_[OLD_TO_NEW].Value() != nullptr) ReleaseSlotSet<OLD_TO_NEW>();
ulan 2017/03/20 14:27:15 Can we fold the guard into the ReleaseSlotSet fun
Hannes Payer (out of office) 2017/03/20 15:07:08 Done.
1119 if (old_to_old_slots_ != nullptr) ReleaseOldToOldSlots(); 1119 if (slot_set_[OLD_TO_OLD].Value() != nullptr) ReleaseSlotSet<OLD_TO_OLD>();
1120 if (typed_old_to_new_slots_.Value() != nullptr) ReleaseTypedOldToNewSlots(); 1120 if (typed_slot_set_[OLD_TO_NEW].Value() != nullptr)
1121 if (typed_old_to_old_slots_ != nullptr) ReleaseTypedOldToOldSlots(); 1121 ReleaseTypedSlotSet<OLD_TO_NEW>();
1122 if (typed_slot_set_[OLD_TO_OLD].Value() != nullptr)
1123 ReleaseTypedSlotSet<OLD_TO_OLD>();
1122 if (local_tracker_ != nullptr) ReleaseLocalTracker(); 1124 if (local_tracker_ != nullptr) ReleaseLocalTracker();
1123 if (young_generation_bitmap_ != nullptr) ReleaseExternalBitmap(); 1125 if (young_generation_bitmap_ != nullptr) ReleaseExternalBitmap();
1124 } 1126 }
1125 1127
1126 static SlotSet* AllocateSlotSet(size_t size, Address page_start) { 1128 static SlotSet* AllocateAndInitializeSlotSet(size_t size, Address page_start) {
1127 size_t pages = (size + Page::kPageSize - 1) / Page::kPageSize; 1129 size_t pages = (size + Page::kPageSize - 1) / Page::kPageSize;
1128 DCHECK(pages > 0); 1130 DCHECK(pages > 0);
1129 SlotSet* slot_set = new SlotSet[pages]; 1131 SlotSet* slot_set = new SlotSet[pages];
1130 for (size_t i = 0; i < pages; i++) { 1132 for (size_t i = 0; i < pages; i++) {
1131 slot_set[i].SetPageStart(page_start + i * Page::kPageSize); 1133 slot_set[i].SetPageStart(page_start + i * Page::kPageSize);
1132 } 1134 }
1133 return slot_set; 1135 return slot_set;
1134 } 1136 }
1135 1137
1136 void MemoryChunk::AllocateOldToNewSlots() { 1138 template SlotSet* MemoryChunk::AllocateSlotSet<OLD_TO_NEW>();
1137 DCHECK(nullptr == old_to_new_slots_.Value()); 1139 template SlotSet* MemoryChunk::AllocateSlotSet<OLD_TO_OLD>();
1138 old_to_new_slots_.SetValue(AllocateSlotSet(size_, address())); 1140
1141 template <RememberedSetType type>
1142 SlotSet* MemoryChunk::AllocateSlotSet() {
1143 SlotSet* slot_set = AllocateAndInitializeSlotSet(size_, address());
1144 if (!slot_set_[type].TrySetValue(nullptr, slot_set)) {
1145 delete[] slot_set;
1146 slot_set = slot_set_[type].Value();
1147 DCHECK(slot_set);
1148 return slot_set;
1149 }
1150 return slot_set;
1139 } 1151 }
1140 1152
1141 void MemoryChunk::ReleaseOldToNewSlots() { 1153 template void MemoryChunk::ReleaseSlotSet<OLD_TO_NEW>();
1142 SlotSet* old_to_new_slots = old_to_new_slots_.Value(); 1154 template void MemoryChunk::ReleaseSlotSet<OLD_TO_OLD>();
1143 delete[] old_to_new_slots; 1155
1144 old_to_new_slots_.SetValue(nullptr); 1156 template <RememberedSetType type>
1157 void MemoryChunk::ReleaseSlotSet() {
1158 SlotSet* slot_set = slot_set_[type].Value();
1159 delete[] slot_set;
1160 slot_set_[type].SetValue(nullptr);
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 delete typed_slot_set;
1161 1185 typed_slot_set_[type].SetValue(nullptr);
1162 void MemoryChunk::ReleaseTypedOldToNewSlots() {
1163 TypedSlotSet* typed_old_to_new_slots = typed_old_to_new_slots_.Value();
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 } 1186 }
1177 1187
1178 void MemoryChunk::AllocateLocalTracker() { 1188 void MemoryChunk::AllocateLocalTracker() {
1179 DCHECK_NULL(local_tracker_); 1189 DCHECK_NULL(local_tracker_);
1180 local_tracker_ = new LocalArrayBufferTracker(heap()); 1190 local_tracker_ = new LocalArrayBufferTracker(heap());
1181 } 1191 }
1182 1192
1183 void MemoryChunk::ReleaseLocalTracker() { 1193 void MemoryChunk::ReleaseLocalTracker() {
1184 DCHECK_NOT_NULL(local_tracker_); 1194 DCHECK_NOT_NULL(local_tracker_);
1185 delete local_tracker_; 1195 delete local_tracker_;
(...skipping 2090 matching lines...) Expand 10 before | Expand all | Expand 10 after
3276 object->ShortPrint(); 3286 object->ShortPrint();
3277 PrintF("\n"); 3287 PrintF("\n");
3278 } 3288 }
3279 printf(" --------------------------------------\n"); 3289 printf(" --------------------------------------\n");
3280 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); 3290 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes());
3281 } 3291 }
3282 3292
3283 #endif // DEBUG 3293 #endif // DEBUG
3284 } // namespace internal 3294 } // namespace internal
3285 } // namespace v8 3295 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698