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; | |
23 class Isolate; | 22 class Isolate; |
24 | 23 |
25 // ----------------------------------------------------------------------------- | 24 // ----------------------------------------------------------------------------- |
26 // Heap structures: | 25 // Heap structures: |
27 // | 26 // |
28 // A JS heap consists of a young generation, an old generation, and a large | 27 // A JS heap consists of a young generation, an old generation, and a large |
29 // object space. The young generation is divided into two semispaces. A | 28 // object space. The young generation is divided into two semispaces. A |
30 // scavenger implements Cheney's copying algorithm. The old generation is | 29 // scavenger implements Cheney's copying algorithm. The old generation is |
31 // separated into a map space and an old object space. The map space contains | 30 // separated into a map space and an old object space. The map space contains |
32 // all (and only) map objects, the rest of old objects go into the old space. | 31 // all (and only) map objects, the rest of old objects go into the old space. |
(...skipping 1709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1742 void Reset(); | 1741 void Reset(); |
1743 | 1742 |
1744 void ResetStats() { wasted_bytes_ = 0; } | 1743 void ResetStats() { wasted_bytes_ = 0; } |
1745 | 1744 |
1746 // Return the number of bytes available on the free list. | 1745 // Return the number of bytes available on the free list. |
1747 intptr_t Available() { | 1746 intptr_t Available() { |
1748 return small_list_.available() + medium_list_.available() + | 1747 return small_list_.available() + medium_list_.available() + |
1749 large_list_.available() + huge_list_.available(); | 1748 large_list_.available() + huge_list_.available(); |
1750 } | 1749 } |
1751 | 1750 |
1752 // The method tries to find a {FreeSpace} node of at least {size_in_bytes} | |
1753 // size in the free list category exactly matching the size. If no suitable | |
1754 // node could be found, the method falls back to retrieving a {FreeSpace} | |
1755 // from the large or huge free list category. | |
1756 // | |
1757 // Can be used concurrently. | |
1758 MUST_USE_RESULT FreeSpace* TryRemoveMemory(intptr_t hint_size_in_bytes); | |
1759 | |
1760 bool IsEmpty() { | 1751 bool IsEmpty() { |
1761 return small_list_.IsEmpty() && medium_list_.IsEmpty() && | 1752 return small_list_.IsEmpty() && medium_list_.IsEmpty() && |
1762 large_list_.IsEmpty() && huge_list_.IsEmpty(); | 1753 large_list_.IsEmpty() && huge_list_.IsEmpty(); |
1763 } | 1754 } |
1764 | 1755 |
1765 // Used after booting the VM. | 1756 // Used after booting the VM. |
1766 void RepairLists(Heap* heap); | 1757 void RepairLists(Heap* heap); |
1767 | 1758 |
1768 intptr_t EvictFreeListItems(Page* p); | 1759 intptr_t EvictFreeListItems(Page* p); |
1769 bool ContainsPageFreeListItems(Page* p); | 1760 bool ContainsPageFreeListItems(Page* p); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1861 | 1852 |
1862 Object* object_; | 1853 Object* object_; |
1863 }; | 1854 }; |
1864 | 1855 |
1865 | 1856 |
1866 STATIC_ASSERT(sizeof(AllocationResult) == kPointerSize); | 1857 STATIC_ASSERT(sizeof(AllocationResult) == kPointerSize); |
1867 | 1858 |
1868 | 1859 |
1869 class PagedSpace : public Space { | 1860 class PagedSpace : public Space { |
1870 public: | 1861 public: |
1871 static const intptr_t kCompactionMemoryWanted = 500 * KB; | |
1872 | |
1873 // Creates a space with an id. | 1862 // Creates a space with an id. |
1874 PagedSpace(Heap* heap, AllocationSpace id, Executability executable); | 1863 PagedSpace(Heap* heap, AllocationSpace id, Executability executable); |
1875 | 1864 |
1876 virtual ~PagedSpace() { TearDown(); } | 1865 virtual ~PagedSpace() { TearDown(); } |
1877 | 1866 |
1878 // Set up the space using the given address range of virtual memory (from | 1867 // Set up the space using the given address range of virtual memory (from |
1879 // the memory allocator's initial chunk) if possible. If the block of | 1868 // the memory allocator's initial chunk) if possible. If the block of |
1880 // addresses is not big enough to contain a single page-aligned page, a | 1869 // addresses is not big enough to contain a single page-aligned page, a |
1881 // fresh chunk will be allocated. | 1870 // fresh chunk will be allocated. |
1882 bool SetUp(); | 1871 bool SetUp(); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2064 void EvictEvacuationCandidatesFromLinearAllocationArea(); | 2053 void EvictEvacuationCandidatesFromLinearAllocationArea(); |
2065 | 2054 |
2066 bool CanExpand(size_t size); | 2055 bool CanExpand(size_t size); |
2067 | 2056 |
2068 // Returns the number of total pages in this space. | 2057 // Returns the number of total pages in this space. |
2069 int CountTotalPages(); | 2058 int CountTotalPages(); |
2070 | 2059 |
2071 // Return size of allocatable area on a page in this space. | 2060 // Return size of allocatable area on a page in this space. |
2072 inline int AreaSize() { return area_size_; } | 2061 inline int AreaSize() { return area_size_; } |
2073 | 2062 |
2074 virtual bool is_local() { return false; } | |
2075 | |
2076 // Merges {other} into the current space. Note that this modifies {other}, | 2063 // Merges {other} into the current space. Note that this modifies {other}, |
2077 // e.g., removes its bump pointer area and resets statistics. | 2064 // e.g., removes its bump pointer area and resets statistics. |
2078 void MergeCompactionSpace(CompactionSpace* other); | 2065 void MergeCompactionSpace(CompactionSpace* other); |
2079 | 2066 |
2080 void DivideUponCompactionSpaces(CompactionSpaceCollection** other, int num, | 2067 void MoveOverFreeMemory(PagedSpace* other); |
2081 intptr_t limit = kCompactionMemoryWanted); | |
2082 | 2068 |
2083 // Refills the free list from the corresponding free list filled by the | 2069 virtual bool is_local() { return false; } |
2084 // sweeper. | |
2085 virtual void RefillFreeList(); | |
2086 | 2070 |
2087 protected: | 2071 protected: |
2088 void AddMemory(Address start, intptr_t size); | |
2089 | |
2090 FreeSpace* TryRemoveMemory(intptr_t size_in_bytes); | |
2091 | |
2092 void MoveOverFreeMemory(PagedSpace* other); | |
2093 | |
2094 // PagedSpaces that should be included in snapshots have different, i.e., | 2072 // PagedSpaces that should be included in snapshots have different, i.e., |
2095 // smaller, initial pages. | 2073 // smaller, initial pages. |
2096 virtual bool snapshotable() { return true; } | 2074 virtual bool snapshotable() { return true; } |
2097 | 2075 |
2098 FreeList* free_list() { return &free_list_; } | 2076 FreeList* free_list() { return &free_list_; } |
2099 | 2077 |
2100 bool HasPages() { return anchor_.next_page() != &anchor_; } | 2078 bool HasPages() { return anchor_.next_page() != &anchor_; } |
2101 | 2079 |
2102 // Cleans up the space, frees all pages in this space except those belonging | 2080 // Cleans up the space, frees all pages in this space except those belonging |
2103 // to the initial chunk, uncommits addresses in the initial chunk. | 2081 // to the initial chunk, uncommits addresses in the initial chunk. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2144 // The sweeper threads iterate over the list of pointer and data space pages | 2122 // The sweeper threads iterate over the list of pointer and data space pages |
2145 // and sweep these pages concurrently. They will stop sweeping after the | 2123 // and sweep these pages concurrently. They will stop sweeping after the |
2146 // end_of_unswept_pages_ page. | 2124 // end_of_unswept_pages_ page. |
2147 Page* end_of_unswept_pages_; | 2125 Page* end_of_unswept_pages_; |
2148 | 2126 |
2149 // Mutex guarding any concurrent access to the space. | 2127 // Mutex guarding any concurrent access to the space. |
2150 base::Mutex space_mutex_; | 2128 base::Mutex space_mutex_; |
2151 | 2129 |
2152 friend class MarkCompactCollector; | 2130 friend class MarkCompactCollector; |
2153 friend class PageIterator; | 2131 friend class PageIterator; |
2154 | |
2155 // Used in cctest. | |
2156 friend class HeapTester; | |
2157 }; | 2132 }; |
2158 | 2133 |
2159 | 2134 |
2160 class NumberAndSizeInfo BASE_EMBEDDED { | 2135 class NumberAndSizeInfo BASE_EMBEDDED { |
2161 public: | 2136 public: |
2162 NumberAndSizeInfo() : number_(0), bytes_(0) {} | 2137 NumberAndSizeInfo() : number_(0), bytes_(0) {} |
2163 | 2138 |
2164 int number() const { return number_; } | 2139 int number() const { return number_; } |
2165 void increment_number(int num) { number_ += num; } | 2140 void increment_number(int num) { number_ += num; } |
2166 | 2141 |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2824 public: | 2799 public: |
2825 CompactionSpace(Heap* heap, AllocationSpace id, Executability executable) | 2800 CompactionSpace(Heap* heap, AllocationSpace id, Executability executable) |
2826 : PagedSpace(heap, id, executable) {} | 2801 : PagedSpace(heap, id, executable) {} |
2827 | 2802 |
2828 // Adds external memory starting at {start} of {size_in_bytes} to the space. | 2803 // Adds external memory starting at {start} of {size_in_bytes} to the space. |
2829 void AddExternalMemory(Address start, int size_in_bytes) { | 2804 void AddExternalMemory(Address start, int size_in_bytes) { |
2830 IncreaseCapacity(size_in_bytes); | 2805 IncreaseCapacity(size_in_bytes); |
2831 Free(start, size_in_bytes); | 2806 Free(start, size_in_bytes); |
2832 } | 2807 } |
2833 | 2808 |
2834 virtual bool is_local() override { return true; } | 2809 virtual bool is_local() { return true; } |
2835 | |
2836 virtual void RefillFreeList() override; | |
2837 | 2810 |
2838 protected: | 2811 protected: |
2839 // The space is temporary and not included in any snapshots. | 2812 // The space is temporary and not included in any snapshots. |
2840 virtual bool snapshotable() override { return false; } | 2813 virtual bool snapshotable() { return false; } |
2841 }; | 2814 }; |
2842 | 2815 |
2843 | 2816 |
2844 // A collection of |CompactionSpace|s used by a single compaction task. | 2817 // A collection of |CompactionSpace|s used by a single compaction task. |
2845 class CompactionSpaceCollection : public Malloced { | 2818 class CompactionSpaceCollection : public Malloced { |
2846 public: | 2819 public: |
2847 explicit CompactionSpaceCollection(Heap* heap) | 2820 explicit CompactionSpaceCollection(Heap* heap) |
2848 : old_space_(heap, OLD_SPACE, Executability::NOT_EXECUTABLE), | 2821 : old_space_(heap, OLD_SPACE, Executability::NOT_EXECUTABLE), |
2849 code_space_(heap, CODE_SPACE, Executability::EXECUTABLE) {} | 2822 code_space_(heap, CODE_SPACE, Executability::EXECUTABLE) {} |
2850 | 2823 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3056 count = 0; | 3029 count = 0; |
3057 } | 3030 } |
3058 // Must be small, since an iteration is used for lookup. | 3031 // Must be small, since an iteration is used for lookup. |
3059 static const int kMaxComments = 64; | 3032 static const int kMaxComments = 64; |
3060 }; | 3033 }; |
3061 #endif | 3034 #endif |
3062 } // namespace internal | 3035 } // namespace internal |
3063 } // namespace v8 | 3036 } // namespace v8 |
3064 | 3037 |
3065 #endif // V8_HEAP_SPACES_H_ | 3038 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |