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" |
11 #include "src/base/platform/condition-variable.h" | |
12 #include "src/cancelable-task.h" | |
13 #include "src/heap/marking.h" | 11 #include "src/heap/marking.h" |
14 #include "src/heap/spaces.h" | 12 #include "src/heap/spaces.h" |
15 #include "src/heap/store-buffer.h" | 13 #include "src/heap/store-buffer.h" |
16 | 14 |
17 namespace v8 { | 15 namespace v8 { |
18 namespace internal { | 16 namespace internal { |
19 | 17 |
20 // Callback function, returns whether an object is alive. The heap size | 18 // Callback function, returns whether an object is alive. The heap size |
21 // of the object is returned in size. It optionally updates the offset | 19 // of the object is returned in size. It optionally updates the offset |
22 // to the first live object in the page (only used for old and map objects). | 20 // to the first live object in the page (only used for old and map objects). |
(...skipping 24 matching lines...) Expand all Loading... |
47 } | 45 } |
48 | 46 |
49 private: | 47 private: |
50 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectMarking); | 48 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectMarking); |
51 }; | 49 }; |
52 | 50 |
53 // ---------------------------------------------------------------------------- | 51 // ---------------------------------------------------------------------------- |
54 // Marking deque for tracing live objects. | 52 // Marking deque for tracing live objects. |
55 class MarkingDeque { | 53 class MarkingDeque { |
56 public: | 54 public: |
57 explicit MarkingDeque(Heap* heap) | 55 MarkingDeque() |
58 : backing_store_(nullptr), | 56 : backing_store_(nullptr), |
59 backing_store_committed_size_(0), | 57 backing_store_committed_size_(0), |
60 array_(nullptr), | 58 array_(nullptr), |
61 top_(0), | 59 top_(0), |
62 bottom_(0), | 60 bottom_(0), |
63 mask_(0), | 61 mask_(0), |
64 overflowed_(false), | 62 overflowed_(false), |
65 in_use_(false), | 63 in_use_(false) {} |
66 uncommit_task_pending_(false), | |
67 uncommit_task_id_(0), | |
68 heap_(heap) {} | |
69 | 64 |
70 void SetUp(); | 65 void SetUp(); |
71 void TearDown(); | 66 void TearDown(); |
72 | 67 |
73 // Ensures that the marking deque is committed and will stay committed until | |
74 // StopUsing() is called. | |
75 void StartUsing(); | 68 void StartUsing(); |
76 void StopUsing(); | 69 void StopUsing(); |
77 void Clear(); | 70 void Clear(); |
78 | 71 |
79 inline bool IsFull() { return ((top_ + 1) & mask_) == bottom_; } | 72 inline bool IsFull() { return ((top_ + 1) & mask_) == bottom_; } |
80 | 73 |
81 inline bool IsEmpty() { return top_ == bottom_; } | 74 inline bool IsEmpty() { return top_ == bottom_; } |
82 | 75 |
83 bool overflowed() const { return overflowed_; } | 76 bool overflowed() const { return overflowed_; } |
84 | 77 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 115 } |
123 } | 116 } |
124 | 117 |
125 HeapObject** array() { return array_; } | 118 HeapObject** array() { return array_; } |
126 int bottom() { return bottom_; } | 119 int bottom() { return bottom_; } |
127 int top() { return top_; } | 120 int top() { return top_; } |
128 int mask() { return mask_; } | 121 int mask() { return mask_; } |
129 void set_top(int top) { top_ = top; } | 122 void set_top(int top) { top_ = top; } |
130 | 123 |
131 private: | 124 private: |
132 // This task uncommits the marking_deque backing store if | |
133 // markin_deque->in_use_ is false. | |
134 class UncommitTask : public CancelableTask { | |
135 public: | |
136 explicit UncommitTask(Isolate* isolate, MarkingDeque* marking_deque) | |
137 : CancelableTask(isolate), marking_deque_(marking_deque) {} | |
138 | |
139 private: | |
140 // CancelableTask override. | |
141 void RunInternal() override { | |
142 base::LockGuard<base::Mutex> guard(&marking_deque_->mutex_); | |
143 if (!marking_deque_->in_use_) { | |
144 marking_deque_->Uncommit(); | |
145 } | |
146 marking_deque_->uncommit_task_pending_ = false; | |
147 marking_deque_->uncommit_task_barrier_.NotifyOne(); | |
148 } | |
149 | |
150 MarkingDeque* marking_deque_; | |
151 DISALLOW_COPY_AND_ASSIGN(UncommitTask); | |
152 }; | |
153 | |
154 static const size_t kMaxSize = 4 * MB; | 125 static const size_t kMaxSize = 4 * MB; |
155 static const size_t kMinSize = 256 * KB; | 126 static const size_t kMinSize = 256 * KB; |
156 | 127 |
157 // Must be called with mutex lock. | |
158 void EnsureCommitted(); | 128 void EnsureCommitted(); |
159 | |
160 // Must be called with mutex lock. | |
161 void Uncommit(); | 129 void Uncommit(); |
162 | 130 |
163 // Must be called with mutex lock. | |
164 void StartUncommitTask(); | |
165 | |
166 void CancelOrWaitForUncommitTask(); | |
167 | |
168 base::Mutex mutex_; | |
169 base::ConditionVariable uncommit_task_barrier_; | |
170 | |
171 base::VirtualMemory* backing_store_; | 131 base::VirtualMemory* backing_store_; |
172 size_t backing_store_committed_size_; | 132 size_t backing_store_committed_size_; |
173 HeapObject** array_; | 133 HeapObject** array_; |
174 // array_[(top - 1) & mask_] is the top element in the deque. The Deque is | 134 // 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 | 135 // empty when top_ == bottom_. It is full when top_ + 1 == bottom |
176 // (mod mask + 1). | 136 // (mod mask + 1). |
177 int top_; | 137 int top_; |
178 int bottom_; | 138 int bottom_; |
179 int mask_; | 139 int mask_; |
180 bool overflowed_; | 140 bool overflowed_; |
181 // 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. | |
183 bool in_use_; | 141 bool in_use_; |
184 bool uncommit_task_pending_; | |
185 uint32_t uncommit_task_id_; | |
186 Heap* heap_; | |
187 | 142 |
188 DISALLOW_COPY_AND_ASSIGN(MarkingDeque); | 143 DISALLOW_COPY_AND_ASSIGN(MarkingDeque); |
189 }; | 144 }; |
190 | 145 |
191 | 146 |
192 // CodeFlusher collects candidates for code flushing during marking and | 147 // CodeFlusher collects candidates for code flushing during marking and |
193 // processes those candidates after marking has completed in order to | 148 // processes those candidates after marking has completed in order to |
194 // reset those functions referencing code objects that would otherwise | 149 // reset those functions referencing code objects that would otherwise |
195 // be unreachable. Code objects can be referenced in two ways: | 150 // be unreachable. Code objects can be referenced in two ways: |
196 // - SharedFunctionInfo references unoptimized code. | 151 // - SharedFunctionInfo references unoptimized code. |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 | 730 |
776 private: | 731 private: |
777 MarkCompactCollector* collector_; | 732 MarkCompactCollector* collector_; |
778 }; | 733 }; |
779 | 734 |
780 V8_EXPORT_PRIVATE const char* AllocationSpaceName(AllocationSpace space); | 735 V8_EXPORT_PRIVATE const char* AllocationSpaceName(AllocationSpace space); |
781 } // namespace internal | 736 } // namespace internal |
782 } // namespace v8 | 737 } // namespace v8 |
783 | 738 |
784 #endif // V8_HEAP_MARK_COMPACT_H_ | 739 #endif // V8_HEAP_MARK_COMPACT_H_ |
OLD | NEW |