| 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 |
| 163 // Creates back pointers for all map transitions, stores them in | 164 // Creates back pointers for all map transitions, stores them in |
| 164 // the prototype field. The original prototype pointers are restored | 165 // the prototype field. The original prototype pointers are restored |
| 165 // in ClearNonLiveTransitions(). All JSObject maps | 166 // in ClearNonLiveTransitions(). All JSObject maps |
| 166 // connected by map transitions have the same prototype object, which | 167 // connected by map transitions have the same prototype object, which |
| 167 // is why we can use this field temporarily for back pointers. | 168 // is why we can use this field temporarily for back pointers. |
| 168 static void CreateBackPointers(); | 169 static void CreateBackPointers(); |
| 169 | 170 |
| 170 // Mark a Map and its DescriptorArray together, skipping transitions. | 171 // Mark a Map and its DescriptorArray together, skipping transitions. |
| 171 static void MarkMapContents(Map* map); | 172 static void MarkMapContents(Map* map); |
| 172 static void MarkDescriptorArray(DescriptorArray* descriptors); | 173 static void MarkDescriptorArray(DescriptorArray* descriptors); |
| 173 | 174 |
| 174 // Mark the heap roots and all objects reachable from them. | 175 // Mark the heap roots and all objects reachable from them. |
| 175 static void ProcessRoots(RootMarkingVisitor* visitor); | 176 static void MarkRoots(RootMarkingVisitor* visitor); |
| 177 |
| 178 // Mark the symbol table specially. References to symbols from the |
| 179 // symbol table are weak. |
| 180 static void MarkSymbolTable(); |
| 176 | 181 |
| 177 // Mark objects in object groups that have at least one object in the | 182 // Mark objects in object groups that have at least one object in the |
| 178 // group marked. | 183 // group marked. |
| 179 static void MarkObjectGroups(); | 184 static void MarkObjectGroups(); |
| 180 | 185 |
| 181 // Mark all objects in an object group with at least one marked | 186 // Mark all objects in an object group with at least one marked |
| 182 // object, then all objects reachable from marked objects in object | 187 // object, then all objects reachable from marked objects in object |
| 183 // groups, and repeat. | 188 // groups, and repeat. |
| 184 static void ProcessObjectGroups(MarkingVisitor* visitor); | 189 static void ProcessObjectGroups(MarkingVisitor* visitor); |
| 185 | 190 |
| 186 // Mark objects reachable (transitively) from objects in the marking stack | 191 // Mark objects reachable (transitively) from objects in the marking stack |
| 187 // or overflowed in the heap. | 192 // or overflowed in the heap. |
| 188 static void ProcessMarkingStack(MarkingVisitor* visitor); | 193 static void ProcessMarkingStack(MarkingVisitor* visitor); |
| 189 | 194 |
| 190 // Mark objects reachable (transitively) from objects in the marking | 195 // Mark objects reachable (transitively) from objects in the marking |
| 191 // stack. This function empties the marking stack, but may leave | 196 // stack. This function empties the marking stack, but may leave |
| 192 // overflowed objects in the heap, in which case the marking stack's | 197 // overflowed objects in the heap, in which case the marking stack's |
| 193 // overflow flag will be set. | 198 // overflow flag will be set. |
| 194 static void EmptyMarkingStack(MarkingVisitor* visitor); | 199 static void EmptyMarkingStack(MarkingVisitor* visitor); |
| 195 | 200 |
| 196 // Refill the marking stack with overflowed objects from the heap. This | 201 // Refill the marking stack with overflowed objects from the heap. This |
| 197 // function either leaves the marking stack full or clears the overflow | 202 // function either leaves the marking stack full or clears the overflow |
| 198 // flag on the marking stack. | 203 // flag on the marking stack. |
| 199 static void RefillMarkingStack(); | 204 static void RefillMarkingStack(); |
| 200 | 205 |
| 201 // Callback function for telling whether the object *p must be marked. | 206 // Callback function for telling whether the object *p must be marked. |
| 202 static bool MustBeMarked(Object** p); | 207 static bool MustBeMarked(Object** p); |
| 203 | 208 |
| 204 #ifdef DEBUG | 209 #ifdef DEBUG |
| 205 static void UpdateLiveObjectCount(HeapObject* obj); | 210 // The scale argument is positive 1 if we are marking an object and |
| 211 // -1 if we are clearing the mark bit of an object that we didn't |
| 212 // actually want marked. |
| 213 static void UpdateLiveObjectCount(HeapObject* obj, int scale); |
| 206 #endif | 214 #endif |
| 207 | 215 |
| 208 // We sweep the large object space in the same way whether we are | 216 // 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. | 217 // compacting or not, because the large object space is never compacted. |
| 210 static void SweepLargeObjectSpace(); | 218 static void SweepLargeObjectSpace(); |
| 211 | 219 |
| 212 // Test whether a (possibly marked) object is a Map. | 220 // Test whether a (possibly marked) object is a Map. |
| 213 static inline bool SafeIsMap(HeapObject* object); | 221 static inline bool SafeIsMap(HeapObject* object); |
| 214 | 222 |
| 215 // Map transitions from a live map to a dead map must be killed. | 223 // 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 | 406 |
| 399 friend class UnmarkObjectVisitor; | 407 friend class UnmarkObjectVisitor; |
| 400 static void UnmarkObject(HeapObject* obj); | 408 static void UnmarkObject(HeapObject* obj); |
| 401 #endif | 409 #endif |
| 402 }; | 410 }; |
| 403 | 411 |
| 404 | 412 |
| 405 } } // namespace v8::internal | 413 } } // namespace v8::internal |
| 406 | 414 |
| 407 #endif // V8_MARK_COMPACT_H_ | 415 #endif // V8_MARK_COMPACT_H_ |
| OLD | NEW |