Chromium Code Reviews| Index: src/heap/spaces.cc |
| diff --git a/src/heap/spaces.cc b/src/heap/spaces.cc |
| index 98bc12851140eb610591b7fd451baac13bcb3386..0ebde36c3ba8fe3e01ce403496869b08e847037e 100644 |
| --- a/src/heap/spaces.cc |
| +++ b/src/heap/spaces.cc |
| @@ -527,10 +527,10 @@ MemoryChunk* MemoryChunk::Initialize(Heap* heap, Address base, size_t size, |
| chunk->flags_ = Flags(NO_FLAGS); |
| chunk->set_owner(owner); |
| chunk->InitializeReservedMemory(); |
| - chunk->old_to_new_slots_.SetValue(nullptr); |
| - chunk->old_to_old_slots_ = nullptr; |
| - chunk->typed_old_to_new_slots_.SetValue(nullptr); |
| - chunk->typed_old_to_old_slots_ = nullptr; |
| + chunk->slot_set_[OLD_TO_NEW].SetValue(nullptr); |
| + chunk->slot_set_[OLD_TO_OLD].SetValue(nullptr); |
| + chunk->typed_slot_set_[OLD_TO_NEW].SetValue(nullptr); |
| + chunk->typed_slot_set_[OLD_TO_OLD].SetValue(nullptr); |
| chunk->skip_list_ = nullptr; |
| chunk->progress_bar_ = 0; |
| chunk->high_water_mark_.SetValue(static_cast<intptr_t>(area_start - base)); |
| @@ -1115,15 +1115,17 @@ void MemoryChunk::ReleaseAllocatedMemory() { |
| delete mutex_; |
| mutex_ = nullptr; |
| } |
| - if (old_to_new_slots_.Value() != nullptr) ReleaseOldToNewSlots(); |
| - if (old_to_old_slots_ != nullptr) ReleaseOldToOldSlots(); |
| - if (typed_old_to_new_slots_.Value() != nullptr) ReleaseTypedOldToNewSlots(); |
| - if (typed_old_to_old_slots_ != nullptr) ReleaseTypedOldToOldSlots(); |
| + 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.
|
| + if (slot_set_[OLD_TO_OLD].Value() != nullptr) ReleaseSlotSet<OLD_TO_OLD>(); |
| + if (typed_slot_set_[OLD_TO_NEW].Value() != nullptr) |
| + ReleaseTypedSlotSet<OLD_TO_NEW>(); |
| + if (typed_slot_set_[OLD_TO_OLD].Value() != nullptr) |
| + ReleaseTypedSlotSet<OLD_TO_OLD>(); |
| if (local_tracker_ != nullptr) ReleaseLocalTracker(); |
| if (young_generation_bitmap_ != nullptr) ReleaseExternalBitmap(); |
| } |
| -static SlotSet* AllocateSlotSet(size_t size, Address page_start) { |
| +static SlotSet* AllocateAndInitializeSlotSet(size_t size, Address page_start) { |
| size_t pages = (size + Page::kPageSize - 1) / Page::kPageSize; |
| DCHECK(pages > 0); |
| SlotSet* slot_set = new SlotSet[pages]; |
| @@ -1133,46 +1135,54 @@ static SlotSet* AllocateSlotSet(size_t size, Address page_start) { |
| return slot_set; |
| } |
| -void MemoryChunk::AllocateOldToNewSlots() { |
| - DCHECK(nullptr == old_to_new_slots_.Value()); |
| - old_to_new_slots_.SetValue(AllocateSlotSet(size_, address())); |
| -} |
| +template SlotSet* MemoryChunk::AllocateSlotSet<OLD_TO_NEW>(); |
| +template SlotSet* MemoryChunk::AllocateSlotSet<OLD_TO_OLD>(); |
| -void MemoryChunk::ReleaseOldToNewSlots() { |
| - SlotSet* old_to_new_slots = old_to_new_slots_.Value(); |
| - delete[] old_to_new_slots; |
| - old_to_new_slots_.SetValue(nullptr); |
| +template <RememberedSetType type> |
| +SlotSet* MemoryChunk::AllocateSlotSet() { |
| + SlotSet* slot_set = AllocateAndInitializeSlotSet(size_, address()); |
| + if (!slot_set_[type].TrySetValue(nullptr, slot_set)) { |
| + delete[] slot_set; |
| + slot_set = slot_set_[type].Value(); |
| + DCHECK(slot_set); |
| + return slot_set; |
| + } |
| + return slot_set; |
| } |
| -void MemoryChunk::AllocateOldToOldSlots() { |
| - DCHECK(nullptr == old_to_old_slots_); |
| - old_to_old_slots_ = AllocateSlotSet(size_, address()); |
| -} |
| +template void MemoryChunk::ReleaseSlotSet<OLD_TO_NEW>(); |
| +template void MemoryChunk::ReleaseSlotSet<OLD_TO_OLD>(); |
| -void MemoryChunk::ReleaseOldToOldSlots() { |
| - delete[] old_to_old_slots_; |
| - old_to_old_slots_ = nullptr; |
| +template <RememberedSetType type> |
| +void MemoryChunk::ReleaseSlotSet() { |
| + SlotSet* slot_set = slot_set_[type].Value(); |
| + delete[] slot_set; |
| + slot_set_[type].SetValue(nullptr); |
| } |
| -void MemoryChunk::AllocateTypedOldToNewSlots() { |
| - DCHECK(nullptr == typed_old_to_new_slots_.Value()); |
| - typed_old_to_new_slots_.SetValue(new TypedSlotSet(address())); |
| -} |
| +template TypedSlotSet* MemoryChunk::AllocateTypedSlotSet<OLD_TO_NEW>(); |
| +template TypedSlotSet* MemoryChunk::AllocateTypedSlotSet<OLD_TO_OLD>(); |
| -void MemoryChunk::ReleaseTypedOldToNewSlots() { |
| - TypedSlotSet* typed_old_to_new_slots = typed_old_to_new_slots_.Value(); |
| - delete typed_old_to_new_slots; |
| - typed_old_to_new_slots_.SetValue(nullptr); |
| +template <RememberedSetType type> |
| +TypedSlotSet* MemoryChunk::AllocateTypedSlotSet() { |
| + TypedSlotSet* slot_set = new TypedSlotSet(address()); |
| + if (!typed_slot_set_[type].TrySetValue(nullptr, slot_set)) { |
| + delete slot_set; |
| + slot_set = typed_slot_set_[type].Value(); |
| + DCHECK(slot_set); |
| + return slot_set; |
| + } |
| + return slot_set; |
| } |
| -void MemoryChunk::AllocateTypedOldToOldSlots() { |
| - DCHECK(nullptr == typed_old_to_old_slots_); |
| - typed_old_to_old_slots_ = new TypedSlotSet(address()); |
| -} |
| +template void MemoryChunk::ReleaseTypedSlotSet<OLD_TO_NEW>(); |
| +template void MemoryChunk::ReleaseTypedSlotSet<OLD_TO_OLD>(); |
| -void MemoryChunk::ReleaseTypedOldToOldSlots() { |
| - delete typed_old_to_old_slots_; |
| - typed_old_to_old_slots_ = nullptr; |
| +template <RememberedSetType type> |
| +void MemoryChunk::ReleaseTypedSlotSet() { |
| + TypedSlotSet* typed_slot_set = typed_slot_set_[type].Value(); |
| + delete typed_slot_set; |
| + typed_slot_set_[type].SetValue(nullptr); |
| } |
| void MemoryChunk::AllocateLocalTracker() { |