Chromium Code Reviews| 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/store-buffer.h" | 5 #include "src/heap/store-buffer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "src/counters.h" | 9 #include "src/counters.h" |
| 10 #include "src/heap/incremental-marking.h" | 10 #include "src/heap/incremental-marking.h" |
| 11 #include "src/isolate.h" | 11 #include "src/isolate.h" |
| 12 #include "src/objects-inl.h" | 12 #include "src/objects-inl.h" |
| 13 #include "src/v8.h" | 13 #include "src/v8.h" |
| 14 | 14 |
| 15 namespace v8 { | 15 namespace v8 { |
| 16 namespace internal { | 16 namespace internal { |
| 17 | 17 |
| 18 StoreBuffer::StoreBuffer(Heap* heap) | 18 StoreBuffer::StoreBuffer(Heap* heap) |
| 19 : heap_(heap), | 19 : heap_(heap), top_(nullptr), current_(0), virtual_memory_(nullptr) { |
| 20 top_(nullptr), | 20 for (int i = 0; i < kStoreBuffers; i++) { |
| 21 start_(nullptr), | 21 start_[i] = nullptr; |
| 22 limit_(nullptr), | 22 limit_[i] = nullptr; |
| 23 virtual_memory_(nullptr) {} | 23 lazy_top_[i] = nullptr; |
| 24 } | |
| 25 task_running_ = false; | |
| 26 } | |
| 24 | 27 |
| 25 void StoreBuffer::SetUp() { | 28 void StoreBuffer::SetUp() { |
| 26 // Allocate 3x the buffer size, so that we can start the new store buffer | 29 // Allocate 3x the buffer size, so that we can start the new store buffer |
| 27 // aligned to 2x the size. This lets us use a bit test to detect the end of | 30 // aligned to 2x the size. This lets us use a bit test to detect the end of |
| 28 // the area. | 31 // the area. |
| 29 virtual_memory_ = new base::VirtualMemory(kStoreBufferSize * 2); | 32 virtual_memory_ = new base::VirtualMemory(kStoreBufferSize * 3); |
| 30 uintptr_t start_as_int = | 33 uintptr_t start_as_int = |
| 31 reinterpret_cast<uintptr_t>(virtual_memory_->address()); | 34 reinterpret_cast<uintptr_t>(virtual_memory_->address()); |
| 32 start_ = reinterpret_cast<Address*>(RoundUp(start_as_int, kStoreBufferSize)); | 35 start_[0] = |
| 33 limit_ = start_ + (kStoreBufferSize / kPointerSize); | 36 reinterpret_cast<Address*>(RoundUp(start_as_int, kStoreBufferSize)); |
| 37 limit_[0] = start_[0] + (kStoreBufferSize / kPointerSize); | |
| 38 start_[1] = limit_[0]; | |
| 39 limit_[1] = start_[1] + (kStoreBufferSize / kPointerSize); | |
| 34 | 40 |
| 35 DCHECK(reinterpret_cast<Address>(start_) >= virtual_memory_->address()); | |
| 36 DCHECK(reinterpret_cast<Address>(limit_) >= virtual_memory_->address()); | |
| 37 Address* vm_limit = reinterpret_cast<Address*>( | 41 Address* vm_limit = reinterpret_cast<Address*>( |
| 38 reinterpret_cast<char*>(virtual_memory_->address()) + | 42 reinterpret_cast<char*>(virtual_memory_->address()) + |
| 39 virtual_memory_->size()); | 43 virtual_memory_->size()); |
| 40 DCHECK(start_ <= vm_limit); | 44 |
| 41 DCHECK(limit_ <= vm_limit); | |
| 42 USE(vm_limit); | 45 USE(vm_limit); |
| 43 DCHECK((reinterpret_cast<uintptr_t>(limit_) & kStoreBufferMask) == 0); | 46 for (int i = 0; i < kStoreBuffers; i++) { |
| 47 DCHECK(reinterpret_cast<Address>(start_[i]) >= virtual_memory_->address()); | |
| 48 DCHECK(reinterpret_cast<Address>(limit_[i]) >= virtual_memory_->address()); | |
| 49 DCHECK(start_[i] <= vm_limit); | |
| 50 DCHECK(limit_[i] <= vm_limit); | |
| 51 DCHECK((reinterpret_cast<uintptr_t>(limit_[i]) & kStoreBufferMask) == 0); | |
| 52 } | |
| 44 | 53 |
| 45 if (!virtual_memory_->Commit(reinterpret_cast<Address>(start_), | 54 if (!virtual_memory_->Commit(reinterpret_cast<Address>(start_[0]), |
| 46 kStoreBufferSize, | 55 kStoreBufferSize * kStoreBuffers, |
| 47 false)) { // Not executable. | 56 false)) { // Not executable. |
| 48 V8::FatalProcessOutOfMemory("StoreBuffer::SetUp"); | 57 V8::FatalProcessOutOfMemory("StoreBuffer::SetUp"); |
| 49 } | 58 } |
| 50 top_ = start_; | 59 current_ = 0; |
| 60 top_ = start_[current_]; | |
| 51 } | 61 } |
| 52 | 62 |
| 53 | 63 |
| 54 void StoreBuffer::TearDown() { | 64 void StoreBuffer::TearDown() { |
| 55 delete virtual_memory_; | 65 delete virtual_memory_; |
| 56 top_ = start_ = limit_ = nullptr; | 66 top_ = nullptr; |
| 67 for (int i = 0; i < kStoreBuffers; i++) { | |
| 68 start_[i] = nullptr; | |
| 69 limit_[i] = nullptr; | |
| 70 lazy_top_[i] = nullptr; | |
| 71 } | |
| 57 } | 72 } |
| 58 | 73 |
| 59 | 74 |
| 60 void StoreBuffer::StoreBufferOverflow(Isolate* isolate) { | 75 void StoreBuffer::StoreBufferOverflow(Isolate* isolate) { |
| 61 isolate->heap()->store_buffer()->MoveEntriesToRememberedSet(); | 76 isolate->heap()->store_buffer()->FlipStoreBuffers(); |
| 62 isolate->counters()->store_buffer_overflows()->Increment(); | 77 isolate->counters()->store_buffer_overflows()->Increment(); |
| 63 } | 78 } |
| 64 | 79 |
| 65 void StoreBuffer::MoveEntriesToRememberedSet() { | 80 void StoreBuffer::FlipStoreBuffers() { |
| 66 if (top_ == start_) return; | 81 base::LockGuard<base::Mutex> guard(&mutex_); |
| 67 DCHECK(top_ <= limit_); | 82 int other = (current_ + 1) % kStoreBuffers; |
| 68 for (Address* current = start_; current < top_; current++) { | 83 if (lazy_top_[other]) { |
| 84 MoveEntriesToRememberedSet(other); | |
|
ulan
2016/10/28 10:12:29
Since MoveEntriesToRememberedSet already checks fo
Hannes Payer (out of office)
2016/10/28 10:15:25
Done.
| |
| 85 } | |
| 86 lazy_top_[current_] = top_; | |
| 87 current_ = other; | |
| 88 top_ = start_[current_]; | |
| 89 | |
| 90 if (!task_running_) { | |
| 91 task_running_ = true; | |
| 92 Task* task = new Task(heap_->isolate(), this); | |
| 93 V8::GetCurrentPlatform()->CallOnBackgroundThread( | |
| 94 task, v8::Platform::kShortRunningTask); | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 void StoreBuffer::MoveEntriesToRememberedSet(int index) { | |
| 99 if (!lazy_top_[index]) return; | |
| 100 DCHECK_GE(index, 0); | |
| 101 DCHECK_LT(index, kStoreBuffers); | |
| 102 for (Address* current = start_[index]; current < lazy_top_[index]; | |
| 103 current++) { | |
| 69 DCHECK(!heap_->code_space()->Contains(*current)); | 104 DCHECK(!heap_->code_space()->Contains(*current)); |
| 70 Address addr = *current; | 105 Address addr = *current; |
| 71 Page* page = Page::FromAnyPointerAddress(heap_, addr); | 106 Page* page = Page::FromAnyPointerAddress(heap_, addr); |
| 72 RememberedSet<OLD_TO_NEW>::Insert(page, addr); | 107 if (IsDeletionAddress(addr)) { |
| 108 current++; | |
| 109 Address end = *current; | |
| 110 DCHECK(!IsDeletionAddress(end)); | |
| 111 addr = UnmarkDeletionAddress(addr); | |
| 112 if (end) { | |
| 113 RememberedSet<OLD_TO_NEW>::RemoveRange(page, addr, end, | |
| 114 SlotSet::PREFREE_EMPTY_BUCKETS); | |
| 115 } else { | |
| 116 RememberedSet<OLD_TO_NEW>::Remove(page, addr); | |
| 117 } | |
| 118 } else { | |
| 119 DCHECK(!IsDeletionAddress(addr)); | |
| 120 RememberedSet<OLD_TO_NEW>::Insert(page, addr); | |
| 121 } | |
| 73 } | 122 } |
| 74 top_ = start_; | 123 lazy_top_[index] = nullptr; |
| 124 } | |
| 125 | |
| 126 void StoreBuffer::MoveAllEntriesToRememberedSet() { | |
| 127 base::LockGuard<base::Mutex> guard(&mutex_); | |
| 128 int other = (current_ + 1) % kStoreBuffers; | |
| 129 if (lazy_top_[other]) { | |
| 130 MoveEntriesToRememberedSet(other); | |
| 131 } | |
| 132 lazy_top_[current_] = top_; | |
| 133 MoveEntriesToRememberedSet(current_); | |
| 134 top_ = start_[current_]; | |
| 135 } | |
| 136 | |
| 137 void StoreBuffer::ConcurrentlyProcessStoreBuffer() { | |
| 138 base::LockGuard<base::Mutex> guard(&mutex_); | |
| 139 int other = (current_ + 1) % kStoreBuffers; | |
| 140 if (lazy_top_[other]) { | |
| 141 MoveEntriesToRememberedSet(other); | |
| 142 } | |
| 143 task_running_ = false; | |
| 144 } | |
| 145 | |
| 146 void StoreBuffer::DeleteEntry(Address start, Address end) { | |
| 147 if (top_ + sizeof(Address) * 2 > limit_[current_]) { | |
| 148 StoreBufferOverflow(heap_->isolate()); | |
| 149 } | |
| 150 *top_ = MarkDeletionAddress(start); | |
| 151 top_++; | |
| 152 *top_ = end; | |
| 153 top_++; | |
| 75 } | 154 } |
| 76 | 155 |
| 77 } // namespace internal | 156 } // namespace internal |
| 78 } // namespace v8 | 157 } // namespace v8 |
| OLD | NEW |