| 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 1713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1724 #endif | 1724 #endif |
| 1725 | 1725 |
| 1726 protected: | 1726 protected: |
| 1727 // Virtual function in the superclass. Slow path of AllocateRaw. | 1727 // Virtual function in the superclass. Slow path of AllocateRaw. |
| 1728 HeapObject* SlowAllocateRaw(int size_in_bytes); | 1728 HeapObject* SlowAllocateRaw(int size_in_bytes); |
| 1729 | 1729 |
| 1730 // Virtual function in the superclass. Allocate linearly at the start of | 1730 // Virtual function in the superclass. Allocate linearly at the start of |
| 1731 // the page after current_page (there is assumed to be one). | 1731 // the page after current_page (there is assumed to be one). |
| 1732 HeapObject* AllocateInNextPage(Page* current_page, int size_in_bytes); | 1732 HeapObject* AllocateInNextPage(Page* current_page, int size_in_bytes); |
| 1733 | 1733 |
| 1734 void ResetFreeList() { |
| 1735 free_list_.Reset(); |
| 1736 } |
| 1737 |
| 1734 private: | 1738 private: |
| 1735 // The size of objects in this space. | 1739 // The size of objects in this space. |
| 1736 int object_size_in_bytes_; | 1740 int object_size_in_bytes_; |
| 1737 | 1741 |
| 1738 // The name of this space. | 1742 // The name of this space. |
| 1739 const char* name_; | 1743 const char* name_; |
| 1740 | 1744 |
| 1741 // The space's free list. | 1745 // The space's free list. |
| 1742 FixedSizeFreeList free_list_; | 1746 FixedSizeFreeList free_list_; |
| 1743 }; | 1747 }; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1765 bool MapPointersEncodable() { | 1769 bool MapPointersEncodable() { |
| 1766 if (!FLAG_use_big_map_space) { | 1770 if (!FLAG_use_big_map_space) { |
| 1767 ASSERT(CountTotalPages() <= kMaxMapPageIndex); | 1771 ASSERT(CountTotalPages() <= kMaxMapPageIndex); |
| 1768 return true; | 1772 return true; |
| 1769 } | 1773 } |
| 1770 int n_of_pages = Capacity() / Page::kObjectAreaSize; | 1774 int n_of_pages = Capacity() / Page::kObjectAreaSize; |
| 1771 ASSERT(n_of_pages == CountTotalPages()); | 1775 ASSERT(n_of_pages == CountTotalPages()); |
| 1772 return n_of_pages <= kMaxMapPageIndex; | 1776 return n_of_pages <= kMaxMapPageIndex; |
| 1773 } | 1777 } |
| 1774 | 1778 |
| 1779 // Should be called after forced sweep to find out if map space needs |
| 1780 // compaction. |
| 1781 int NeedsCompaction(int live_maps) { |
| 1782 return !MapPointersEncodable() && live_maps <= kCompactionThreshold; |
| 1783 } |
| 1784 |
| 1785 Address TopAfterCompaction(int live_maps) { |
| 1786 ASSERT(NeedsCompaction(live_maps)); |
| 1787 |
| 1788 int pages_left = live_maps / kMapsPerPage; |
| 1789 PageIterator it(this, PageIterator::ALL_PAGES); |
| 1790 while (pages_left-- > 0) { |
| 1791 ASSERT(it.has_next()); |
| 1792 it.next()->ClearRSet(); |
| 1793 } |
| 1794 ASSERT(it.has_next()); |
| 1795 Page* top_page = it.next(); |
| 1796 top_page->ClearRSet(); |
| 1797 ASSERT(top_page->is_valid()); |
| 1798 |
| 1799 int offset = live_maps % kMapsPerPage * Map::kSize; |
| 1800 Address top = top_page->ObjectAreaStart() + offset; |
| 1801 ASSERT(top < top_page->ObjectAreaEnd()); |
| 1802 ASSERT(Contains(top)); |
| 1803 |
| 1804 return top; |
| 1805 } |
| 1806 |
| 1807 void FinishCompaction(Address new_top, int live_maps) { |
| 1808 Page* top_page = Page::FromAddress(new_top); |
| 1809 ASSERT(top_page->is_valid()); |
| 1810 |
| 1811 SetAllocationInfo(&allocation_info_, top_page); |
| 1812 allocation_info_.top = new_top; |
| 1813 |
| 1814 int new_size = live_maps * Map::kSize; |
| 1815 accounting_stats_.DeallocateBytes(accounting_stats_.Size()); |
| 1816 accounting_stats_.AllocateBytes(new_size); |
| 1817 |
| 1818 #ifdef DEBUG |
| 1819 if (FLAG_enable_slow_asserts) { |
| 1820 int actual_size = 0; |
| 1821 for (Page* p = first_page_; p != top_page; p = p->next_page()) |
| 1822 actual_size += kMapsPerPage * Map::kSize; |
| 1823 actual_size += (new_top - top_page->ObjectAreaStart()); |
| 1824 ASSERT(accounting_stats_.Size() == actual_size); |
| 1825 } |
| 1826 #endif |
| 1827 |
| 1828 Shrink(); |
| 1829 ResetFreeList(); |
| 1830 } |
| 1831 |
| 1775 protected: | 1832 protected: |
| 1776 #ifdef DEBUG | 1833 #ifdef DEBUG |
| 1777 virtual void VerifyObject(HeapObject* obj); | 1834 virtual void VerifyObject(HeapObject* obj); |
| 1778 #endif | 1835 #endif |
| 1779 | 1836 |
| 1780 private: | 1837 private: |
| 1838 static const int kMapsPerPage = Page::kObjectAreaSize / Map::kSize; |
| 1839 |
| 1840 // Do map space compaction if there is a page gap. |
| 1841 static const int kCompactionThreshold = kMapsPerPage * (kMaxMapPageIndex - 1); |
| 1842 |
| 1781 // An array of page start address in a map space. | 1843 // An array of page start address in a map space. |
| 1782 Address page_addresses_[kMaxMapPageIndex + 1]; | 1844 Address page_addresses_[kMaxMapPageIndex + 1]; |
| 1783 | 1845 |
| 1784 public: | 1846 public: |
| 1785 TRACK_MEMORY("MapSpace") | 1847 TRACK_MEMORY("MapSpace") |
| 1786 }; | 1848 }; |
| 1787 | 1849 |
| 1788 | 1850 |
| 1789 // ----------------------------------------------------------------------------- | 1851 // ----------------------------------------------------------------------------- |
| 1790 // Old space for all global object property cell objects | 1852 // Old space for all global object property cell objects |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1983 | 2045 |
| 1984 private: | 2046 private: |
| 1985 LargeObjectChunk* current_; | 2047 LargeObjectChunk* current_; |
| 1986 HeapObjectCallback size_func_; | 2048 HeapObjectCallback size_func_; |
| 1987 }; | 2049 }; |
| 1988 | 2050 |
| 1989 | 2051 |
| 1990 } } // namespace v8::internal | 2052 } } // namespace v8::internal |
| 1991 | 2053 |
| 1992 #endif // V8_SPACES_H_ | 2054 #endif // V8_SPACES_H_ |
| OLD | NEW |