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

Side by Side Diff: src/spaces.h

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, 10 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/runtime.cc ('k') | src/spaces.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 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 // used as a marking stack and its page headers are destroyed. 590 // used as a marking stack and its page headers are destroyed.
591 static Page* InitializePagesInChunk(int chunk_id, int pages_in_chunk, 591 static Page* InitializePagesInChunk(int chunk_id, int pages_in_chunk,
592 PagedSpace* owner); 592 PagedSpace* owner);
593 }; 593 };
594 594
595 595
596 // ----------------------------------------------------------------------------- 596 // -----------------------------------------------------------------------------
597 // Interface for heap object iterator to be implemented by all object space 597 // Interface for heap object iterator to be implemented by all object space
598 // object iterators. 598 // object iterators.
599 // 599 //
600 // NOTE: The space specific object iterators also implements the own has_next() 600 // NOTE: The space specific object iterators also implements the own next()
601 // and next() methods which are used to avoid using virtual functions 601 // method which is used to avoid using virtual functions
602 // iterating a specific space. 602 // iterating a specific space.
603 603
604 class ObjectIterator : public Malloced { 604 class ObjectIterator : public Malloced {
605 public: 605 public:
606 virtual ~ObjectIterator() { } 606 virtual ~ObjectIterator() { }
607 607
608 virtual bool has_next_object() = 0;
609 virtual HeapObject* next_object() = 0; 608 virtual HeapObject* next_object() = 0;
610 }; 609 };
611 610
612 611
613 // ----------------------------------------------------------------------------- 612 // -----------------------------------------------------------------------------
614 // Heap object iterator in new/old/map spaces. 613 // Heap object iterator in new/old/map spaces.
615 // 614 //
616 // A HeapObjectIterator iterates objects from a given address to the 615 // A HeapObjectIterator iterates objects from a given address to the
617 // top of a space. The given address must be below the current 616 // top of a space. The given address must be below the current
618 // allocation pointer (space top). There are some caveats. 617 // allocation pointer (space top). There are some caveats.
(...skipping 19 matching lines...) Expand all
638 // address is not given, the iterator starts from the space bottom. 637 // address is not given, the iterator starts from the space bottom.
639 // If the size function is not given, the iterator calls the default 638 // If the size function is not given, the iterator calls the default
640 // Object::Size(). 639 // Object::Size().
641 explicit HeapObjectIterator(PagedSpace* space); 640 explicit HeapObjectIterator(PagedSpace* space);
642 HeapObjectIterator(PagedSpace* space, HeapObjectCallback size_func); 641 HeapObjectIterator(PagedSpace* space, HeapObjectCallback size_func);
643 HeapObjectIterator(PagedSpace* space, Address start); 642 HeapObjectIterator(PagedSpace* space, Address start);
644 HeapObjectIterator(PagedSpace* space, 643 HeapObjectIterator(PagedSpace* space,
645 Address start, 644 Address start,
646 HeapObjectCallback size_func); 645 HeapObjectCallback size_func);
647 646
648 inline bool has_next(); 647 inline HeapObject* next() {
649 inline HeapObject* next(); 648 return (cur_addr_ < cur_limit_) ? FromCurrentPage() : FromNextPage();
649 }
650 650
651 // implementation of ObjectIterator. 651 // implementation of ObjectIterator.
652 virtual bool has_next_object() { return has_next(); }
653 virtual HeapObject* next_object() { return next(); } 652 virtual HeapObject* next_object() { return next(); }
654 653
655 private: 654 private:
656 Address cur_addr_; // current iteration point 655 Address cur_addr_; // current iteration point
657 Address end_addr_; // end iteration point 656 Address end_addr_; // end iteration point
658 Address cur_limit_; // current page limit 657 Address cur_limit_; // current page limit
659 HeapObjectCallback size_func_; // size function 658 HeapObjectCallback size_func_; // size function
660 Page* end_page_; // caches the page of the end address 659 Page* end_page_; // caches the page of the end address
661 660
662 // Slow path of has_next, checks whether there are more objects in 661 HeapObject* FromCurrentPage() {
663 // the next page. 662 ASSERT(cur_addr_ < cur_limit_);
664 bool HasNextInNextPage(); 663
664 HeapObject* obj = HeapObject::FromAddress(cur_addr_);
665 int obj_size = (size_func_ == NULL) ? obj->Size() : size_func_(obj);
666 ASSERT_OBJECT_SIZE(obj_size);
667
668 cur_addr_ += obj_size;
669 ASSERT(cur_addr_ <= cur_limit_);
670
671 return obj;
672 }
673
674 // Slow path of next, goes into the next page.
675 HeapObject* FromNextPage();
665 676
666 // Initializes fields. 677 // Initializes fields.
667 void Initialize(Address start, Address end, HeapObjectCallback size_func); 678 void Initialize(Address start, Address end, HeapObjectCallback size_func);
668 679
669 #ifdef DEBUG 680 #ifdef DEBUG
670 // Verifies whether fields have valid values. 681 // Verifies whether fields have valid values.
671 void Verify(); 682 void Verify();
672 #endif 683 #endif
673 }; 684 };
674 685
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 // iterator is created are not iterated. 1210 // iterator is created are not iterated.
1200 class SemiSpaceIterator : public ObjectIterator { 1211 class SemiSpaceIterator : public ObjectIterator {
1201 public: 1212 public:
1202 // Create an iterator over the objects in the given space. If no start 1213 // Create an iterator over the objects in the given space. If no start
1203 // address is given, the iterator starts from the bottom of the space. If 1214 // address is given, the iterator starts from the bottom of the space. If
1204 // no size function is given, the iterator calls Object::Size(). 1215 // no size function is given, the iterator calls Object::Size().
1205 explicit SemiSpaceIterator(NewSpace* space); 1216 explicit SemiSpaceIterator(NewSpace* space);
1206 SemiSpaceIterator(NewSpace* space, HeapObjectCallback size_func); 1217 SemiSpaceIterator(NewSpace* space, HeapObjectCallback size_func);
1207 SemiSpaceIterator(NewSpace* space, Address start); 1218 SemiSpaceIterator(NewSpace* space, Address start);
1208 1219
1209 bool has_next() {return current_ < limit_; }
1210
1211 HeapObject* next() { 1220 HeapObject* next() {
1212 ASSERT(has_next()); 1221 if (current_ == limit_) return NULL;
1213 1222
1214 HeapObject* object = HeapObject::FromAddress(current_); 1223 HeapObject* object = HeapObject::FromAddress(current_);
1215 int size = (size_func_ == NULL) ? object->Size() : size_func_(object); 1224 int size = (size_func_ == NULL) ? object->Size() : size_func_(object);
1216 1225
1217 current_ += size; 1226 current_ += size;
1218 return object; 1227 return object;
1219 } 1228 }
1220 1229
1221 // Implementation of the ObjectIterator functions. 1230 // Implementation of the ObjectIterator functions.
1222 virtual bool has_next_object() { return has_next(); }
1223 virtual HeapObject* next_object() { return next(); } 1231 virtual HeapObject* next_object() { return next(); }
1224 1232
1225 private: 1233 private:
1226 void Initialize(NewSpace* space, Address start, Address end, 1234 void Initialize(NewSpace* space, Address start, Address end,
1227 HeapObjectCallback size_func); 1235 HeapObjectCallback size_func);
1228 1236
1229 // The semispace. 1237 // The semispace.
1230 SemiSpace* space_; 1238 SemiSpace* space_;
1231 // The current iteration point. 1239 // The current iteration point.
1232 Address current_; 1240 Address current_;
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1793 bool NeedsCompaction(int live_maps) { 1801 bool NeedsCompaction(int live_maps) {
1794 return !MapPointersEncodable() && live_maps <= CompactionThreshold(); 1802 return !MapPointersEncodable() && live_maps <= CompactionThreshold();
1795 } 1803 }
1796 1804
1797 Address TopAfterCompaction(int live_maps) { 1805 Address TopAfterCompaction(int live_maps) {
1798 ASSERT(NeedsCompaction(live_maps)); 1806 ASSERT(NeedsCompaction(live_maps));
1799 1807
1800 int pages_left = live_maps / kMapsPerPage; 1808 int pages_left = live_maps / kMapsPerPage;
1801 PageIterator it(this, PageIterator::ALL_PAGES); 1809 PageIterator it(this, PageIterator::ALL_PAGES);
1802 while (pages_left-- > 0) { 1810 while (pages_left-- > 0) {
1803 it.has_next(); // Must be called for side-effects, see bug 586.
1804 ASSERT(it.has_next()); 1811 ASSERT(it.has_next());
1805 it.next()->ClearRSet(); 1812 it.next()->ClearRSet();
1806 } 1813 }
1807 it.has_next(); // Must be called for side-effects, see bug 586.
1808 ASSERT(it.has_next()); 1814 ASSERT(it.has_next());
1809 Page* top_page = it.next(); 1815 Page* top_page = it.next();
1810 top_page->ClearRSet(); 1816 top_page->ClearRSet();
1811 ASSERT(top_page->is_valid()); 1817 ASSERT(top_page->is_valid());
1812 1818
1813 int offset = live_maps % kMapsPerPage * Map::kSize; 1819 int offset = live_maps % kMapsPerPage * Map::kSize;
1814 Address top = top_page->ObjectAreaStart() + offset; 1820 Address top = top_page->ObjectAreaStart() + offset;
1815 ASSERT(top < top_page->ObjectAreaEnd()); 1821 ASSERT(top < top_page->ObjectAreaEnd());
1816 ASSERT(Contains(top)); 1822 ASSERT(Contains(top));
1817 1823
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
2047 public: 2053 public:
2048 TRACK_MEMORY("LargeObjectSpace") 2054 TRACK_MEMORY("LargeObjectSpace")
2049 }; 2055 };
2050 2056
2051 2057
2052 class LargeObjectIterator: public ObjectIterator { 2058 class LargeObjectIterator: public ObjectIterator {
2053 public: 2059 public:
2054 explicit LargeObjectIterator(LargeObjectSpace* space); 2060 explicit LargeObjectIterator(LargeObjectSpace* space);
2055 LargeObjectIterator(LargeObjectSpace* space, HeapObjectCallback size_func); 2061 LargeObjectIterator(LargeObjectSpace* space, HeapObjectCallback size_func);
2056 2062
2057 bool has_next() { return current_ != NULL; }
2058 HeapObject* next(); 2063 HeapObject* next();
2059 2064
2060 // implementation of ObjectIterator. 2065 // implementation of ObjectIterator.
2061 virtual bool has_next_object() { return has_next(); }
2062 virtual HeapObject* next_object() { return next(); } 2066 virtual HeapObject* next_object() { return next(); }
2063 2067
2064 private: 2068 private:
2065 LargeObjectChunk* current_; 2069 LargeObjectChunk* current_;
2066 HeapObjectCallback size_func_; 2070 HeapObjectCallback size_func_;
2067 }; 2071 };
2068 2072
2069 2073
2070 } } // namespace v8::internal 2074 } } // namespace v8::internal
2071 2075
2072 #endif // V8_SPACES_H_ 2076 #endif // V8_SPACES_H_
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | src/spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698