OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 10 matching lines...) Expand all Loading... |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_MARK_COMPACT_H_ | 28 #ifndef V8_MARK_COMPACT_H_ |
29 #define V8_MARK_COMPACT_H_ | 29 #define V8_MARK_COMPACT_H_ |
30 | 30 |
| 31 #include "spaces.h" |
| 32 |
31 namespace v8 { | 33 namespace v8 { |
32 namespace internal { | 34 namespace internal { |
33 | 35 |
34 // Callback function, returns whether an object is alive. The heap size | 36 // Callback function, returns whether an object is alive. The heap size |
35 // of the object is returned in size. It optionally updates the offset | 37 // of the object is returned in size. It optionally updates the offset |
36 // to the first live object in the page (only used for old and map objects). | 38 // to the first live object in the page (only used for old and map objects). |
37 typedef bool (*IsAliveFunction)(HeapObject* obj, int* size, int* offset); | 39 typedef bool (*IsAliveFunction)(HeapObject* obj, int* size, int* offset); |
38 | 40 |
39 // Forward declarations. | 41 // Forward declarations. |
| 42 class CodeFlusher; |
| 43 class GCTracer; |
| 44 class MarkingVisitor; |
40 class RootMarkingVisitor; | 45 class RootMarkingVisitor; |
41 class MarkingVisitor; | 46 |
| 47 |
| 48 // ---------------------------------------------------------------------------- |
| 49 // Marking stack for tracing live objects. |
| 50 |
| 51 class MarkingStack { |
| 52 public: |
| 53 MarkingStack() : low_(NULL), top_(NULL), high_(NULL), overflowed_(false) { } |
| 54 |
| 55 void Initialize(Address low, Address high) { |
| 56 top_ = low_ = reinterpret_cast<HeapObject**>(low); |
| 57 high_ = reinterpret_cast<HeapObject**>(high); |
| 58 overflowed_ = false; |
| 59 } |
| 60 |
| 61 bool is_full() const { return top_ >= high_; } |
| 62 |
| 63 bool is_empty() const { return top_ <= low_; } |
| 64 |
| 65 bool overflowed() const { return overflowed_; } |
| 66 |
| 67 void clear_overflowed() { overflowed_ = false; } |
| 68 |
| 69 // Push the (marked) object on the marking stack if there is room, |
| 70 // otherwise mark the object as overflowed and wait for a rescan of the |
| 71 // heap. |
| 72 void Push(HeapObject* object) { |
| 73 CHECK(object->IsHeapObject()); |
| 74 if (is_full()) { |
| 75 object->SetOverflow(); |
| 76 overflowed_ = true; |
| 77 } else { |
| 78 *(top_++) = object; |
| 79 } |
| 80 } |
| 81 |
| 82 HeapObject* Pop() { |
| 83 ASSERT(!is_empty()); |
| 84 HeapObject* object = *(--top_); |
| 85 CHECK(object->IsHeapObject()); |
| 86 return object; |
| 87 } |
| 88 |
| 89 private: |
| 90 HeapObject** low_; |
| 91 HeapObject** top_; |
| 92 HeapObject** high_; |
| 93 bool overflowed_; |
| 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(MarkingStack); |
| 96 }; |
42 | 97 |
43 | 98 |
44 // ------------------------------------------------------------------------- | 99 // ------------------------------------------------------------------------- |
45 // Mark-Compact collector | 100 // Mark-Compact collector |
46 // | 101 // |
47 // All methods are static. | 102 // All methods are static. |
48 | 103 |
49 class MarkCompactCollector: public AllStatic { | 104 class OverflowedObjectsScanner; |
| 105 |
| 106 class MarkCompactCollector { |
50 public: | 107 public: |
51 // Type of functions to compute forwarding addresses of objects in | 108 // Type of functions to compute forwarding addresses of objects in |
52 // compacted spaces. Given an object and its size, return a (non-failure) | 109 // compacted spaces. Given an object and its size, return a (non-failure) |
53 // Object* that will be the object after forwarding. There is a separate | 110 // Object* that will be the object after forwarding. There is a separate |
54 // allocation function for each (compactable) space based on the location | 111 // allocation function for each (compactable) space based on the location |
55 // of the object before compaction. | 112 // of the object before compaction. |
56 typedef MaybeObject* (*AllocationFunction)(HeapObject* object, | 113 typedef MaybeObject* (*AllocationFunction)(Heap* heap, |
| 114 HeapObject* object, |
57 int object_size); | 115 int object_size); |
58 | 116 |
59 // Type of functions to encode the forwarding address for an object. | 117 // Type of functions to encode the forwarding address for an object. |
60 // Given the object, its size, and the new (non-failure) object it will be | 118 // Given the object, its size, and the new (non-failure) object it will be |
61 // forwarded to, encode the forwarding address. For paged spaces, the | 119 // forwarded to, encode the forwarding address. For paged spaces, the |
62 // 'offset' input/output parameter contains the offset of the forwarded | 120 // 'offset' input/output parameter contains the offset of the forwarded |
63 // object from the forwarding address of the previous live object in the | 121 // object from the forwarding address of the previous live object in the |
64 // page as input, and is updated to contain the offset to be used for the | 122 // page as input, and is updated to contain the offset to be used for the |
65 // next live object in the same page. For spaces using a different | 123 // next live object in the same page. For spaces using a different |
66 // encoding (ie, contiguous spaces), the offset parameter is ignored. | 124 // encoding (ie, contiguous spaces), the offset parameter is ignored. |
67 typedef void (*EncodingFunction)(HeapObject* old_object, | 125 typedef void (*EncodingFunction)(Heap* heap, |
| 126 HeapObject* old_object, |
68 int object_size, | 127 int object_size, |
69 Object* new_object, | 128 Object* new_object, |
70 int* offset); | 129 int* offset); |
71 | 130 |
72 // Type of functions to process non-live objects. | 131 // Type of functions to process non-live objects. |
73 typedef void (*ProcessNonLiveFunction)(HeapObject* object); | 132 typedef void (*ProcessNonLiveFunction)(HeapObject* object); |
74 | 133 |
| 134 // Pointer to member function, used in IterateLiveObjects. |
| 135 typedef int (MarkCompactCollector::*LiveObjectCallback)(HeapObject* obj); |
| 136 |
75 // Set the global force_compaction flag, it must be called before Prepare | 137 // Set the global force_compaction flag, it must be called before Prepare |
76 // to take effect. | 138 // to take effect. |
77 static void SetForceCompaction(bool value) { | 139 void SetForceCompaction(bool value) { |
78 force_compaction_ = value; | 140 force_compaction_ = value; |
79 } | 141 } |
80 | 142 |
81 | 143 |
82 static void Initialize(); | 144 static void Initialize(); |
83 | 145 |
84 // Prepares for GC by resetting relocation info in old and map spaces and | 146 // Prepares for GC by resetting relocation info in old and map spaces and |
85 // choosing spaces to compact. | 147 // choosing spaces to compact. |
86 static void Prepare(GCTracer* tracer); | 148 void Prepare(GCTracer* tracer); |
87 | 149 |
88 // Performs a global garbage collection. | 150 // Performs a global garbage collection. |
89 static void CollectGarbage(); | 151 void CollectGarbage(); |
90 | 152 |
91 // True if the last full GC performed heap compaction. | 153 // True if the last full GC performed heap compaction. |
92 static bool HasCompacted() { return compacting_collection_; } | 154 bool HasCompacted() { return compacting_collection_; } |
93 | 155 |
94 // True after the Prepare phase if the compaction is taking place. | 156 // True after the Prepare phase if the compaction is taking place. |
95 static bool IsCompacting() { | 157 bool IsCompacting() { |
96 #ifdef DEBUG | 158 #ifdef DEBUG |
97 // For the purposes of asserts we don't want this to keep returning true | 159 // For the purposes of asserts we don't want this to keep returning true |
98 // after the collection is completed. | 160 // after the collection is completed. |
99 return state_ != IDLE && compacting_collection_; | 161 return state_ != IDLE && compacting_collection_; |
100 #else | 162 #else |
101 return compacting_collection_; | 163 return compacting_collection_; |
102 #endif | 164 #endif |
103 } | 165 } |
104 | 166 |
105 // The count of the number of objects left marked at the end of the last | 167 // The count of the number of objects left marked at the end of the last |
106 // completed full GC (expected to be zero). | 168 // completed full GC (expected to be zero). |
107 static int previous_marked_count() { return previous_marked_count_; } | 169 int previous_marked_count() { return previous_marked_count_; } |
108 | 170 |
109 // During a full GC, there is a stack-allocated GCTracer that is used for | 171 // During a full GC, there is a stack-allocated GCTracer that is used for |
110 // bookkeeping information. Return a pointer to that tracer. | 172 // bookkeeping information. Return a pointer to that tracer. |
111 static GCTracer* tracer() { return tracer_; } | 173 GCTracer* tracer() { return tracer_; } |
112 | 174 |
113 #ifdef DEBUG | 175 #ifdef DEBUG |
114 // Checks whether performing mark-compact collection. | 176 // Checks whether performing mark-compact collection. |
115 static bool in_use() { return state_ > PREPARE_GC; } | 177 bool in_use() { return state_ > PREPARE_GC; } |
116 static bool are_map_pointers_encoded() { return state_ == UPDATE_POINTERS; } | 178 bool are_map_pointers_encoded() { return state_ == UPDATE_POINTERS; } |
117 #endif | 179 #endif |
118 | 180 |
119 // Determine type of object and emit deletion log event. | 181 // Determine type of object and emit deletion log event. |
120 static void ReportDeleteIfNeeded(HeapObject* obj); | 182 static void ReportDeleteIfNeeded(HeapObject* obj); |
121 | 183 |
122 // Returns size of a possibly marked object. | 184 // Returns size of a possibly marked object. |
123 static int SizeOfMarkedObject(HeapObject* obj); | 185 static int SizeOfMarkedObject(HeapObject* obj); |
124 | 186 |
125 // Distinguishable invalid map encodings (for single word and multiple words) | 187 // Distinguishable invalid map encodings (for single word and multiple words) |
126 // that indicate free regions. | 188 // that indicate free regions. |
127 static const uint32_t kSingleFreeEncoding = 0; | 189 static const uint32_t kSingleFreeEncoding = 0; |
128 static const uint32_t kMultiFreeEncoding = 1; | 190 static const uint32_t kMultiFreeEncoding = 1; |
129 | 191 |
| 192 inline Heap* heap() const { return heap_; } |
| 193 |
| 194 CodeFlusher* code_flusher() { return code_flusher_; } |
| 195 inline bool is_code_flushing_enabled() const { return code_flusher_ != NULL; } |
| 196 void EnableCodeFlushing(bool enable); |
| 197 |
130 private: | 198 private: |
| 199 MarkCompactCollector(); |
| 200 ~MarkCompactCollector(); |
| 201 |
131 #ifdef DEBUG | 202 #ifdef DEBUG |
132 enum CollectorState { | 203 enum CollectorState { |
133 IDLE, | 204 IDLE, |
134 PREPARE_GC, | 205 PREPARE_GC, |
135 MARK_LIVE_OBJECTS, | 206 MARK_LIVE_OBJECTS, |
136 SWEEP_SPACES, | 207 SWEEP_SPACES, |
137 ENCODE_FORWARDING_ADDRESSES, | 208 ENCODE_FORWARDING_ADDRESSES, |
138 UPDATE_POINTERS, | 209 UPDATE_POINTERS, |
139 RELOCATE_OBJECTS | 210 RELOCATE_OBJECTS |
140 }; | 211 }; |
141 | 212 |
142 // The current stage of the collector. | 213 // The current stage of the collector. |
143 static CollectorState state_; | 214 CollectorState state_; |
144 #endif | 215 #endif |
145 | 216 |
146 // Global flag that forces a compaction. | 217 // Global flag that forces a compaction. |
147 static bool force_compaction_; | 218 bool force_compaction_; |
148 | 219 |
149 // Global flag indicating whether spaces were compacted on the last GC. | 220 // Global flag indicating whether spaces were compacted on the last GC. |
150 static bool compacting_collection_; | 221 bool compacting_collection_; |
151 | 222 |
152 // Global flag indicating whether spaces will be compacted on the next GC. | 223 // Global flag indicating whether spaces will be compacted on the next GC. |
153 static bool compact_on_next_gc_; | 224 bool compact_on_next_gc_; |
154 | 225 |
155 // The number of objects left marked at the end of the last completed full | 226 // The number of objects left marked at the end of the last completed full |
156 // GC (expected to be zero). | 227 // GC (expected to be zero). |
157 static int previous_marked_count_; | 228 int previous_marked_count_; |
158 | 229 |
159 // A pointer to the current stack-allocated GC tracer object during a full | 230 // A pointer to the current stack-allocated GC tracer object during a full |
160 // collection (NULL before and after). | 231 // collection (NULL before and after). |
161 static GCTracer* tracer_; | 232 GCTracer* tracer_; |
162 | 233 |
163 // Finishes GC, performs heap verification if enabled. | 234 // Finishes GC, performs heap verification if enabled. |
164 static void Finish(); | 235 void Finish(); |
165 | 236 |
166 // ----------------------------------------------------------------------- | 237 // ----------------------------------------------------------------------- |
167 // Phase 1: Marking live objects. | 238 // Phase 1: Marking live objects. |
168 // | 239 // |
169 // Before: The heap has been prepared for garbage collection by | 240 // Before: The heap has been prepared for garbage collection by |
170 // MarkCompactCollector::Prepare() and is otherwise in its | 241 // MarkCompactCollector::Prepare() and is otherwise in its |
171 // normal state. | 242 // normal state. |
172 // | 243 // |
173 // After: Live objects are marked and non-live objects are unmarked. | 244 // After: Live objects are marked and non-live objects are unmarked. |
174 | 245 |
175 | 246 |
176 friend class RootMarkingVisitor; | 247 friend class RootMarkingVisitor; |
177 friend class MarkingVisitor; | 248 friend class MarkingVisitor; |
178 friend class StaticMarkingVisitor; | 249 friend class StaticMarkingVisitor; |
179 friend class CodeMarkingVisitor; | 250 friend class CodeMarkingVisitor; |
180 friend class SharedFunctionInfoMarkingVisitor; | 251 friend class SharedFunctionInfoMarkingVisitor; |
181 | 252 |
182 static void PrepareForCodeFlushing(); | 253 void PrepareForCodeFlushing(); |
183 | 254 |
184 // Marking operations for objects reachable from roots. | 255 // Marking operations for objects reachable from roots. |
185 static void MarkLiveObjects(); | 256 void MarkLiveObjects(); |
186 | 257 |
187 static void MarkUnmarkedObject(HeapObject* obj); | 258 void MarkUnmarkedObject(HeapObject* obj); |
188 | 259 |
189 static inline void MarkObject(HeapObject* obj) { | 260 inline void MarkObject(HeapObject* obj) { |
190 if (!obj->IsMarked()) MarkUnmarkedObject(obj); | 261 if (!obj->IsMarked()) MarkUnmarkedObject(obj); |
191 } | 262 } |
192 | 263 |
193 static inline void SetMark(HeapObject* obj) { | 264 inline void SetMark(HeapObject* obj); |
194 tracer_->increment_marked_count(); | |
195 #ifdef DEBUG | |
196 UpdateLiveObjectCount(obj); | |
197 #endif | |
198 obj->SetMark(); | |
199 } | |
200 | 265 |
201 // Creates back pointers for all map transitions, stores them in | 266 // Creates back pointers for all map transitions, stores them in |
202 // the prototype field. The original prototype pointers are restored | 267 // the prototype field. The original prototype pointers are restored |
203 // in ClearNonLiveTransitions(). All JSObject maps | 268 // in ClearNonLiveTransitions(). All JSObject maps |
204 // connected by map transitions have the same prototype object, which | 269 // connected by map transitions have the same prototype object, which |
205 // is why we can use this field temporarily for back pointers. | 270 // is why we can use this field temporarily for back pointers. |
206 static void CreateBackPointers(); | 271 void CreateBackPointers(); |
207 | 272 |
208 // Mark a Map and its DescriptorArray together, skipping transitions. | 273 // Mark a Map and its DescriptorArray together, skipping transitions. |
209 static void MarkMapContents(Map* map); | 274 void MarkMapContents(Map* map); |
210 static void MarkDescriptorArray(DescriptorArray* descriptors); | 275 void MarkDescriptorArray(DescriptorArray* descriptors); |
211 | 276 |
212 // Mark the heap roots and all objects reachable from them. | 277 // Mark the heap roots and all objects reachable from them. |
213 static void MarkRoots(RootMarkingVisitor* visitor); | 278 void MarkRoots(RootMarkingVisitor* visitor); |
214 | 279 |
215 // Mark the symbol table specially. References to symbols from the | 280 // Mark the symbol table specially. References to symbols from the |
216 // symbol table are weak. | 281 // symbol table are weak. |
217 static void MarkSymbolTable(); | 282 void MarkSymbolTable(); |
218 | 283 |
219 // Mark objects in object groups that have at least one object in the | 284 // Mark objects in object groups that have at least one object in the |
220 // group marked. | 285 // group marked. |
221 static void MarkObjectGroups(); | 286 void MarkObjectGroups(); |
222 | 287 |
223 // Mark objects in implicit references groups if their parent object | 288 // Mark objects in implicit references groups if their parent object |
224 // is marked. | 289 // is marked. |
225 static void MarkImplicitRefGroups(); | 290 void MarkImplicitRefGroups(); |
226 | 291 |
227 // Mark all objects which are reachable due to host application | 292 // Mark all objects which are reachable due to host application |
228 // logic like object groups or implicit references' groups. | 293 // logic like object groups or implicit references' groups. |
229 static void ProcessExternalMarking(); | 294 void ProcessExternalMarking(); |
230 | 295 |
231 // Mark objects reachable (transitively) from objects in the marking stack | 296 // Mark objects reachable (transitively) from objects in the marking stack |
232 // or overflowed in the heap. | 297 // or overflowed in the heap. |
233 static void ProcessMarkingStack(); | 298 void ProcessMarkingStack(); |
234 | 299 |
235 // Mark objects reachable (transitively) from objects in the marking | 300 // Mark objects reachable (transitively) from objects in the marking |
236 // stack. This function empties the marking stack, but may leave | 301 // stack. This function empties the marking stack, but may leave |
237 // overflowed objects in the heap, in which case the marking stack's | 302 // overflowed objects in the heap, in which case the marking stack's |
238 // overflow flag will be set. | 303 // overflow flag will be set. |
239 static void EmptyMarkingStack(); | 304 void EmptyMarkingStack(); |
240 | 305 |
241 // Refill the marking stack with overflowed objects from the heap. This | 306 // Refill the marking stack with overflowed objects from the heap. This |
242 // function either leaves the marking stack full or clears the overflow | 307 // function either leaves the marking stack full or clears the overflow |
243 // flag on the marking stack. | 308 // flag on the marking stack. |
244 static void RefillMarkingStack(); | 309 void RefillMarkingStack(); |
245 | 310 |
246 // Callback function for telling whether the object *p is an unmarked | 311 // Callback function for telling whether the object *p is an unmarked |
247 // heap object. | 312 // heap object. |
248 static bool IsUnmarkedHeapObject(Object** p); | 313 static bool IsUnmarkedHeapObject(Object** p); |
249 | 314 |
250 #ifdef DEBUG | 315 #ifdef DEBUG |
251 static void UpdateLiveObjectCount(HeapObject* obj); | 316 void UpdateLiveObjectCount(HeapObject* obj); |
252 #endif | 317 #endif |
253 | 318 |
254 // We sweep the large object space in the same way whether we are | 319 // We sweep the large object space in the same way whether we are |
255 // compacting or not, because the large object space is never compacted. | 320 // compacting or not, because the large object space is never compacted. |
256 static void SweepLargeObjectSpace(); | 321 void SweepLargeObjectSpace(); |
257 | 322 |
258 // Test whether a (possibly marked) object is a Map. | 323 // Test whether a (possibly marked) object is a Map. |
259 static inline bool SafeIsMap(HeapObject* object); | 324 static inline bool SafeIsMap(HeapObject* object); |
260 | 325 |
261 // Map transitions from a live map to a dead map must be killed. | 326 // Map transitions from a live map to a dead map must be killed. |
262 // We replace them with a null descriptor, with the same key. | 327 // We replace them with a null descriptor, with the same key. |
263 static void ClearNonLiveTransitions(); | 328 void ClearNonLiveTransitions(); |
264 | 329 |
265 // ----------------------------------------------------------------------- | 330 // ----------------------------------------------------------------------- |
266 // Phase 2: Sweeping to clear mark bits and free non-live objects for | 331 // Phase 2: Sweeping to clear mark bits and free non-live objects for |
267 // a non-compacting collection, or else computing and encoding | 332 // a non-compacting collection, or else computing and encoding |
268 // forwarding addresses for a compacting collection. | 333 // forwarding addresses for a compacting collection. |
269 // | 334 // |
270 // Before: Live objects are marked and non-live objects are unmarked. | 335 // Before: Live objects are marked and non-live objects are unmarked. |
271 // | 336 // |
272 // After: (Non-compacting collection.) Live objects are unmarked, | 337 // After: (Non-compacting collection.) Live objects are unmarked, |
273 // non-live regions have been added to their space's free | 338 // non-live regions have been added to their space's free |
(...skipping 24 matching lines...) Expand all Loading... |
298 // The Page::mc_first_forwarded field contains the (nonencoded) | 363 // The Page::mc_first_forwarded field contains the (nonencoded) |
299 // forwarding address of the first live object in the page. | 364 // forwarding address of the first live object in the page. |
300 // | 365 // |
301 // In both the new space and the paged spaces, a linked list | 366 // In both the new space and the paged spaces, a linked list |
302 // of live regions is constructructed (linked through | 367 // of live regions is constructructed (linked through |
303 // pointers in the non-live region immediately following each | 368 // pointers in the non-live region immediately following each |
304 // live region) to speed further passes of the collector. | 369 // live region) to speed further passes of the collector. |
305 | 370 |
306 // Encodes forwarding addresses of objects in compactable parts of the | 371 // Encodes forwarding addresses of objects in compactable parts of the |
307 // heap. | 372 // heap. |
308 static void EncodeForwardingAddresses(); | 373 void EncodeForwardingAddresses(); |
309 | 374 |
310 // Encodes the forwarding addresses of objects in new space. | 375 // Encodes the forwarding addresses of objects in new space. |
311 static void EncodeForwardingAddressesInNewSpace(); | 376 void EncodeForwardingAddressesInNewSpace(); |
312 | 377 |
313 // Function template to encode the forwarding addresses of objects in | 378 // Function template to encode the forwarding addresses of objects in |
314 // paged spaces, parameterized by allocation and non-live processing | 379 // paged spaces, parameterized by allocation and non-live processing |
315 // functions. | 380 // functions. |
316 template<AllocationFunction Alloc, ProcessNonLiveFunction ProcessNonLive> | 381 template<AllocationFunction Alloc, ProcessNonLiveFunction ProcessNonLive> |
317 static void EncodeForwardingAddressesInPagedSpace(PagedSpace* space); | 382 void EncodeForwardingAddressesInPagedSpace(PagedSpace* space); |
318 | 383 |
319 // Iterates live objects in a space, passes live objects | 384 // Iterates live objects in a space, passes live objects |
320 // to a callback function which returns the heap size of the object. | 385 // to a callback function which returns the heap size of the object. |
321 // Returns the number of live objects iterated. | 386 // Returns the number of live objects iterated. |
322 static int IterateLiveObjects(NewSpace* space, HeapObjectCallback size_f); | 387 int IterateLiveObjects(NewSpace* space, LiveObjectCallback size_f); |
323 static int IterateLiveObjects(PagedSpace* space, HeapObjectCallback size_f); | 388 int IterateLiveObjects(PagedSpace* space, LiveObjectCallback size_f); |
324 | 389 |
325 // Iterates the live objects between a range of addresses, returning the | 390 // Iterates the live objects between a range of addresses, returning the |
326 // number of live objects. | 391 // number of live objects. |
327 static int IterateLiveObjectsInRange(Address start, Address end, | 392 int IterateLiveObjectsInRange(Address start, Address end, |
328 HeapObjectCallback size_func); | 393 LiveObjectCallback size_func); |
329 | 394 |
330 // If we are not compacting the heap, we simply sweep the spaces except | 395 // If we are not compacting the heap, we simply sweep the spaces except |
331 // for the large object space, clearing mark bits and adding unmarked | 396 // for the large object space, clearing mark bits and adding unmarked |
332 // regions to each space's free list. | 397 // regions to each space's free list. |
333 static void SweepSpaces(); | 398 void SweepSpaces(); |
334 | 399 |
335 // ----------------------------------------------------------------------- | 400 // ----------------------------------------------------------------------- |
336 // Phase 3: Updating pointers in live objects. | 401 // Phase 3: Updating pointers in live objects. |
337 // | 402 // |
338 // Before: Same as after phase 2 (compacting collection). | 403 // Before: Same as after phase 2 (compacting collection). |
339 // | 404 // |
340 // After: All pointers in live objects, including encoded map | 405 // After: All pointers in live objects, including encoded map |
341 // pointers, are updated to point to their target's new | 406 // pointers, are updated to point to their target's new |
342 // location. | 407 // location. |
343 | 408 |
344 friend class UpdatingVisitor; // helper for updating visited objects | 409 friend class UpdatingVisitor; // helper for updating visited objects |
345 | 410 |
346 // Updates pointers in all spaces. | 411 // Updates pointers in all spaces. |
347 static void UpdatePointers(); | 412 void UpdatePointers(); |
348 | 413 |
349 // Updates pointers in an object in new space. | 414 // Updates pointers in an object in new space. |
350 // Returns the heap size of the object. | 415 // Returns the heap size of the object. |
351 static int UpdatePointersInNewObject(HeapObject* obj); | 416 int UpdatePointersInNewObject(HeapObject* obj); |
352 | 417 |
353 // Updates pointers in an object in old spaces. | 418 // Updates pointers in an object in old spaces. |
354 // Returns the heap size of the object. | 419 // Returns the heap size of the object. |
355 static int UpdatePointersInOldObject(HeapObject* obj); | 420 int UpdatePointersInOldObject(HeapObject* obj); |
356 | 421 |
357 // Calculates the forwarding address of an object in an old space. | 422 // Calculates the forwarding address of an object in an old space. |
358 static Address GetForwardingAddressInOldSpace(HeapObject* obj); | 423 static Address GetForwardingAddressInOldSpace(HeapObject* obj); |
359 | 424 |
360 // ----------------------------------------------------------------------- | 425 // ----------------------------------------------------------------------- |
361 // Phase 4: Relocating objects. | 426 // Phase 4: Relocating objects. |
362 // | 427 // |
363 // Before: Pointers to live objects are updated to point to their | 428 // Before: Pointers to live objects are updated to point to their |
364 // target's new location. | 429 // target's new location. |
365 // | 430 // |
366 // After: Objects have been moved to their new addresses. | 431 // After: Objects have been moved to their new addresses. |
367 | 432 |
368 // Relocates objects in all spaces. | 433 // Relocates objects in all spaces. |
369 static void RelocateObjects(); | 434 void RelocateObjects(); |
370 | 435 |
371 // Converts a code object's inline target to addresses, convention from | 436 // Converts a code object's inline target to addresses, convention from |
372 // address to target happens in the marking phase. | 437 // address to target happens in the marking phase. |
373 static int ConvertCodeICTargetToAddress(HeapObject* obj); | 438 int ConvertCodeICTargetToAddress(HeapObject* obj); |
374 | 439 |
375 // Relocate a map object. | 440 // Relocate a map object. |
376 static int RelocateMapObject(HeapObject* obj); | 441 int RelocateMapObject(HeapObject* obj); |
377 | 442 |
378 // Relocates an old object. | 443 // Relocates an old object. |
379 static int RelocateOldPointerObject(HeapObject* obj); | 444 int RelocateOldPointerObject(HeapObject* obj); |
380 static int RelocateOldDataObject(HeapObject* obj); | 445 int RelocateOldDataObject(HeapObject* obj); |
381 | 446 |
382 // Relocate a property cell object. | 447 // Relocate a property cell object. |
383 static int RelocateCellObject(HeapObject* obj); | 448 int RelocateCellObject(HeapObject* obj); |
384 | 449 |
385 // Helper function. | 450 // Helper function. |
386 static inline int RelocateOldNonCodeObject(HeapObject* obj, | 451 inline int RelocateOldNonCodeObject(HeapObject* obj, |
387 PagedSpace* space); | 452 PagedSpace* space); |
388 | 453 |
389 // Relocates an object in the code space. | 454 // Relocates an object in the code space. |
390 static int RelocateCodeObject(HeapObject* obj); | 455 int RelocateCodeObject(HeapObject* obj); |
391 | 456 |
392 // Copy a new object. | 457 // Copy a new object. |
393 static int RelocateNewObject(HeapObject* obj); | 458 int RelocateNewObject(HeapObject* obj); |
394 | 459 |
395 #ifdef DEBUG | 460 #ifdef DEBUG |
396 // ----------------------------------------------------------------------- | 461 // ----------------------------------------------------------------------- |
397 // Debugging variables, functions and classes | 462 // Debugging variables, functions and classes |
398 // Counters used for debugging the marking phase of mark-compact or | 463 // Counters used for debugging the marking phase of mark-compact or |
399 // mark-sweep collection. | 464 // mark-sweep collection. |
400 | 465 |
401 // Size of live objects in Heap::to_space_. | 466 // Size of live objects in Heap::to_space_. |
402 static int live_young_objects_size_; | 467 int live_young_objects_size_; |
403 | 468 |
404 // Size of live objects in Heap::old_pointer_space_. | 469 // Size of live objects in Heap::old_pointer_space_. |
405 static int live_old_pointer_objects_size_; | 470 int live_old_pointer_objects_size_; |
406 | 471 |
407 // Size of live objects in Heap::old_data_space_. | 472 // Size of live objects in Heap::old_data_space_. |
408 static int live_old_data_objects_size_; | 473 int live_old_data_objects_size_; |
409 | 474 |
410 // Size of live objects in Heap::code_space_. | 475 // Size of live objects in Heap::code_space_. |
411 static int live_code_objects_size_; | 476 int live_code_objects_size_; |
412 | 477 |
413 // Size of live objects in Heap::map_space_. | 478 // Size of live objects in Heap::map_space_. |
414 static int live_map_objects_size_; | 479 int live_map_objects_size_; |
415 | 480 |
416 // Size of live objects in Heap::cell_space_. | 481 // Size of live objects in Heap::cell_space_. |
417 static int live_cell_objects_size_; | 482 int live_cell_objects_size_; |
418 | 483 |
419 // Size of live objects in Heap::lo_space_. | 484 // Size of live objects in Heap::lo_space_. |
420 static int live_lo_objects_size_; | 485 int live_lo_objects_size_; |
421 | 486 |
422 // Number of live bytes in this collection. | 487 // Number of live bytes in this collection. |
423 static int live_bytes_; | 488 int live_bytes_; |
424 | 489 |
425 friend class MarkObjectVisitor; | 490 friend class MarkObjectVisitor; |
426 static void VisitObject(HeapObject* obj); | 491 static void VisitObject(HeapObject* obj); |
427 | 492 |
428 friend class UnmarkObjectVisitor; | 493 friend class UnmarkObjectVisitor; |
429 static void UnmarkObject(HeapObject* obj); | 494 static void UnmarkObject(HeapObject* obj); |
430 #endif | 495 #endif |
| 496 |
| 497 Heap* heap_; |
| 498 MarkingStack marking_stack_; |
| 499 CodeFlusher* code_flusher_; |
| 500 |
| 501 friend class Heap; |
| 502 friend class OverflowedObjectsScanner; |
431 }; | 503 }; |
432 | 504 |
433 | 505 |
434 } } // namespace v8::internal | 506 } } // namespace v8::internal |
435 | 507 |
436 #endif // V8_MARK_COMPACT_H_ | 508 #endif // V8_MARK_COMPACT_H_ |
OLD | NEW |