OLD | NEW |
1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 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_SEQUENTIAL_MARKING_DEQUE_ | 5 #ifndef V8_HEAP_SEQUENTIAL_MARKING_DEQUE_ |
6 #define V8_HEAP_SEQUENTIAL_MARKING_DEQUE_ | 6 #define V8_HEAP_SEQUENTIAL_MARKING_DEQUE_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "src/base/platform/mutex.h" | 10 #include "src/base/platform/mutex.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 88 |
89 template <typename Callback> | 89 template <typename Callback> |
90 void Iterate(Callback callback) { | 90 void Iterate(Callback callback) { |
91 int i = bottom_; | 91 int i = bottom_; |
92 while (i != top_) { | 92 while (i != top_) { |
93 callback(array_[i]); | 93 callback(array_[i]); |
94 i = (i + 1) & mask_; | 94 i = (i + 1) & mask_; |
95 } | 95 } |
96 } | 96 } |
97 | 97 |
98 HeapObject** array() { return array_; } | 98 // Calls the specified callback on each element of the deque and replaces |
99 int bottom() { return bottom_; } | 99 // the element with the result of the callback. If the callback returns |
| 100 // nullptr then the element is removed from the deque. |
| 101 // The callback must accept HeapObject* and return HeapObject*. |
| 102 template <typename Callback> |
| 103 void Update(Callback callback) { |
| 104 int i = bottom_; |
| 105 int new_top = bottom_; |
| 106 while (i != top_) { |
| 107 HeapObject* object = callback(array_[i]); |
| 108 if (object) { |
| 109 array_[new_top] = object; |
| 110 new_top = (new_top + 1) & mask_; |
| 111 } |
| 112 i = (i + 1) & mask_; |
| 113 } |
| 114 top_ = new_top; |
| 115 } |
| 116 |
100 int top() { return top_; } | 117 int top() { return top_; } |
101 int mask() { return mask_; } | |
102 void set_top(int top) { top_ = top; } | |
103 | 118 |
104 private: | 119 private: |
105 // This task uncommits the marking_deque backing store if | 120 // This task uncommits the marking_deque backing store if |
106 // markin_deque->in_use_ is false. | 121 // markin_deque->in_use_ is false. |
107 class UncommitTask : public CancelableTask { | 122 class UncommitTask : public CancelableTask { |
108 public: | 123 public: |
109 explicit UncommitTask(Isolate* isolate, | 124 explicit UncommitTask(Isolate* isolate, |
110 SequentialMarkingDeque* marking_deque) | 125 SequentialMarkingDeque* marking_deque) |
111 : CancelableTask(isolate), marking_deque_(marking_deque) {} | 126 : CancelableTask(isolate), marking_deque_(marking_deque) {} |
112 | 127 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 bool uncommit_task_pending_; | 169 bool uncommit_task_pending_; |
155 Heap* heap_; | 170 Heap* heap_; |
156 | 171 |
157 DISALLOW_COPY_AND_ASSIGN(SequentialMarkingDeque); | 172 DISALLOW_COPY_AND_ASSIGN(SequentialMarkingDeque); |
158 }; | 173 }; |
159 | 174 |
160 } // namespace internal | 175 } // namespace internal |
161 } // namespace v8 | 176 } // namespace v8 |
162 | 177 |
163 #endif // V8_SEQUENTIAL_MARKING_DEQUE_ | 178 #endif // V8_SEQUENTIAL_MARKING_DEQUE_ |
OLD | NEW |