| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1411 // An object in the group is marked, so mark as grey all white heap | 1411 // An object in the group is marked, so mark as grey all white heap |
| 1412 // objects in the group. | 1412 // objects in the group. |
| 1413 for (int j = 0; j < objects.length(); ++j) { | 1413 for (int j = 0; j < objects.length(); ++j) { |
| 1414 Object* object = *objects[j]; | 1414 Object* object = *objects[j]; |
| 1415 if (object->IsHeapObject()) { | 1415 if (object->IsHeapObject()) { |
| 1416 HeapObject* heap_object = HeapObject::cast(object); | 1416 HeapObject* heap_object = HeapObject::cast(object); |
| 1417 MarkBit mark = Marking::MarkBitFrom(heap_object); | 1417 MarkBit mark = Marking::MarkBitFrom(heap_object); |
| 1418 MarkObject(heap_object, mark); | 1418 MarkObject(heap_object, mark); |
| 1419 } | 1419 } |
| 1420 } | 1420 } |
| 1421 |
| 1421 // Once the entire group has been colored grey, set the object group | 1422 // Once the entire group has been colored grey, set the object group |
| 1422 // to NULL so it won't be processed again. | 1423 // to NULL so it won't be processed again. |
| 1423 delete object_groups->at(i); | 1424 delete entry; |
| 1424 object_groups->at(i) = NULL; | 1425 object_groups->at(i) = NULL; |
| 1425 } | 1426 } |
| 1426 } | 1427 } |
| 1427 | 1428 |
| 1428 | 1429 |
| 1430 void MarkCompactCollector::MarkImplicitRefGroups() { |
| 1431 List<ImplicitRefGroup*>* ref_groups = GlobalHandles::ImplicitRefGroups(); |
| 1432 |
| 1433 for (int i = 0; i < ref_groups->length(); i++) { |
| 1434 ImplicitRefGroup* entry = ref_groups->at(i); |
| 1435 if (entry == NULL) continue; |
| 1436 |
| 1437 if (!IsMarked(entry->parent_)) continue; |
| 1438 |
| 1439 List<Object**>& children = entry->children_; |
| 1440 // A parent object is marked, so mark as gray all child white heap |
| 1441 // objects. |
| 1442 for (int j = 0; j < children.length(); ++j) { |
| 1443 if ((*children[j])->IsHeapObject()) { |
| 1444 HeapObject* child = HeapObject::cast(*children[j]); |
| 1445 MarkBit mark = Marking::MarkBitFrom(child); |
| 1446 MarkObject(child, mark); |
| 1447 } |
| 1448 } |
| 1449 |
| 1450 // Once the entire group has been colored gray, set the group |
| 1451 // to NULL so it won't be processed again. |
| 1452 delete entry; |
| 1453 ref_groups->at(i) = NULL; |
| 1454 } |
| 1455 } |
| 1456 |
| 1457 |
| 1429 // Mark all objects reachable from the objects on the marking stack. | 1458 // Mark all objects reachable from the objects on the marking stack. |
| 1430 // Before: the marking stack contains zero or more heap object pointers. | 1459 // Before: the marking stack contains zero or more heap object pointers. |
| 1431 // After: the marking stack is empty, and all objects reachable from the | 1460 // After: the marking stack is empty, and all objects reachable from the |
| 1432 // marking stack have been marked, or are overflowed in the heap. | 1461 // marking stack have been marked, or are overflowed in the heap. |
| 1433 void MarkCompactCollector::EmptyMarkingStack() { | 1462 void MarkCompactCollector::EmptyMarkingStack() { |
| 1434 while (!marking_stack.is_empty()) { | 1463 while (!marking_stack.is_empty()) { |
| 1435 HeapObject* object = marking_stack.Pop(); | 1464 HeapObject* object = marking_stack.Pop(); |
| 1436 ASSERT(object->IsHeapObject()); | 1465 ASSERT(object->IsHeapObject()); |
| 1437 ASSERT(Heap::Contains(object)); | 1466 ASSERT(Heap::Contains(object)); |
| 1438 ASSERT(IsMarked(object)); | 1467 ASSERT(IsMarked(object)); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1494 // objects in the heap. | 1523 // objects in the heap. |
| 1495 void MarkCompactCollector::ProcessMarkingStack() { | 1524 void MarkCompactCollector::ProcessMarkingStack() { |
| 1496 EmptyMarkingStack(); | 1525 EmptyMarkingStack(); |
| 1497 while (marking_stack.overflowed()) { | 1526 while (marking_stack.overflowed()) { |
| 1498 RefillMarkingStack(); | 1527 RefillMarkingStack(); |
| 1499 EmptyMarkingStack(); | 1528 EmptyMarkingStack(); |
| 1500 } | 1529 } |
| 1501 } | 1530 } |
| 1502 | 1531 |
| 1503 | 1532 |
| 1504 void MarkCompactCollector::ProcessObjectGroups() { | 1533 void MarkCompactCollector::ProcessExternalMarking() { |
| 1505 bool work_to_do = true; | 1534 bool work_to_do = true; |
| 1506 ASSERT(marking_stack.is_empty()); | 1535 ASSERT(marking_stack.is_empty()); |
| 1507 while (work_to_do) { | 1536 while (work_to_do) { |
| 1508 MarkObjectGroups(); | 1537 MarkObjectGroups(); |
| 1538 MarkImplicitRefGroups(); |
| 1509 work_to_do = !marking_stack.is_empty(); | 1539 work_to_do = !marking_stack.is_empty(); |
| 1510 ProcessMarkingStack(); | 1540 ProcessMarkingStack(); |
| 1511 } | 1541 } |
| 1512 } | 1542 } |
| 1513 | 1543 |
| 1514 | 1544 |
| 1515 void MarkCompactCollector::MarkLiveObjects() { | 1545 void MarkCompactCollector::MarkLiveObjects() { |
| 1516 GCTracer::Scope gc_scope(tracer_, GCTracer::Scope::MC_MARK); | 1546 GCTracer::Scope gc_scope(tracer_, GCTracer::Scope::MC_MARK); |
| 1517 // The recursive GC marker detects when it is nearing stack overflow, | 1547 // The recursive GC marker detects when it is nearing stack overflow, |
| 1518 // and switches to a different marking system. JS interrupts interfere | 1548 // and switches to a different marking system. JS interrupts interfere |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1529 Heap::new_space()->FromSpaceHigh()); | 1559 Heap::new_space()->FromSpaceHigh()); |
| 1530 | 1560 |
| 1531 ASSERT(!marking_stack.overflowed()); | 1561 ASSERT(!marking_stack.overflowed()); |
| 1532 | 1562 |
| 1533 PrepareForCodeFlushing(); | 1563 PrepareForCodeFlushing(); |
| 1534 | 1564 |
| 1535 RootMarkingVisitor root_visitor; | 1565 RootMarkingVisitor root_visitor; |
| 1536 MarkRoots(&root_visitor); | 1566 MarkRoots(&root_visitor); |
| 1537 | 1567 |
| 1538 // The objects reachable from the roots are marked, yet unreachable | 1568 // The objects reachable from the roots are marked, yet unreachable |
| 1539 // objects are unmarked. Mark objects reachable from object groups | 1569 // objects are unmarked. Mark objects reachable due to host |
| 1540 // containing at least one marked object, and continue until no new | 1570 // application specific logic. |
| 1541 // objects are reachable from the object groups. | 1571 ProcessExternalMarking(); |
| 1542 ProcessObjectGroups(); | |
| 1543 | 1572 |
| 1544 // The objects reachable from the roots or object groups are marked, | 1573 // The objects reachable from the roots or object groups are marked, |
| 1545 // yet unreachable objects are unmarked. Mark objects reachable | 1574 // yet unreachable objects are unmarked. Mark objects reachable |
| 1546 // only from weak global handles. | 1575 // only from weak global handles. |
| 1547 // | 1576 // |
| 1548 // First we identify nonlive weak handles and mark them as pending | 1577 // First we identify nonlive weak handles and mark them as pending |
| 1549 // destruction. | 1578 // destruction. |
| 1550 GlobalHandles::IdentifyWeakHandles(&IsUnmarkedHeapObject); | 1579 GlobalHandles::IdentifyWeakHandles(&IsUnmarkedHeapObject); |
| 1551 // Then we mark the objects and process the transitive closure. | 1580 // Then we mark the objects and process the transitive closure. |
| 1552 GlobalHandles::IterateWeakRoots(&root_visitor); | 1581 GlobalHandles::IterateWeakRoots(&root_visitor); |
| 1553 while (marking_stack.overflowed()) { | 1582 while (marking_stack.overflowed()) { |
| 1554 RefillMarkingStack(); | 1583 RefillMarkingStack(); |
| 1555 EmptyMarkingStack(); | 1584 EmptyMarkingStack(); |
| 1556 } | 1585 } |
| 1557 | 1586 |
| 1558 // Repeat the object groups to mark unmarked groups reachable from the | 1587 // Repeat host application specific marking to mark unmarked objects |
| 1559 // weak roots. | 1588 // reachable from the weak roots. |
| 1560 ProcessObjectGroups(); | 1589 ProcessExternalMarking(); |
| 1561 | 1590 |
| 1562 AfterMarking(); | 1591 AfterMarking(); |
| 1563 } | 1592 } |
| 1564 | 1593 |
| 1565 | 1594 |
| 1566 void MarkCompactCollector::AfterMarking() { | 1595 void MarkCompactCollector::AfterMarking() { |
| 1567 // Prune the symbol table removing all symbols only pointed to by the | 1596 // Prune the symbol table removing all symbols only pointed to by the |
| 1568 // symbol table. Cannot use symbol_table() here because the symbol | 1597 // symbol table. Cannot use symbol_table() here because the symbol |
| 1569 // table is marked. | 1598 // table is marked. |
| 1570 SymbolTable* symbol_table = Heap::raw_unchecked_symbol_table(); | 1599 SymbolTable* symbol_table = Heap::raw_unchecked_symbol_table(); |
| 1571 SymbolTableCleaner v; | 1600 SymbolTableCleaner v; |
| 1572 symbol_table->IterateElements(&v); | 1601 symbol_table->IterateElements(&v); |
| 1573 symbol_table->ElementsRemoved(v.PointersRemoved()); | 1602 symbol_table->ElementsRemoved(v.PointersRemoved()); |
| 1574 ExternalStringTable::Iterate(&v); | 1603 ExternalStringTable::Iterate(&v); |
| 1575 ExternalStringTable::CleanUp(); | 1604 ExternalStringTable::CleanUp(); |
| 1576 | 1605 |
| 1577 // Process the weak references. | 1606 // Process the weak references. |
| 1578 MarkCompactWeakObjectRetainer mark_compact_object_retainer; | 1607 MarkCompactWeakObjectRetainer mark_compact_object_retainer; |
| 1579 Heap::ProcessWeakReferences(&mark_compact_object_retainer); | 1608 Heap::ProcessWeakReferences(&mark_compact_object_retainer); |
| 1580 | 1609 |
| 1581 // Remove object groups after marking phase. | 1610 // Remove object groups after marking phase. |
| 1582 GlobalHandles::RemoveObjectGroups(); | 1611 GlobalHandles::RemoveObjectGroups(); |
| 1612 GlobalHandles::RemoveImplicitRefGroups(); |
| 1583 | 1613 |
| 1584 // Flush code from collected candidates. | 1614 // Flush code from collected candidates. |
| 1585 if (FLAG_flush_code) { | 1615 if (FLAG_flush_code) { |
| 1586 FlushCode::ProcessCandidates(); | 1616 FlushCode::ProcessCandidates(); |
| 1587 } | 1617 } |
| 1588 | 1618 |
| 1589 // Clean up dead objects from the runtime profiler. | 1619 // Clean up dead objects from the runtime profiler. |
| 1590 RuntimeProfiler::RemoveDeadSamples(); | 1620 RuntimeProfiler::RemoveDeadSamples(); |
| 1591 } | 1621 } |
| 1592 | 1622 |
| (...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2534 } | 2564 } |
| 2535 | 2565 |
| 2536 | 2566 |
| 2537 void MarkCompactCollector::Initialize() { | 2567 void MarkCompactCollector::Initialize() { |
| 2538 StaticPointersToNewGenUpdatingVisitor::Initialize(); | 2568 StaticPointersToNewGenUpdatingVisitor::Initialize(); |
| 2539 StaticMarkingVisitor::Initialize(); | 2569 StaticMarkingVisitor::Initialize(); |
| 2540 } | 2570 } |
| 2541 | 2571 |
| 2542 | 2572 |
| 2543 } } // namespace v8::internal | 2573 } } // namespace v8::internal |
| OLD | NEW |