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 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
555 } | 555 } |
556 | 556 |
557 | 557 |
558 bool MarkCompactCollector::MustBeMarked(Object** p) { | 558 bool MarkCompactCollector::MustBeMarked(Object** p) { |
559 // Check whether *p is a HeapObject pointer. | 559 // Check whether *p is a HeapObject pointer. |
560 if (!(*p)->IsHeapObject()) return false; | 560 if (!(*p)->IsHeapObject()) return false; |
561 return !HeapObject::cast(*p)->IsMarked(); | 561 return !HeapObject::cast(*p)->IsMarked(); |
562 } | 562 } |
563 | 563 |
564 | 564 |
565 // Helper class to unmark marked objects in a range of pointers but | 565 class SymbolMarkingVisitor : public ObjectVisitor { |
566 // not recursively. | |
567 class UnmarkingVisitor : public ObjectVisitor { | |
568 public: | 566 public: |
569 void VisitPointers(Object** start, Object** end) { | 567 void VisitPointers(Object** start, Object** end) { |
568 MarkingVisitor marker; | |
570 for (Object** p = start; p < end; p++) { | 569 for (Object** p = start; p < end; p++) { |
571 if ((*p)->IsHeapObject() && HeapObject::cast(*p)->IsMarked()) { | 570 if (!(*p)->IsHeapObject()) continue; |
iposva
2009/05/05 05:05:19
Can there be non-heap entries in the symbol table?
| |
572 MarkCompactCollector::ClearMark(HeapObject::cast(*p)); | 571 |
573 } | 572 HeapObject* object = HeapObject::cast(*p); |
Kasper Lund
2009/05/05 05:22:34
The newlines here look weird. How about moving the
Kevin Millikin (Chromium)
2009/05/05 05:34:07
I could do that, but the comment goes with the con
| |
573 // If the object is marked, we have marked or are in the process | |
574 // of marking subparts. | |
575 if (object->IsMarked()) continue; | |
576 | |
577 // The object is unmarked, we do not need to unmark to use its | |
578 // map. | |
579 Map* map = object->map(); | |
580 object->IterateBody(map->instance_type(), | |
Kasper Lund
2009/05/05 05:22:34
I'd compute the size before the IterateBody call,
Kevin Millikin (Chromium)
2009/05/05 05:34:07
That's not the way I roll.
| |
581 object->SizeFromMap(map), | |
582 &marker); | |
574 } | 583 } |
575 } | 584 } |
576 }; | 585 }; |
577 | 586 |
578 | 587 |
579 void MarkCompactCollector::ProcessRoots(RootMarkingVisitor* visitor) { | 588 void MarkCompactCollector::MarkSymbolTable() { |
580 // Handle the symbol table specially. Mark the prefix and the | |
581 // symbol table itself. Do not mark the symbol table entries, but | |
582 // do explicitly mark all other objects reachable from them. | |
583 // | |
584 // Objects reachable from symbols are marked as live so as to ensure | 589 // Objects reachable from symbols are marked as live so as to ensure |
585 // that if the symbol itself remains alive after GC for any reason, | 590 // that if the symbol itself remains alive after GC for any reason, |
586 // and if it is a sliced string or a cons string backed by an | 591 // and if it is a sliced string or a cons string backed by an |
587 // external string (even indirectly), then the external string does | 592 // external string (even indirectly), then the external string does |
588 // not receive a weak reference callback. | 593 // not receive a weak reference callback. |
589 SymbolTable* symbol_table = SymbolTable::cast(Heap::symbol_table()); | 594 SymbolTable* symbol_table = SymbolTable::cast(Heap::symbol_table()); |
590 // First mark everything reachable from the symbol table, then | |
591 // unmark just the elements themselves. | |
592 symbol_table->Iterate(visitor); | |
593 // There may be overflowed objects in the heap. Visit them now. | |
594 while (marking_stack.overflowed()) { | |
595 RefillMarkingStack(); | |
596 EmptyMarkingStack(visitor->stack_visitor()); | |
597 } | |
598 UnmarkingVisitor unmarking_visitor; | |
599 symbol_table->IterateElements(&unmarking_visitor); | |
600 // Mark the symbol table itself. | 595 // Mark the symbol table itself. |
601 SetMark(symbol_table); | 596 SetMark(symbol_table); |
597 // Explicitly mark the prefix. | |
598 MarkingVisitor marker; | |
599 symbol_table->IteratePrefix(&marker); | |
600 ProcessMarkingStack(&marker); | |
601 // Mark subparts of the symbols but not the symbols themselves | |
602 // (unless reachable from another symbol). | |
603 SymbolMarkingVisitor symbol_marker; | |
604 symbol_table->IterateElements(&symbol_marker); | |
605 ProcessMarkingStack(&marker); | |
606 } | |
602 | 607 |
608 | |
609 void MarkCompactCollector::MarkRoots(RootMarkingVisitor* visitor) { | |
603 // Mark the heap roots including global variables, stack variables, | 610 // Mark the heap roots including global variables, stack variables, |
604 // etc., and all objects reachable from them. | 611 // etc., and all objects reachable from them. |
605 Heap::IterateStrongRoots(visitor); | 612 Heap::IterateStrongRoots(visitor); |
606 | 613 |
614 // Handle the symbol table specially. | |
615 MarkSymbolTable(); | |
616 | |
607 // There may be overflowed objects in the heap. Visit them now. | 617 // There may be overflowed objects in the heap. Visit them now. |
608 while (marking_stack.overflowed()) { | 618 while (marking_stack.overflowed()) { |
609 RefillMarkingStack(); | 619 RefillMarkingStack(); |
610 EmptyMarkingStack(visitor->stack_visitor()); | 620 EmptyMarkingStack(visitor->stack_visitor()); |
611 } | 621 } |
612 } | 622 } |
613 | 623 |
614 | 624 |
615 void MarkCompactCollector::MarkObjectGroups() { | 625 void MarkCompactCollector::MarkObjectGroups() { |
616 List<ObjectGroup*>* object_groups = GlobalHandles::ObjectGroups(); | 626 List<ObjectGroup*>* object_groups = GlobalHandles::ObjectGroups(); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
737 state_ = MARK_LIVE_OBJECTS; | 747 state_ = MARK_LIVE_OBJECTS; |
738 #endif | 748 #endif |
739 // The to space contains live objects, the from space is used as a marking | 749 // The to space contains live objects, the from space is used as a marking |
740 // stack. | 750 // stack. |
741 marking_stack.Initialize(Heap::new_space()->FromSpaceLow(), | 751 marking_stack.Initialize(Heap::new_space()->FromSpaceLow(), |
742 Heap::new_space()->FromSpaceHigh()); | 752 Heap::new_space()->FromSpaceHigh()); |
743 | 753 |
744 ASSERT(!marking_stack.overflowed()); | 754 ASSERT(!marking_stack.overflowed()); |
745 | 755 |
746 RootMarkingVisitor root_visitor; | 756 RootMarkingVisitor root_visitor; |
747 ProcessRoots(&root_visitor); | 757 MarkRoots(&root_visitor); |
748 | 758 |
749 // The objects reachable from the roots are marked black, unreachable | 759 // The objects reachable from the roots are marked black, unreachable |
750 // objects are white. Mark objects reachable from object groups with at | 760 // objects are white. Mark objects reachable from object groups with at |
751 // least one marked object, and continue until no new objects are | 761 // least one marked object, and continue until no new objects are |
752 // reachable from the object groups. | 762 // reachable from the object groups. |
753 ProcessObjectGroups(root_visitor.stack_visitor()); | 763 ProcessObjectGroups(root_visitor.stack_visitor()); |
754 | 764 |
755 // The objects reachable from the roots or object groups are marked black, | 765 // The objects reachable from the roots or object groups are marked black, |
756 // unreachable objects are white. Process objects reachable only from | 766 // unreachable objects are white. Process objects reachable only from |
757 // weak global handles. | 767 // weak global handles. |
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1786 | 1796 |
1787 void MarkCompactCollector::RebuildRSets() { | 1797 void MarkCompactCollector::RebuildRSets() { |
1788 #ifdef DEBUG | 1798 #ifdef DEBUG |
1789 ASSERT(state_ == RELOCATE_OBJECTS); | 1799 ASSERT(state_ == RELOCATE_OBJECTS); |
1790 state_ = REBUILD_RSETS; | 1800 state_ = REBUILD_RSETS; |
1791 #endif | 1801 #endif |
1792 Heap::RebuildRSets(); | 1802 Heap::RebuildRSets(); |
1793 } | 1803 } |
1794 | 1804 |
1795 } } // namespace v8::internal | 1805 } } // namespace v8::internal |
OLD | NEW |