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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // | 135 // |
136 // Before: The heap has been prepared for garbage collection by | 136 // Before: The heap has been prepared for garbage collection by |
137 // MarkCompactCollector::Prepare() and is otherwise in its | 137 // MarkCompactCollector::Prepare() and is otherwise in its |
138 // normal state. | 138 // normal state. |
139 // | 139 // |
140 // After: Live objects are marked and non-live objects are unmarked. | 140 // After: Live objects are marked and non-live objects are unmarked. |
141 | 141 |
142 | 142 |
143 friend class RootMarkingVisitor; | 143 friend class RootMarkingVisitor; |
144 friend class MarkingVisitor; | 144 friend class MarkingVisitor; |
| 145 friend class UnmarkingVisitor; |
145 | 146 |
146 // Marking operations for objects reachable from roots. | 147 // Marking operations for objects reachable from roots. |
147 static void MarkLiveObjects(); | 148 static void MarkLiveObjects(); |
148 | 149 |
149 static void MarkUnmarkedObject(HeapObject* obj); | 150 static void MarkUnmarkedObject(HeapObject* obj); |
150 | 151 |
151 static inline void MarkObject(HeapObject* obj) { | 152 static inline void MarkObject(HeapObject* obj) { |
152 if (!obj->IsMarked()) MarkUnmarkedObject(obj); | 153 if (!obj->IsMarked()) MarkUnmarkedObject(obj); |
153 } | 154 } |
154 | 155 |
155 static inline void SetMark(HeapObject* obj) { | 156 static inline void SetMark(HeapObject* obj) { |
156 tracer_->increment_marked_count(); | 157 tracer_->increment_marked_count(); |
157 #ifdef DEBUG | 158 #ifdef DEBUG |
158 UpdateLiveObjectCount(obj); | 159 UpdateLiveObjectCount(obj, 1); |
159 #endif | 160 #endif |
160 obj->SetMark(); | 161 obj->SetMark(); |
161 } | 162 } |
162 | 163 |
| 164 // Used to clear mark bits during marking for objects that are not |
| 165 // actually live. Since it updates bookkeeping state, it is not |
| 166 // used when clearing mark bits on live objects (eg, during |
| 167 // sweeping). |
| 168 static inline void ClearMark(HeapObject* obj) { |
| 169 obj->ClearMark(); |
| 170 tracer_->decrement_marked_count(); |
| 171 #ifdef DEBUG |
| 172 UpdateLiveObjectCount(obj, -1); |
| 173 #endif |
| 174 } |
| 175 |
163 // Creates back pointers for all map transitions, stores them in | 176 // Creates back pointers for all map transitions, stores them in |
164 // the prototype field. The original prototype pointers are restored | 177 // the prototype field. The original prototype pointers are restored |
165 // in ClearNonLiveTransitions(). All JSObject maps | 178 // in ClearNonLiveTransitions(). All JSObject maps |
166 // connected by map transitions have the same prototype object, which | 179 // connected by map transitions have the same prototype object, which |
167 // is why we can use this field temporarily for back pointers. | 180 // is why we can use this field temporarily for back pointers. |
168 static void CreateBackPointers(); | 181 static void CreateBackPointers(); |
169 | 182 |
170 // Mark a Map and its DescriptorArray together, skipping transitions. | 183 // Mark a Map and its DescriptorArray together, skipping transitions. |
171 static void MarkMapContents(Map* map); | 184 static void MarkMapContents(Map* map); |
172 static void MarkDescriptorArray(DescriptorArray* descriptors); | 185 static void MarkDescriptorArray(DescriptorArray* descriptors); |
(...skipping 22 matching lines...) Expand all Loading... |
195 | 208 |
196 // Refill the marking stack with overflowed objects from the heap. This | 209 // Refill the marking stack with overflowed objects from the heap. This |
197 // function either leaves the marking stack full or clears the overflow | 210 // function either leaves the marking stack full or clears the overflow |
198 // flag on the marking stack. | 211 // flag on the marking stack. |
199 static void RefillMarkingStack(); | 212 static void RefillMarkingStack(); |
200 | 213 |
201 // Callback function for telling whether the object *p must be marked. | 214 // Callback function for telling whether the object *p must be marked. |
202 static bool MustBeMarked(Object** p); | 215 static bool MustBeMarked(Object** p); |
203 | 216 |
204 #ifdef DEBUG | 217 #ifdef DEBUG |
205 static void UpdateLiveObjectCount(HeapObject* obj); | 218 // The scale argument is positive 1 if we are marking an object and |
| 219 // -1 if we are clearing the mark bit of an object that we didn't |
| 220 // actually want marked. |
| 221 static void UpdateLiveObjectCount(HeapObject* obj, int scale); |
206 #endif | 222 #endif |
207 | 223 |
208 // We sweep the large object space in the same way whether we are | 224 // We sweep the large object space in the same way whether we are |
209 // compacting or not, because the large object space is never compacted. | 225 // compacting or not, because the large object space is never compacted. |
210 static void SweepLargeObjectSpace(); | 226 static void SweepLargeObjectSpace(); |
211 | 227 |
212 // Test whether a (possibly marked) object is a Map. | 228 // Test whether a (possibly marked) object is a Map. |
213 static inline bool SafeIsMap(HeapObject* object); | 229 static inline bool SafeIsMap(HeapObject* object); |
214 | 230 |
215 // Map transitions from a live map to a dead map must be killed. | 231 // Map transitions from a live map to a dead map must be killed. |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 414 |
399 friend class UnmarkObjectVisitor; | 415 friend class UnmarkObjectVisitor; |
400 static void UnmarkObject(HeapObject* obj); | 416 static void UnmarkObject(HeapObject* obj); |
401 #endif | 417 #endif |
402 }; | 418 }; |
403 | 419 |
404 | 420 |
405 } } // namespace v8::internal | 421 } } // namespace v8::internal |
406 | 422 |
407 #endif // V8_MARK_COMPACT_H_ | 423 #endif // V8_MARK_COMPACT_H_ |
OLD | NEW |