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

Side by Side Diff: src/heap.cc

Issue 555072: Merge ObjectIterator::has_next and ObjectIterator::next methods.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 11 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/heap.h ('k') | src/heap-profiler.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 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 #endif 320 #endif
321 321
322 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) 322 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING)
323 ReportStatisticsBeforeGC(); 323 ReportStatisticsBeforeGC();
324 #endif 324 #endif
325 } 325 }
326 326
327 int Heap::SizeOfObjects() { 327 int Heap::SizeOfObjects() {
328 int total = 0; 328 int total = 0;
329 AllSpaces spaces; 329 AllSpaces spaces;
330 while (Space* space = spaces.next()) { 330 for (Space* space = spaces.next(); space != NULL; space = spaces.next()) {
331 total += space->Size(); 331 total += space->Size();
332 } 332 }
333 return total; 333 return total;
334 } 334 }
335 335
336 void Heap::GarbageCollectionEpilogue() { 336 void Heap::GarbageCollectionEpilogue() {
337 #ifdef DEBUG 337 #ifdef DEBUG
338 allow_allocation(true); 338 allow_allocation(true);
339 ZapFromSpace(); 339 ZapFromSpace();
340 340
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 } 725 }
726 } 726 }
727 }; 727 };
728 728
729 729
730 static void VerifyNonPointerSpacePointers() { 730 static void VerifyNonPointerSpacePointers() {
731 // Verify that there are no pointers to new space in spaces where we 731 // Verify that there are no pointers to new space in spaces where we
732 // do not expect them. 732 // do not expect them.
733 VerifyNonPointerSpacePointersVisitor v; 733 VerifyNonPointerSpacePointersVisitor v;
734 HeapObjectIterator code_it(Heap::code_space()); 734 HeapObjectIterator code_it(Heap::code_space());
735 while (code_it.has_next()) { 735 for (HeapObject* object = code_it.next();
736 HeapObject* object = code_it.next(); 736 object != NULL; object = code_it.next())
737 object->Iterate(&v); 737 object->Iterate(&v);
738 }
739 738
740 HeapObjectIterator data_it(Heap::old_data_space()); 739 HeapObjectIterator data_it(Heap::old_data_space());
741 while (data_it.has_next()) data_it.next()->Iterate(&v); 740 for (HeapObject* object = data_it.next();
741 object != NULL; object = data_it.next())
742 object->Iterate(&v);
742 } 743 }
743 #endif 744 #endif
744 745
745 746
746 void Heap::Scavenge() { 747 void Heap::Scavenge() {
747 #ifdef DEBUG 748 #ifdef DEBUG
748 if (FLAG_enable_slow_asserts) VerifyNonPointerSpacePointers(); 749 if (FLAG_enable_slow_asserts) VerifyNonPointerSpacePointers();
749 #endif 750 #endif
750 751
751 gc_state_ = SCAVENGE; 752 gc_state_ = SCAVENGE;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 IterateRoots(&scavenge_visitor, VISIT_ALL_IN_SCAVENGE); 798 IterateRoots(&scavenge_visitor, VISIT_ALL_IN_SCAVENGE);
798 799
799 // Copy objects reachable from the old generation. By definition, 800 // Copy objects reachable from the old generation. By definition,
800 // there are no intergenerational pointers in code or data spaces. 801 // there are no intergenerational pointers in code or data spaces.
801 IterateRSet(old_pointer_space_, &ScavengePointer); 802 IterateRSet(old_pointer_space_, &ScavengePointer);
802 IterateRSet(map_space_, &ScavengePointer); 803 IterateRSet(map_space_, &ScavengePointer);
803 lo_space_->IterateRSet(&ScavengePointer); 804 lo_space_->IterateRSet(&ScavengePointer);
804 805
805 // Copy objects reachable from cells by scavenging cell values directly. 806 // Copy objects reachable from cells by scavenging cell values directly.
806 HeapObjectIterator cell_iterator(cell_space_); 807 HeapObjectIterator cell_iterator(cell_space_);
807 while (cell_iterator.has_next()) { 808 for (HeapObject* cell = cell_iterator.next();
808 HeapObject* cell = cell_iterator.next(); 809 cell != NULL; cell = cell_iterator.next()) {
809 if (cell->IsJSGlobalPropertyCell()) { 810 if (cell->IsJSGlobalPropertyCell()) {
810 Address value_address = 811 Address value_address =
811 reinterpret_cast<Address>(cell) + 812 reinterpret_cast<Address>(cell) +
812 (JSGlobalPropertyCell::kValueOffset - kHeapObjectTag); 813 (JSGlobalPropertyCell::kValueOffset - kHeapObjectTag);
813 scavenge_visitor.VisitPointer(reinterpret_cast<Object**>(value_address)); 814 scavenge_visitor.VisitPointer(reinterpret_cast<Object**>(value_address));
814 } 815 }
815 } 816 }
816 817
817 new_space_front = DoScavenge(&scavenge_visitor, new_space_front); 818 new_space_front = DoScavenge(&scavenge_visitor, new_space_front);
818 819
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 old_pointer_space_->ClearRSet(); 1007 old_pointer_space_->ClearRSet();
1007 RebuildRSets(old_pointer_space_); 1008 RebuildRSets(old_pointer_space_);
1008 1009
1009 Heap::lo_space_->ClearRSet(); 1010 Heap::lo_space_->ClearRSet();
1010 RebuildRSets(lo_space_); 1011 RebuildRSets(lo_space_);
1011 } 1012 }
1012 1013
1013 1014
1014 void Heap::RebuildRSets(PagedSpace* space) { 1015 void Heap::RebuildRSets(PagedSpace* space) {
1015 HeapObjectIterator it(space); 1016 HeapObjectIterator it(space);
1016 while (it.has_next()) Heap::UpdateRSet(it.next()); 1017 for (HeapObject* obj = it.next(); obj != NULL; obj = it.next())
1018 Heap::UpdateRSet(obj);
1017 } 1019 }
1018 1020
1019 1021
1020 void Heap::RebuildRSets(LargeObjectSpace* space) { 1022 void Heap::RebuildRSets(LargeObjectSpace* space) {
1021 LargeObjectIterator it(space); 1023 LargeObjectIterator it(space);
1022 while (it.has_next()) Heap::UpdateRSet(it.next()); 1024 for (HeapObject* obj = it.next(); obj != NULL; obj = it.next())
1025 Heap::UpdateRSet(obj);
1023 } 1026 }
1024 1027
1025 1028
1026 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) 1029 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING)
1027 void Heap::RecordCopiedObject(HeapObject* obj) { 1030 void Heap::RecordCopiedObject(HeapObject* obj) {
1028 bool should_record = false; 1031 bool should_record = false;
1029 #ifdef DEBUG 1032 #ifdef DEBUG
1030 should_record = FLAG_heap_stats; 1033 should_record = FLAG_heap_stats;
1031 #endif 1034 #endif
1032 #ifdef ENABLE_LOGGING_AND_PROFILING 1035 #ifdef ENABLE_LOGGING_AND_PROFILING
(...skipping 2066 matching lines...) Expand 10 before | Expand all | Expand 10 after
3099 return finished; 3102 return finished;
3100 } 3103 }
3101 3104
3102 3105
3103 #ifdef DEBUG 3106 #ifdef DEBUG
3104 3107
3105 void Heap::Print() { 3108 void Heap::Print() {
3106 if (!HasBeenSetup()) return; 3109 if (!HasBeenSetup()) return;
3107 Top::PrintStack(); 3110 Top::PrintStack();
3108 AllSpaces spaces; 3111 AllSpaces spaces;
3109 while (Space* space = spaces.next()) space->Print(); 3112 for (Space* space = spaces.next(); space != NULL; space = spaces.next())
3113 space->Print();
3110 } 3114 }
3111 3115
3112 3116
3113 void Heap::ReportCodeStatistics(const char* title) { 3117 void Heap::ReportCodeStatistics(const char* title) {
3114 PrintF(">>>>>> Code Stats (%s) >>>>>>\n", title); 3118 PrintF(">>>>>> Code Stats (%s) >>>>>>\n", title);
3115 PagedSpace::ResetCodeStatistics(); 3119 PagedSpace::ResetCodeStatistics();
3116 // We do not look for code in new space, map space, or old space. If code 3120 // We do not look for code in new space, map space, or old space. If code
3117 // somehow ends up in those spaces, we would miss it here. 3121 // somehow ends up in those spaces, we would miss it here.
3118 code_space_->CollectCodeStatistics(); 3122 code_space_->CollectCodeStatistics();
3119 lo_space_->CollectCodeStatistics(); 3123 lo_space_->CollectCodeStatistics();
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
3641 lo_space_ = NULL; 3645 lo_space_ = NULL;
3642 } 3646 }
3643 3647
3644 MemoryAllocator::TearDown(); 3648 MemoryAllocator::TearDown();
3645 } 3649 }
3646 3650
3647 3651
3648 void Heap::Shrink() { 3652 void Heap::Shrink() {
3649 // Try to shrink all paged spaces. 3653 // Try to shrink all paged spaces.
3650 PagedSpaces spaces; 3654 PagedSpaces spaces;
3651 while (PagedSpace* space = spaces.next()) space->Shrink(); 3655 for (PagedSpace* space = spaces.next(); space != NULL; space = spaces.next())
3656 space->Shrink();
3652 } 3657 }
3653 3658
3654 3659
3655 #ifdef ENABLE_HEAP_PROTECTION 3660 #ifdef ENABLE_HEAP_PROTECTION
3656 3661
3657 void Heap::Protect() { 3662 void Heap::Protect() {
3658 if (HasBeenSetup()) { 3663 if (HasBeenSetup()) {
3659 AllSpaces spaces; 3664 AllSpaces spaces;
3660 while (Space* space = spaces.next()) space->Protect(); 3665 for (Space* space = spaces.next(); space != NULL; space = spaces.next())
3666 space->Protect();
3661 } 3667 }
3662 } 3668 }
3663 3669
3664 3670
3665 void Heap::Unprotect() { 3671 void Heap::Unprotect() {
3666 if (HasBeenSetup()) { 3672 if (HasBeenSetup()) {
3667 AllSpaces spaces; 3673 AllSpaces spaces;
3668 while (Space* space = spaces.next()) space->Unprotect(); 3674 for (Space* space = spaces.next(); space != NULL; space = spaces.next())
3675 space->Unprotect();
3669 } 3676 }
3670 } 3677 }
3671 3678
3672 #endif 3679 #endif
3673 3680
3674 3681
3675 #ifdef DEBUG 3682 #ifdef DEBUG
3676 3683
3677 class PrintHandleVisitor: public ObjectVisitor { 3684 class PrintHandleVisitor: public ObjectVisitor {
3678 public: 3685 public:
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
3830 3837
3831 3838
3832 void HeapIterator::Shutdown() { 3839 void HeapIterator::Shutdown() {
3833 // Make sure the last iterator is deallocated. 3840 // Make sure the last iterator is deallocated.
3834 delete space_iterator_; 3841 delete space_iterator_;
3835 space_iterator_ = NULL; 3842 space_iterator_ = NULL;
3836 object_iterator_ = NULL; 3843 object_iterator_ = NULL;
3837 } 3844 }
3838 3845
3839 3846
3840 bool HeapIterator::has_next() { 3847 HeapObject* HeapIterator::next() {
3841 // No iterator means we are done. 3848 // No iterator means we are done.
3842 if (object_iterator_ == NULL) return false; 3849 if (object_iterator_ == NULL) return NULL;
3843 3850
3844 if (object_iterator_->has_next_object()) { 3851 if (HeapObject* obj = object_iterator_->next_object()) {
3845 // If the current iterator has more objects we are fine. 3852 // If the current iterator has more objects we are fine.
3846 return true; 3853 return obj;
3847 } else { 3854 } else {
3848 // Go though the spaces looking for one that has objects. 3855 // Go though the spaces looking for one that has objects.
3849 while (space_iterator_->has_next()) { 3856 while (space_iterator_->has_next()) {
3850 object_iterator_ = space_iterator_->next(); 3857 object_iterator_ = space_iterator_->next();
3851 if (object_iterator_->has_next_object()) { 3858 if (HeapObject* obj = object_iterator_->next_object()) {
3852 return true; 3859 return obj;
3853 } 3860 }
3854 } 3861 }
3855 } 3862 }
3856 // Done with the last space. 3863 // Done with the last space.
3857 object_iterator_ = NULL; 3864 object_iterator_ = NULL;
3858 return false; 3865 return NULL;
3859 }
3860
3861
3862 HeapObject* HeapIterator::next() {
3863 if (has_next()) {
3864 return object_iterator_->next_object();
3865 } else {
3866 return NULL;
3867 }
3868 } 3866 }
3869 3867
3870 3868
3871 void HeapIterator::reset() { 3869 void HeapIterator::reset() {
3872 // Restart the iterator. 3870 // Restart the iterator.
3873 Shutdown(); 3871 Shutdown();
3874 Init(); 3872 Init();
3875 } 3873 }
3876 3874
3877 3875
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
4195 void ExternalStringTable::TearDown() { 4193 void ExternalStringTable::TearDown() {
4196 new_space_strings_.Free(); 4194 new_space_strings_.Free();
4197 old_space_strings_.Free(); 4195 old_space_strings_.Free();
4198 } 4196 }
4199 4197
4200 4198
4201 List<Object*> ExternalStringTable::new_space_strings_; 4199 List<Object*> ExternalStringTable::new_space_strings_;
4202 List<Object*> ExternalStringTable::old_space_strings_; 4200 List<Object*> ExternalStringTable::old_space_strings_;
4203 4201
4204 } } // namespace v8::internal 4202 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/heap-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698