OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_HEAP_SPACES_H_ | 5 #ifndef V8_HEAP_SPACES_H_ |
6 #define V8_HEAP_SPACES_H_ | 6 #define V8_HEAP_SPACES_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
(...skipping 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1565 // Interface for heap object iterator to be implemented by all object space | 1565 // Interface for heap object iterator to be implemented by all object space |
1566 // object iterators. | 1566 // object iterators. |
1567 // | 1567 // |
1568 // NOTE: The space specific object iterators also implements the own next() | 1568 // NOTE: The space specific object iterators also implements the own next() |
1569 // method which is used to avoid using virtual functions | 1569 // method which is used to avoid using virtual functions |
1570 // iterating a specific space. | 1570 // iterating a specific space. |
1571 | 1571 |
1572 class ObjectIterator : public Malloced { | 1572 class ObjectIterator : public Malloced { |
1573 public: | 1573 public: |
1574 virtual ~ObjectIterator() {} | 1574 virtual ~ObjectIterator() {} |
1575 | 1575 virtual HeapObject* Next() = 0; |
1576 virtual HeapObject* next_object() = 0; | |
1577 }; | 1576 }; |
1578 | 1577 |
1578 template <class PAGE_TYPE> | |
1579 class PageIteratorImpl | |
Michael Lippautz
2016/06/23 19:43:14
Just moved up.
| |
1580 : public std::iterator<std::forward_iterator_tag, PAGE_TYPE> { | |
brucedawson
2017/06/14 22:07:13
It turns out that std::iterator is deprecated in C
| |
1581 public: | |
1582 explicit PageIteratorImpl(PAGE_TYPE* p) : p_(p) {} | |
1583 PageIteratorImpl(const PageIteratorImpl<PAGE_TYPE>& other) : p_(other.p_) {} | |
1584 PAGE_TYPE* operator*() { return p_; } | |
1585 bool operator==(const PageIteratorImpl<PAGE_TYPE>& rhs) { | |
1586 return rhs.p_ == p_; | |
1587 } | |
1588 bool operator!=(const PageIteratorImpl<PAGE_TYPE>& rhs) { | |
1589 return rhs.p_ != p_; | |
1590 } | |
1591 inline PageIteratorImpl<PAGE_TYPE>& operator++(); | |
1592 inline PageIteratorImpl<PAGE_TYPE> operator++(int); | |
1593 | |
1594 private: | |
1595 PAGE_TYPE* p_; | |
1596 }; | |
1597 | |
1598 typedef PageIteratorImpl<Page> PageIterator; | |
1599 typedef PageIteratorImpl<LargePage> LargePageIterator; | |
1600 | |
1601 class PageRange { | |
1602 public: | |
1603 typedef PageIterator iterator; | |
1604 PageRange(Page* begin, Page* end) : begin_(begin), end_(end) {} | |
1605 explicit PageRange(Page* page) : PageRange(page, page->next_page()) {} | |
1606 iterator begin() { return iterator(begin_); } | |
1607 iterator end() { return iterator(end_); } | |
1608 | |
1609 private: | |
1610 Page* begin_; | |
1611 Page* end_; | |
1612 }; | |
1579 | 1613 |
1580 // ----------------------------------------------------------------------------- | 1614 // ----------------------------------------------------------------------------- |
1581 // Heap object iterator in new/old/map spaces. | 1615 // Heap object iterator in new/old/map spaces. |
1582 // | 1616 // |
1583 // A HeapObjectIterator iterates objects from the bottom of the given space | 1617 // A HeapObjectIterator iterates objects from the bottom of the given space |
1584 // to its top or from the bottom of the given page to its top. | 1618 // to its top or from the bottom of the given page to its top. |
1585 // | 1619 // |
1586 // If objects are allocated in the page during iteration the iterator may | 1620 // If objects are allocated in the page during iteration the iterator may |
1587 // or may not iterate over those objects. The caller must create a new | 1621 // or may not iterate over those objects. The caller must create a new |
1588 // iterator in order to be sure to visit these new objects. | 1622 // iterator in order to be sure to visit these new objects. |
1589 class HeapObjectIterator : public ObjectIterator { | 1623 class HeapObjectIterator : public ObjectIterator { |
1590 public: | 1624 public: |
1591 // Creates a new object iterator in a given space. | 1625 // Creates a new object iterator in a given space. |
1592 explicit HeapObjectIterator(PagedSpace* space); | 1626 explicit HeapObjectIterator(PagedSpace* space); |
1593 explicit HeapObjectIterator(Page* page); | 1627 explicit HeapObjectIterator(Page* page); |
1594 | 1628 |
1595 // Advance to the next object, skipping free spaces and other fillers and | 1629 // Advance to the next object, skipping free spaces and other fillers and |
1596 // skipping the special garbage section of which there is one per space. | 1630 // skipping the special garbage section of which there is one per space. |
1597 // Returns NULL when the iteration has ended. | 1631 // Returns nullptr when the iteration has ended. |
1598 inline HeapObject* Next(); | 1632 inline HeapObject* Next() override; |
1599 inline HeapObject* next_object() override; | |
1600 | 1633 |
1601 private: | 1634 private: |
1602 enum PageMode { kOnePageOnly, kAllPagesInSpace }; | |
1603 | |
1604 Address cur_addr_; // Current iteration point. | |
1605 Address cur_end_; // End iteration point. | |
1606 PagedSpace* space_; | |
1607 PageMode page_mode_; | |
1608 | |
1609 // Fast (inlined) path of next(). | 1635 // Fast (inlined) path of next(). |
1610 inline HeapObject* FromCurrentPage(); | 1636 inline HeapObject* FromCurrentPage(); |
1611 | 1637 |
1612 // Slow path of next(), goes into the next page. Returns false if the | 1638 // Slow path of next(), goes into the next page. Returns false if the |
1613 // iteration has ended. | 1639 // iteration has ended. |
1614 bool AdvanceToNextPage(); | 1640 bool AdvanceToNextPage(); |
1615 | 1641 |
1616 // Initializes fields. | 1642 Address cur_addr_; // Current iteration point. |
1617 inline void Initialize(PagedSpace* owner, Address start, Address end, | 1643 Address cur_end_; // End iteration point. |
1618 PageMode mode); | 1644 PagedSpace* space_; |
1645 PageRange page_range_; | |
1646 PageRange::iterator current_page_; | |
1619 }; | 1647 }; |
1620 | 1648 |
1621 | 1649 |
1622 // ----------------------------------------------------------------------------- | 1650 // ----------------------------------------------------------------------------- |
1623 // A space has a circular list of pages. The next page can be accessed via | 1651 // A space has a circular list of pages. The next page can be accessed via |
1624 // Page::next_page() call. | 1652 // Page::next_page() call. |
1625 | 1653 |
1626 // An abstraction of allocation and relocation pointers in a page-structured | 1654 // An abstraction of allocation and relocation pointers in a page-structured |
1627 // space. | 1655 // space. |
1628 class AllocationInfo { | 1656 class AllocationInfo { |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2060 | 2088 |
2061 private: | 2089 private: |
2062 LocalAllocationBuffer(Heap* heap, AllocationInfo allocation_info); | 2090 LocalAllocationBuffer(Heap* heap, AllocationInfo allocation_info); |
2063 | 2091 |
2064 void Close(); | 2092 void Close(); |
2065 | 2093 |
2066 Heap* heap_; | 2094 Heap* heap_; |
2067 AllocationInfo allocation_info_; | 2095 AllocationInfo allocation_info_; |
2068 }; | 2096 }; |
2069 | 2097 |
2070 template <class PAGE_TYPE> | 2098 class NewSpacePageRange { |
2071 class PageIteratorImpl | |
2072 : public std::iterator<std::forward_iterator_tag, PAGE_TYPE> { | |
2073 public: | 2099 public: |
2074 explicit PageIteratorImpl(PAGE_TYPE* p) : p_(p) {} | 2100 typedef PageRange::iterator iterator; |
2075 PageIteratorImpl(const PageIteratorImpl<PAGE_TYPE>& other) : p_(other.p_) {} | 2101 inline NewSpacePageRange(Address start, Address limit); |
2076 PAGE_TYPE* operator*() { return p_; } | 2102 iterator begin() { return range_.begin(); } |
2077 bool operator==(const PageIteratorImpl<PAGE_TYPE>& rhs) { | 2103 iterator end() { return range_.end(); } |
2078 return rhs.p_ == p_; | |
2079 } | |
2080 bool operator!=(const PageIteratorImpl<PAGE_TYPE>& rhs) { | |
2081 return rhs.p_ != p_; | |
2082 } | |
2083 inline PageIteratorImpl<PAGE_TYPE>& operator++(); | |
2084 inline PageIteratorImpl<PAGE_TYPE> operator++(int); | |
2085 | 2104 |
2086 private: | 2105 private: |
2087 PAGE_TYPE* p_; | 2106 PageRange range_; |
2088 }; | |
2089 | |
2090 typedef PageIteratorImpl<Page> PageIterator; | |
2091 typedef PageIteratorImpl<LargePage> LargePageIterator; | |
2092 | |
2093 class NewSpacePageRange { | |
2094 public: | |
2095 typedef PageIterator iterator; | |
2096 | |
2097 inline NewSpacePageRange(Address start, Address limit); | |
2098 | |
2099 iterator begin() { return iterator(Page::FromAddress(start_)); } | |
2100 iterator end() { | |
2101 return iterator(Page::FromAllocationAreaAddress(limit_)->next_page()); | |
2102 } | |
2103 | |
2104 private: | |
2105 Address start_; | |
2106 Address limit_; | |
2107 }; | 2107 }; |
2108 | 2108 |
2109 class PagedSpace : public Space { | 2109 class PagedSpace : public Space { |
2110 public: | 2110 public: |
2111 typedef PageIterator iterator; | 2111 typedef PageIterator iterator; |
2112 | 2112 |
2113 static const intptr_t kCompactionMemoryWanted = 500 * KB; | 2113 static const intptr_t kCompactionMemoryWanted = 500 * KB; |
2114 | 2114 |
2115 // Creates a space with an id. | 2115 // Creates a space with an id. |
2116 PagedSpace(Heap* heap, AllocationSpace id, Executability executable); | 2116 PagedSpace(Heap* heap, AllocationSpace id, Executability executable); |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2591 // A SemiSpaceIterator is an ObjectIterator that iterates over the active | 2591 // A SemiSpaceIterator is an ObjectIterator that iterates over the active |
2592 // semispace of the heap's new space. It iterates over the objects in the | 2592 // semispace of the heap's new space. It iterates over the objects in the |
2593 // semispace from a given start address (defaulting to the bottom of the | 2593 // semispace from a given start address (defaulting to the bottom of the |
2594 // semispace) to the top of the semispace. New objects allocated after the | 2594 // semispace) to the top of the semispace. New objects allocated after the |
2595 // iterator is created are not iterated. | 2595 // iterator is created are not iterated. |
2596 class SemiSpaceIterator : public ObjectIterator { | 2596 class SemiSpaceIterator : public ObjectIterator { |
2597 public: | 2597 public: |
2598 // Create an iterator over the allocated objects in the given to-space. | 2598 // Create an iterator over the allocated objects in the given to-space. |
2599 explicit SemiSpaceIterator(NewSpace* space); | 2599 explicit SemiSpaceIterator(NewSpace* space); |
2600 | 2600 |
2601 inline HeapObject* Next(); | 2601 inline HeapObject* Next() override; |
2602 | |
2603 // Implementation of the ObjectIterator functions. | |
2604 inline HeapObject* next_object() override; | |
2605 | 2602 |
2606 private: | 2603 private: |
2607 void Initialize(Address start, Address end); | 2604 void Initialize(Address start, Address end); |
2608 | 2605 |
2609 // The current iteration point. | 2606 // The current iteration point. |
2610 Address current_; | 2607 Address current_; |
2611 // The end of iteration. | 2608 // The end of iteration. |
2612 Address limit_; | 2609 Address limit_; |
2613 }; | 2610 }; |
2614 | 2611 |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3116 base::HashMap chunk_map_; | 3113 base::HashMap chunk_map_; |
3117 | 3114 |
3118 friend class LargeObjectIterator; | 3115 friend class LargeObjectIterator; |
3119 }; | 3116 }; |
3120 | 3117 |
3121 | 3118 |
3122 class LargeObjectIterator : public ObjectIterator { | 3119 class LargeObjectIterator : public ObjectIterator { |
3123 public: | 3120 public: |
3124 explicit LargeObjectIterator(LargeObjectSpace* space); | 3121 explicit LargeObjectIterator(LargeObjectSpace* space); |
3125 | 3122 |
3126 HeapObject* Next(); | 3123 HeapObject* Next() override; |
3127 | |
3128 // implementation of ObjectIterator. | |
3129 virtual HeapObject* next_object() { return Next(); } | |
3130 | 3124 |
3131 private: | 3125 private: |
3132 LargePage* current_; | 3126 LargePage* current_; |
3133 }; | 3127 }; |
3134 | 3128 |
3135 // Iterates over the chunks (pages and large object pages) that can contain | 3129 // Iterates over the chunks (pages and large object pages) that can contain |
3136 // pointers to new space or to evacuation candidates. | 3130 // pointers to new space or to evacuation candidates. |
3137 class MemoryChunkIterator BASE_EMBEDDED { | 3131 class MemoryChunkIterator BASE_EMBEDDED { |
3138 public: | 3132 public: |
3139 inline explicit MemoryChunkIterator(Heap* heap); | 3133 inline explicit MemoryChunkIterator(Heap* heap); |
(...skipping 28 matching lines...) Expand all Loading... | |
3168 count = 0; | 3162 count = 0; |
3169 } | 3163 } |
3170 // Must be small, since an iteration is used for lookup. | 3164 // Must be small, since an iteration is used for lookup. |
3171 static const int kMaxComments = 64; | 3165 static const int kMaxComments = 64; |
3172 }; | 3166 }; |
3173 #endif | 3167 #endif |
3174 } // namespace internal | 3168 } // namespace internal |
3175 } // namespace v8 | 3169 } // namespace v8 |
3176 | 3170 |
3177 #endif // V8_HEAP_SPACES_H_ | 3171 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |