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 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 | 1183 |
1184 if (!group_marked) continue; | 1184 if (!group_marked) continue; |
1185 | 1185 |
1186 // An object in the group is marked, so mark as gray all white heap | 1186 // An object in the group is marked, so mark as gray all white heap |
1187 // objects in the group. | 1187 // objects in the group. |
1188 for (int j = 0; j < objects.length(); ++j) { | 1188 for (int j = 0; j < objects.length(); ++j) { |
1189 if ((*objects[j])->IsHeapObject()) { | 1189 if ((*objects[j])->IsHeapObject()) { |
1190 MarkObject(HeapObject::cast(*objects[j])); | 1190 MarkObject(HeapObject::cast(*objects[j])); |
1191 } | 1191 } |
1192 } | 1192 } |
| 1193 |
1193 // Once the entire group has been colored gray, set the object group | 1194 // Once the entire group has been colored gray, set the object group |
1194 // to NULL so it won't be processed again. | 1195 // to NULL so it won't be processed again. |
1195 delete object_groups->at(i); | 1196 delete entry; |
1196 object_groups->at(i) = NULL; | 1197 object_groups->at(i) = NULL; |
1197 } | 1198 } |
1198 } | 1199 } |
1199 | 1200 |
1200 | 1201 |
| 1202 void MarkCompactCollector::MarkImplicitRefGroups() { |
| 1203 List<ImplicitRefGroup*>* ref_groups = GlobalHandles::ImplicitRefGroups(); |
| 1204 |
| 1205 for (int i = 0; i < ref_groups->length(); i++) { |
| 1206 ImplicitRefGroup* entry = ref_groups->at(i); |
| 1207 if (entry == NULL) continue; |
| 1208 |
| 1209 if (!entry->parent_->IsMarked()) continue; |
| 1210 |
| 1211 List<Object**>& children = entry->children_; |
| 1212 // A parent object is marked, so mark as gray all child white heap |
| 1213 // objects. |
| 1214 for (int j = 0; j < children.length(); ++j) { |
| 1215 if ((*children[j])->IsHeapObject()) { |
| 1216 MarkObject(HeapObject::cast(*children[j])); |
| 1217 } |
| 1218 } |
| 1219 |
| 1220 // Once the entire group has been colored gray, set the group |
| 1221 // to NULL so it won't be processed again. |
| 1222 delete entry; |
| 1223 ref_groups->at(i) = NULL; |
| 1224 } |
| 1225 } |
| 1226 |
| 1227 |
1201 // Mark all objects reachable from the objects on the marking stack. | 1228 // Mark all objects reachable from the objects on the marking stack. |
1202 // Before: the marking stack contains zero or more heap object pointers. | 1229 // Before: the marking stack contains zero or more heap object pointers. |
1203 // After: the marking stack is empty, and all objects reachable from the | 1230 // After: the marking stack is empty, and all objects reachable from the |
1204 // marking stack have been marked, or are overflowed in the heap. | 1231 // marking stack have been marked, or are overflowed in the heap. |
1205 void MarkCompactCollector::EmptyMarkingStack() { | 1232 void MarkCompactCollector::EmptyMarkingStack() { |
1206 while (!marking_stack.is_empty()) { | 1233 while (!marking_stack.is_empty()) { |
1207 HeapObject* object = marking_stack.Pop(); | 1234 HeapObject* object = marking_stack.Pop(); |
1208 ASSERT(object->IsHeapObject()); | 1235 ASSERT(object->IsHeapObject()); |
1209 ASSERT(Heap::Contains(object)); | 1236 ASSERT(Heap::Contains(object)); |
1210 ASSERT(object->IsMarked()); | 1237 ASSERT(object->IsMarked()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 // objects in the heap. | 1296 // objects in the heap. |
1270 void MarkCompactCollector::ProcessMarkingStack() { | 1297 void MarkCompactCollector::ProcessMarkingStack() { |
1271 EmptyMarkingStack(); | 1298 EmptyMarkingStack(); |
1272 while (marking_stack.overflowed()) { | 1299 while (marking_stack.overflowed()) { |
1273 RefillMarkingStack(); | 1300 RefillMarkingStack(); |
1274 EmptyMarkingStack(); | 1301 EmptyMarkingStack(); |
1275 } | 1302 } |
1276 } | 1303 } |
1277 | 1304 |
1278 | 1305 |
1279 void MarkCompactCollector::ProcessObjectGroups() { | 1306 void MarkCompactCollector::ProcessExternalMarking() { |
1280 bool work_to_do = true; | 1307 bool work_to_do = true; |
1281 ASSERT(marking_stack.is_empty()); | 1308 ASSERT(marking_stack.is_empty()); |
1282 while (work_to_do) { | 1309 while (work_to_do) { |
1283 MarkObjectGroups(); | 1310 MarkObjectGroups(); |
| 1311 MarkImplicitRefGroups(); |
1284 work_to_do = !marking_stack.is_empty(); | 1312 work_to_do = !marking_stack.is_empty(); |
1285 ProcessMarkingStack(); | 1313 ProcessMarkingStack(); |
1286 } | 1314 } |
1287 } | 1315 } |
1288 | 1316 |
1289 | 1317 |
1290 void MarkCompactCollector::MarkLiveObjects() { | 1318 void MarkCompactCollector::MarkLiveObjects() { |
1291 GCTracer::Scope gc_scope(tracer_, GCTracer::Scope::MC_MARK); | 1319 GCTracer::Scope gc_scope(tracer_, GCTracer::Scope::MC_MARK); |
1292 // The recursive GC marker detects when it is nearing stack overflow, | 1320 // The recursive GC marker detects when it is nearing stack overflow, |
1293 // and switches to a different marking system. JS interrupts interfere | 1321 // and switches to a different marking system. JS interrupts interfere |
(...skipping 10 matching lines...) Expand all Loading... |
1304 Heap::new_space()->FromSpaceHigh()); | 1332 Heap::new_space()->FromSpaceHigh()); |
1305 | 1333 |
1306 ASSERT(!marking_stack.overflowed()); | 1334 ASSERT(!marking_stack.overflowed()); |
1307 | 1335 |
1308 PrepareForCodeFlushing(); | 1336 PrepareForCodeFlushing(); |
1309 | 1337 |
1310 RootMarkingVisitor root_visitor; | 1338 RootMarkingVisitor root_visitor; |
1311 MarkRoots(&root_visitor); | 1339 MarkRoots(&root_visitor); |
1312 | 1340 |
1313 // The objects reachable from the roots are marked, yet unreachable | 1341 // The objects reachable from the roots are marked, yet unreachable |
1314 // objects are unmarked. Mark objects reachable from object groups | 1342 // objects are unmarked. Mark objects reachable due to host |
1315 // containing at least one marked object, and continue until no new | 1343 // application specific logic. |
1316 // objects are reachable from the object groups. | 1344 ProcessExternalMarking(); |
1317 ProcessObjectGroups(); | |
1318 | 1345 |
1319 // The objects reachable from the roots or object groups are marked, | 1346 // The objects reachable from the roots or object groups are marked, |
1320 // yet unreachable objects are unmarked. Mark objects reachable | 1347 // yet unreachable objects are unmarked. Mark objects reachable |
1321 // only from weak global handles. | 1348 // only from weak global handles. |
1322 // | 1349 // |
1323 // First we identify nonlive weak handles and mark them as pending | 1350 // First we identify nonlive weak handles and mark them as pending |
1324 // destruction. | 1351 // destruction. |
1325 GlobalHandles::IdentifyWeakHandles(&IsUnmarkedHeapObject); | 1352 GlobalHandles::IdentifyWeakHandles(&IsUnmarkedHeapObject); |
1326 // Then we mark the objects and process the transitive closure. | 1353 // Then we mark the objects and process the transitive closure. |
1327 GlobalHandles::IterateWeakRoots(&root_visitor); | 1354 GlobalHandles::IterateWeakRoots(&root_visitor); |
1328 while (marking_stack.overflowed()) { | 1355 while (marking_stack.overflowed()) { |
1329 RefillMarkingStack(); | 1356 RefillMarkingStack(); |
1330 EmptyMarkingStack(); | 1357 EmptyMarkingStack(); |
1331 } | 1358 } |
1332 | 1359 |
1333 // Repeat the object groups to mark unmarked groups reachable from the | 1360 // Repeat host application specific marking to mark unmarked objects |
1334 // weak roots. | 1361 // reachable from the weak roots. |
1335 ProcessObjectGroups(); | 1362 ProcessExternalMarking(); |
1336 | 1363 |
1337 // Prune the symbol table removing all symbols only pointed to by the | 1364 // Prune the symbol table removing all symbols only pointed to by the |
1338 // symbol table. Cannot use symbol_table() here because the symbol | 1365 // symbol table. Cannot use symbol_table() here because the symbol |
1339 // table is marked. | 1366 // table is marked. |
1340 SymbolTable* symbol_table = Heap::raw_unchecked_symbol_table(); | 1367 SymbolTable* symbol_table = Heap::raw_unchecked_symbol_table(); |
1341 SymbolTableCleaner v; | 1368 SymbolTableCleaner v; |
1342 symbol_table->IterateElements(&v); | 1369 symbol_table->IterateElements(&v); |
1343 symbol_table->ElementsRemoved(v.PointersRemoved()); | 1370 symbol_table->ElementsRemoved(v.PointersRemoved()); |
1344 ExternalStringTable::Iterate(&v); | 1371 ExternalStringTable::Iterate(&v); |
1345 ExternalStringTable::CleanUp(); | 1372 ExternalStringTable::CleanUp(); |
1346 | 1373 |
1347 // Process the weak references. | 1374 // Process the weak references. |
1348 MarkCompactWeakObjectRetainer mark_compact_object_retainer; | 1375 MarkCompactWeakObjectRetainer mark_compact_object_retainer; |
1349 Heap::ProcessWeakReferences(&mark_compact_object_retainer); | 1376 Heap::ProcessWeakReferences(&mark_compact_object_retainer); |
1350 | 1377 |
1351 // Remove object groups after marking phase. | 1378 // Remove object groups after marking phase. |
1352 GlobalHandles::RemoveObjectGroups(); | 1379 GlobalHandles::RemoveObjectGroups(); |
| 1380 GlobalHandles::RemoveImplicitRefGroups(); |
1353 | 1381 |
1354 // Flush code from collected candidates. | 1382 // Flush code from collected candidates. |
1355 FlushCode::ProcessCandidates(); | 1383 FlushCode::ProcessCandidates(); |
1356 | 1384 |
1357 // Clean up dead objects from the runtime profiler. | 1385 // Clean up dead objects from the runtime profiler. |
1358 RuntimeProfiler::RemoveDeadSamples(); | 1386 RuntimeProfiler::RemoveDeadSamples(); |
1359 } | 1387 } |
1360 | 1388 |
1361 | 1389 |
1362 #ifdef DEBUG | 1390 #ifdef DEBUG |
(...skipping 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2948 } | 2976 } |
2949 | 2977 |
2950 | 2978 |
2951 void MarkCompactCollector::Initialize() { | 2979 void MarkCompactCollector::Initialize() { |
2952 StaticPointersToNewGenUpdatingVisitor::Initialize(); | 2980 StaticPointersToNewGenUpdatingVisitor::Initialize(); |
2953 StaticMarkingVisitor::Initialize(); | 2981 StaticMarkingVisitor::Initialize(); |
2954 } | 2982 } |
2955 | 2983 |
2956 | 2984 |
2957 } } // namespace v8::internal | 2985 } } // namespace v8::internal |
OLD | NEW |