| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 Finish(); | 89 Finish(); |
| 90 | 90 |
| 91 // Save the count of marked objects remaining after the collection and | 91 // Save the count of marked objects remaining after the collection and |
| 92 // null out the GC tracer. | 92 // null out the GC tracer. |
| 93 previous_marked_count_ = tracer_->marked_count(); | 93 previous_marked_count_ = tracer_->marked_count(); |
| 94 ASSERT(previous_marked_count_ == 0); | 94 ASSERT(previous_marked_count_ == 0); |
| 95 tracer_ = NULL; | 95 tracer_ = NULL; |
| 96 } | 96 } |
| 97 | 97 |
| 98 | 98 |
| 99 #ifdef DEBUG | |
| 100 // Helper class for verifying the symbol table. | |
| 101 class SymbolTableVerifier : public ObjectVisitor { | |
| 102 public: | |
| 103 SymbolTableVerifier() { } | |
| 104 void VisitPointers(Object** start, Object** end) { | |
| 105 // Visit all HeapObject pointers in [start, end). | |
| 106 for (Object** p = start; p < end; p++) { | |
| 107 if ((*p)->IsHeapObject()) { | |
| 108 // Check that the symbol is actually a symbol. | |
| 109 ASSERT((*p)->IsNull() || (*p)->IsUndefined() || (*p)->IsSymbol()); | |
| 110 } | |
| 111 } | |
| 112 } | |
| 113 }; | |
| 114 #endif // DEBUG | |
| 115 | |
| 116 | |
| 117 void MarkCompactCollector::Prepare(GCTracer* tracer) { | 99 void MarkCompactCollector::Prepare(GCTracer* tracer) { |
| 118 // Rather than passing the tracer around we stash it in a static member | 100 // Rather than passing the tracer around we stash it in a static member |
| 119 // variable. | 101 // variable. |
| 120 tracer_ = tracer; | 102 tracer_ = tracer; |
| 121 | 103 |
| 122 static const int kFragmentationLimit = 50; // Percent. | 104 static const int kFragmentationLimit = 50; // Percent. |
| 123 #ifdef DEBUG | 105 #ifdef DEBUG |
| 124 ASSERT(state_ == IDLE); | 106 ASSERT(state_ == IDLE); |
| 125 state_ = PREPARE_GC; | 107 state_ = PREPARE_GC; |
| 126 #endif | 108 #endif |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 Page::set_rset_state(Page::NOT_IN_USE); | 141 Page::set_rset_state(Page::NOT_IN_USE); |
| 160 } | 142 } |
| 161 #endif | 143 #endif |
| 162 | 144 |
| 163 PagedSpaces spaces; | 145 PagedSpaces spaces; |
| 164 while (PagedSpace* space = spaces.next()) { | 146 while (PagedSpace* space = spaces.next()) { |
| 165 space->PrepareForMarkCompact(compacting_collection_); | 147 space->PrepareForMarkCompact(compacting_collection_); |
| 166 } | 148 } |
| 167 | 149 |
| 168 #ifdef DEBUG | 150 #ifdef DEBUG |
| 169 SymbolTable* symbol_table = SymbolTable::cast(Heap::symbol_table()); | |
| 170 SymbolTableVerifier v; | |
| 171 symbol_table->IterateElements(&v); | |
| 172 | |
| 173 live_bytes_ = 0; | 151 live_bytes_ = 0; |
| 174 live_young_objects_ = 0; | 152 live_young_objects_ = 0; |
| 175 live_old_pointer_objects_ = 0; | 153 live_old_pointer_objects_ = 0; |
| 176 live_old_data_objects_ = 0; | 154 live_old_data_objects_ = 0; |
| 177 live_code_objects_ = 0; | 155 live_code_objects_ = 0; |
| 178 live_map_objects_ = 0; | 156 live_map_objects_ = 0; |
| 179 live_lo_objects_ = 0; | 157 live_lo_objects_ = 0; |
| 180 #endif | 158 #endif |
| 181 } | 159 } |
| 182 | 160 |
| 183 | 161 |
| 184 void MarkCompactCollector::Finish() { | 162 void MarkCompactCollector::Finish() { |
| 185 #ifdef DEBUG | 163 #ifdef DEBUG |
| 186 SymbolTable* symbol_table = SymbolTable::cast(Heap::symbol_table()); | |
| 187 SymbolTableVerifier v; | |
| 188 symbol_table->IterateElements(&v); | |
| 189 | |
| 190 ASSERT(state_ == SWEEP_SPACES || state_ == REBUILD_RSETS); | 164 ASSERT(state_ == SWEEP_SPACES || state_ == REBUILD_RSETS); |
| 191 state_ = IDLE; | 165 state_ = IDLE; |
| 192 #endif | 166 #endif |
| 193 // The stub cache is not traversed during GC; clear the cache to | 167 // The stub cache is not traversed during GC; clear the cache to |
| 194 // force lazy re-initialization of it. This must be done after the | 168 // force lazy re-initialization of it. This must be done after the |
| 195 // GC, because it relies on the new address of certain old space | 169 // GC, because it relies on the new address of certain old space |
| 196 // objects (empty string, illegal builtin). | 170 // objects (empty string, illegal builtin). |
| 197 StubCache::Clear(); | 171 StubCache::Clear(); |
| 198 } | 172 } |
| 199 | 173 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 // | 213 // |
| 240 // The check performed is: | 214 // The check performed is: |
| 241 // object->IsConsString() && !object->IsSymbol() && | 215 // object->IsConsString() && !object->IsSymbol() && |
| 242 // (ConsString::cast(object)->second() == Heap::empty_string()) | 216 // (ConsString::cast(object)->second() == Heap::empty_string()) |
| 243 // except the maps for the object and its possible substrings might be | 217 // except the maps for the object and its possible substrings might be |
| 244 // marked. | 218 // marked. |
| 245 HeapObject* object = HeapObject::cast(*p); | 219 HeapObject* object = HeapObject::cast(*p); |
| 246 MapWord map_word = object->map_word(); | 220 MapWord map_word = object->map_word(); |
| 247 map_word.ClearMark(); | 221 map_word.ClearMark(); |
| 248 InstanceType type = map_word.ToMap()->instance_type(); | 222 InstanceType type = map_word.ToMap()->instance_type(); |
| 249 if (type >= FIRST_NONSTRING_TYPE || (type & kIsSymbolMask) != 0) { | 223 if ((type & kShortcutTypeMask) != kShortcutTypeTag) return object; |
| 250 return object; | |
| 251 } | |
| 252 | |
| 253 StringRepresentationTag rep = | |
| 254 static_cast<StringRepresentationTag>(type & kStringRepresentationMask); | |
| 255 if (rep != kConsStringTag) return object; | |
| 256 | 224 |
| 257 Object* second = reinterpret_cast<ConsString*>(object)->unchecked_second(); | 225 Object* second = reinterpret_cast<ConsString*>(object)->unchecked_second(); |
| 258 if (reinterpret_cast<String*>(second) != Heap::empty_string()) return object; | 226 if (reinterpret_cast<String*>(second) != Heap::empty_string()) return object; |
| 259 | 227 |
| 260 // Since we don't have the object's start, it is impossible to update the | 228 // Since we don't have the object's start, it is impossible to update the |
| 261 // remembered set. Therefore, we only replace the string with its left | 229 // remembered set. Therefore, we only replace the string with its left |
| 262 // substring when the remembered set does not change. | 230 // substring when the remembered set does not change. |
| 263 Object* first = reinterpret_cast<ConsString*>(object)->unchecked_first(); | 231 Object* first = reinterpret_cast<ConsString*>(object)->unchecked_first(); |
| 264 if (!Heap::InNewSpace(object) && Heap::InNewSpace(first)) return object; | 232 if (!Heap::InNewSpace(object) && Heap::InNewSpace(first)) return object; |
| 265 | 233 |
| (...skipping 1518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1784 | 1752 |
| 1785 void MarkCompactCollector::RebuildRSets() { | 1753 void MarkCompactCollector::RebuildRSets() { |
| 1786 #ifdef DEBUG | 1754 #ifdef DEBUG |
| 1787 ASSERT(state_ == RELOCATE_OBJECTS); | 1755 ASSERT(state_ == RELOCATE_OBJECTS); |
| 1788 state_ = REBUILD_RSETS; | 1756 state_ = REBUILD_RSETS; |
| 1789 #endif | 1757 #endif |
| 1790 Heap::RebuildRSets(); | 1758 Heap::RebuildRSets(); |
| 1791 } | 1759 } |
| 1792 | 1760 |
| 1793 } } // namespace v8::internal | 1761 } } // namespace v8::internal |
| OLD | NEW |