Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: src/mark-compact.cc

Issue 109006: Push the fix for http://crbug.com/9746 to the 1.1 branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/1.1/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/mark-compact.h ('k') | test/cctest/test-strings.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 void MarkCompactCollector::ProcessRoots(RootMarkingVisitor* visitor) { 565 class SymbolMarkingVisitor : public ObjectVisitor {
566 // Mark the heap roots gray, including global variables, stack variables, 566 public:
567 // etc. 567 void VisitPointers(Object** start, Object** end) {
568 MarkingVisitor marker;
569 for (Object** p = start; p < end; p++) {
570 if (!(*p)->IsHeapObject()) continue;
571
572 HeapObject* object = HeapObject::cast(*p);
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(),
581 object->SizeFromMap(map),
582 &marker);
583 }
584 }
585 };
586
587
588 void MarkCompactCollector::MarkSymbolTable() {
589 // Objects reachable from symbols are marked as live so as to ensure
590 // that if the symbol itself remains alive after GC for any reason,
591 // and if it is a sliced string or a cons string backed by an
592 // external string (even indirectly), then the external string does
593 // not receive a weak reference callback.
594 SymbolTable* symbol_table = SymbolTable::cast(Heap::symbol_table());
595 // Mark the symbol table itself.
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 }
607
608
609 void MarkCompactCollector::MarkRoots(RootMarkingVisitor* visitor) {
610 // Mark the heap roots including global variables, stack variables,
611 // etc., and all objects reachable from them.
568 Heap::IterateStrongRoots(visitor); 612 Heap::IterateStrongRoots(visitor);
569 613
570 // Take care of the symbol table specially. 614 // Handle the symbol table specially.
571 SymbolTable* symbol_table = SymbolTable::cast(Heap::symbol_table()); 615 MarkSymbolTable();
572 // 1. Mark the prefix of the symbol table gray.
573 symbol_table->IteratePrefix(visitor);
574 // 2. Mark the symbol table black (ie, do not push it on the marking stack
575 // or mark it overflowed).
576 SetMark(symbol_table);
577 616
578 // There may be overflowed objects in the heap. Visit them now. 617 // There may be overflowed objects in the heap. Visit them now.
579 while (marking_stack.overflowed()) { 618 while (marking_stack.overflowed()) {
580 RefillMarkingStack(); 619 RefillMarkingStack();
581 EmptyMarkingStack(visitor->stack_visitor()); 620 EmptyMarkingStack(visitor->stack_visitor());
582 } 621 }
583 } 622 }
584 623
585 624
586 void MarkCompactCollector::MarkObjectGroups() { 625 void MarkCompactCollector::MarkObjectGroups() {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 state_ = MARK_LIVE_OBJECTS; 747 state_ = MARK_LIVE_OBJECTS;
709 #endif 748 #endif
710 // 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
711 // stack. 750 // stack.
712 marking_stack.Initialize(Heap::new_space()->FromSpaceLow(), 751 marking_stack.Initialize(Heap::new_space()->FromSpaceLow(),
713 Heap::new_space()->FromSpaceHigh()); 752 Heap::new_space()->FromSpaceHigh());
714 753
715 ASSERT(!marking_stack.overflowed()); 754 ASSERT(!marking_stack.overflowed());
716 755
717 RootMarkingVisitor root_visitor; 756 RootMarkingVisitor root_visitor;
718 ProcessRoots(&root_visitor); 757 MarkRoots(&root_visitor);
719 758
720 // The objects reachable from the roots are marked black, unreachable 759 // The objects reachable from the roots are marked black, unreachable
721 // objects are white. Mark objects reachable from object groups with at 760 // objects are white. Mark objects reachable from object groups with at
722 // least one marked object, and continue until no new objects are 761 // least one marked object, and continue until no new objects are
723 // reachable from the object groups. 762 // reachable from the object groups.
724 ProcessObjectGroups(root_visitor.stack_visitor()); 763 ProcessObjectGroups(root_visitor.stack_visitor());
725 764
726 // 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,
727 // unreachable objects are white. Process objects reachable only from 766 // unreachable objects are white. Process objects reachable only from
728 // weak global handles. 767 // weak global handles.
(...skipping 26 matching lines...) Expand all
755 794
756 795
757 static int CountMarkedCallback(HeapObject* obj) { 796 static int CountMarkedCallback(HeapObject* obj) {
758 MapWord map_word = obj->map_word(); 797 MapWord map_word = obj->map_word();
759 map_word.ClearMark(); 798 map_word.ClearMark();
760 return obj->SizeFromMap(map_word.ToMap()); 799 return obj->SizeFromMap(map_word.ToMap());
761 } 800 }
762 801
763 802
764 #ifdef DEBUG 803 #ifdef DEBUG
765 void MarkCompactCollector::UpdateLiveObjectCount(HeapObject* obj) { 804 void MarkCompactCollector::UpdateLiveObjectCount(HeapObject* obj, int scale) {
766 live_bytes_ += obj->Size(); 805 ASSERT(scale == -1 || scale == 1);
806 live_bytes_ += obj->Size() * scale;
767 if (Heap::new_space()->Contains(obj)) { 807 if (Heap::new_space()->Contains(obj)) {
768 live_young_objects_++; 808 live_young_objects_ += scale;
769 } else if (Heap::map_space()->Contains(obj)) { 809 } else if (Heap::map_space()->Contains(obj)) {
770 ASSERT(obj->IsMap()); 810 ASSERT(obj->IsMap());
771 live_map_objects_++; 811 live_map_objects_ += scale;
772 } else if (Heap::old_pointer_space()->Contains(obj)) { 812 } else if (Heap::old_pointer_space()->Contains(obj)) {
773 live_old_pointer_objects_++; 813 live_old_pointer_objects_ += scale;
774 } else if (Heap::old_data_space()->Contains(obj)) { 814 } else if (Heap::old_data_space()->Contains(obj)) {
775 live_old_data_objects_++; 815 live_old_data_objects_ += scale;
776 } else if (Heap::code_space()->Contains(obj)) { 816 } else if (Heap::code_space()->Contains(obj)) {
777 live_code_objects_++; 817 live_code_objects_ += scale;
778 } else if (Heap::lo_space()->Contains(obj)) { 818 } else if (Heap::lo_space()->Contains(obj)) {
779 live_lo_objects_++; 819 live_lo_objects_ +=scale;
780 } else { 820 } else {
781 UNREACHABLE(); 821 UNREACHABLE();
782 } 822 }
783 } 823 }
784 #endif // DEBUG 824 #endif // DEBUG
785 825
786 826
787 void MarkCompactCollector::SweepLargeObjectSpace() { 827 void MarkCompactCollector::SweepLargeObjectSpace() {
788 #ifdef DEBUG 828 #ifdef DEBUG
789 ASSERT(state_ == MARK_LIVE_OBJECTS); 829 ASSERT(state_ == MARK_LIVE_OBJECTS);
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 1796
1757 void MarkCompactCollector::RebuildRSets() { 1797 void MarkCompactCollector::RebuildRSets() {
1758 #ifdef DEBUG 1798 #ifdef DEBUG
1759 ASSERT(state_ == RELOCATE_OBJECTS); 1799 ASSERT(state_ == RELOCATE_OBJECTS);
1760 state_ = REBUILD_RSETS; 1800 state_ = REBUILD_RSETS;
1761 #endif 1801 #endif
1762 Heap::RebuildRSets(); 1802 Heap::RebuildRSets();
1763 } 1803 }
1764 1804
1765 } } // namespace v8::internal 1805 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/mark-compact.h ('k') | test/cctest/test-strings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698