| 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 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 int page_extra_; | 975 int page_extra_; |
| 976 | 976 |
| 977 // Sets allocation pointer to a page bottom. | 977 // Sets allocation pointer to a page bottom. |
| 978 static void SetAllocationInfo(AllocationInfo* alloc_info, Page* p); | 978 static void SetAllocationInfo(AllocationInfo* alloc_info, Page* p); |
| 979 | 979 |
| 980 // Returns the top page specified by an allocation info structure. | 980 // Returns the top page specified by an allocation info structure. |
| 981 static Page* TopPageOf(AllocationInfo alloc_info) { | 981 static Page* TopPageOf(AllocationInfo alloc_info) { |
| 982 return Page::FromAllocationTop(alloc_info.limit); | 982 return Page::FromAllocationTop(alloc_info.limit); |
| 983 } | 983 } |
| 984 | 984 |
| 985 int CountPagesToTop() { |
| 986 Page* p = Page::FromAllocationTop(allocation_info_.top); |
| 987 PageIterator it(this, PageIterator::ALL_PAGES); |
| 988 int counter = 1; |
| 989 while (it.has_next()) { |
| 990 if (it.next() == p) return counter; |
| 991 counter++; |
| 992 } |
| 993 UNREACHABLE(); |
| 994 return -1; |
| 995 } |
| 996 |
| 985 // Expands the space by allocating a fixed number of pages. Returns false if | 997 // Expands the space by allocating a fixed number of pages. Returns false if |
| 986 // it cannot allocate requested number of pages from OS. Newly allocated | 998 // it cannot allocate requested number of pages from OS. Newly allocated |
| 987 // pages are append to the last_page; | 999 // pages are append to the last_page; |
| 988 bool Expand(Page* last_page); | 1000 bool Expand(Page* last_page); |
| 989 | 1001 |
| 990 // Generic fast case allocation function that tries linear allocation in | 1002 // Generic fast case allocation function that tries linear allocation in |
| 991 // the top page of 'alloc_info'. Returns NULL on failure. | 1003 // the top page of 'alloc_info'. Returns NULL on failure. |
| 992 inline HeapObject* AllocateLinearly(AllocationInfo* alloc_info, | 1004 inline HeapObject* AllocateLinearly(AllocationInfo* alloc_info, |
| 993 int size_in_bytes); | 1005 int size_in_bytes); |
| 994 | 1006 |
| (...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1746 FixedSizeFreeList free_list_; | 1758 FixedSizeFreeList free_list_; |
| 1747 }; | 1759 }; |
| 1748 | 1760 |
| 1749 | 1761 |
| 1750 // ----------------------------------------------------------------------------- | 1762 // ----------------------------------------------------------------------------- |
| 1751 // Old space for all map objects | 1763 // Old space for all map objects |
| 1752 | 1764 |
| 1753 class MapSpace : public FixedSpace { | 1765 class MapSpace : public FixedSpace { |
| 1754 public: | 1766 public: |
| 1755 // Creates a map space object with a maximum capacity. | 1767 // Creates a map space object with a maximum capacity. |
| 1756 MapSpace(int max_capacity, AllocationSpace id) | 1768 MapSpace(int max_capacity, int max_map_space_pages, AllocationSpace id) |
| 1757 : FixedSpace(max_capacity, id, Map::kSize, "map") {} | 1769 : FixedSpace(max_capacity, id, Map::kSize, "map"), |
| 1770 max_map_space_pages_(max_map_space_pages) { |
| 1771 ASSERT(max_map_space_pages < kMaxMapPageIndex); |
| 1772 } |
| 1758 | 1773 |
| 1759 // Prepares for a mark-compact GC. | 1774 // Prepares for a mark-compact GC. |
| 1760 virtual void PrepareForMarkCompact(bool will_compact); | 1775 virtual void PrepareForMarkCompact(bool will_compact); |
| 1761 | 1776 |
| 1762 // Given an index, returns the page address. | 1777 // Given an index, returns the page address. |
| 1763 Address PageAddress(int page_index) { return page_addresses_[page_index]; } | 1778 Address PageAddress(int page_index) { return page_addresses_[page_index]; } |
| 1764 | 1779 |
| 1765 // Constants. | 1780 static const int kMaxMapPageIndex = 1 << MapWord::kMapPageIndexBits; |
| 1766 static const int kMaxMapPageIndex = (1 << MapWord::kMapPageIndexBits) - 1; | |
| 1767 | 1781 |
| 1768 // Are map pointers encodable into map word? | 1782 // Are map pointers encodable into map word? |
| 1769 bool MapPointersEncodable() { | 1783 bool MapPointersEncodable() { |
| 1770 if (!FLAG_use_big_map_space) { | 1784 if (!FLAG_use_big_map_space) { |
| 1771 ASSERT(CountTotalPages() <= kMaxMapPageIndex); | 1785 ASSERT(CountPagesToTop() <= kMaxMapPageIndex); |
| 1772 return true; | 1786 return true; |
| 1773 } | 1787 } |
| 1774 int n_of_pages = Capacity() / Page::kObjectAreaSize; | 1788 return CountPagesToTop() <= max_map_space_pages_; |
| 1775 ASSERT(n_of_pages == CountTotalPages()); | |
| 1776 return n_of_pages <= kMaxMapPageIndex; | |
| 1777 } | 1789 } |
| 1778 | 1790 |
| 1779 // Should be called after forced sweep to find out if map space needs | 1791 // Should be called after forced sweep to find out if map space needs |
| 1780 // compaction. | 1792 // compaction. |
| 1781 bool NeedsCompaction(int live_maps) { | 1793 bool NeedsCompaction(int live_maps) { |
| 1782 return !MapPointersEncodable() && live_maps <= kCompactionThreshold; | 1794 return !MapPointersEncodable() && live_maps <= CompactionThreshold(); |
| 1783 } | 1795 } |
| 1784 | 1796 |
| 1785 Address TopAfterCompaction(int live_maps) { | 1797 Address TopAfterCompaction(int live_maps) { |
| 1786 ASSERT(NeedsCompaction(live_maps)); | 1798 ASSERT(NeedsCompaction(live_maps)); |
| 1787 | 1799 |
| 1788 int pages_left = live_maps / kMapsPerPage; | 1800 int pages_left = live_maps / kMapsPerPage; |
| 1789 PageIterator it(this, PageIterator::ALL_PAGES); | 1801 PageIterator it(this, PageIterator::ALL_PAGES); |
| 1790 while (pages_left-- > 0) { | 1802 while (pages_left-- > 0) { |
| 1803 it.has_next(); // Must be called for side-effects, see bug 586. |
| 1791 ASSERT(it.has_next()); | 1804 ASSERT(it.has_next()); |
| 1792 it.next()->ClearRSet(); | 1805 it.next()->ClearRSet(); |
| 1793 } | 1806 } |
| 1807 it.has_next(); // Must be called for side-effects, see bug 586. |
| 1794 ASSERT(it.has_next()); | 1808 ASSERT(it.has_next()); |
| 1795 Page* top_page = it.next(); | 1809 Page* top_page = it.next(); |
| 1796 top_page->ClearRSet(); | 1810 top_page->ClearRSet(); |
| 1797 ASSERT(top_page->is_valid()); | 1811 ASSERT(top_page->is_valid()); |
| 1798 | 1812 |
| 1799 int offset = live_maps % kMapsPerPage * Map::kSize; | 1813 int offset = live_maps % kMapsPerPage * Map::kSize; |
| 1800 Address top = top_page->ObjectAreaStart() + offset; | 1814 Address top = top_page->ObjectAreaStart() + offset; |
| 1801 ASSERT(top < top_page->ObjectAreaEnd()); | 1815 ASSERT(top < top_page->ObjectAreaEnd()); |
| 1802 ASSERT(Contains(top)); | 1816 ASSERT(Contains(top)); |
| 1803 | 1817 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1831 | 1845 |
| 1832 protected: | 1846 protected: |
| 1833 #ifdef DEBUG | 1847 #ifdef DEBUG |
| 1834 virtual void VerifyObject(HeapObject* obj); | 1848 virtual void VerifyObject(HeapObject* obj); |
| 1835 #endif | 1849 #endif |
| 1836 | 1850 |
| 1837 private: | 1851 private: |
| 1838 static const int kMapsPerPage = Page::kObjectAreaSize / Map::kSize; | 1852 static const int kMapsPerPage = Page::kObjectAreaSize / Map::kSize; |
| 1839 | 1853 |
| 1840 // Do map space compaction if there is a page gap. | 1854 // Do map space compaction if there is a page gap. |
| 1841 static const int kCompactionThreshold = kMapsPerPage * (kMaxMapPageIndex - 1); | 1855 int CompactionThreshold() { |
| 1856 return kMapsPerPage * (max_map_space_pages_ - 1); |
| 1857 } |
| 1858 |
| 1859 const int max_map_space_pages_; |
| 1842 | 1860 |
| 1843 // An array of page start address in a map space. | 1861 // An array of page start address in a map space. |
| 1844 Address page_addresses_[kMaxMapPageIndex + 1]; | 1862 Address page_addresses_[kMaxMapPageIndex]; |
| 1845 | 1863 |
| 1846 public: | 1864 public: |
| 1847 TRACK_MEMORY("MapSpace") | 1865 TRACK_MEMORY("MapSpace") |
| 1848 }; | 1866 }; |
| 1849 | 1867 |
| 1850 | 1868 |
| 1851 // ----------------------------------------------------------------------------- | 1869 // ----------------------------------------------------------------------------- |
| 1852 // Old space for all global object property cell objects | 1870 // Old space for all global object property cell objects |
| 1853 | 1871 |
| 1854 class CellSpace : public FixedSpace { | 1872 class CellSpace : public FixedSpace { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2045 | 2063 |
| 2046 private: | 2064 private: |
| 2047 LargeObjectChunk* current_; | 2065 LargeObjectChunk* current_; |
| 2048 HeapObjectCallback size_func_; | 2066 HeapObjectCallback size_func_; |
| 2049 }; | 2067 }; |
| 2050 | 2068 |
| 2051 | 2069 |
| 2052 } } // namespace v8::internal | 2070 } } // namespace v8::internal |
| 2053 | 2071 |
| 2054 #endif // V8_SPACES_H_ | 2072 #endif // V8_SPACES_H_ |
| OLD | NEW |