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 "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/atomic-utils.h" | 9 #include "src/atomic-utils.h" |
10 #include "src/base/atomicops.h" | 10 #include "src/base/atomicops.h" |
11 #include "src/base/bits.h" | 11 #include "src/base/bits.h" |
12 #include "src/base/platform/mutex.h" | 12 #include "src/base/platform/mutex.h" |
13 #include "src/flags.h" | 13 #include "src/flags.h" |
14 #include "src/hashmap.h" | 14 #include "src/hashmap.h" |
15 #include "src/list.h" | 15 #include "src/list.h" |
16 #include "src/objects.h" | 16 #include "src/objects.h" |
17 #include "src/utils.h" | 17 #include "src/utils.h" |
18 | 18 |
19 namespace v8 { | 19 namespace v8 { |
20 namespace internal { | 20 namespace internal { |
21 | 21 |
22 class CompactionSpaceCollection; | |
22 class Isolate; | 23 class Isolate; |
23 | 24 |
24 // ----------------------------------------------------------------------------- | 25 // ----------------------------------------------------------------------------- |
25 // Heap structures: | 26 // Heap structures: |
26 // | 27 // |
27 // A JS heap consists of a young generation, an old generation, and a large | 28 // A JS heap consists of a young generation, an old generation, and a large |
28 // object space. The young generation is divided into two semispaces. A | 29 // object space. The young generation is divided into two semispaces. A |
29 // scavenger implements Cheney's copying algorithm. The old generation is | 30 // scavenger implements Cheney's copying algorithm. The old generation is |
30 // separated into a map space and an old object space. The map space contains | 31 // separated into a map space and an old object space. The map space contains |
31 // all (and only) map objects, the rest of old objects go into the old space. | 32 // all (and only) map objects, the rest of old objects go into the old space. |
(...skipping 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1719 return kLargeAllocationMax; | 1720 return kLargeAllocationMax; |
1720 } | 1721 } |
1721 return maximum_freed; | 1722 return maximum_freed; |
1722 } | 1723 } |
1723 | 1724 |
1724 // Allocate a block of size 'size_in_bytes' from the free list. The block | 1725 // Allocate a block of size 'size_in_bytes' from the free list. The block |
1725 // is unitialized. A failure is returned if no block is available. | 1726 // is unitialized. A failure is returned if no block is available. |
1726 // The size should be a non-zero multiple of the word size. | 1727 // The size should be a non-zero multiple of the word size. |
1727 MUST_USE_RESULT HeapObject* Allocate(int size_in_bytes); | 1728 MUST_USE_RESULT HeapObject* Allocate(int size_in_bytes); |
1728 | 1729 |
1730 // The method tries to find a {FreeSpace} node of at least {size_in_bytes} | |
1731 // size in the free list category exactly matching the size. If no suitable | |
1732 // node could be found, the method falls back to retrieving a {FreeSpace} not | |
ulan
2015/10/13 10:01:23
Remove "not" from "a {FreeSpace} not"
Michael Lippautz
2015/10/13 10:37:57
Done.
| |
1733 // from the large or huge free list category. | |
1734 // | |
1735 // Can be used concurrently. | |
1736 MUST_USE_RESULT FreeSpace* TryRemoveMemory(intptr_t hint_size_in_bytes); | |
1737 | |
1729 bool IsEmpty() { | 1738 bool IsEmpty() { |
1730 return small_list_.IsEmpty() && medium_list_.IsEmpty() && | 1739 return small_list_.IsEmpty() && medium_list_.IsEmpty() && |
1731 large_list_.IsEmpty() && huge_list_.IsEmpty(); | 1740 large_list_.IsEmpty() && huge_list_.IsEmpty(); |
1732 } | 1741 } |
1733 | 1742 |
1734 #ifdef DEBUG | 1743 #ifdef DEBUG |
1735 void Zap(); | 1744 void Zap(); |
1736 intptr_t SumFreeLists(); | 1745 intptr_t SumFreeLists(); |
1737 bool IsVeryLong(); | 1746 bool IsVeryLong(); |
1738 #endif | 1747 #endif |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1773 return &large_list_; | 1782 return &large_list_; |
1774 case kHuge: | 1783 case kHuge: |
1775 return &huge_list_; | 1784 return &huge_list_; |
1776 default: | 1785 default: |
1777 UNREACHABLE(); | 1786 UNREACHABLE(); |
1778 } | 1787 } |
1779 UNREACHABLE(); | 1788 UNREACHABLE(); |
1780 return nullptr; | 1789 return nullptr; |
1781 } | 1790 } |
1782 | 1791 |
1783 | |
1784 PagedSpace* owner_; | 1792 PagedSpace* owner_; |
1785 Heap* heap_; | 1793 Heap* heap_; |
1786 base::Mutex mutex_; | 1794 base::Mutex mutex_; |
1787 intptr_t wasted_bytes_; | 1795 intptr_t wasted_bytes_; |
1788 FreeListCategory small_list_; | 1796 FreeListCategory small_list_; |
1789 FreeListCategory medium_list_; | 1797 FreeListCategory medium_list_; |
1790 FreeListCategory large_list_; | 1798 FreeListCategory large_list_; |
1791 FreeListCategory huge_list_; | 1799 FreeListCategory huge_list_; |
1792 | 1800 |
1793 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList); | 1801 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1832 | 1840 |
1833 Object* object_; | 1841 Object* object_; |
1834 }; | 1842 }; |
1835 | 1843 |
1836 | 1844 |
1837 STATIC_ASSERT(sizeof(AllocationResult) == kPointerSize); | 1845 STATIC_ASSERT(sizeof(AllocationResult) == kPointerSize); |
1838 | 1846 |
1839 | 1847 |
1840 class PagedSpace : public Space { | 1848 class PagedSpace : public Space { |
1841 public: | 1849 public: |
1850 static const intptr_t kCompactionMemoryWanted = 500 * KB; | |
1851 | |
1842 // Creates a space with an id. | 1852 // Creates a space with an id. |
1843 PagedSpace(Heap* heap, AllocationSpace id, Executability executable); | 1853 PagedSpace(Heap* heap, AllocationSpace id, Executability executable); |
1844 | 1854 |
1845 virtual ~PagedSpace() { TearDown(); } | 1855 virtual ~PagedSpace() { TearDown(); } |
1846 | 1856 |
1847 // Set up the space using the given address range of virtual memory (from | 1857 // Set up the space using the given address range of virtual memory (from |
1848 // the memory allocator's initial chunk) if possible. If the block of | 1858 // the memory allocator's initial chunk) if possible. If the block of |
1849 // addresses is not big enough to contain a single page-aligned page, a | 1859 // addresses is not big enough to contain a single page-aligned page, a |
1850 // fresh chunk will be allocated. | 1860 // fresh chunk will be allocated. |
1851 bool SetUp(); | 1861 bool SetUp(); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2033 void EvictEvacuationCandidatesFromFreeLists(); | 2043 void EvictEvacuationCandidatesFromFreeLists(); |
2034 | 2044 |
2035 bool CanExpand(size_t size); | 2045 bool CanExpand(size_t size); |
2036 | 2046 |
2037 // Returns the number of total pages in this space. | 2047 // Returns the number of total pages in this space. |
2038 int CountTotalPages(); | 2048 int CountTotalPages(); |
2039 | 2049 |
2040 // Return size of allocatable area on a page in this space. | 2050 // Return size of allocatable area on a page in this space. |
2041 inline int AreaSize() { return area_size_; } | 2051 inline int AreaSize() { return area_size_; } |
2042 | 2052 |
2053 virtual bool is_local() { return false; } | |
2054 | |
2043 // Merges {other} into the current space. Note that this modifies {other}, | 2055 // Merges {other} into the current space. Note that this modifies {other}, |
2044 // e.g., removes its bump pointer area and resets statistics. | 2056 // e.g., removes its bump pointer area and resets statistics. |
2045 void MergeCompactionSpace(CompactionSpace* other); | 2057 void MergeCompactionSpace(CompactionSpace* other); |
2046 | 2058 |
2059 void DivideUponCompactionSpaces(CompactionSpaceCollection** other, int num, | |
2060 intptr_t limit = kCompactionMemoryWanted); | |
2061 | |
2062 // Refills the free list from the corresponding free list filled by the | |
2063 // sweeper. | |
2064 virtual void RefillFreeList(); | |
2065 | |
2066 protected: | |
2067 void AddMemory(Address start, intptr_t size); | |
2068 | |
2069 FreeSpace* TryRemoveMemory(intptr_t size_in_bytes); | |
2070 | |
2047 void MoveOverFreeMemory(PagedSpace* other); | 2071 void MoveOverFreeMemory(PagedSpace* other); |
2048 | 2072 |
2049 virtual bool is_local() { return false; } | |
2050 | |
2051 protected: | |
2052 // PagedSpaces that should be included in snapshots have different, i.e., | 2073 // PagedSpaces that should be included in snapshots have different, i.e., |
2053 // smaller, initial pages. | 2074 // smaller, initial pages. |
2054 virtual bool snapshotable() { return true; } | 2075 virtual bool snapshotable() { return true; } |
2055 | 2076 |
2056 FreeList* free_list() { return &free_list_; } | 2077 FreeList* free_list() { return &free_list_; } |
2057 | 2078 |
2058 bool HasPages() { return anchor_.next_page() != &anchor_; } | 2079 bool HasPages() { return anchor_.next_page() != &anchor_; } |
2059 | 2080 |
2060 // Cleans up the space, frees all pages in this space except those belonging | 2081 // Cleans up the space, frees all pages in this space except those belonging |
2061 // to the initial chunk, uncommits addresses in the initial chunk. | 2082 // to the initial chunk, uncommits addresses in the initial chunk. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2102 // The sweeper threads iterate over the list of pointer and data space pages | 2123 // The sweeper threads iterate over the list of pointer and data space pages |
2103 // and sweep these pages concurrently. They will stop sweeping after the | 2124 // and sweep these pages concurrently. They will stop sweeping after the |
2104 // end_of_unswept_pages_ page. | 2125 // end_of_unswept_pages_ page. |
2105 Page* end_of_unswept_pages_; | 2126 Page* end_of_unswept_pages_; |
2106 | 2127 |
2107 // Mutex guarding any concurrent access to the space. | 2128 // Mutex guarding any concurrent access to the space. |
2108 base::Mutex space_mutex_; | 2129 base::Mutex space_mutex_; |
2109 | 2130 |
2110 friend class MarkCompactCollector; | 2131 friend class MarkCompactCollector; |
2111 friend class PageIterator; | 2132 friend class PageIterator; |
2133 | |
2134 // Used in cctest. | |
2135 friend class HeapTester; | |
2112 }; | 2136 }; |
2113 | 2137 |
2114 | 2138 |
2115 class NumberAndSizeInfo BASE_EMBEDDED { | 2139 class NumberAndSizeInfo BASE_EMBEDDED { |
2116 public: | 2140 public: |
2117 NumberAndSizeInfo() : number_(0), bytes_(0) {} | 2141 NumberAndSizeInfo() : number_(0), bytes_(0) {} |
2118 | 2142 |
2119 int number() const { return number_; } | 2143 int number() const { return number_; } |
2120 void increment_number(int num) { number_ += num; } | 2144 void increment_number(int num) { number_ += num; } |
2121 | 2145 |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2779 public: | 2803 public: |
2780 CompactionSpace(Heap* heap, AllocationSpace id, Executability executable) | 2804 CompactionSpace(Heap* heap, AllocationSpace id, Executability executable) |
2781 : PagedSpace(heap, id, executable) {} | 2805 : PagedSpace(heap, id, executable) {} |
2782 | 2806 |
2783 // Adds external memory starting at {start} of {size_in_bytes} to the space. | 2807 // Adds external memory starting at {start} of {size_in_bytes} to the space. |
2784 void AddExternalMemory(Address start, int size_in_bytes) { | 2808 void AddExternalMemory(Address start, int size_in_bytes) { |
2785 IncreaseCapacity(size_in_bytes); | 2809 IncreaseCapacity(size_in_bytes); |
2786 Free(start, size_in_bytes); | 2810 Free(start, size_in_bytes); |
2787 } | 2811 } |
2788 | 2812 |
2789 virtual bool is_local() { return true; } | 2813 virtual bool is_local() override { return true; } |
2814 | |
2815 virtual void RefillFreeList() override; | |
2790 | 2816 |
2791 protected: | 2817 protected: |
2792 // The space is temporary and not included in any snapshots. | 2818 // The space is temporary and not included in any snapshots. |
2793 virtual bool snapshotable() { return false; } | 2819 virtual bool snapshotable() override { return false; } |
2794 }; | 2820 }; |
2795 | 2821 |
2796 | 2822 |
2797 // A collection of |CompactionSpace|s used by a single compaction task. | 2823 // A collection of |CompactionSpace|s used by a single compaction task. |
2798 class CompactionSpaceCollection : public Malloced { | 2824 class CompactionSpaceCollection : public Malloced { |
2799 public: | 2825 public: |
2800 explicit CompactionSpaceCollection(Heap* heap) | 2826 explicit CompactionSpaceCollection(Heap* heap) |
2801 : old_space_(heap, OLD_SPACE, Executability::NOT_EXECUTABLE), | 2827 : old_space_(heap, OLD_SPACE, Executability::NOT_EXECUTABLE), |
2802 code_space_(heap, CODE_SPACE, Executability::EXECUTABLE) {} | 2828 code_space_(heap, CODE_SPACE, Executability::EXECUTABLE) {} |
2803 | 2829 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3009 count = 0; | 3035 count = 0; |
3010 } | 3036 } |
3011 // Must be small, since an iteration is used for lookup. | 3037 // Must be small, since an iteration is used for lookup. |
3012 static const int kMaxComments = 64; | 3038 static const int kMaxComments = 64; |
3013 }; | 3039 }; |
3014 #endif | 3040 #endif |
3015 } // namespace internal | 3041 } // namespace internal |
3016 } // namespace v8 | 3042 } // namespace v8 |
3017 | 3043 |
3018 #endif // V8_HEAP_SPACES_H_ | 3044 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |