OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef V8_HEAP_MARK_COMPACT_H_ | 5 #ifndef V8_HEAP_MARK_COMPACT_H_ |
6 #define V8_HEAP_MARK_COMPACT_H_ | 6 #define V8_HEAP_MARK_COMPACT_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 explicit MarkingDeque(Heap* heap) | 57 explicit MarkingDeque(Heap* heap) |
58 : backing_store_(nullptr), | 58 : backing_store_(nullptr), |
59 backing_store_committed_size_(0), | 59 backing_store_committed_size_(0), |
60 array_(nullptr), | 60 array_(nullptr), |
61 top_(0), | 61 top_(0), |
62 bottom_(0), | 62 bottom_(0), |
63 mask_(0), | 63 mask_(0), |
64 overflowed_(false), | 64 overflowed_(false), |
65 in_use_(false), | 65 in_use_(false), |
66 uncommit_task_pending_(false), | 66 uncommit_task_pending_(false), |
67 uncommit_task_id_(0), | |
68 heap_(heap) {} | 67 heap_(heap) {} |
69 | 68 |
70 void SetUp(); | 69 void SetUp(); |
71 void TearDown(); | 70 void TearDown(); |
72 | 71 |
73 // Ensures that the marking deque is committed and will stay committed until | 72 // Ensures that the marking deque is committed and will stay committed until |
74 // StopUsing() is called. | 73 // StopUsing() is called. |
75 void StartUsing(); | 74 void StartUsing(); |
76 void StopUsing(); | 75 void StopUsing(); |
77 void Clear(); | 76 void Clear(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 : CancelableTask(isolate), marking_deque_(marking_deque) {} | 136 : CancelableTask(isolate), marking_deque_(marking_deque) {} |
138 | 137 |
139 private: | 138 private: |
140 // CancelableTask override. | 139 // CancelableTask override. |
141 void RunInternal() override { | 140 void RunInternal() override { |
142 base::LockGuard<base::Mutex> guard(&marking_deque_->mutex_); | 141 base::LockGuard<base::Mutex> guard(&marking_deque_->mutex_); |
143 if (!marking_deque_->in_use_) { | 142 if (!marking_deque_->in_use_) { |
144 marking_deque_->Uncommit(); | 143 marking_deque_->Uncommit(); |
145 } | 144 } |
146 marking_deque_->uncommit_task_pending_ = false; | 145 marking_deque_->uncommit_task_pending_ = false; |
147 marking_deque_->uncommit_task_barrier_.NotifyOne(); | |
148 } | 146 } |
149 | 147 |
150 MarkingDeque* marking_deque_; | 148 MarkingDeque* marking_deque_; |
151 DISALLOW_COPY_AND_ASSIGN(UncommitTask); | 149 DISALLOW_COPY_AND_ASSIGN(UncommitTask); |
152 }; | 150 }; |
153 | 151 |
154 static const size_t kMaxSize = 4 * MB; | 152 static const size_t kMaxSize = 4 * MB; |
155 static const size_t kMinSize = 256 * KB; | 153 static const size_t kMinSize = 256 * KB; |
156 | 154 |
157 // Must be called with mutex lock. | 155 // Must be called with mutex lock. |
158 void EnsureCommitted(); | 156 void EnsureCommitted(); |
159 | 157 |
160 // Must be called with mutex lock. | 158 // Must be called with mutex lock. |
161 void Uncommit(); | 159 void Uncommit(); |
162 | 160 |
163 // Must be called with mutex lock. | 161 // Must be called with mutex lock. |
164 void StartUncommitTask(); | 162 void StartUncommitTask(); |
165 | 163 |
166 void CancelOrWaitForUncommitTask(); | |
167 | |
168 base::Mutex mutex_; | 164 base::Mutex mutex_; |
169 base::ConditionVariable uncommit_task_barrier_; | |
170 | 165 |
171 base::VirtualMemory* backing_store_; | 166 base::VirtualMemory* backing_store_; |
172 size_t backing_store_committed_size_; | 167 size_t backing_store_committed_size_; |
173 HeapObject** array_; | 168 HeapObject** array_; |
174 // array_[(top - 1) & mask_] is the top element in the deque. The Deque is | 169 // array_[(top - 1) & mask_] is the top element in the deque. The Deque is |
175 // empty when top_ == bottom_. It is full when top_ + 1 == bottom | 170 // empty when top_ == bottom_. It is full when top_ + 1 == bottom |
176 // (mod mask + 1). | 171 // (mod mask + 1). |
177 int top_; | 172 int top_; |
178 int bottom_; | 173 int bottom_; |
179 int mask_; | 174 int mask_; |
180 bool overflowed_; | 175 bool overflowed_; |
181 // in_use_ == true after taking mutex lock implies that the marking deque is | 176 // in_use_ == true after taking mutex lock implies that the marking deque is |
182 // committed and will stay committed at least until in_use_ == false. | 177 // committed and will stay committed at least until in_use_ == false. |
183 bool in_use_; | 178 bool in_use_; |
184 bool uncommit_task_pending_; | 179 bool uncommit_task_pending_; |
185 uint32_t uncommit_task_id_; | |
186 Heap* heap_; | 180 Heap* heap_; |
187 | 181 |
188 DISALLOW_COPY_AND_ASSIGN(MarkingDeque); | 182 DISALLOW_COPY_AND_ASSIGN(MarkingDeque); |
189 }; | 183 }; |
190 | 184 |
191 | 185 |
192 // CodeFlusher collects candidates for code flushing during marking and | 186 // CodeFlusher collects candidates for code flushing during marking and |
193 // processes those candidates after marking has completed in order to | 187 // processes those candidates after marking has completed in order to |
194 // reset those functions referencing code objects that would otherwise | 188 // reset those functions referencing code objects that would otherwise |
195 // be unreachable. Code objects can be referenced in two ways: | 189 // be unreachable. Code objects can be referenced in two ways: |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 | 769 |
776 private: | 770 private: |
777 MarkCompactCollector* collector_; | 771 MarkCompactCollector* collector_; |
778 }; | 772 }; |
779 | 773 |
780 V8_EXPORT_PRIVATE const char* AllocationSpaceName(AllocationSpace space); | 774 V8_EXPORT_PRIVATE const char* AllocationSpaceName(AllocationSpace space); |
781 } // namespace internal | 775 } // namespace internal |
782 } // namespace v8 | 776 } // namespace v8 |
783 | 777 |
784 #endif // V8_HEAP_MARK_COMPACT_H_ | 778 #endif // V8_HEAP_MARK_COMPACT_H_ |
OLD | NEW |